Beispiel #1
0
        public void Update(uint n)
        {
            LimitHoldEmState lhes = new LimitHoldEmState();

            lhes.Reset();
            Node node = new Node(lhes);
            MonteCarleTreeSearch mcts = new MonteCarleTreeSearch(this, node, true);

            for (uint i = 0; i < n; ++i)
            {
                Console.WriteLine("Iteration " + i.ToString() + " of " + n.ToString());
                mcts.Reset();
                mcts.Search();

                ++nEpisodes;
            }
        }
Beispiel #2
0
        public void Initialize()
        {
            LimitHoldEmState state = new LimitHoldEmState();

            state.Reset();
            List <LimitHoldEmState> states = new List <LimitHoldEmState> {
                (LimitHoldEmState)state.Clone()
            };

            uint[] nBuckets = new uint[4] {
                169, 1000, 500, 200
            };

            for (int i = 0; i < 169; ++i)
            {
                policy[i.ToString()] = new InformationState();
            }

            while (states.Count != 0)
            {
                state = states[0];
                states.RemoveAt(0);

                List <LimitHoldEmAction> actions = state.GetActions();
                foreach (LimitHoldEmAction action in actions)
                {
                    LimitHoldEmState newState = state.Step(action);

                    for (int bucket = 0; bucket < nBuckets[state.street]; ++bucket)
                    {
                        policy[bucket.ToString() + newState.previousActions] = new InformationState();
                    }

                    if (!newState.isTerminal)
                    {
                        states.Add(newState);
                    }
                }
            }
        }
Beispiel #3
0
        static void Play(LHEPolicy lhePolicy, uint userIndex = 0)
        {
            LimitHoldEmState  state              = new LimitHoldEmState();
            LimitHoldEmAction selectedAction     = LimitHoldEmAction.Call;
            string            selectedActionName = "";
            double            winnings           = 0;

            while (true)
            {
                state.Reset();
                while (!state.isTerminal)
                {
                    if (state.playerIndex == userIndex)
                    {
                        Console.WriteLine("Your cards: " + state.holeCards[userIndex]);
                        Console.WriteLine("Community cards: " + state.communityCards);
                        Console.WriteLine("Total winnings so far: " + winnings);
                        uint pot = state.potContributions[0] + state.potContributions[1];
                        Console.WriteLine("Pot: " + pot);

                        selectedActionName = "";

                        while (selectedActionName != "c" && selectedActionName != "f" && selectedActionName != "r")
                        {
                            selectedActionName = Console.ReadLine();
                            selectedActionName = selectedActionName.ToLower();

                            if (selectedActionName == "q" || selectedActionName == "quit")
                            {
                                Environment.Exit(0);
                            }
                        }
                        switch (selectedActionName)
                        {
                        case "c":
                            selectedAction = LimitHoldEmAction.Call;
                            break;

                        case "f":
                            selectedAction = LimitHoldEmAction.Fold;
                            break;

                        case "r":
                            selectedAction = LimitHoldEmAction.Raise;
                            break;
                        }
                    }
                    else
                    {
                        uint              bucket    = state.Discretize(state.street, state.playerIndex);
                        string            policyKey = bucket.ToString() + state.previousActions;
                        string            actionName;
                        LimitHoldEmAction bestAction     = LimitHoldEmAction.Call;
                        double            bestValue      = double.MinValue;
                        string            bestActionName = "c";
                        foreach (LimitHoldEmAction action in state.GetActions())
                        {
                            switch (action)
                            {
                            case LimitHoldEmAction.Fold:
                                actionName = "f";
                                break;

                            case LimitHoldEmAction.Raise:
                                actionName = "r";
                                break;

                            default:
                                actionName = "c";
                                break;
                            }

                            string newKey      = policyKey + actionName;
                            double actionValue = lhePolicy.policy[newKey].value;
                            if (state.playerIndex == 1)
                            {
                                actionValue *= -1;
                            }

                            if (actionValue > bestValue)
                            {
                                bestValue      = actionValue;
                                bestAction     = action;
                                bestActionName = actionName;
                            }

                            selectedAction     = bestAction;
                            selectedActionName = bestActionName;
                        }

                        Console.WriteLine("\nSmoothUCT: " + selectedActionName + "\n");
                    }

                    state = state.Step(selectedAction);
                }

                uint opponent = (userIndex == 0) ? 1u : 0;
                Console.WriteLine("\nSmoothUCT cards: " + state.holeCards[opponent]);
                double hand_winnings;
                if ((state.reward > 0 && userIndex == 0) || (state.reward < 0 && userIndex == 1))
                {
                    hand_winnings = state.potContributions[opponent];
                    Console.WriteLine("You win " + hand_winnings);
                    winnings += hand_winnings;
                }
                else if (state.reward == 0)
                {
                    Console.WriteLine("Split pot");
                }
                else
                {
                    hand_winnings = state.potContributions[userIndex];
                    Console.WriteLine("SmoothUCT wins " + hand_winnings);
                    winnings -= hand_winnings;
                }

                userIndex = (userIndex + 1) % 2;
                Console.WriteLine("==========================================================================================");
            }
        }