Esempio n. 1
0
        static int Main(string[] args)
        {
            if (!Parser.ParseArgumentsWithUsage(args, _cmdLine))
            {
                return(1);
            }
            if (_cmdLine.DebuggerLaunch)
            {
                Debugger.Launch();
            }

            foreach (string propsFile in _cmdLine.PropsFiles)
            {
                Console.WriteLine("Input file: {0}", propsFile);
                IChanceAbstraction ca = ChanceAbstractionHelper.CreateFromPropsFile(propsFile);
                if (_cmdLine.PreflopRanges)
                {
                    AnalyzeHeChanceAbstraction.PrintPreflopRanges(ca);
                }
                ShowHands(ca);
                Console.WriteLine();
            }

            return(0);
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            if (!Parser.ParseArgumentsWithUsage(args, _cmdLine))
            {
                return(1);
            }
            if (_cmdLine.DebuggerLaunch)
            {
                Debugger.Launch();
            }
            Props caProps = XmlSerializerExt.Deserialize <Props>(_cmdLine.ChanceAbstractionFile);

            caProps.Set("IsCreatingClusterTree", "true");

            IChanceAbstraction ca = ChanceAbstractionHelper.CreateFromProps(caProps);

            Console.WriteLine("CA: {0}", ca.Name);

            List <int> samplesCount = new List <int>();

            foreach (string sc in  _cmdLine.SamplesCount.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
            {
                samplesCount.Add(int.Parse(sc));
            }

            int rngSeed = _cmdLine.RngSeed == 0 ? (int)DateTime.Now.Ticks : _cmdLine.RngSeed;

            Console.WriteLine("RNG seed: {0}", rngSeed);

            CaMcGen gen = new CaMcGen
            {
                Clusterizer = (IClusterizer)ca,
                IsVerbose   = true,
                // IsVerboseSamples = true,
                RngSeed      = rngSeed,
                SamplesCount = samplesCount.ToArray()
            };

            ClusterTree rt = new ClusterTree();

            rt.Root = gen.Generate();
            string dir      = Path.GetDirectoryName(_cmdLine.ChanceAbstractionFile);
            string file     = Path.GetFileNameWithoutExtension(_cmdLine.ChanceAbstractionFile) + ".dat";
            string fileName = Path.Combine(dir, file);

            Console.WriteLine("Writing range tree to {0}", fileName);
            rt.Write(fileName);

            return(0);
        }
Esempio n. 3
0
        /// <summary>
        /// Creates files for each chance abstraction based on the template file.
        /// Tries to reuse the same chance abstration if buckets strings are the same
        /// to test Patience in this mode.
        /// </summary>
        /// <param name="runDir"></param>
        /// <param name="bucketizerStrings"></param>
        /// <returns></returns>
        private IChanceAbstraction[] PrepareConfigsAndChanceAbstractions(string runDir, string[] bucketizerStrings)
        {
            string botPropsFile = Path.Combine(runDir, "props.xml");
            Props  botProps     = XmlSerializerExt.Deserialize <Props>(botPropsFile);

            IChanceAbstraction[] chanceAbstractions = new IChanceAbstraction[bucketizerStrings.Length];

            string caPropsTemplateFile = Path.Combine(runDir, "chance-abstraction-props-template.xml");

            for (int p = 0; p < bucketizerStrings.Length; ++p)
            {
                for (int p1 = 0; p1 < p; ++p1)
                {
                    // Try to reuse the same chance abstraction.
                    if (bucketizerStrings[p1] == bucketizerStrings[p])
                    {
                        botProps.Set(string.Format("ChanceAbstraction-{0}", p),
                                     string.Format("chance-abstraction-props-{0}.xml", p1));
                        botProps.Set(string.Format("Strategy-{0}", p), string.Format("strategy-{0}.dat", p1));
                        chanceAbstractions[p] = chanceAbstractions[p1];
                        goto next;
                    }
                }

                Props caProps = XmlSerializerExt.Deserialize <Props>(caPropsTemplateFile);
                caProps.Set("BucketsString", bucketizerStrings[p]);
                botProps.Set(string.Format("ChanceAbstraction-{0}", p),
                             string.Format("chance-abstraction-props-{0}.xml", p));

                string caPropsFileRel = string.Format("chance-abstraction-props-{0}.xml", p);
                string caPropsFileAbs = Path.Combine(runDir, caPropsFileRel);
                XmlSerializerExt.Serialize(caProps, caPropsFileAbs);
                botProps.Set(string.Format("ChanceAbstraction-{0}", p), caPropsFileRel);
                botProps.Set(string.Format("Strategy-{0}", p), string.Format("strategy-{0}.dat", p));

                chanceAbstractions[p] = ChanceAbstractionHelper.CreateFromProps(caProps);

                next :;
            }
            XmlSerializerExt.Serialize(botProps, botPropsFile);
            File.Delete(caPropsTemplateFile);
            return(chanceAbstractions);
        }
Esempio n. 4
0
        static int Main(string[] args)
        {
            if (!Parser.ParseArgumentsWithUsage(args, _cmdLine))
            {
                return(1);
            }

            if (_cmdLine.DebuggerLaunch)
            {
                Debugger.Launch();
            }

            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(_cmdLine.GameDef.Get(Props.Global));

            if (gd.MinPlayers != _cmdLine.ChanceAbstractionFiles.Length)
            {
                Console.WriteLine("Number of chance abstractions ({0}) does not match to the minimal number of players in game definition ({1})",
                                  _cmdLine.ChanceAbstractionFiles.Length, gd.MinPlayers);
                return(1);
            }

            IChanceAbstraction[] chanceAbstractions = new IChanceAbstraction[_cmdLine.ChanceAbstractionFiles.Length];
            bool   areAbstractionsEqual             = true;
            string fileName0 = _cmdLine.ChanceAbstractionFiles[0].Get().ToUpperInvariant();

            for (int p = 0; p < chanceAbstractions.Length; ++p)
            {
                string fileName = _cmdLine.ChanceAbstractionFiles[p];
                if (fileName.ToUpperInvariant() != fileName0)
                {
                    areAbstractionsEqual = false;
                }
                chanceAbstractions[p] = ChanceAbstractionHelper.CreateFromPropsFile(fileName);
                Console.WriteLine("CA pos {0}: {1}", p, chanceAbstractions[p].Name);
            }

            Console.WriteLine("Abstractions are {0}.", areAbstractionsEqual ? "equal" : "unequal");
            Console.Write("Samples: {0:#,#}. ", _cmdLine.SamplesCount);

            if (_cmdLine.RunsCount > 0)
            {
                Console.Write("Runs: {0:#,#}", _cmdLine.RunsCount);
            }
            else
            {
                Console.WriteLine("Runs: unlimited");
                Console.Write("Press 'q' to quit asap, 'f' to finish run.");
            }
            Console.WriteLine();

            for (int run = 0; ;)
            {
                int rngSeed = (int)DateTime.Now.Ticks;

                Console.Write("Run:{0}, seed:{1}. ", run, rngSeed);

                DateTime startTime = DateTime.Now;

                CtMcGen.Tree tree = CtMcGen.Generate(gd, chanceAbstractions, areAbstractionsEqual, _cmdLine.SamplesCount, rngSeed, Feedback);

                double genTime = (DateTime.Now - startTime).TotalSeconds;

                string fileName = SaveFile(tree, gd, chanceAbstractions);

                Int64 samplesDone = (Int64)tree.SamplesCount;

                Console.WriteLine("Samples: {0:#,#}, time: {1:0.0} s, {2:#,#} sm/s, file: {3}",
                                  samplesDone,
                                  genTime,
                                  samplesDone / genTime,
                                  fileName);

                ++run;
                if (_cmdLine.RunsCount > 0)
                {
                    if (run >= _cmdLine.RunsCount)
                    {
                        break;
                    }
                }
                else
                {
                    ProcessKeys();
                    if (_quitAsap || _finishRun)
                    {
                        Console.WriteLine("Exiting on user request");
                        break;
                    }
                }
            }
            return(0);
        }
Esempio n. 5
0
        void Initialize()
        {
            _playerInfoProps = new Props();
            string strDir = _creationParams.Get("StrategyDir");

            _playerInfoProps.Set("StrategyDir", strDir);
            string propsFile = Path.Combine(strDir, "props.xml");
            Props  props     = XmlSerializerExt.Deserialize <Props>(propsFile);

            int rngSeed = int.Parse(_creationParams.GetDefault("RngSeed", "0"));

            if (rngSeed == 0)
            {
                rngSeed = (int)DateTime.Now.Ticks;
            }

            _checkBlinds = bool.Parse(_creationParams.GetDefault("CheckBlinds", "true"));

            string amountCompareMethodText = _creationParams.GetDefault("AmountSearchMethod", "Equal");

            if (amountCompareMethodText == "Equal")
            {
                _amountSearchMethod = AmountSearchMethod.Equal;
            }
            else if (amountCompareMethodText == "Closest")
            {
                _amountSearchMethod = AmountSearchMethod.Closest;
            }
            else
            {
                throw new ApplicationException(string.Format("Unknown amount compare method {0}", amountCompareMethodText));
            }

            _relProbabIgnoreLevel = double.Parse(_creationParams.GetDefault("RelProbabIgnoreLevel", "0.0"), CultureInfo.InvariantCulture);
            _playerInfoProps.Set("RelProbabIgnoreLevel", _relProbabIgnoreLevel.ToString());

            // Use MersenneTwister because it is under our control on all platforms and
            // is probably better than System.Random.
            Random underlyingRng = new MersenneTwister(rngSeed);

            _moveSelector = new DiscreteProbabilityRng(underlyingRng);
            _playerInfoProps.Set("RngSeed", rngSeed.ToString());

            _deckDescr = XmlSerializerExt.Deserialize <DeckDescriptor>(props.Get("DeckDescriptor"));

            _chanceAbsrtractions = new IChanceAbstraction[0];

            // Create chance abstractions
            for (int pos = 0; ; pos++)
            {
                string caPropName  = String.Format("ChanceAbstraction-{0}", pos);
                string relFileName = props.Get(caPropName);
                if (string.IsNullOrEmpty(relFileName))
                {
                    break;
                }
                Array.Resize(ref _chanceAbsrtractions, _chanceAbsrtractions.Length + 1);

                string absFileName = Path.Combine(strDir, relFileName);
                _chanceAbsrtractions[pos] = ChanceAbstractionHelper.CreateFromPropsFile(absFileName);
                _playerInfoProps.Set(caPropName + ".Name", _chanceAbsrtractions[pos].Name);
            }

            Dictionary <string, int> fileToPos = new Dictionary <string, int>();

            _strategies = new StrategyTree[0];
            _strIndexes = new UFTreeChildrenIndex[0];

            // Load strategies, reuse if file is the same
            for (int pos = 0; ; pos++)
            {
                string strPropName = String.Format("Strategy-{0}", pos);
                string relFileName = props.Get(strPropName);
                if (string.IsNullOrEmpty(relFileName))
                {
                    break;
                }
                Array.Resize(ref _strategies, _strategies.Length + 1);
                Array.Resize(ref _strIndexes, _strIndexes.Length + 1);

                string absFileName = Path.Combine(strDir, relFileName);
                int    existingPos;
                if (fileToPos.TryGetValue(absFileName, out existingPos))
                {
                    _strategies[pos] = _strategies[existingPos];
                    _strIndexes[pos] = _strIndexes[existingPos];
                }
                else
                {
                    fileToPos.Add(absFileName, pos);
                    _strategies[pos] = StrategyTree.ReadFDA <StrategyTree>(absFileName);
                    _strIndexes[pos] = new UFTreeChildrenIndex(_strategies[pos], Path.Combine(strDir, "strategy-idx.dat"), false);
                }
                _playerInfoProps.Set(strPropName + ".Version", _strategies[pos].Version.ToString());
            }

            // Read blinds
            for (int strPos = 0; strPos < _strategies.Length; ++strPos)
            {
                StringBuilder sb = new StringBuilder();
                for (int playerPos = 0; playerPos < _strategies.Length; ++playerPos)
                {
                    StrategyTreeNode stNode = new StrategyTreeNode();
                    _strategies[strPos].GetNode(playerPos + 1, &stNode);
                    sb.AppendFormat("{0:0.000000 }", stNode.Amount);
                }
                _playerInfoProps.Set("Blinds." + strPos.ToString(), sb.ToString());
            }
        }