Ejemplo n.º 1
0
float score_cards(std::vector<std::string> cards_str) {
    std::vector<int> cards;
    for(int i=0; i<cards_str.size(); i++) { // convert cards to integers
        cards.push_back( card2int(cards_str[i]) );
    }

    int rank = 0;
    SevenEval const eval7;
    FiveEval  const eval5;
    switch ( cards.size() ) {
        case 2: rank=score_2_cards(cards[0],cards[1]); break;
        case 5: rank=eval5.GetRank(cards[0],cards[1],cards[2],cards[3],cards[4]); break;
        case 6: 
                for(int i=0; i<6; i++) {
                    std::vector<int> cpy = cards;
                    cpy.erase(cpy.begin() + i );

                    int new_rank = eval5.GetRank(cpy[0],cpy[1],cpy[2],cpy[3],cpy[4]);
                    rank = rank < new_rank ? new_rank : rank;
                }
                break;
        case 7: rank=eval7.GetRank(cards[0],cards[1],cards[2],cards[3],cards[4],cards[5],cards[6]); break;
        default: rank=0;
    }

    return (rank/100);
}
Ejemplo n.º 2
0
TEST(SevenEval, Regression) {
  FiveEval const five_eval;
  SevenEval const seven_eval;
  for (int i=0; i<46; ++i) {
    for (int j=i+1; j<47; ++j) {
      for (int k=j+1; k<48; ++k) {
        for (int l=k+1; l<49; ++l) {
          for (int m=l+1; m<50; ++m) {
            for (int n=m+1; n<51; ++n) {
              for (int p=n+1; p<52; ++p) {
                int const five_rank = five_eval.GetRank(i, j, k, l, m, n, p);
                int const seven_rank = seven_eval.GetRank(i, j, k, l, m, n, p);
                ASSERT_EQ(five_rank, seven_rank) << "Ranks at "
                                                 << i << ", "
                                                 << j << ", "
                                                 << k << ", "
                                                 << l << ", "
                                                 << m << ", "
                                                 << n << ", "
                                                 << p
                                                 << " differ.";
              }
            }
          }
        }
      }
    }
  }
}
Ejemplo n.º 3
0
static inline PyObject* specialeval_get_score(PyObject* self, PyObject* args)
{
  short cards[MAX_CARDS_IN];
  short numCards = 7;

  fill_n(cards, MAX_CARDS_IN, -1);

  if(PyArg_ParseTuple(args, "iiiii|ii", &cards[0], &cards[1], &cards[2], 
     &cards[3], &cards[4], &cards[5], &cards[6]))
  {
    for(short i=0; i<MAX_CARDS_IN; i++)
    {
      if(cards[i] <= 0)
      {
        numCards = i; 
        break;
      }
      else
        cards[i]--; // python offsets them by one so we can see the end of our arguments easier
    }
  }
  else
    return NULL;

  short* deck = createDeck(cards, numCards); 
  unsigned short count=0;
  unsigned int sum=0;
  unsigned int ours=0;
  static const FiveEval eval5;
  static const SevenEval eval7;
    

  if(numCards == 5)
  {
    // get hand score possibilities for them and sum them
    for(short i=0; i<NUM_CARDS_IN_DECK-numCards; i++)
    {
      for(short j=0; j<i; j++)
      {
        sum += eval5.GetRank(cards[0], cards[1], cards[2], deck[i], deck[j]);
        count++;
      }
    }

    ours = eval5.GetRank(cards[0], cards[1], cards[2], cards[3], cards[4]);
  }
  else if(numCards == 6)
  {
    unsigned int oursnum = 0;
    // this isn't officially supported... emulate it by guessing the final card too
    for(short i=0; i<NUM_CARDS_IN_DECK-numCards; i++)
    {
      for(short j=0; j<i; j++)
      {
        for(short k=0; k<j; k++)
        {
          sum += eval7.GetRank(cards[0], cards[1], cards[2], cards[3], 
              deck[i], deck[j], deck[k]);
          count++;
        }
        ours += eval7.GetRank(cards[0], cards[1], cards[2], cards[3], cards[4], deck[i], deck[j]);
        oursnum++;
      }
    }

    ours /= oursnum;
  }
  else
  {
    // get hand score possibilities for them and sum them
    for(short i=0; i<NUM_CARDS_IN_DECK-numCards; i++)
    {
      for(short j=0; j<i; j++)
      {
        sum += eval7.GetRank(cards[0], cards[1], cards[2], cards[3], cards[4], 
            deck[i], deck[j]);
        count++;
      }
    }

      ours = eval7.GetRank(cards[0], cards[1], cards[2], cards[3], cards[4], 
          cards[5], cards[6]);
  }

  delete[] deck;
  return Py_BuildValue("i",  sum/count - ours + 1);
}