Exemplo n.º 1
0
        public void Test_Constructor()
        {
            // No preflop bucketing by pocket
            Props p = new string[]
            {
                "SomeProp", "SomeVal"
            };
            PreflopPocketCA pfca = new PreflopPocketCA(p, 4);

            Assert.IsNull(pfca.PocketKindToAbstrCard);

            // Do preflop bucketing by pocket
            p = new string[]
            {
                "Pockets3", "AA KK",
                "Pockets2", "QQ JJ TT",
                "Pockets1", "AKs AKo AQs",
            };
            pfca = new PreflopPocketCA(p, 4);
            Assert.IsNotNull(pfca.PocketKindToAbstrCard);
            Assert.AreEqual((int)HePocketKind.__Count, pfca.PocketKindToAbstrCard.Length);
            for (int i = 0; i < (int)HePocketKind.__Count; ++i)
            {
                HePocketKind pk = (HePocketKind)i;
                switch (pk)
                {
                case HePocketKind._AA:
                case HePocketKind._KK:
                    Assert.AreEqual(3, pfca.PocketKindToAbstrCard[i]);
                    break;

                case HePocketKind._QQ:
                case HePocketKind._JJ:
                case HePocketKind._TT:
                    Assert.AreEqual(2, pfca.PocketKindToAbstrCard[i]);
                    break;

                case HePocketKind._AKs:
                case HePocketKind._AKo:
                case HePocketKind._AQs:
                    Assert.AreEqual(1, pfca.PocketKindToAbstrCard[i]);
                    break;

                default:
                    Assert.AreEqual(0, pfca.PocketKindToAbstrCard[i], pk.ToString());
                    break;
                }
            }
        }
Exemplo n.º 2
0
        public void Print(TextWriter tw)
        {
            tw.WriteLine("{0}", Name);
            int[] totalCount = new int[_positions.Count];
            for (int pos = 0; pos < _positions.Count; pos++)
            {
                foreach (Record r in _positions[pos])
                {
                    totalCount[pos] += r.count;
                }
            }

            tw.Write("Pos ");
            for (int pos = 0; pos < _positions.Count; pos++)
            {
                tw.Write("                                    {0}", pos);
            }
            tw.WriteLine();

            tw.Write("Poc ");
            for (int pos = 0; pos < _positions.Count; pos++)
            {
                tw.Write("     Count    Result     Av,mb   Freq");
            }
            tw.WriteLine();

            Record [] totalRecord = new Record[_positions.Count].Fill(i => new Record());

            for (HePocketKind pocketKind = 0; pocketKind < HePocketKind.__Count; ++pocketKind)
            {
                Console.Write("{0,-3} ", pocketKind.ToString().Substring(1));
                for (int pos = 0; pos < _positions.Count; pos++)
                {
                    Record r = _positions[pos][(int)pocketKind];
                    totalRecord[pos].result += r.result;
                    totalRecord[pos].count  += r.count;
                    PrintRecord(tw, totalCount[pos], r);
                }
                Console.WriteLine();
            }
            Console.Write("ALL ");
            for (int pos = 0; pos < _positions.Count; pos++)
            {
                PrintRecord(tw, totalCount[pos], totalRecord[pos]);
            }
            Console.WriteLine();
        }
Exemplo n.º 3
0
        static HePocket()
        {
            int[] rangePos = new int[(int)HePocketKind.__Count];
            for (int p = 0; p < (int)HePocketKind.__Count; ++p)
            {
                HePocketKind kind       = (HePocketKind)p;
                string       name       = kind.ToString();
                string       kindString = name.Substring(1);

                _kindToString[p] = kindString;
                _stringToKind.Add(kindString, kind);

                string  c1        = name.Substring(1, 1);
                string  c2        = name.Substring(2, 1);
                string  type      = name.Length == 4 ? name.Substring(3, 1) : "";
                CardSet cs        = new CardSet();
                int     rangeSize = 6;
                if (type == "s")
                {
                    // Suited
                    cs        = StdDeck.Descriptor.GetCardSet(c1 + "c " + c2 + "c");
                    rangeSize = 4;
                }
                else if (type == "o")
                {
                    // Offsuit
                    cs        = StdDeck.Descriptor.GetCardSet(c1 + "c " + c2 + "d");
                    rangeSize = 12;
                }
                else
                {
                    // Pair
                    cs        = StdDeck.Descriptor.GetCardSet(c1 + "c " + c2 + "d");
                    rangeSize = 6;
                }

                _kindToSuitNormalizedCardset[p] = cs;
                _kindToHand[p]          = StdDeck.Descriptor.GetIndexesAscending(cs).ToArray();
                _cardSetToKind[cs]      = kind;
                _kindToRange[(int)kind] = new CardSet[rangeSize];
            }
            CardEnum.Combin(StdDeck.Descriptor, 2, CardSet.Empty, CardSet.Empty, AddPocket, rangePos);
        }
Exemplo n.º 4
0
        private static void MonteCarlo()
        {
            // Create new arrays for preflop values
            for (int pos = 0; pos < 2; ++pos)
            {
                _createPreflopValues.Walk(_neytiri, _neytiri.Positions[pos]);
            }

            DateTime start = DateTime.Now;

            for (int ourPos = 0; ourPos < _neytiri.Positions.Length; ++ourPos)
            {
                Console.WriteLine("Position {0}", ourPos);

                ActionTreeNode        root         = _neytiri.Positions[1 - ourPos];
                List <ActionTreeNode> strategyPath = new List <ActionTreeNode>(100);
                strategyPath.Add(root);
                // Advance to the node where we get cards
                while (strategyPath[strategyPath.Count - 1].State.CurrentActor != ourPos)
                {
                    strategyPath.Add(strategyPath[strategyPath.Count - 1].Children[0]);
                }
                for (HePocketKind pocketKind = 0; pocketKind < HePocketKind.__Count; ++pocketKind)
                {
                    CardSet pocket = HePockets.PocketKindToCardSet(pocketKind);

                    if (_pockets.Count > 0 && !_pockets.Contains(pocket))
                    {
                        // Skip the pocket if command line specifies which pockets to include and it's not there.
                        continue;
                    }

                    Console.Write("{0} ", pocketKind.ToString().Substring(1));

                    MonteCarloStrategyFinder.DoMonteCarlo(_neytiri,
                                                          ourPos, pocket, 0, "",
                                                          strategyPath, _cmdLine.mcCount);

                    WalkTree <ActionTree, ActionTreeNode, int> copyValues =
                        new WalkTree <ActionTree, ActionTreeNode, int>
                    {
                        OnNodeBegin = (t, n, s, d) =>
                        {
                            if (n.State.Round > 0)
                            {
                                return(false);
                            }
                            n.PreflopValues[(int)pocketKind] = n.Value;
                            return(true);
                        }
                    };
                    copyValues.Walk(_neytiri, root);
                }
                Console.WriteLine();
            }
            DateTime finish = DateTime.Now;
            double   sec    = (finish - start).TotalSeconds;

            Console.WriteLine("Done {0} monte-carlo trials for every pocket in each position in {1:0.0} sec",
                              _cmdLine.mcCount, sec);
            Console.WriteLine("Writing Neytiri strategy to {0} ...", _cmdLine.neytiri);
            _neytiri.XmlSerialize(_cmdLine.neytiri, new XmlWriterSettings {
                Indent = false
            });
        }