muffinman1015

pokersort hand_convert and reencoding

Dec 9th, 2019
772
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.50 KB | None | 0 0
  1. VI convert_to_hand(int n){
  2.     VI hand(21);
  3.     int C0 = n % 52;
  4.     int suit0 = C0 % 4;
  5.     int rank0 = (C0 - suit0)/4;
  6.     //cout << "Card 0 has rank: " << rank0 << " and suit: " << suit0 << endl;
  7.     hand[rank0]++;
  8.  
  9.     int C1 =  n/52 % 52;
  10.     int suit1 = C1 % 4;
  11.     int rank1 = (C1 - suit1)/4;
  12.     //cout << "Card 1 has rank: " << rank1 << " and suit: " << suit1 << endl;
  13.     hand[rank1]++;
  14.  
  15.     int C2 =  (int)(n/pow(52, 2)) % 52;
  16.     int suit2 = C2 % 4;
  17.     int rank2 = (C2 - suit2)/4;
  18.     //cout << "Card 2 has rank: " << rank2 << " and suit: " << suit2 << endl;
  19.     hand[rank2]++;
  20.  
  21.     int C3 =  (int)(n/pow(52,3)) % 52;
  22.     int suit3 = C3 % 4;
  23.     int rank3 = (C3- suit3)/4;
  24.     //cout << "Card 3 has rank: " << rank3 << " and suit: " << suit3 << endl;
  25.     hand[rank3]++;
  26.  
  27.     int C4 =  (int)(n/(pow(52,4))) % 52;
  28.     int suit4 = C4 % 4;
  29.     int rank4 = (C4 - suit4)/4;
  30.     //cout << "Card 4 has rank: " << rank4 << " and suit: " << suit4 << endl;
  31.     hand[rank4]++;
  32.  
  33.     get_nonzero_indicies(hand);
  34.     if (hand[NUM_UNIQUE]!= 5){
  35.         //cout << "Hand has repeated cards." << endl;
  36.         print(hand);
  37.         return hand;
  38.     } else {
  39.         if(suit0 == suit1 && suit1 == suit2 && suit2 == suit3 && suit3 == suit4){
  40.             //cout << "Hand is a flush." << endl;
  41.             hand[INDEX_FLUSH] = 1;
  42.         }
  43.         if(hand[0] == 1 && hand[1] == 1 && hand[2] == 1 && hand[3] == 1 && hand[12] == 1){
  44.             //cout << "Hand is a straight." << endl;
  45.             hand[INDEX_STRAIGHT] = 1;
  46.             print(hand);
  47.             return hand;
  48.         }
  49.         for (int i = RANK_FIRSTCARD; i < RANK_FIFTHCARD; i++){
  50.             //cout << "First card rank: " << hand[i] << "    Second card rank: " << hand[i+1] << endl;
  51.             if (hand[i+1] - hand[i] != 1) {
  52.                 //cout << "Hand is not a straight." << endl;
  53.                 print(hand);
  54.                 return hand;
  55.             }
  56.         }
  57.         //cout << "Hand is a straight." << endl;
  58.         //hand[INDEX_STRAIGHT] = 1;
  59.         print(hand);
  60.         return hand;
  61.     }
  62. }
  63.  
  64. int eval(VI& hand) {
  65.     int coeff;
  66.     int exp;
  67.     int res = INT_MAX;
  68.     for (int i = 0; i < 13; i++) {
  69.         coeff = (int)(pow(13 - i, 2));
  70.         exp = 8 - (hand[i]*2 - 1 + 3 * hand[INDEX_STRAIGHT] + 4 * hand[INDEX_FLUSH]);
  71.         if (exp <= 8) {
  72.             cout << "For index i: coeff is " << coeff << " and exp is " << exp << endl;
  73.             res -= coeff * (int)(pow(9, exp));
  74.         }
  75.     }
  76.     return res;
  77. }
Add Comment
Please, Sign In to add comment