Exemplo n.º 1
0
        static void Main(string[] args)
        {
            const double time  = 5.0;
            ulong        board = Hand.ParseHand("");
            ulong        dead  = Hand.ParseHand("");

            // Table Header
            Console.Write(",");
            for (int i = 1; i <= 9; i++)
            {
                Console.Write("{0},", i);
            }
            Console.WriteLine();

            // Iterates through one representative hand of each of the 169 possible
            // pocket hand types
            foreach (ulong pocket in PocketHands.Hands169())
            {
                // Show Pocker Hand
                Console.Write("\"{0}\",", Hand.MaskToString(pocket));

                // Calculate and Display the Approximate odds for 1-9 opponents
                for (int opponents = 1; opponents <= 9; opponents++)
                {
                    Console.Write("{0}%,", WinOddsMonteCarlo(pocket, board, dead, opponents, time) * 100.0);
                }
                Console.WriteLine();
            }
        }
Exemplo n.º 2
0
        public static void CreatePocketHandsLookUp(int opponents)
        {
            double[] ppot = new double[169];
            double[] npot = new double[169];
            double[] winp = new double[169];
            double[] hs   = new double[169];

            using (TextWriter writer = new StreamWriter("preflops" + opponents + ".txt"))
            {
                foreach (ulong hc in PocketHands.Hands169())
                {
                    Hand.PocketHand169Enum handType = Hand.PocketHand169Type(hc);

                    //Console.WriteLine(handType.ToString());
                    int index = (int)handType;
                    Hand.HandPotential(hc, 0UL, out ppot[index], out npot[index], opponents, 0.1);
                    winp[index] = Hand.WinOdds(hc, 0UL, 0UL, opponents, 0.1);
                    hs[index]   = Hand.HandStrength(hc, 0UL, opponents, 0.1);

                    Console.WriteLine(index);
                    writer.WriteLine("new [] { " + ppot[index] + ", "
                                     + npot[index] + ", "
                                     + winp[index] + ", "
                                     + hs[index] + " },");
                }
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            // This will iterate through all the possible "connected suited" pocket hands
            foreach (ulong pocketmask in PocketHands.Query("Card169"))
            {
                // Insert calculation here.
                Console.WriteLine(Hand.MaskToString(pocketmask));
            }

            // Looks at an AKs match up (specifically As Ks) against all possible
            // opponents hands that are connected and suited.
            ulong mask = Hand.Evaluate("As Ks"); // AKs

            foreach (ulong oppmask in PocketHands.Query("Connected Suited", mask))
            {
                // Insert calculation here.
                //Console.WriteLine(Hand.MaskToString(oppmask));
            }


            // Iterates through all possible "Connected Suited" versus
            // "Connected Offsuit" match ups.
            foreach (ulong playermask in PocketHands.Query("Connected Suited"))
            {
                foreach (ulong oppmask in PocketHands.Query("Connected Offsuit", playermask))
                {
                    foreach (ulong board in Hand.Hands(0UL, playermask | oppmask, 5))
                    {
                        // Insert Calculation Here
                        // Console.WriteLine(Hand.MaskToString(board));
                    }
                }
            }

            // Randomly selects 100000 possible hands when player starts with a
            // suited connector
            ulong[] masks = PocketHands.Query("Connected Suited");
            for (int trials = 0; trials < 100000; trials++)
            {
                // Select a random player hand from the list of possible
                // Connected Suited hands.
                ulong randomPlayerHandMask = Hand.RandomHand(masks, 0UL, 2);
                // Get a random opponent hand
                ulong randomOpponentHandMask = Hand.RandomHand(randomPlayerHandMask, 2);
                // Get a random board
                ulong boardMask = Hand.RandomHand(randomPlayerHandMask | randomOpponentHandMask, 5);

                // Insert evaluation here
            }
        }
Exemplo n.º 4
0
        private double[] StartingHandsToVector()
        {
            var vector = new double[8];

            if (!this.isUpdated)
            {
                return(vector);
            }
            else
            {
                var group = (int)PocketHands.GroupType(this.pocket.Mask);

                if (group != 8)
                {
                    vector[group] = 1.0;
                }

                return(vector);
            }
        }
Exemplo n.º 5
0
        private double[] StartingHandsToBinary()
        {
            var arrayLength = 4;

            if (!this.isUpdated)
            {
                return(new double[arrayLength]);
            }
            else
            {
                var n = (int)PocketHands.GroupType(this.pocket.Mask);

                if (n == 8)
                {
                    var ranks = Hand.Cards(this.pocket.Mask).Select(s => Hand.CardRank(Hand.ParseCard(s)));

                    var isContainedAce = Hand.Cards(this.pocket.Mask)
                                         .Select(s => Hand.CardRank(Hand.ParseCard(s)) == Hand.RankAce)
                                         .Any(p => p == true);

                    if (ranks.Contains(Hand.RankAce))
                    {
                        n = 8;
                    }
                    else if (ranks.Contains(Hand.RankKing))
                    {
                        n = 9;
                    }
                    else if (Hand.IsSuited(this.pocket.Mask))
                    {
                        var gap = Hand.GapCount(this.pocket.Mask);

                        Debug.Assert(gap != 0 && gap != 1, "It is expected that the gap is 2, 3, -1");

                        if (gap == 2)
                        {
                            n = 10;
                        }
                        else if (gap == 3)
                        {
                            n = 11;
                        }
                        else
                        {
                            n = 12;
                        }
                    }
                    else
                    {
                        var gap = Hand.GapCount(this.pocket.Mask);

                        if (gap == 0)
                        {
                            // 43o, 32o
                            n = 13;
                        }
                        else if (gap == 1)
                        {
                            n = 14;
                        }
                        else
                        {
                            n = 15;
                        }
                    }
                }

                return(this.IntToBinary(n, arrayLength));
            }
        }
Exemplo n.º 6
0
        public static void CreateTurnLookUpTable(int numOpponents)
        {
            int situations = 0;
            int skipped    = 0;

            CreateHandProbabilityDelegate        d           = new CreateHandProbabilityDelegate(CreateHandProbability);
            Dictionary <ulong, HashSet <ulong> > lookupTable = new Dictionary <ulong, HashSet <ulong> >();

            foreach (ulong pockets in PocketHands.Hands169())
            {
                Hand.PocketHand169Enum handType = Hand.PocketHand169Type(pockets);
                ulong[] flops = EnumerateFlop(pockets);
                situations += flops.Length;
                Console.WriteLine("Hand: {0}", Hand.MaskToString(pockets));
                List <ulong> pocketList = new List <ulong>();
                List <ulong> boardList  = new List <ulong>();
                foreach (ulong flop in flops)
                {
                    for (int t = 51; t >= 0; t--)
                    {
                        ulong turn = Hand.Mask(t);
                        if (Hand.BitCount(pockets | flop | turn) != 6)
                        {
                            continue;
                        }
                        ulong isoPockets, isoTurn;
                        Transform(pockets, flop | turn, out isoPockets, out isoTurn, false);
                        if (!lookupTable.ContainsKey(isoPockets))
                        {
                            lookupTable.Add(isoPockets, new HashSet <ulong>());
                        }
                        if (lookupTable[isoPockets].Contains(isoTurn))
                        {
                            skipped++;
                            continue;
                        }
                        lookupTable[isoPockets].Add(isoTurn);
                        pocketList.Add(isoPockets);
                        boardList.Add(isoTurn);
                    }
                }
                IAsyncResult[] results = new IAsyncResult[pocketList.Count];

                for (int i = 0, r = 0; i < pocketList.Count; i++)
                {
                    results[r++] = d.BeginInvoke(pocketList[i], boardList[i], numOpponents, null, null);
                }

                Dictionary <ulong, List <HandProbabilities> > probabilities = new Dictionary <ulong, List <HandProbabilities> >();
                for (int i = 0; i < results.Length; i++)
                {
                    HandProbabilities prob = d.EndInvoke(results[i]);
                    if (!probabilities.ContainsKey(prob.Pockets))
                    {
                        probabilities.Add(prob.Pockets, new List <HandProbabilities>());
                    }

                    probabilities[prob.Pockets].Add(prob);
                }

                foreach (var pair in probabilities)
                {
                    SaveProbabilities(pair.Value, pair.Key, numOpponents, Round.Turn);
                }
            }
        }
Exemplo n.º 7
0
        public static void CreateFlopLookUpTable()
        {
            int situations = 0;
            int skipped    = 0;

            CreateHandProbabilityDelegate        d           = new CreateHandProbabilityDelegate(CreateHandProbability);
            Dictionary <ulong, HashSet <ulong> > lookupTable = new Dictionary <ulong, HashSet <ulong> >();

            foreach (ulong pockets in PocketHands.Hands169())
            {
                Hand.PocketHand169Enum handType = Hand.PocketHand169Type(pockets);
                ulong[] flops = EnumerateFlop(pockets);
                situations += flops.Length;
                Console.WriteLine("Hand: {0} Flops: {1}", Hand.MaskToString(pockets), flops.Length);
                List <ulong> pocketList = new List <ulong>();
                List <ulong> boardList  = new List <ulong>();
                foreach (ulong flop in flops)
                {
                    ulong isoPockets, isoFlop;
                    Transform(pockets, flop, out isoPockets, out isoFlop, false);
                    if (!lookupTable.ContainsKey(isoPockets))
                    {
                        lookupTable.Add(isoPockets, new HashSet <ulong>());
                    }
                    if (lookupTable[isoPockets].Contains(isoFlop))
                    {
                        skipped++;
                        continue;
                    }
                    lookupTable[isoPockets].Add(isoFlop);
                    pocketList.Add(isoPockets);
                    boardList.Add(isoFlop);
                }
                IAsyncResult[] results = new IAsyncResult[pocketList.Count * 5];

                for (int i = 0, r = 0; i < pocketList.Count; i++)
                {
                    results[r++] = d.BeginInvoke(pocketList[i], boardList[i], 1, null, null);
                    results[r++] = d.BeginInvoke(pocketList[i], boardList[i], 2, null, null);
                    results[r++] = d.BeginInvoke(pocketList[i], boardList[i], 3, null, null);
                    results[r++] = d.BeginInvoke(pocketList[i], boardList[i], 4, null, null);
                    results[r++] = d.BeginInvoke(pocketList[i], boardList[i], 5, null, null);
                }

                Dictionary <ulong, List <HandProbabilities> >[] probabilities = new Dictionary <ulong, List <HandProbabilities> > [5];
                for (int i = 0; i < 5; i++)
                {
                    probabilities[i] = new Dictionary <ulong, List <HandProbabilities> >();
                }
                for (int i = 0; i < results.Length; i++)
                {
                    HandProbabilities prob = d.EndInvoke(results[i]);
                    if (!probabilities[prob.OpponentCount - 1].ContainsKey(prob.Pockets))
                    {
                        probabilities[prob.OpponentCount - 1].Add(prob.Pockets, new List <HandProbabilities>());
                    }

                    probabilities[prob.OpponentCount - 1][prob.Pockets].Add(prob);
                }

                for (int opponents = 1; opponents <= 5; opponents++)
                {
                    foreach (var pair in probabilities[opponents - 1])
                    {
                        SaveProbabilities(pair.Value, pair.Key, opponents, Round.Flop);
                    }
                }
            }
            Console.WriteLine("Situations: {0} Skipped: {1} Estimated time: {2} hours", situations, skipped, Math.Round(situations * 0.04 / 3600.0, 2));
        }
Exemplo n.º 8
0
        public double getEquity(HoldemHand.Hand hero, List <Villain> opponents, HoldemHand.Hand board)
        {
            ulong  heroMask           = hero.MaskValue;
            ulong  boardMask          = board.MaskValue;
            string mergedVillainRange = "";

            // Will need a more sophisticated method for merging all the villain ranges
            foreach (Villain v in opponents)
            {
                mergedVillainRange += v.range;
            }

            // A Pocket Query Returns an array of all
            // hands that meet the criterion.
            ulong[] opposingRange = PocketHands.Query(mergedVillainRange);
            //ulong[] hero = PocketHands.Query("Connected Offsuit");

            // Holds stats
            long heroWins = 0, villainsWin = 0,
                 ties = 0, count = 0;

            // Iterate through 10000 trials.
            for (int trials = 0; trials < 10000; trials++)
            {
                // Pick a random pocket hand out of
                // player1's query set
                //ulong player1Mask = Hand.RandomHand(player1, 0UL, 2);

                // Pick a random pocket hand for player2
                ulong villainMask = HoldemHand.Hand.RandomHand(opposingRange, heroMask, 2);

                // Pick a random board
                // Need to write a method for creating a random entire board if preflop, just turn/river on flop etc
                // Based on the board given parameter
                //ulong boardMask
                //    = Hand.RandomHand(player1Mask | player2Mask, 5);

                // Create a hand value for each player
                uint heroHandValue =
                    HoldemHand.Hand.Evaluate(boardMask | heroMask, 7);
                uint villainHandValue =
                    HoldemHand.Hand.Evaluate(boardMask | villainMask, 7);

                // Calculate Winners
                if (heroHandValue > villainHandValue)
                {
                    heroWins++;
                }
                else if (heroHandValue < villainHandValue)
                {
                    villainsWin++;
                }
                else
                {
                    ties++;
                }
                count++;
            }

            return((heroWins + ties / 2.0) / ((double)count) * 100.0);
        }