Beispiel #1
0
/*
 * Set the game state according to the given JSON
 * game: the game state to set
 * json: a JSON representation of the game state
 */
void SetGameState(GameState *game, cJSON *json)
{
    game->round_id = JSON_INT(json, "round_id");
    game->initial_stack = JSON_INT(json, "initial_stack");
    game->stack = JSON_INT(json, "stack");
    game->current_bet = JSON_INT(json, "current_bet");
    game->call_amount = JSON_INT(json, "call_amount");
    game->phase = GetPhase(JSON_STRING(json, "betting_phase"));
    game->your_turn = JSON_INT(json, "your_turn");

    //Set the AI's list of opponents
    SetGameOpponents(game, JSON(json, "players_at_table"));

    //Update the current pot
    game->current_pot = game->current_bet;
    for (int i = 0; i < game->num_opponents; i++)
    {
        game->current_pot += game->opponents[i].current_bet;
    }

    //Set the AI's hand and the community cards
    game->handsize = GetCardArray(game->hand, JSON(json, "hand"));
    game->communitysize = GetCardArray(game->community, JSON(json, "community_cards"));

    UpdateGameDeck(game);
}
Beispiel #2
0
int main(int argc, char **argv)
{
    char *handranksfile = DEFAULT_HANDRANKS_FILE;
    char *hand[NUM_HAND];
    char *community[NUM_COMMUNITY];
    char *last_arg;
    int num_community = argc - 3;
    int num_playing = DEFAULT_NUM_PLAYING;
    int simulated;
    double winprob;
    PokerAI *AI;

    InitEvaluator(handranksfile);

    if (argc < 3)
    {
        fprintf(stderr, "Usage: ./winprob hand1 hand2 [comm1, .. , comm5] [-nx]\n");
        fprintf(stderr, "\tWhere x is the number of opponents (3 by default)\n");
        exit(1);
    }

    for (int i = 0; i < NUM_HAND; i++)
    {
        hand[i] = argv[i + 1];
    }

    for (int i = 0; i < num_community - 1; i++)
    {
        community[i] = argv[NUM_HAND + i + 1];
    }

    //Check if the last card is a community card
    //or a specifier of the number of players
    last_arg = argv[NUM_HAND + num_community];
    if (!strncmp(last_arg, "-n", strlen("-n")))
    {
        num_playing = atoi(last_arg + strlen("-n"));
        num_community--;
    }
    else
    {
        community[num_community - 1] = last_arg;
    }

    AI = CreatePokerAI(TIMEOUT);
    SetHand(AI, hand, NUM_HAND);
    SetCommunity(AI, community, num_community);
    UpdateGameDeck(&AI->game);
    AI->game.num_playing = num_playing;
    winprob = GetWinProbability(AI);
    simulated = AI->games_simulated;

    printf("Win probability: %.2lf%%\n", winprob * 100);
    printf("Games simulated: %dk\n", simulated / 1000);

    //Clean up resources
    DestroyPokerAI(AI);
    return 0;
}
/*
 * Set the game state according to the given JSON
 * game: the game state to set
 * json: a JSON representation of the game state
 */
void SetGameState(GameState *game, stMsg_t stOneMsg)
{
	if (0 == strcasecmp(stOneMsg.m_szType, "seat")){
		SetGameStateRoundStart(game, stOneMsg);
	} else if (0 == strcasecmp(stOneMsg.m_szType, "hold")) {
		SetGameStateHold(game, stOneMsg);
	} else if (0 == strcasecmp(stOneMsg.m_szType, "flop")) {
		SetGameStateFlop(game, stOneMsg);
	} else if (0 == strcasecmp(stOneMsg.m_szType, "turn")) {
		SetGameStateTurn(game, stOneMsg);
	} else if (0 == strcasecmp(stOneMsg.m_szType, "river")) {
		SetGameStateRiver(game, stOneMsg);
	} else if (0 == strcasecmp(stOneMsg.m_szType, "inquire")) {
		SetGameStateInquire(game, stOneMsg);
	} else if (0 == strcasecmp(stOneMsg.m_szType, "blind")) {
		SetGameStateBlind(game, stOneMsg);
	} else {
		;
	}
	UpdateGameDeck(game);    
}