コード例 #1
0
ファイル: Main.cs プロジェクト: tansey/console_holdem
        public static void Main(string[] args)
        {
            Console.WriteLine("Loading opponents...");
            var seats = new Seat[6];
            seats[0] = new Seat(1, "TeeJayorTJ5", 1000, new WekaPlayer(CLASSIFIER_DIR + "preflop.model",CLASSIFIER_DIR + "flop.model",CLASSIFIER_DIR + "turn.model",CLASSIFIER_DIR + "river.model"));
            seats[1] = new Seat(2, "Dave_Wilkes", 1000, new WekaPlayer(CLASSIFIER_DIR + "preflop.model",CLASSIFIER_DIR + "flop.model",CLASSIFIER_DIR + "turn.model",CLASSIFIER_DIR + "river.model"));
            seats[2] = new Seat(3, "Some_Killa", 1000, new WekaPlayer(CLASSIFIER_DIR + "preflop.model",CLASSIFIER_DIR + "flop.model",CLASSIFIER_DIR + "turn.model",CLASSIFIER_DIR + "river.model"));
            seats[3] = new Seat(4, "Better_Boy", 1000, new WekaPlayer(CLASSIFIER_DIR + "preflop.model",CLASSIFIER_DIR + "flop.model",CLASSIFIER_DIR + "turn.model",CLASSIFIER_DIR + "river.model"));
            seats[4] = new Seat(5, "Kiddo1973", 1000, new WekaPlayer(CLASSIFIER_DIR + "preflop.model",CLASSIFIER_DIR + "flop.model",CLASSIFIER_DIR + "turn.model",CLASSIFIER_DIR + "river.model"));
            seats[5] = new Seat(6, "Human", 1000, new ConsolePlayer());
            var blinds = new double[] { 10, 20 };
            uint handNumber = 0;
            Console.WriteLine("Starting simulation");
            HandEngine engine = new HandEngine();
            while(true)
            {
                HandHistory results = new HandHistory(seats, handNumber, handNumber % (uint)seats.Length + 1, blinds, 0, BettingStructure.Limit);
                //engine.PlayHand(results, cachedHands[(int)handNumber]);
                engine.PlayHand(results);

                Console.WriteLine(results.ToString(true));
                Thread.Sleep(2000);

                foreach(var seat in seats)
                    if(seat.Chips == 0)
                    {
                        Console.WriteLine("{0} rebuys for $1000", seat.Name);
                        seat.Chips = 1000;
                    }

                handNumber++;
            }
        }
コード例 #2
0
        public void setup()
        {
            players = new Seat[5];
            for (int i = 0; i < 5; i++)
                players[i] = new Seat(i, "Player" + i, 1000);

            potMan = new PotManager(players);
        }
コード例 #3
0
ファイル: Pot.cs プロジェクト: tansey/holdem_engine
        /// <summary>
        /// Creates a new, empty Pot with the given name.
        /// </summary>
        public Pot(string potName, Seat[] players)
        {
            this.players = players;

            //.NET defaults to false on booleans, no need to initialize
            eligible = new bool[players.Length];

            size = 0;
            eligibleCount = 0;
            name = potName;
        }
コード例 #4
0
 public void SetUp()
 {
     engine = new HandEngine();
     seqPlayers = new Seat[5];
     for (int i = 0; i < seqPlayers.Length; i++)
     {
         seqPlayers[i] = new Seat();
         seqPlayers[i].Chips = 200.0;
         seqPlayers[i].Name = "Seq" + i;
         seqPlayers[i].SeatNumber = i + 1;
     }
     blinds = new double[] { 1, 2 };
 }
コード例 #5
0
        public void SetUp()
        {
            engine = new HandEngine();

            #region Setup the actions
            Action[] jcloub = new Action[]{
                new Action("jcloub", Action.ActionTypes.Raise, 15),
                new Action("jcloub", Action.ActionTypes.Bet, 10),
                new Action("jcloub", Action.ActionTypes.Bet, 20),
                new Action("jcloub", Action.ActionTypes.Bet, 20),
            };

            Action[] makelgrus = new Action[]{
                new Action("MakelGrus", Action.ActionTypes.Call, 10),
                new Action("MakelGrus", Action.ActionTypes.Call, 10),
                new Action("MakelGrus", Action.ActionTypes.Call, 20),
                new Action("MakelGrus", Action.ActionTypes.Fold),
            };

            Action[] hustler_ed = new Action[]{
                new Action("Hustler_Ed", Action.ActionTypes.Call, 10),
                new Action("Hustler_Ed", Action.ActionTypes.Call, 10),
                new Action("Hustler_Ed", Action.ActionTypes.Call, 10),
                new Action("Hustler_Ed", Action.ActionTypes.Call, 20),
                new Action("Hustler_Ed", Action.ActionTypes.Fold),
            };

            Action[] shammybaby = new Action[]{
                new Action("Shammybaby", Action.ActionTypes.Fold),
            };

            Action[] marine0193 = new Action[]{
                new Action("marine0193", Action.ActionTypes.Fold),
            };

            Action[] teejayortj5 = new Action[]{
                new Action("TeeJayorTJ5", Action.ActionTypes.Fold),
            };
            #endregion

            #region Setup players
            SequencePlayer[] brains = new SequencePlayer[]{
                new SequencePlayer(jcloub),
                new SequencePlayer(makelgrus),
                new SequencePlayer(hustler_ed),
                new SequencePlayer(shammybaby),
                new SequencePlayer(marine0193),
                new SequencePlayer(teejayortj5)
            };

            var seqPlayers = new Seat[]{
                new Seat(1, "jcloub", 2044.5, brains[0]),
                new Seat(3, "MakelGrus", 498, brains[1]),
                new Seat(5, "Hustler_Ed", 470, brains[2]),
                new Seat(6, "Shammybaby", 551, brains[3]),
                new Seat(8, "marine0193", 538, brains[4]),
                new Seat(10, "TeeJayorTJ5", 484, brains[5])
            };
            #endregion

            var blinds = new double[] { 5, 10 };

            engine = new HandEngine();
            hist = new HandHistory(seqPlayers, 1, 10, blinds, 0, BettingStructure.Limit);
            engine.PlayHand(hist);
        }
コード例 #6
0
        public HandHistory Resume(PokerHand savedHand, CachedHand cache)
        {
            _cache = cache;

            #region Restore hand context
            _seats = new Seat[savedHand.Players.Length];
            var orderedPlayers = savedHand.Players.OrderBy(p => p.Seat);
            for (int i = 0; i < _seats.Length; i++)
            {
                var player = orderedPlayers.ElementAt(i);
                _seats[i] = new Seat(player.Seat, player.Name, (double)player.Stack);
            }

            ulong handNum = ulong.Parse(savedHand.Context.ID);
            uint  button  = (uint)savedHand.Context.Button;

            List <double> blinds = new List <double>();
            if (savedHand.Context.SmallBlind > 0m)
            {
                blinds.Add((double)savedHand.Context.SmallBlind);
            }
            if (savedHand.Context.BigBlind > 0m)
            {
                blinds.Add((double)savedHand.Context.BigBlind);
            }
            double           ante = (double)savedHand.Context.Ante;
            BettingStructure bs   = BettingStructure.None;

            switch (savedHand.Context.BettingType)
            {
            case BettingType.FixedLimit: bs = BettingStructure.Limit; break;

            case BettingType.NoLimit: bs = BettingStructure.NoLimit; break;

            case BettingType.PotLimit: bs = BettingStructure.PotLimit; break;

            default: throw new Exception("Unspecified betting structure.");
            }

            _history = new HandHistory(_seats, handNum, button, blinds.ToArray(), ante, bs);
            #endregion

            //Create a new map from player names to player chips for the BetManager
            Dictionary <string, double> namesToChips = new Dictionary <string, double>();

            //Create a new list of players for the PlayerManager
            _playerIndices      = new CircularList <int>();
            _playerIndices.Loop = true;

            // Initialize the names to chips map and find the index of the button
            for (int i = 0; i < _seats.Length; i++)
            {
                namesToChips[_seats[i].Name] = _seats[i].Chips;
                if (_seats[i].SeatNumber == _history.Button)
                {
                    _buttonIdx = i;
                    _utgIdx    = (i + 1) % _seats.Length;
                }
            }

            // Create a circular list of players, in order of first to act
            for (int i = (_buttonIdx + 1) % _seats.Length; _playerIndices.Count < _seats.Length;)
            {
                _playerIndices.Add(i);
                i = (i + 1) % _seats.Length;
            }

            _betManager = new BetManager(namesToChips, _history.BettingStructure, _history.AllBlinds, _history.Ante);
            _potManager = new PotManager(_seats);

            _history.CurrentRound = Round.Predeal;
            if (savedHand.Blinds == null)
            {
                savedHand.Blinds = new Blind[0];
            }
            if (!restoreBlinds(savedHand))
            {
                return(_history);
            }

            DealHoleCards();

            if (_betManager.In <= 1)
            {
                _history.CurrentRound = Round.Over;
                return(_history);
            }

            _history.CurrentRound = Round.Preflop;

            if (_betManager.CanStillBet > 1)
            {
                if (savedHand.Rounds == null || savedHand.Rounds.Length == 0)
                {
                    savedHand.Rounds = new PokerHandHistory.Round[] { new PokerHandHistory.Round()
                                                                      {
                                                                          Actions = new PokerHandHistory.Action[0]
                                                                      } }
                }
                ;
                else if (savedHand.Rounds[0].Actions == null)
                {
                    savedHand.Rounds[0].Actions = new PokerHandHistory.Action[0];
                }
                if (!restoreBets(savedHand.Rounds[0].Actions, _history.PreflopActions))
                {
                    return(_history);
                }
            }
            if (_betManager.In <= 1)
            {
                payWinners();
                _history.CurrentRound = Round.Over;
                return(_history);
            }

            DealFlop();
            _history.CurrentRound = Round.Flop;

            if (_betManager.CanStillBet > 1)
            {
                if (savedHand.Rounds.Length < 2)
                {
                    savedHand.Rounds = new PokerHandHistory.Round[] { savedHand.Rounds[0], new PokerHandHistory.Round()
                                                                      {
                                                                          Actions = new PokerHandHistory.Action[0]
                                                                      } }
                }
                ;
                else if (savedHand.Rounds[1].Actions == null)
                {
                    savedHand.Rounds[1].Actions = new PokerHandHistory.Action[0];
                }

                if (!restoreBets(savedHand.Rounds[1].Actions, _history.FlopActions))
                {
                    return(_history);
                }
            }
            if (_betManager.In <= 1)
            {
                payWinners();
                _history.CurrentRound = Round.Over;
                return(_history);
            }

            DealTurn();
            _history.CurrentRound = Round.Turn;

            if (_betManager.CanStillBet > 1)
            {
                if (savedHand.Rounds.Length < 3)
                {
                    savedHand.Rounds = new PokerHandHistory.Round[] { savedHand.Rounds[0], savedHand.Rounds[1], new PokerHandHistory.Round()
                                                                      {
                                                                          Actions = new PokerHandHistory.Action[0]
                                                                      } }
                }
                ;
                else if (savedHand.Rounds[2].Actions == null)
                {
                    savedHand.Rounds[2].Actions = new PokerHandHistory.Action[0];
                }

                if (!restoreBets(savedHand.Rounds[2].Actions, _history.TurnActions))
                {
                    return(_history);
                }
            }
            if (_betManager.In <= 1)
            {
                payWinners();
                _history.CurrentRound = Round.Over;
                return(_history);
            }

            DealRiver();
            _history.CurrentRound = Round.River;

            if (_betManager.CanStillBet > 1)
            {
                if (savedHand.Rounds.Length < 4)
                {
                    savedHand.Rounds = new PokerHandHistory.Round[] { savedHand.Rounds[0], savedHand.Rounds[1], savedHand.Rounds[2], new PokerHandHistory.Round()
                                                                      {
                                                                          Actions = new PokerHandHistory.Action[0]
                                                                      } }
                }
                ;
                else if (savedHand.Rounds[3].Actions == null)
                {
                    savedHand.Rounds[3].Actions = new PokerHandHistory.Action[0];
                }

                if (!restoreBets(savedHand.Rounds[3].Actions, _history.RiverActions))
                {
                    return(_history);
                }
            }
            if (_betManager.In <= 1)
            {
                payWinners();
                _history.CurrentRound = Round.Over;
                return(_history);
            }

            payWinners();
            _history.ShowDown     = true;
            _history.CurrentRound = Round.Over;
            return(_history);
        }
コード例 #7
0
 public TournamentHandHistory(Seat[] players, ulong handNumber, uint button, double[] blinds, double ante, BettingStructure bs)
     : base(players, handNumber, button, blinds, ante, bs)
 {
 }
コード例 #8
0
ファイル: Main.cs プロジェクト: tansey/evolve_vs_expert
        public static void Main(string[] args)
        {
            //			Random rand = new Random();
            //			for(int i = 0; i < 42*25 + 25*10 + 10*3; i++)
            //				Console.Write("{0},", rand.NextDouble() * 10.0 - 5.0);
            //			return;

            int argIdx = 0;
            int hands = 10000;// int.Parse(args[argIdx++]);
            int numPlayers = 6; //int.Parse(args[argIdx++]);

            string neuralnetPath = args[argIdx++]; //Path.GetFullPath(@"./models/sample.network");
            string resultsPath = args[argIdx++];
            string finishedFlagsPath = args[argIdx++];

            IEnumerable<double> weights;
            FeedForwardNeuralNetwork net;
            using(TextReader reader = new StreamReader(neuralnetPath))
            {
                string line = reader.ReadLine();
                int inputs = int.Parse(line);
                int outputs = 3;

                line = reader.ReadLine();
                int[] hidden = line.Split(',').Select(t => int.Parse(t)).ToArray();

                net = new FeedForwardNeuralNetwork(inputs, outputs, hidden);

                line = reader.ReadLine();
                weights = line.Split(',').Select(t => double.Parse(t));
                net.SetWeights(weights);
            }
            Console.WriteLine("Loaded neural network now. Now loading weka model...");
            var Bot = new WekaPlayer(Path.GetFullPath(@"./models/preflop.model"),
                                     Path.GetFullPath(@"./models/flop.model"),
                                     Path.GetFullPath(@"./models/turn.model"),
                                     Path.GetFullPath(@"./models/river.model"));

            var neuralNetPlayer = new NeuralNetworkPlayer(net);

            HandEngine engine = new HandEngine();
            double[] blinds = new double[]{ 10, 20 };
            uint button = 1;

            int humanSeat = 3;
            Seat[] players = new Seat[numPlayers];
            for(int i = 1; i <= numPlayers; i++)
            {
                if(i == humanSeat)
                    players[i-1] = new Seat(i, "NeuralNetwork", 1000, neuralNetPlayer);
                else
                    players[i-1] = new Seat(i, "Bot" + i, 1000, Bot);
            }

            HandHistory[] histories = new HandHistory[hands];
            double score = 0;
            var start = DateTime.UtcNow;
            for(int curHand = 0; curHand < hands; curHand++)
            {
                if(curHand % 100 == 0)
                    Console.WriteLine(curHand);
                HandHistory history = new HandHistory(players, (ulong)curHand, button, blinds, 0, BettingStructure.Limit);

                engine.PlayHand(history);

                histories[curHand] = history;

                button++;
                if(button > players.Length)
                    button = 1;

                // record winnings and reset chips
                foreach(var player in players)
                {
                    if(player.SeatNumber == humanSeat)
                        score += player.Chips - 1000;
                    player.Chips = 1000;
                }
            }
            var end = DateTime.UtcNow;

            Console.WriteLine("Total winnings: {0}", score);
            Console.WriteLine("Time: {0}", end - start);

            using(TextWriter writer = new StreamWriter(resultsPath))
                writer.WriteLine(-score);

            File.Create(finishedFlagsPath);
        }
コード例 #9
0
ファイル: HandServer.cs プロジェクト: tansey/holdem_engine
        public HandHistory Resume(PokerHand savedHand, CachedHand cache)
        {
            _cache = cache;

            #region Restore hand context
            _seats = new Seat[savedHand.Players.Length];
            var orderedPlayers = savedHand.Players.OrderBy(p => p.Seat);
            for (int i = 0; i < _seats.Length; i++)
            {
                var player = orderedPlayers.ElementAt(i);
                _seats[i] = new Seat(player.Seat, player.Name, (double)player.Stack);
            }

            ulong handNum = ulong.Parse(savedHand.Context.ID);
            uint button = (uint)savedHand.Context.Button;

            List<double> blinds = new List<double>();
            if (savedHand.Context.SmallBlind > 0m)
                blinds.Add((double)savedHand.Context.SmallBlind);
            if (savedHand.Context.BigBlind > 0m)
                blinds.Add((double)savedHand.Context.BigBlind);
            double ante = (double)savedHand.Context.Ante;
            BettingStructure bs = BettingStructure.None;
            switch (savedHand.Context.BettingType)
            {
                case BettingType.FixedLimit: bs = BettingStructure.Limit; break;
                case BettingType.NoLimit: bs = BettingStructure.NoLimit; break;
                case BettingType.PotLimit: bs = BettingStructure.PotLimit; break;
                default: throw new Exception("Unspecified betting structure.");
            }
            _history = new HandHistory(_seats, handNum, button, blinds.ToArray(), ante, bs);
            #endregion

            //Create a new map from player names to player chips for the BetManager
            Dictionary<string, double> namesToChips = new Dictionary<string, double>();

            //Create a new list of players for the PlayerManager
            _playerIndices = new CircularList<int>();
            _playerIndices.Loop = true;

            // Initialize the names to chips map and find the index of the button
            for (int i = 0; i < _seats.Length; i++)
            {
                namesToChips[_seats[i].Name] = _seats[i].Chips;
                if (_seats[i].SeatNumber == _history.Button)
                {
                    _buttonIdx = i;
                    _utgIdx = (i + 1) % _seats.Length;
                }
            }

            // Create a circular list of players, in order of first to act
            for (int i = (_buttonIdx + 1) % _seats.Length; _playerIndices.Count < _seats.Length; )
            {
                _playerIndices.Add(i);
                i = (i + 1) % _seats.Length;
            }

            _betManager = new BetManager(namesToChips, _history.BettingStructure, _history.AllBlinds, _history.Ante);
            _potManager = new PotManager(_seats);

            _history.CurrentRound = Round.Predeal;
            if(savedHand.Blinds == null)
                savedHand.Blinds = new Blind[0];
            if (!restoreBlinds(savedHand))
                return _history;

            DealHoleCards();

            if (_betManager.In <= 1)
            {
                _history.CurrentRound = Round.Over;
                return _history;
            }

            _history.CurrentRound = Round.Preflop;

            if (_betManager.CanStillBet > 1)
            {
                if(savedHand.Rounds == null || savedHand.Rounds.Length == 0)
                    savedHand.Rounds = new PokerHandHistory.Round[] { new PokerHandHistory.Round(){Actions = new PokerHandHistory.Action[0]} };
                else if(savedHand.Rounds[0].Actions == null)
                    savedHand.Rounds[0].Actions = new PokerHandHistory.Action[0];
                if (!restoreBets(savedHand.Rounds[0].Actions, _history.PreflopActions))
                    return _history;
            }
            if (_betManager.In <= 1)
            {
                payWinners();
                _history.CurrentRound = Round.Over;
                return _history;
            }

            DealFlop();
            _history.CurrentRound = Round.Flop;

            if (_betManager.CanStillBet > 1)
            {
                if (savedHand.Rounds.Length < 2)
                    savedHand.Rounds = new PokerHandHistory.Round[]{savedHand.Rounds[0], new PokerHandHistory.Round(){Actions = new PokerHandHistory.Action[0]}};
                else if(savedHand.Rounds[1].Actions == null)
                    savedHand.Rounds[1].Actions = new PokerHandHistory.Action[0];

                if (!restoreBets(savedHand.Rounds[1].Actions, _history.FlopActions))
                    return _history;
            }
            if (_betManager.In <= 1)
            {
                payWinners();
                _history.CurrentRound = Round.Over;
                return _history;
            }

            DealTurn();
            _history.CurrentRound = Round.Turn;

            if (_betManager.CanStillBet > 1)
            {
                if (savedHand.Rounds.Length < 3)
                    savedHand.Rounds = new PokerHandHistory.Round[]{savedHand.Rounds[0], savedHand.Rounds[1], new PokerHandHistory.Round(){Actions = new PokerHandHistory.Action[0]}};
                else if(savedHand.Rounds[2].Actions == null)
                    savedHand.Rounds[2].Actions = new PokerHandHistory.Action[0];

                if (!restoreBets(savedHand.Rounds[2].Actions, _history.TurnActions))
                    return _history;
            }
            if (_betManager.In <= 1)
            {
                payWinners();
                _history.CurrentRound = Round.Over;
                return _history;
            }

            DealRiver();
            _history.CurrentRound = Round.River;

            if (_betManager.CanStillBet > 1)
            {
                if (savedHand.Rounds.Length < 4)
                    savedHand.Rounds = new PokerHandHistory.Round[]{savedHand.Rounds[0], savedHand.Rounds[1], savedHand.Rounds[2], new PokerHandHistory.Round(){Actions = new PokerHandHistory.Action[0]}};
                else if(savedHand.Rounds[3].Actions == null)
                    savedHand.Rounds[3].Actions = new PokerHandHistory.Action[0];

                if (!restoreBets(savedHand.Rounds[3].Actions, _history.RiverActions))
                    return _history;
            }
            if (_betManager.In <= 1)
            {
                payWinners();
                _history.CurrentRound = Round.Over;
                return _history;
            }

            payWinners();
            _history.ShowDown = true;
            _history.CurrentRound = Round.Over;
            return _history;
        }