Wednesday, 15 August 2012

java - Sorting a hand of poker -


I'm trying to hand over one hand of poker based on their rank and suit, but it's still completely Note that the suit has been sorted but not ranked

My hand before:

1: King of Hearts 2: Four Diamonds 3: Seven of the clubs: King of the Club 5: 6 of the three: 6 of diamonds: Two of the clubs: 8 King of Diamonds 9: Four Spread 10: Diamonds Three:

After R:

1: Fours of four: King of Hearts 3: Three Heart 4: Two Clubs 5: King's Club 6: King of Seven: 7 of 7: King of Diamonds 8: Diamond five 9: four diamonds 10: three diamonds

card object

  compare public int (card which) {if (this.suit.ordinal () & Gt; that.suit.ordinal ()) {return1; } If (this.suit.ordinal () & lt; that.suit.ordinal ()) {return -1; } Int rank 1 = (this.rank.ordinal () + 11)% 13; // A & gt; K into rank 2 = (rank .cordinal (+ 11)% 13; If (rank 1 & ranks2) returns 1; If (rank 1 and lieutenant; rank 2) returns -1; Return 0; }  

Player object

  public void tryTest () {card temp = new card (); (At i = 0; i & lt; countcard; i ++) {for (int j = 0; j and lieutenant; cowg card; j ++) {if (player hand [i] com. Compere to (player hund [Ja])> 0) {temp = this .playerHand [ja]; This.playerHand [j] = this.playerHand [i]; This.playerHand [i] = temp; AEEE, two, three, four, five, six, seven, eight, nine, ten, jack, rhine, rank of honor  
 , king;  

Enum suite

  Diamond, club, hearts, spades;  

In some standards, see which code you have now with everything Comparisons, and then swaps them if one is larger than the other, although it can move you backwards:

1, 2

2> 1 Therefore Swap

2,1

The nearest algorithm will be the sort of bubble sort, which uses slightly different indexes: (i-1; J ++) {if ( Player Hands [J.] Compere (player hand [J + 1]) Gt; 0) {temp = this.playerHand [j + 1]; this. Player [and 1] = this. Player [and] [j]; This .playerHand [j] = temp; }}}


No comments:

Post a Comment