Exemple #1
0
        public static void PokerSessionShouldDistributePotsCorrectly(DistributePotTestCase testCase)
        {
            var players = testCase.Players.Select(p => new Player
            {
                PlayerPot = testCase.PlayerPot,
                Cards     = CardParser.ParseCards(p.Cards).ToList(),
                Strategy  = p.Folds
                        ? (IPlayerStrategy) new FoldAlwaysStategy()
                        : new AllInStrategy()
            }).ToList();

            var session = new PokerSession(players);

            session.CheatCommunityCards(CardParser.ParseCards(testCase.CommunityCards).ToList());
            session.Simulate();

            CollectionAssert.AreEqual(
                expected: testCase.Players.Select(p => p.ExpectedPot).ToList(),
                actual: players.Select(p => p.PlayerPot)
                );
        }
Exemple #2
0
        private IntermediateSimulationResult ComputeChances(SimulationOptions options, IList <Card> cards)
        {
            var runner = new BenchmarkRunner();
            var result = runner.Run(new BenchmarkOptions <IntermediateSimulationResult>
            {
                BatchSize = 16,
                Seed      = new IntermediateSimulationResult {
                    Draw = 0, Runs = 0, Won = 0, WonSingle = 0, Balance = 0
                },
                RunOnce = () =>
                {
                    var startingPot = 1;
                    var playerIndex = 0;
                    var players     = MakePlayers(options, startingPot);
                    var session     = new PokerSession(players);
                    session.CheatPlayerCards(session.Players[playerIndex], cards);
                    session.Simulate();

                    var won       = session.Winners.Contains(session.Players[playerIndex]);
                    var wonSingle = won && session.Winners.Count == 1;
                    var balance   = -startingPot + session.Players[0].PlayerPot;

                    return(new IntermediateSimulationResult
                    {
                        Draw = (session.Winners.Count == session.Players.Count) ? 1 : 0,
                        WonSingle = (won && session.Winners.Count == 1) ? 1 : 0,
                        Won = won ? 1 : 0,
                        Balance = balance,
                        Runs = 1
                    });
                },
                Combine = (a, b) =>
                {
                    return(new IntermediateSimulationResult
                    {
                        Won = (a.Won + b.Won),
                        WonSingle = (a.WonSingle + b.WonSingle),
                        Draw = (a.Draw + b.Draw),
                        Balance = (a.Balance + b.Balance),
                        Runs = (a.Runs + b.Runs)
                    });
                },
                QuantifiedValues = new List <QuantifiedValueOptions <IntermediateSimulationResult> > {
                    new QuantifiedValueOptions <IntermediateSimulationResult> {
                        GetQuantifiedValue   = a => (double)a.Won / a.Runs,
                        ConfidenceLevel      = options.ConfidenceLevel,
                        DesiredRelativeError = options.WinLoseRatesDesiredRelativeError
                    },
                    new QuantifiedValueOptions <IntermediateSimulationResult> {
                        GetQuantifiedValue   = a => (double)a.WonSingle / a.Runs,
                        ConfidenceLevel      = options.ConfidenceLevel,
                        DesiredRelativeError = options.WinLoseRatesDesiredRelativeError
                    },
                    new QuantifiedValueOptions <IntermediateSimulationResult> {
                        GetQuantifiedValue   = a => (double)(a.Runs - a.Won) / a.Runs,
                        ConfidenceLevel      = options.ConfidenceLevel,
                        DesiredRelativeError = options.WinLoseRatesDesiredRelativeError
                    },
                    new QuantifiedValueOptions <IntermediateSimulationResult> {
                        GetQuantifiedValue   = a => (double)a.Balance / a.Runs,
                        ConfidenceLevel      = options.ConfidenceLevel,
                        DesiredAbsoluteError = options.BalanceDesiredAbsoluteError
                    }
                }
            });

            return(result);
        }