コード例 #1
0
        void ParseActionsForHe(ServerMessage msg, GameRecord gr)
        {
            string[] privateCards = msg.GetPrivateCards();
            // Reverse positions for our format
            for (int p = 1; p >= 0; --p)
            {
                string cards = privateCards[p];
                if (cards == "")
                {
                    cards = "? ?";
                }
                else
                {
                    cards = CardsFromAcpc(cards);
                }
                PokerAction a = PokerAction.d(1 - p, cards);
                gr.Actions.Add(a);
            }

            for (int r = 0; r <= msg.Round; ++r)
            {
                if (r > 0)
                {
                    PokerAction a = PokerAction.d(CardsFromAcpc(msg.Cards[r]));
                    gr.Actions.Add(a);
                }
                for (int move = 0; move < msg.Betting[r].Length; ++move)
                {
                    PokerAction a        = null;
                    int         position = r == 0 ? move % 2 : 1 - (move % 2);
                    switch (msg.Betting[r][move])
                    {
                    case 'r':
                        a = PokerAction.r(position, r < 2 ? 1 : 2);
                        break;

                    case 'c':
                        a = PokerAction.c(position);
                        break;

                    case 'f':
                        a = PokerAction.f(position);
                        break;
                    }
                    gr.Actions.Add(a);
                }
            }
        }
コード例 #2
0
        public void Test_GameString_GameDef_NotOver()
        {
            GameDefinition gameDef = LoadGameDef();

            string gameString = "14; P1{100 .5 0} P2{200 1 0}; 0d{Ac Ad} 1d{Kc Kd};";

            GameState gs = new GameState(gameString, gameDef);

            VerifyGameState(gs, "14", false, 0, 1.5, 1, 1, 1, false, 0, 2, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.f, Ak.c, Ak.r });
            VerifyPlayerState(gs.Players[0], "P1", 99.5, "Ac Ad", 0.5, 0.5, 0, false, false, true, true);
            VerifyPlayerState(gs.Players[1], "P2", 199, "Kc Kd", 1, 1, 0, false, false, true, true);

            gs.UpdateByAction(PokerAction.c(0), gameDef);
            VerifyGameState(gs, "14", false, 0, 2, 1, 1, 0, false, 1, 0, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.c, Ak.r });
            VerifyPlayerState(gs.Players[0], "P1", 99, "Ac Ad", 1, 1, 0, false, false, false, true);
            VerifyPlayerState(gs.Players[1], "P2", 199, "Kc Kd", 1, 1, 0, false, false, true, true);

            gs.UpdateByAction(PokerAction.c(1), gameDef);
            VerifyGameState(gs, "14", false, 0, 2, 1, 1, 1, true, GameState.DealerPosition, 0, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.d });
            VerifyPlayerState(gs.Players[0], "P1", 99, "Ac Ad", 1, 1, 0, false, false, false, true);
            VerifyPlayerState(gs.Players[1], "P2", 199, "Kc Kd", 1, 1, 0, false, false, false, true);

            gs.UpdateByAction(PokerAction.d("As 2d 4d"), gameDef);
            VerifyGameState(gs, "14", false, 1, 2, 0, 0, GameState.DealerPosition, false, 1, 1, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.c, Ak.r });
            VerifyPlayerState(gs.Players[0], "P1", 99, "Ac Ad As 2d 4d", 1, 0, 0, false, false, true, true);
            VerifyPlayerState(gs.Players[1], "P2", 199, "Kc Kd As 2d 4d", 1, 0, 0, false, false, true, true);

            gs.UpdateByAction(PokerAction.r(1, gameDef.BetStructure[1]), gameDef);
            VerifyGameState(gs, "14", false, 1, 3, 1, 1, 1, false, 0, 0, 0, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] { Ak.f, Ak.c, Ak.r });
            VerifyPlayerState(gs.Players[0], "P1", 99, "Ac Ad As 2d 4d", 1, 0, 0, false, false, true, true);
            VerifyPlayerState(gs.Players[1], "P2", 198, "Kc Kd As 2d 4d", 2, 1, 0, false, false, false, true);

            gs.UpdateByAction(PokerAction.f(0), gameDef);
            VerifyGameState(gs, "14", true, 1, 3, 1, 1, 0, false, GameState.InvalidPosition, 0, 1, false, 2);
            VerifyGameStateMethods(gs, gameDef, new Ak[] {});
            VerifyPlayerState(gs.Players[0], "P1", 99, "Ac Ad As 2d 4d", 1, 0, -1, true, false, false, false);
            VerifyPlayerState(gs.Players[1], "P2", 201, "Kc Kd As 2d 4d", 2, 1, 1, false, false, false, true);
        }
コード例 #3
0
        public void Test_GameString_NoGameDef_NotOver()
        {
            // As we do not have GameDef, CurrentActor == invalid and IsDealerAction is false.

            string gameString = "11;P1{100 5 0} P2{200 10 0}; 0d{Ah Ad} 1d{Kh Kd} 0r13 1r10;";

            GameState gs = new GameState(gameString, null);

            VerifyGameState(gs, "11", false, 0, 56, 33, 3, 1, false, GameState.InvalidPosition, 0, 0, false, 2);
            VerifyPlayerState(gs.Players[0], "P1", 77, "Ah Ad", 23, 23, 0, false, false, true, true);
            VerifyPlayerState(gs.Players[1], "P2", 167, "Kh Kd", 33, 33, 0, false, false, false, true);

            gs.UpdateByAction(PokerAction.c(0), null);
            VerifyGameState(gs, "11", false, 0, 66, 33, 3, 0, true, GameState.InvalidPosition, 0, 0, false, 2);
            VerifyPlayerState(gs.Players[0], "P1", 67, "Ah Ad", 33, 33, 0, false, false, false, true);
            VerifyPlayerState(gs.Players[1], "P2", 167, "Kh Kd", 33, 33, 0, false, false, false, true);


            gs.UpdateByAction(PokerAction.d("As 2d 4d"), null);

            VerifyGameState(gs, "11", false, 1, 66, 0, 0,
                            GameState.DealerPosition, false, GameState.InvalidPosition, 1, 0, false, 2);
            VerifyPlayerState(gs.Players[0], "P1", 67, "Ah Ad As 2d 4d", 33, 0, 0, false, false, true, true);
            VerifyPlayerState(gs.Players[1], "P2", 167, "Kh Kd As 2d 4d", 33, 0, 0, false, false, true, true);


            gs.UpdateByAction(PokerAction.r(1, 15), null);
            VerifyGameState(gs, "11", false, 1, 81, 15, 1,
                            1, false, GameState.InvalidPosition, 0, 0, false, 2);
            VerifyPlayerState(gs.Players[0], "P1", 67, "Ah Ad As 2d 4d", 33, 0, 0, false, false, true, true);
            VerifyPlayerState(gs.Players[1], "P2", 152, "Kh Kd As 2d 4d", 48, 15, 0, false, false, false, true);

            gs.UpdateByAction(PokerAction.f(0), null);
            VerifyGameState(gs, "11", true, 1, 81, 15, 1,
                            0, false, GameState.InvalidPosition, 0, 1, false, 2);
            VerifyPlayerState(gs.Players[0], "P1", 67, "Ah Ad As 2d 4d", 33, 0, -33, true, false, false, false);
            VerifyPlayerState(gs.Players[1], "P2", 233, "Kh Kd As 2d 4d", 48, 15, 33, false, false, false, true);
        }
コード例 #4
0
ファイル: Patience.cs プロジェクト: ivan-alles/poker-acpc
        private PokerAction ConvertStrActionToPokerAction(int nextStNodeIdx)
        {
            StrategyTreeNode nextStNode = new StrategyTreeNode();

            _strategies[_pos].GetNode(nextStNodeIdx, &nextStNode);
            if (!nextStNode.IsPlayerAction(_pos))
            {
                throw new ApplicationException(String.Format("{0} : wrong move: {1}", GetBotStateDiagText(), nextStNode.ToStrategicString(null)));
            }
            double amount = nextStNode.Amount;

            double raiseAmount = _gameState.Players[_pos].Bet + amount - _gameState.Bet;

            if (raiseAmount > 0)
            {
                return(PokerAction.r(_pos, raiseAmount));
            }
            if (amount == 0 && _gameState.Players[_pos].Bet < _gameState.Bet)
            {
                return(PokerAction.f(_pos));
            }
            return(PokerAction.c(_pos));
        }
コード例 #5
0
        private void LoadStrategy()
        {
            Regex reProbabTriple = new Regex(@"^([^\s]+)\s+([^\s]+)\s+([^\s]+)\s+([^\s]+)", RegexOptions.Compiled);

            using (StreamReader reader = new StreamReader(SourceFile))
            {
                // For debugging
                int lineCount = 0;
                for (; ;)
                {
                    string line = reader.ReadLine();
                    lineCount++;
                    // Console.WriteLine(line);
                    if (line.StartsWith("#"))
                    {
                        continue;
                    }

                    Match  m            = reProbabTriple.Match(line);
                    string actionString = m.Groups[1].Value;

                    double probabR = double.Parse(m.Groups[2].Value, CultureInfo.InvariantCulture);
                    double probabC = double.Parse(m.Groups[3].Value, CultureInfo.InvariantCulture);
                    double probabF = double.Parse(m.Groups[4].Value, CultureInfo.InvariantCulture);

                    int round;
                    List <PokerAction> actions = ParseActionString(actionString, out round);

                    GameState gs = new GameState(GameDef);
                    foreach (PokerAction a in actions)
                    {
                        gs.UpdateByAction(a, GameDef);
                    }

                    List <Ak> allowedActions = gs.GetAllowedActions(GameDef);

                    if (allowedActions.Contains(Ak.r))
                    {
                        actions.Add(PokerAction.r(HeroPosition, GetRaiseAmount(round)));
                        UpdateProbability(actions.ToArray(), probabR);
                        actions.RemoveAt(actions.Count - 1);
                    }

                    if (allowedActions.Contains(Ak.c))
                    {
                        actions.Add(PokerAction.c(HeroPosition));
                        UpdateProbability(actions.ToArray(), probabC);
                        actions.RemoveAt(actions.Count - 1);
                    }

                    if (allowedActions.Contains(Ak.f))
                    {
                        actions.Add(PokerAction.f(HeroPosition));
                        UpdateProbability(actions.ToArray(), probabF);
                    }

                    if (reader.EndOfStream)
                    {
                        break;
                    }
                }
            }
        }
コード例 #6
0
 public override PokerAction OnActionRequired(string gameString)
 {
     return(PokerAction.f(0));
 }