2015华为软赛(六)——拓展功能函数

点滴记录总结,一天一打鸡血。

2015年5月华为组织了一次软件精英挑战赛,赛题是德州扑克手牌AI~

环境及测试说明:http://pan.baidu.com/s/1dD2dL0P

拓展有点炫富的嫌疑,“复杂”会好点么, 好土,吧。

先说说有哪些信息要收集,比如玩家数players、筹码数jetton、盲注blind、跟注call、跟注总数total_call、每圈投资数gameJetton,以及简单对手模型。
上一节基本的信息收集后就可以开始打牌了,这意味着自己只能看到牌,其他一无所知。这一节会丰富一下信息,也算是个提高了。

把这些信息的更新全部放在void UpdateGameInfo (const char *buffer);中,定义如下:

void    UpdateGameInfo (const char *buffer) {
    char data[DATA_SIZE] = {0};
    const char *recv = NULL;
    int pos  = 0;
    int cardValue;
    int cardType;
    int i;
    if ((recv = strstr(buffer, "seat/ \n")) != NULL) {
        InitMyData();

        i = 0;//count players messages;
        while ((recv = strstr(recv, " \n")) != NULL) {
            if (*(recv+2) != '/')
                i++;
            else    
                break;
            recv = recv + 2;
        }
        //set players
        gameInfo.players = i;

        if ((recv = strstr(buffer, reg_id)) != NULL) {  
            //set jetton
            memset(data, '\0', DATA_SIZE);
            pos = 0;
            recv = recv + strlen(reg_id) + 1;
            while (*(recv+pos) != ' ')
                pos++;
            strncpy(data, recv, pos);
            gameInfo.jetton = atoi(data);
        }
        //set blind     
        if ((recv = strstr(buffer, "small")) != NULL) { 
            memset(gameInfo.s_blind, '\0', DATA_SIZE);
            pos = 0;
            recv = recv + 13;
            while (*(recv+pos) != ' ')
                pos++;
            strncpy(gameInfo.s_blind, recv, pos);
        }
        if ((recv = strstr(buffer, "big")) != NULL) {   
            memset(gameInfo.b_blind, '\0', DATA_SIZE);
            pos = 0;
            recv = recv + 11;
            while (*(recv+pos) != ' ')
                pos++;
            strncpy(gameInfo.b_blind, recv, pos);
        }
    }
    if ((recv = strstr(buffer, "hold/ \n")) != NULL) {
        UpdateCards(recv, HOLD);
    }
    if ((recv = strstr(buffer, "inquire/ \n")) != NULL) {
        int players;
        int temp;

        //set after my turn players
        gameInfo.left = 0;
        if (game_circle > HOLD) {
            int left_player = 0;
            recv = strstr(buffer, gameInfo.b_blind) ;
            while ((recv = strstr(recv, " \n")) != NULL) {
                if (*(recv+2) == 't') {
                    gameInfo.left = left_player;
                    break;
                }
                else {
                    if (*(recv-3) != 'o')
                        left_player++;
                }
                recv = recv + 2;
            }

        }

        //set folds
        recv = buffer;
        gameInfo.folds = 0;
        while ((recv = strstr(recv, "fold")) != NULL) {
            recv = recv + 4;
            gameInfo.folds++;
        }

        //set jetton
        if ((recv = strstr(buffer, reg_id)) != NULL) {  
            memset(data, '\0', DATA_SIZE);
            pos = 0;
            recv = recv + strlen(reg_id) + 1;
            while (*(recv+pos) != ' ')
                pos++;
            strncpy(data, recv, pos);
            gameInfo.jetton = atoi(data);
        }

        //set call
        recv = strstr(buffer, "inquire/"); 
        recv = recv + 10;
        while ((recv = strstr(recv, " \n")) != NULL) {
            if (*(recv-1) == 'd' && *(recv-2) == 'l')
                recv = recv + 2;
            else
                break;
        }
        memset(data, '\0', DATA_SIZE);
        recv = recv - 1;
        pos = 0;
        while (*(recv-pos) != ' ')
            pos++;
        recv = recv - pos - 1;
        pos = 0;
        while (*(recv-pos) != ' ')
            pos++;
        strncpy(data, recv-pos+1, pos);
        gameInfo.call = atoi(data);
        gameInfo.total_call = gameInfo.call;

        if ((recv = strstr(buffer, reg_id)) != NULL) {
            memset(data, '\0', DATA_SIZE);
            pos = 0;
            recv = recv + strlen(reg_id) + 1;
            i=0;
            while (i != 3) {
                if (*(recv + pos) == ' ') {
                i++;
                    if (i == 3)
                        break;
                    recv = recv + pos;
                    pos = 0;
                }   
                pos++;
            }
            recv = recv + 1;
            strncpy(data, recv, pos-1);
            gameInfo.call -= atoi(data);
        }   
        //set opponent
        if (game_circle ==  HOLD) {
            int small = strcmp(gameInfo.s_blind, reg_id);
            int big = strcmp(gameInfo.b_blind, reg_id);
            if (small != 0 && big != 0 && gameInfo.total_call > 500) {
                char my_call[20];
                memset(data, '\0', DATA_SIZE);
                sprintf(data, "%d", gameInfo.total_call);
                memset(my_call, '\0', 20);

                strcpy(my_call, "raise ");
                strcat(my_call, data);

                if ((recv = strstr(buffer, my_call)) != NULL) {
                    pos = 0;
                    while (*(recv-pos) != '\n')
                        pos--;
                    recv = recv - pos + 1;
                    pos = 0;
                    while (*(recv + pos) != ' ')
                        pos++;
                    memset(data, '\0', DATA_SIZE);
                    strncpy(data, recv, pos);
                    strcpy(opponent.bigid, data);
                }

            }
        }
        if (intimidate == HOLD && game_circle ==  FLOP) {
            if ((recv = strstr(buffer, "raise")) != NULL) {
                temp = 0;
                pos = 1;    
                recv = strstr(recv, " \n");
                if (*(recv + 2) != 't') {
                    opponent.ifcall = 2;
                }
            }
            if ((recv = strstr(buffer, "call")) != NULL ) {
                temp = 0;
                pos = 1;    
                recv = strstr(recv, " \n");
                if (*(recv + 2) != 't') {
                    opponent.ifcall = 1;
                }
            }
        }
        if (intimidate == FLOP && game_circle == TURN ) {
            if ((recv = strstr(buffer, "raise")) != NULL) {
                temp = 0;
                pos = 1;    
                recv = strstr(recv, " \n");
                if (*(recv + 2) != 't') {
                    opponent.ifcall = 2;
                }
            }
            if ((recv = strstr(buffer, "call")) != NULL ) {
                temp = 0;
                pos = 1;    
                recv = strstr(recv, " \n");
                if (*(recv + 2) != 't') {
                    opponent.ifcall = 1;
                }
            }
        }
        if (intimidate == TURN && game_circle == RIVER ) {
            if ((recv = strstr(buffer, "raise")) != NULL) {
                temp = 0;
                pos = 1;    
                recv = strstr(recv, " \n");
                if (*(recv + 2) != 't') {
                    opponent.ifcall = 2;
                }
            }
            if ((recv = strstr(buffer, "call")) != NULL ) {
                temp = 0;
                pos = 1;    
                recv = strstr(recv, " \n");
                if (*(recv + 2) != 't') {
                    opponent.ifcall = 1;
                }
            }
        }
        //set gameJetton
        switch (game_circle) {
            case HOLD: gameJetton.hold += gameInfo.call; break;
            case FLOP: gameJetton.flop += gameInfo.call; break;
            case TURN: gameJetton.turn += gameInfo.call; break;
            default: break;
        }   
    }
}

这里解释一下对手模型,基于这样一种哲学思想:
玩牌的过程中总会遇到一些喜欢吓唬人的对手,而该对手总是在别人下注很少或让牌的情况下突然加注很多。我就会这么做。那么问题来了,要是他跟了呢?那么久需要把告诉自己,这个有人跟了,我需要采取进一步策略:只要不是高牌,加到底。这样可能有风险,但是如果他是大牌,他不会在一开始加注很少,所以放开手做吧。不这样,根本挣不到钱的!

点赞