My code for Pair, 2 pair etc work, except when I code for a straight hand
When I separate the sort function like below I can get it...
Expand|Select|Wrap|Line Numbers
- public void straight()
- {
- int locations[] = new int[ 5 ], z = 0;
- for ( int y = 0; y < numbers.length; y++ )
- if ( numbers[ y ] == 1 )
- locations[ z++ ] = y;
- bubbleSort( locations );
- int faceValue = locations[ 0 ];
- for ( int m = 1; m < locations.length; m++ ) {
- if ( faceValue != locations[ m ] - 1 )
- return; // not a straight
- else
- faceValue = locations[ m ];
- }
- output += "Straight ";
- status.setText( output );
- }
- // sort hand in ascending order
- private void bubbleSort( int values[] )
- {
- for ( int pass = 1; pass < values.length; pass++ )
- for ( int comp = 0; comp < values.length - 1; comp++ )
- if ( values[ comp ] > values[ comp + 1 ] ) {
- int temp = values[ comp ];
- values[ comp ] = values[ comp + 1 ];
- values[ comp + 1 ] = values[ comp ];
- }
- }
Expand|Select|Wrap|Line Numbers
- public void straight( Card hand[] )
- {
- int locations[] = new int[ 5 ];
- int z = 0;
- int numbers[] = totalHand( hand );
- for ( int y = 0; y < numbers.length; y++ )
- {
- if ( numbers[ y ] == 1 )
- locations[ z++ ] = y;
- } // end for
- int faceValue = locations[ 0 ];
- if ( faceValue == 0 ) // special case, faceValue is Ace
- {
- faceValue = 13;
- for ( int m = locations.length - 1; m >= 1; m-- )
- {
- if ( faceValue != locations[ m ] + 1 )
- return; // not a straight
- else
- faceValue = locations[ m ];
- } // end if
- } // end if
- else
- {
- for ( int m = 1; m < locations.length; m++ )
- {
- if ( faceValue != locations[ m ] - 1 )
- return; // not a straight
- else
- faceValue = locations[ m ];
- } // end if
- } // end else
- System.out.println( "Straight" );
- } // end method straight