src/main/java/pokerai/game/eval/indiana/HandEvaluator.c
long value(int x1, int x2, int x3, int x4, int x5) {
    int z0 = div4[x1], z1 = div4[x2], z2 = div4[x3], z3 = div4[x4], z4 = div4[x5];
    int c0 = mod4[x1], c1 = mod4[x2], c2 = mod4[x3], c3 = mod4[x4], c4 = mod4[x5];
    boolean flush = (c0 == c1 && c1 == c2 && c2 == c3 && c3 == c4);

    // Num of diff cards
    int diff = 0;
    if (z0 != z1) diff++; if (z1 != z2) diff++; if (z2 != z3) diff++; if (z3 != z4) diff++;

    boolean straight = false;
    //straight = (z4 == z0-4 && z1 == z0-1 && z2 == z1-1 && z3 == z2-1); // detect A straight?
    if (diff == 4) {
      if (z4 == z0 - 4) straight = true;
        else if (z0 == 12 && z1 == 3) straight = true;  // A 5 4 3 2
    }

    // 1. royal flush, 2. straight flush
    if (straight && flush) {
      return 10000000 + z0; // only highest card matters, rest are the same
    }

    // 3. four of a kind
    if (diff == 1 && z1 == z2 && z2 == z3) {
        if (z0 != z1) return 8000000 + mult[5][z1] + z0;
           else return 8000000 + mult[5][z1] + z4;
    }

    // 4. full hause
    if (diff == 1) {
      if (z0 == z2) { // aaabb
        return 7000000 + mult[5][z2] + z4;
      } else {
        return 7000000 + mult[5][z2] + z0;
      }
    }

    // 5. Flush
    if (flush) {
      return 6000000 + mult[5][z0] + mult[4][z1] + mult[3][z2] + mult[2][z3] + mult[1][z4];     // all card matters
    }

    // 6. Straight
    if (straight) {
      if (z0 == 12 && z1 == 3) return 5000000 + z1; // this is 5-high straight A 5 4 3 2
      return 5000000 + z0; // Only the highest card matters, rest are ignored
    }

    // 7. Three of a kind
    if (diff == 2) {
      // aaabc, abbbc, abccc
      if (z2 == z0) return 4000000 + mult[5][z2] + mult[2][z3] + z4;
      if (z2 == z4) return 4000000 + mult[5][z2] + mult[2][z0] + z1;
      if (z1 == z3) return 4000000 + mult[5][z2] + mult[2][z0] + z4;
    }

    // 8. Two pairs
    if (diff == 2) {
      // aabbc, aabcc, abbcc
      if (z0 == z1) {
        if (z2 == z3) return 3000000 + mult[5][z0] + mult[3][z2];
        if (z3 == z4) return 3000000 + mult[5][z0] + mult[3][z3];
      }
      if (z1 == z2 && z3 == z4) return 3000000 + mult[5][z1] + mult[3][z3];
    }

   // 9. One pair
    if (diff == 3) {
      // aabcd, baacd, bcaad, bcdaa
      if (z0 == z1) return 2000000 + mult[5][z0] + mult[3][z2] + mult[2][z3] + mult[1][z4];
      if (z1 == z2) return 2000000 + mult[5][z1] + mult[3][z0] + mult[2][z3] + mult[1][z4];
      if (z2 == z3) return 2000000 + mult[5][z2] + mult[3][z0] + mult[2][z1] + mult[1][z4];
      if (z3 == z4) return 2000000 + mult[5][z3] + mult[3][z0] + mult[2][z1] + mult[1][z2];
    }

    // 10. High card
    return mult[5][z0] + mult[4][z1] + mult[3][z2] + mult[2][z3] + mult[1][z4];   // all card matters
  }
// calculate the value of a hand according all rules
// cards that are given as input here should be sorted in desceding order!
calculate the value of a hand according all rules
cards that are given as input here should be sorted in desceding order!
calculate the value of a hand according all rules cards that are given as input here should be sorted in desceding order!
long value(int x1, int x2, int x3, int x4, int x5) {
    int z0 = div4[x1], z1 = div4[x2], z2 = div4[x3], z3 = div4[x4], z4 = div4[x5];
    int c0 = mod4[x1], c1 = mod4[x2], c2 = mod4[x3], c3 = mod4[x4], c4 = mod4[x5];
    boolean flush = (c0 == c1 && c1 == c2 && c2 == c3 && c3 == c4);
    int diff = 0;
    if (z0 != z1) diff++; if (z1 != z2) diff++; if (z2 != z3) diff++; if (z3 != z4) diff++;
    boolean straight = false;
    if (diff == 4) {
      if (z4 == z0 - 4) straight = true;
        else if (z0 == 12 && z1 == 3) straight = true;  
    }
    if (straight && flush) {
      return 10000000 + z0; 
    }
    if (diff == 1 && z1 == z2 && z2 == z3) {
        if (z0 != z1) return 8000000 + mult[5][z1] + z0;
           else return 8000000 + mult[5][z1] + z4;
    }
    if (diff == 1) {
      if (z0 == z2) { 
        return 7000000 + mult[5][z2] + z4;
      } else {
        return 7000000 + mult[5][z2] + z0;
      }
    }
    if (flush) {
      return 6000000 + mult[5][z0] + mult[4][z1] + mult[3][z2] + mult[2][z3] + mult[1][z4];     
    }
    if (straight) {
      if (z0 == 12 && z1 == 3) return 5000000 + z1; 
      return 5000000 + z0; 
    }
    if (diff == 2) {
      if (z2 == z0) return 4000000 + mult[5][z2] + mult[2][z3] + z4;
      if (z2 == z4) return 4000000 + mult[5][z2] + mult[2][z0] + z1;
      if (z1 == z3) return 4000000 + mult[5][z2] + mult[2][z0] + z4;
    }
    if (diff == 2) {
      if (z0 == z1) {
        if (z2 == z3) return 3000000 + mult[5][z0] + mult[3][z2];
        if (z3 == z4) return 3000000 + mult[5][z0] + mult[3][z3];
      }
      if (z1 == z2 && z3 == z4) return 3000000 + mult[5][z1] + mult[3][z3];
    }
    if (diff == 3) {
      if (z0 == z1) return 2000000 + mult[5][z0] + mult[3][z2] + mult[2][z3] + mult[1][z4];
      if (z1 == z2) return 2000000 + mult[5][z1] + mult[3][z0] + mult[2][z3] + mult[1][z4];
      if (z2 == z3) return 2000000 + mult[5][z2] + mult[3][z0] + mult[2][z1] + mult[1][z4];
      if (z3 == z4) return 2000000 + mult[5][z3] + mult[3][z0] + mult[2][z1] + mult[1][z2];
    }
    return mult[5][z0] + mult[4][z1] + mult[3][z2] + mult[2][z3] + mult[1][z4];   
  }
long value ( int x1 , int x2 , int x3 , int x4 , int x5 ) { int z0 = div4 [ x1 ] , z1 = div4 [ x2 ] , z2 = div4 [ x3 ] , z3 = div4 [ x4 ] , z4 = div4 [ x5 ] ; int c0 = mod4 [ x1 ] , c1 = mod4 [ x2 ] , c2 = mod4 [ x3 ] , c3 = mod4 [ x4 ] , c4 = mod4 [ x5 ] ; boolean flush = ( c0 == c1 && c1 == c2 && c2 == c3 && c3 == c4 ) ; int diff = 0 ; if ( z0 != z1 ) diff ++ ; if ( z1 != z2 ) diff ++ ; if ( z2 != z3 ) diff ++ ; if ( z3 != z4 ) diff ++ ; boolean straight = false ; if ( diff == 4 ) { if ( z4 == z0 - 4 ) straight = true ; else if ( z0 == 12 && z1 == 3 ) straight = true ; } if ( straight && flush ) { return 10000000 + z0 ; } if ( diff == 1 && z1 == z2 && z2 == z3 ) { if ( z0 != z1 ) return 8000000 + mult [ 5 ] [ z1 ] + z0 ; else return 8000000 + mult [ 5 ] [ z1 ] + z4 ; } if ( diff == 1 ) { if ( z0 == z2 ) { return 7000000 + mult [ 5 ] [ z2 ] + z4 ; } else { return 7000000 + mult [ 5 ] [ z2 ] + z0 ; } } if ( flush ) { return 6000000 + mult [ 5 ] [ z0 ] + mult [ 4 ] [ z1 ] + mult [ 3 ] [ z2 ] + mult [ 2 ] [ z3 ] + mult [ 1 ] [ z4 ] ; } if ( straight ) { if ( z0 == 12 && z1 == 3 ) return 5000000 + z1 ; return 5000000 + z0 ; } if ( diff == 2 ) { if ( z2 == z0 ) return 4000000 + mult [ 5 ] [ z2 ] + mult [ 2 ] [ z3 ] + z4 ; if ( z2 == z4 ) return 4000000 + mult [ 5 ] [ z2 ] + mult [ 2 ] [ z0 ] + z1 ; if ( z1 == z3 ) return 4000000 + mult [ 5 ] [ z2 ] + mult [ 2 ] [ z0 ] + z4 ; } if ( diff == 2 ) { if ( z0 == z1 ) { if ( z2 == z3 ) return 3000000 + mult [ 5 ] [ z0 ] + mult [ 3 ] [ z2 ] ; if ( z3 == z4 ) return 3000000 + mult [ 5 ] [ z0 ] + mult [ 3 ] [ z3 ] ; } if ( z1 == z2 && z3 == z4 ) return 3000000 + mult [ 5 ] [ z1 ] + mult [ 3 ] [ z3 ] ; } if ( diff == 3 ) { if ( z0 == z1 ) return 2000000 + mult [ 5 ] [ z0 ] + mult [ 3 ] [ z2 ] + mult [ 2 ] [ z3 ] + mult [ 1 ] [ z4 ] ; if ( z1 == z2 ) return 2000000 + mult [ 5 ] [ z1 ] + mult [ 3 ] [ z0 ] + mult [ 2 ] [ z3 ] + mult [ 1 ] [ z4 ] ; if ( z2 == z3 ) return 2000000 + mult [ 5 ] [ z2 ] + mult [ 3 ] [ z0 ] + mult [ 2 ] [ z1 ] + mult [ 1 ] [ z4 ] ; if ( z3 == z4 ) return 2000000 + mult [ 5 ] [ z3 ] + mult [ 3 ] [ z0 ] + mult [ 2 ] [ z1 ] + mult [ 1 ] [ z2 ] ; } return mult [ 5 ] [ z0 ] + mult [ 4 ] [ z1 ] + mult [ 3 ] [ z2 ] + mult [ 2 ] [ z3 ] + mult [ 1 ] [ z4 ] ; }
calculate the value of a hand according all rules
cards that are given as input here should be sorted in desceding order!
calculate the value of a hand according all rules cards that are given as input here should be sorted in desceding order!
// Num of diff cards //straight = (z4 == z0-4 && z1 == z0-1 && z2 == z1-1 && z3 == z2-1); // detect A straight? // A 5 4 3 2 // 1. royal flush, 2. straight flush // only highest card matters, rest are the same // 3. four of a kind // 4. full hause // aaabb // 5. Flush // all card matters // 6. Straight // this is 5-high straight A 5 4 3 2 // Only the highest card matters, rest are ignored // 7. Three of a kind // aaabc, abbbc, abccc // 8. Two pairs // aabbc, aabcc, abbcc // 9. One pair // aabcd, baacd, bcaad, bcdaa // 10. High card // all card matters