コード例 #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);
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: ivan-alles/poker-acpc
        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);
        }
コード例 #3
0
ファイル: Patience.cs プロジェクト: ivan-alles/poker-acpc
        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());
            }
        }