Plays of a hand of poker between a list of players. Designed for fast local use by AI agents. Author: Wesley Tansey
Beispiel #1
0
        public TableManger(Int16 maxPlayers)
        {
            this.Seats = new Seat[maxPlayers];

            //
            this.engine = new HandEngine();
        }
Beispiel #2
0
        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++;
            }
        }
Beispiel #3
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 };
 }
        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);
        }
Beispiel #5
0
        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);
        }