/* * Manually set the AI's community cards * ai: the pokerAI to update * community: the cards to give the AI * communitysize: the number of community cards in play */ void SetCommunity(PokerAI *ai, char **community, int communitysize) { ai->game.communitysize = communitysize; for (int i = 0; i < communitysize; i++) { ai->game.community[i] = StringToCard(community[i]); } }
CardsSet* MakeCardsSet(bp::object& o) { CardsSet* result = new CardsSet(); bp::stl_input_iterator<string> begin(o), end; for (auto it = begin; it != end; it++) { result->Add(StringToCard(*it)); } return result; }
/* * Manually set the AI's hand cards * ai: the pokerAI to update * hand: the cards to give the AI * handsize: the number of cards in the AI's hand */ void SetHand(PokerAI *ai, char **hand, int handsize) { ai->game.handsize = handsize; for (int i = 0; i < handsize; i++) { ai->game.hand[i] = StringToCard(hand[i]); } }
/* * Set the card array to the given JSON array * cards: the int array of where to place the results * json: a JSON array of card strings * return: the number of cards in the array */ int GetCardArray(int *cards, cJSON *json) { int i; for (i = 0; i < cJSON_GetArraySize(json); i++) { cards[i] = StringToCard( JSON_ARRAY_ELEM(json, i)->valuestring); } return cJSON_GetArraySize(json); }
void CommandLoop(int self_id) { Command cmd = GetCommand(); /* No switch for strings :( */ switch (cmd.type) { case CommandType_Reveal: assert(cmd.params.size() == 2); break; case CommandType_Out: assert(cmd.params.size() >= 1 && cmd.params.size() <= 3); if (std::stoi(cmd.params[0]) == self_id) { Debug() << "Oh noes, we lost!"; exit(0); } for (uint i = 1; i < cmd.params.size(); i++) { RemoveCardAllPlayers(StringToCard(cmd.params[i])); } break; case CommandType_Player: assert(cmd.params.size() == 1); if (std::stoi(cmd.params[0]) != self_id) break; MakeMove(self_id); break; case CommandType_Played: assert(cmd.params.size() >= 1 && cmd.params.size() <= 4); // Remove played card (cmd.params[1]) from possibilities break; case CommandType_Protected: assert(cmd.params.size() == 1); Debug() << "Dammit, didn't realise player " << cmd.params[0] << " was protected"; break; case CommandType_Swap: assert(cmd.params.size() == 1); break; case CommandType_Discard: assert(cmd.params.size() == 2); break; /* These commands shouldn't happen here. */ case CommandType_Ident: case CommandType_Players: case CommandType_Start: case CommandType_Draw: default: Debug() << "D: Unrecognised command! \"" << cmd.type << "\""; exit(1); } }
void SetGameStateRiver(GameState *game, stMsg_t stOneMsg) { if (stOneMsg.m_nRowNo < 1) { printf("ERROR wrong row number in flop msg! \n"); } game->communitysize = 5; game->your_turn = 0; game->phase_last = game->phase; game->phase = GetPhase("river"); game->call_no = 0; game->raise_no = 0; stMsgRow_t stMsgRow = *(stOneMsg.m_pstMsgRow[0]); char card[3] = {'\0'}; HoldCardMsgRowToChar3(card, stMsgRow.m_szWordRest[0], stMsgRow.m_szWordRest[1]); game->community[5-1] = StringToCard(card); }
// set game->hand[0] game->hand[1] void SetGameStateHold(GameState *game, stMsg_t stOneMsg) { if (stOneMsg.m_nRowNo < 2) { printf("ERROR wrong row number in hold msg! \n"); } game->handsize = 2; game->your_turn = 0; game->phase_last = game->phase; game->phase = GetPhase("deal"); game->call_no = 0; game->raise_no = 0; for (int i = 0; i < 2; ++i) { stMsgRow_t stMsgRow = *(stOneMsg.m_pstMsgRow[i]); char card[3] = {'\0'}; HoldCardMsgRowToChar3(card, stMsgRow.m_szWordRest[0], stMsgRow.m_szWordRest[1]); game->hand[i] = StringToCard(card); } }
void SetGameStateFlop(GameState *game, stMsg_t stOneMsg) { if (stOneMsg.m_nRowNo < 3) { printf("ERROR wrong row number in flop msg! \n"); } game->communitysize = 3; game->your_turn = 0; game->phase_last = game->phase; game->phase = GetPhase("flop"); game->call_no = 0; game->raise_no = 0; for (int i = 0; i < 3; ++i) { stMsgRow_t stMsgRow = *(stOneMsg.m_pstMsgRow[i]); char card[3] = {'\0'}; HoldCardMsgRowToChar3(card, stMsgRow.m_szWordRest[0], stMsgRow.m_szWordRest[1]); game->community[i] = StringToCard(card); } }
uint32_t GetCardBitWrap(const std::string& card) { return GetCardBit(StringToCard(card)); }
Card DoMove(float* /*moveValue*/) override { bp::object res = this->get_override("do_move")(); return StringToCard(bp::extract<string>(res)); }