德州扑克 - 模拟一轮下注算法

时间:2014-03-27 23:17:08

标签: c# algorithm poker

我正在尝试为德州扑克模拟创建一个算法,这个代码的特定部分需要围绕每个坐着的扑克机器人和投注做出决定。该算法可以包含所有代理人是折叠还是消失全部,或者每个剩余玩家都调用了最高赌注的时候。

此算法似乎在99%的时间内都有效,但有时会出现一个角落情况,其中一个代理人进入allIn并且它一直在桌子周围,但不会使下注顺序中的最后一个代理人调用AllIn加注。

任何人都可以在我的代码中发现逻辑错误,或者可能建议使用完全不同的算法吗?我尝试用断点捕获错误,但问题是它很少发生,当实际发生这种情况时很难断开代码。

        while (callCount < agentsInHand)
    {


        if (!agents[betPosition].folded && !agents[betPosition].allIn)
        {
            bettingDecision = agents[betPosition].MakeDecision(tournament, this, minRaise, agentsInHand);


            if (bettingDecision[0] == 0 && chipsToCall > 0)
            {
                //fold                    
                agentsInHand--;
                agents[betPosition].folded = true;
                tournament.AddDecision(agents[betPosition], 0d);
            }
            else if (bettingDecision[0] == 1 || ((chipsToCall <= preFlopBets[betPosition] && betRound == 0) ||(chipsToCall <= flopBets[betPosition] && betRound == 1) ||(chipsToCall <= turnBets[betPosition] && betRound == 2) ||(chipsToCall <= riverBets[betPosition] && betRound == 3)) && bettingDecision[0] == 0)
            {
                //call                    
                tournament.AddDecision(agents[betPosition], 1d);

                if (betRound == 0)
                {
                    int chipsBet = agents[betPosition].BetChips(chipsToCall - preFlopBets[betPosition], this);
                    pot += chipsBet;
                }
                else if (betRound == 1)
                {
                    int chipsBet = agents[betPosition].BetChips(chipsToCall - flopBets[betPosition], this);
                    pot += chipsBet;
                }
                else if (betRound == 2)
                {
                    int chipsBet = agents[betPosition].BetChips(chipsToCall - turnBets[betPosition], this);
                    pot += chipsBet;
                }
                else
                {
                    int chipsBet = agents[betPosition].BetChips(chipsToCall - riverBets[betPosition], this);
                    pot += chipsBet;
                }

                if (agents[betPosition].allIn)
                {
                    agentsInHand--;
                }
                else
                {
                    callCount++;
                }


            }
            else
            {
                //raise
                callCount = 1;

                if (betRound == 0)
                {
                    int chipsBet = agents[betPosition].BetChips(bettingDecision[1], this);
                    tournament.AddDecision(agents[betPosition], Convert.ToDouble(preFlopBets[betPosition]) / Convert.ToDouble(chipsToCall));
                    pot += chipsBet;
                    if (minRaise < preFlopBets[betPosition] - chipsToCall)
                    {
                        minRaise = preFlopBets[betPosition] - chipsToCall;
                    }
                    chipsToCall = preFlopBets.Max();
                }
                else if (betRound == 1)
                {
                    int chipsBet = agents[betPosition].BetChips(bettingDecision[1], this);
                    tournament.AddDecision(agents[betPosition], Convert.ToDouble(flopBets[betPosition]) / Convert.ToDouble(chipsToCall));
                    pot += chipsBet;
                    if (minRaise < flopBets[betPosition] - chipsToCall)
                    {
                        minRaise = flopBets[betPosition] - chipsToCall;
                    }
                    chipsToCall = flopBets.Max();
                }
                else if (betRound == 2)
                {
                    int chipsBet = agents[betPosition].BetChips(bettingDecision[1], this);
                    tournament.AddDecision(agents[betPosition], Convert.ToDouble(turnBets[betPosition]) / Convert.ToDouble(chipsToCall));
                    pot += chipsBet;
                    if (minRaise < turnBets[betPosition] - chipsToCall)
                    {
                        minRaise = turnBets[betPosition] - chipsToCall;
                    }
                    chipsToCall = turnBets.Max();
                }
                else
                {
                    int chipsBet = agents[betPosition].BetChips(bettingDecision[1], this);
                    tournament.AddDecision(agents[betPosition], Convert.ToDouble(riverBets[betPosition]) / Convert.ToDouble(chipsToCall));
                    pot += chipsBet;
                    if (minRaise < riverBets[betPosition] - chipsToCall)
                    {
                        minRaise = riverBets[betPosition] - chipsToCall;
                    }
                    chipsToCall = riverBets.Max();
                }

                if (agents[betPosition].allIn)
                {
                    agentsInHand--;

                    if (betRound == 0)
                    {
                        if (preFlopBets[betPosition] >= chipsToCall)
                        {
                            callCount = 0;
                        }
                    }
                    else if (betRound == 1)
                    {
                        if (flopBets[betPosition] >= chipsToCall)
                        {
                            callCount = 0;
                        }
                    }
                    else if (betRound == 2)
                    {
                        if (turnBets[betPosition] >= chipsToCall)
                        {
                            callCount = 0;
                        }
                    }
                    else
                    {
                        if (riverBets[betPosition] >= chipsToCall)
                        {
                            callCount = 0;
                        }
                    }


                }
            }
        }
        else
        {

        }

        betPosition++;
        if (betPosition == 9)
        {
            betPosition = 0;
        }
        while (!IsSeatTaken(betPosition))
        {
            betPosition++;
            if (betPosition == 9)
            {
                betPosition = 0;
            }
        }
    }

}

感谢您的帮助。

0 个答案:

没有答案