Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VI convert_to_hand(int n){
- VI hand(21);
- int C0 = n % 52;
- int suit0 = C0 % 4;
- int rank0 = (C0 - suit0)/4;
- //cout << "Card 0 has rank: " << rank0 << " and suit: " << suit0 << endl;
- hand[rank0]++;
- int C1 = n/52 % 52;
- int suit1 = C1 % 4;
- int rank1 = (C1 - suit1)/4;
- //cout << "Card 1 has rank: " << rank1 << " and suit: " << suit1 << endl;
- hand[rank1]++;
- int C2 = (int)(n/pow(52, 2)) % 52;
- int suit2 = C2 % 4;
- int rank2 = (C2 - suit2)/4;
- //cout << "Card 2 has rank: " << rank2 << " and suit: " << suit2 << endl;
- hand[rank2]++;
- int C3 = (int)(n/pow(52,3)) % 52;
- int suit3 = C3 % 4;
- int rank3 = (C3- suit3)/4;
- //cout << "Card 3 has rank: " << rank3 << " and suit: " << suit3 << endl;
- hand[rank3]++;
- int C4 = (int)(n/(pow(52,4))) % 52;
- int suit4 = C4 % 4;
- int rank4 = (C4 - suit4)/4;
- //cout << "Card 4 has rank: " << rank4 << " and suit: " << suit4 << endl;
- hand[rank4]++;
- get_nonzero_indicies(hand);
- if (hand[NUM_UNIQUE]!= 5){
- //cout << "Hand has repeated cards." << endl;
- print(hand);
- return hand;
- } else {
- if(suit0 == suit1 && suit1 == suit2 && suit2 == suit3 && suit3 == suit4){
- //cout << "Hand is a flush." << endl;
- hand[INDEX_FLUSH] = 1;
- }
- if(hand[0] == 1 && hand[1] == 1 && hand[2] == 1 && hand[3] == 1 && hand[12] == 1){
- //cout << "Hand is a straight." << endl;
- hand[INDEX_STRAIGHT] = 1;
- print(hand);
- return hand;
- }
- for (int i = RANK_FIRSTCARD; i < RANK_FIFTHCARD; i++){
- //cout << "First card rank: " << hand[i] << " Second card rank: " << hand[i+1] << endl;
- if (hand[i+1] - hand[i] != 1) {
- //cout << "Hand is not a straight." << endl;
- print(hand);
- return hand;
- }
- }
- //cout << "Hand is a straight." << endl;
- //hand[INDEX_STRAIGHT] = 1;
- print(hand);
- return hand;
- }
- }
- int eval(VI& hand) {
- int coeff;
- int exp;
- int res = INT_MAX;
- for (int i = 0; i < 13; i++) {
- coeff = (int)(pow(13 - i, 2));
- exp = 8 - (hand[i]*2 - 1 + 3 * hand[INDEX_STRAIGHT] + 4 * hand[INDEX_FLUSH]);
- if (exp <= 8) {
- cout << "For index i: coeff is " << coeff << " and exp is " << exp << endl;
- res -= coeff * (int)(pow(9, exp));
- }
- }
- return res;
- }
Add Comment
Please, Sign In to add comment