コード例 #1
0
        public void Test_DeserializeHandWrittenWithSchema()
        {
            string testResourcesPath = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly());

            SessionSuiteCfg ssc = XmlSerializerExt.Deserialize <SessionSuiteCfg>(
                Path.Combine(testResourcesPath, "SessionSuiteCfg_Test.xml"));

            Assert.IsNotNull(ssc);
            Assert.AreEqual("Test Suite", ssc.Name);
            Assert.AreEqual(2, ssc.LocalPlayers.Length);
            Assert.AreEqual("RaiserBot1", ssc.LocalPlayers[0].Name);
            Assert.AreEqual("players.dll", ssc.LocalPlayers[0].Assembly.RawValue);
            Assert.AreEqual("players.RaiserBot", ssc.LocalPlayers[0].Type.RawValue);
            Assert.AreEqual(1, ssc.LocalPlayers[0].CreationParameters.Count);
            Assert.AreEqual("Some creation configuration", ssc.LocalPlayers[0].CreationParameters.Get("p1"));
            Assert.AreEqual(2, ssc.Sessions.Length);
            // Session 0
            Assert.AreEqual("Ring Game", ssc.Sessions[0].Name);
            Assert.AreEqual(SessionKind.RingGame, ssc.Sessions[0].Kind);
            Assert.AreEqual(1000, ssc.Sessions[0].GamesCount);
            Assert.AreEqual(36, ssc.Sessions[0].RngSeed);
            Assert.AreEqual(2, ssc.Sessions[0].Players.Length);
            Assert.AreEqual("RaiserBot1", ssc.Sessions[0].Players[0].Name);
            Assert.AreEqual(2, ssc.Sessions[0].Players[0].SessionParameters.Count);
            Assert.AreEqual("v1", ssc.Sessions[0].Players[0].SessionParameters.Get("p1"));
            Assert.AreEqual("v2", ssc.Sessions[0].Players[0].SessionParameters.Get("p2"));
            Assert.AreEqual("GameDef1", ssc.Sessions[0].GameDefinition.Name);

            // Session 1
            Assert.AreEqual(0, ssc.Sessions[1].RngSeed);
            Assert.AreEqual("GameDef2", ssc.Sessions[1].GameDefinition.Name);
        }
コード例 #2
0
        public void Test_BuildFiles()
        {
            int heroPos = 0;

            string         gdFile = Props.Global.Expand("${bds.DataDir}\\ai.pkr.metastrategy.kuhn.gamedef.1.xml");
            GameDefinition gd     = XmlSerializerExt.Deserialize <GameDefinition>(gdFile);

            string workingDir = Directory.GetCurrentDirectory() + @"..\..\..\..\";

            Console.Write("Game:{0} pos:{1}", gd.Name, heroPos);
            EquilibriumSolverLp solver = new EquilibriumSolverLp();

            solver.HeroPosition = heroPos;
            solver.GameDef      = gd;
            solver.Calculate();

            using (TextWriter tw = new StreamWriter(Path.Combine(workingDir, "hero-tree.gv")))
            {
                HeroTreeVis vis = new HeroTreeVis {
                    Output = tw, Solver = solver
                };
                vis.MergePrivateDeals = true;
                vis.GraphAttributes.Map["fontname"] = "arial";

                vis.GraphAttributes.fontsize = 10;
                vis.EdgeAttributes.fontsize  = 10;
                vis.NodeAttributes.fontsize  = 10;

                vis.Walk(solver.PlayerTrees[heroPos]);
            }

            using (TextWriter tw = new StreamWriter(Path.Combine(workingDir, "game-tree.gv")))
            {
                GameTreeVis vis = new GameTreeVis {
                    Output = tw, Solver = solver
                };
                vis.MergePrivateDeals = true;
                vis.GraphAttributes.Map["fontname"] = "arial";

                vis.GraphAttributes.fontsize = 10;
                vis.EdgeAttributes.fontsize  = 10;
                vis.NodeAttributes.fontsize  = 10;

                vis.Walk(solver.GameTree);
            }

            using (TextWriter tw = new StreamWriter(Path.Combine(workingDir, "opp-tree.gv")))
            {
                OppTreeVis vis = new OppTreeVis {
                    Output = tw, Solver = solver
                };
                vis.GraphAttributes.Map["fontname"] = "arial";

                vis.GraphAttributes.fontsize = 10;
                vis.EdgeAttributes.fontsize  = 10;
                vis.NodeAttributes.fontsize  = 10;

                vis.Walk(solver.PlayerTrees[1 - heroPos]);
            }
        }
コード例 #3
0
        public void Test_XmlSerialization()
        {
            DeckDescriptor dd = new DeckDescriptor("TestDeck", _cardNames1, _cardSets1);

            StringBuilder sb = new StringBuilder();

            using (TextWriter tw = new StringWriter(sb))
            {
                dd.XmlSerialize(tw);
            }

            Console.WriteLine(sb.ToString());

            DeckDescriptor dd2;

            using (TextReader textReader = new StringReader(sb.ToString()))
            {
                dd2 = XmlSerializerExt.Deserialize <DeckDescriptor>(textReader);
            }

            dd2.ConstructFromXml(null);

            Assert.IsNotNull(dd2);

            Assert.AreEqual(dd.Name, dd2.Name);
            Assert.AreEqual(dd.Size, dd2.Size);
            Assert.AreEqual(dd.CardNames, dd2.CardNames);
            Assert.AreEqual(dd.CardSets, dd2.CardSets);
            Assert.AreEqual(dd.FullDeck, dd2.FullDeck);
            Assert.AreEqual(dd.FullDeckIndexes, dd2.FullDeckIndexes);
        }
コード例 #4
0
        public void Test_CopyConstructor()
        {
            string         testResourcesPath = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly());
            GameDefinition gd1;

            XmlSerializerExt.Deserialize(out gd1, Path.Combine(testResourcesPath, "gamedef-test.xml"));

            GameDefinition gd2 = new GameDefinition(gd1);

            Assert.AreEqual(gd1.Name, gd2.Name);
            Assert.AreEqual(gd1.RoundsCount, gd2.RoundsCount);
            Assert.AreEqual(gd1.MinPlayers, gd2.MinPlayers);
            Assert.AreEqual(gd1.MaxPlayers, gd2.MaxPlayers);
            Assert.AreEqual(gd1.BetStructure, gd2.BetStructure);
            Assert.AreEqual(gd1.BlindStructure, gd2.BlindStructure);
            Assert.AreEqual(gd1.PrivateCardsCount, gd2.PrivateCardsCount);
            Assert.AreEqual(gd1.PublicCardsCount, gd2.PublicCardsCount);
            Assert.AreEqual(gd1.SharedCardsCount, gd2.SharedCardsCount);
            Assert.AreEqual(gd1.BetsCountLimits, gd2.BetsCountLimits);
            Assert.AreEqual(gd1.FirstActor, gd2.FirstActor);
            Assert.AreEqual(gd1.FirstActorHeadsUp, gd2.FirstActorHeadsUp);
            Assert.AreEqual(gd1.LimitKind, gd2.LimitKind);
            Assert.AreEqual(gd1.DeckDescrFile, gd2.DeckDescrFile);
            Assert.AreEqual(gd1.DeckDescr, gd2.DeckDescr);
            Assert.AreEqual(gd1.GameRulesAssemblyFile, gd2.GameRulesAssemblyFile);
            Assert.AreEqual(gd1.GameRulesType, gd2.GameRulesType);
            Assert.AreEqual(gd1.GameRulesCreationParams, gd2.GameRulesCreationParams);
            Assert.AreEqual(gd1.GameRules, gd2.GameRules);
        }
コード例 #5
0
        public void Test_XmlSerialization()
        {
            PlayerState ps1 = new PlayerState();

            ps1.Stack = 100;
            ps1.Bet   = 23;
            ps1.Hand  = "Ah Ad";

            StringBuilder sb = new StringBuilder();

            using (TextWriter tw = new StringWriter(sb))
            {
                ps1.XmlSerialize(tw);
            }

            Console.WriteLine(sb.ToString());

            PlayerState ps2;

            using (TextReader tr = new StringReader(sb.ToString()))
            {
                XmlSerializerExt.Deserialize(out ps2, tr);
            }

            Assert.AreEqual(ps1, ps2);
        }
コード例 #6
0
        public void Test_DeserializeHandWrittenWithSchema()
        {
            string subdirName        = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            string testResourcesPath = Path.Combine(Props.Global.Get("bds.TestDir"), subdirName);

            GameDefinition gd;

            XmlSerializerExt.Deserialize(out gd, Path.Combine(testResourcesPath, "gamedef-test.xml"));

            Assert.IsNotNull(gd);
            Assert.AreEqual("HE.FL.Max2", gd.Name);
            Assert.AreEqual(new int[] { 4, 4, 4, 4 }, gd.BetsCountLimits);
            Assert.AreEqual(new double[] { 1, 1, 2, 2 }, gd.BetStructure);
            Assert.AreEqual(new double[] { .5, 1 }, gd.BlindStructure);
            Assert.AreEqual(new int[] { 2, 0, 0, 0 }, gd.PrivateCardsCount);
            Assert.AreEqual(new int[] { 0, 0, 0, 0 }, gd.PublicCardsCount);
            Assert.AreEqual(new int[] { 0, 3, 1, 1 }, gd.SharedCardsCount);
            Assert.AreEqual(new int[] { 2, 0, 0, 0 }, gd.FirstActor);
            Assert.AreEqual(new int[] { 0, 1, 1, 1 }, gd.FirstActorHeadsUp);
            Assert.AreEqual(LimitKind.FixedLimit, gd.LimitKind);
            Assert.AreEqual(2, gd.MinPlayers);
            Assert.AreEqual(2, gd.MaxPlayers);
            Assert.AreEqual(4, gd.RoundsCount);
            Assert.AreEqual(1, gd.GameRulesCreationParams.Count);
            Assert.AreEqual("Test configuration", gd.GameRulesCreationParams.Get("p1"));

            Assert.AreEqual("TestDeckDescriptor", gd.DeckDescr.Name);

            Assert.IsNotNull(gd.GameRules);
            Assert.IsTrue(gd.GameRules is GameRulesHelper);
            GameRulesHelper testGameRules = (GameRulesHelper)gd.GameRules;

            Assert.AreEqual(1, testGameRules.Config.Count);
            Assert.AreEqual("Test configuration", testGameRules.Config.Get("p1"));
        }
コード例 #7
0
        public void Test_XmlSerialization()
        {
            GameDefinition gd1 = new GameDefinition();

            gd1.MinPlayers      = 2;
            gd1.MaxPlayers      = 2;
            gd1.BetsCountLimits = new int[] { 4, 4, 4, 4 };
            gd1.BetStructure    = new double[] { 1, 1, 2, 2 };

            StringBuilder sb = new StringBuilder();

            using (TextWriter tw = new StringWriter(sb))
            {
                gd1.XmlSerialize(tw);
            }

            Console.WriteLine(sb.ToString());

            GameDefinition gd2;

            using (TextReader textReader = new StringReader(sb.ToString()))
            {
                XmlSerializerExt.Deserialize(out gd2, textReader);
            }

            Assert.IsNotNull(gd2);
        }
コード例 #8
0
        public static void ToTxt(StrategyTree t, TextWriter w)
        {
            w.WriteLine("SeralizationFormat {0}", SERIALIZATION_FORMAT);
            XmlWriterSettings s = new XmlWriterSettings {
                Indent = false, NewLineChars = ""
            };

            w.Write("Version ");
            XmlSerializerExt.Serialize(t.Version, w, s);
            w.WriteLine();
            w.WriteLine("NodesCount {0}", t.NodesCount);
            for (Int64 n = 0; n < t.NodesCount; ++n)
            {
                w.WriteLine("Id {0}", n);
                w.WriteLine("D {0}", t.GetDepth(n));
                w.WriteLine("P {0}", t.Nodes[n].Position);
                if (t.Nodes[n].IsDealerAction)
                {
                    w.WriteLine("C {0}", t.Nodes[n].Card);
                }
                else
                {
                    w.WriteLine("A {0}", TextDumpHelper.DoubleToBinString(t.Nodes[n].Amount));
                    w.WriteLine("Pr {0}", TextDumpHelper.DoubleToBinString(t.Nodes[n].Probab));
                }
            }
        }
コード例 #9
0
        public void Test_LeducHe()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/leduc-he.gamedef.xml"));

            ShowTree(gd);
        }
コード例 #10
0
        public void Test_Session()
        {
            string testResourcesPath = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly());

            instance           = this;
            SessionSuiteRunner = new SessionSuiteRunner();
            SessionSuiteRunner.Configuration = XmlSerializerExt.Deserialize <SessionSuiteCfg>(
                Path.Combine(testResourcesPath, "SessionSuiteRunner_Test_Sessions.xml"));

            SessionSuiteRunner.Run();

            Assert.AreEqual(2, _players.Count);


            Assert.IsNotNull(_gameRules1);
            Assert.AreEqual(1, _gameRules1.OnCreateCount);

            Assert.IsNotNull(_gameRules2);
            Assert.AreEqual(1, _gameRules2.OnCreateCount);

            for (int p = 0; p < _players.Count; ++p)
            {
                Assert.AreEqual(1, _players[p].OnServerConnectCount);
                Assert.AreEqual(1, _players[p].OnServerDisconnectCount);
                Assert.AreEqual(2, _players[p].OnSessionBeginCount);
                Assert.AreEqual(2, _players[p].OnSessionEndCount);
                Assert.AreEqual(5, _players[p].OnGameBeginCount);
                Assert.AreEqual(10, _players[p].OnActionRequiredCount);
                Assert.AreEqual(5, _players[p].OnGameEndCount);
            }
        }
コード例 #11
0
        public void Test_AnalyzeS()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml"));
            ChanceTree ct0 = CreateChanceTreeByGameDef.Create(gd);

            AnalyzeChanceTree.AnalyzeS(ct0);
        }
コード例 #12
0
        public void Test_LeducHe()
        {
            _gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/leduc-he.gamedef.xml"));
            ActionTree tree = CreateActionTreeByGameDef.Create(_gd);

            VerifyActionTree(tree, _expLeducHe);
        }
コード例 #13
0
        public void Test_Kuhn()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml"));
            ChanceTree ct = CreateChanceTreeByGameDef.Create(gd);

            double [] expectedProbabs = new double[] { 1, 1.0 / 3, 1.0 / 3, 1.0 / 3 };
            CreateAndVerifyPlayerTrees(gd, ct, expectedProbabs);
        }
コード例 #14
0
        GameDefinition LoadGameDef()
        {
            string         subdirName        = Path.GetFileNameWithoutExtension(Assembly.GetExecutingAssembly().CodeBase);
            string         testResourcesPath = Path.Combine(Props.Global.Get("bds.TestDir"), subdirName);
            GameDefinition gd;

            XmlSerializerExt.Deserialize(out gd, Path.Combine(testResourcesPath, "gamedef-test.xml"));
            return(gd);
        }
コード例 #15
0
        public void Test_GetHandSizes()
        {
            string         testResourcesPath = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly());
            GameDefinition gd =
                XmlSerializerExt.Deserialize <GameDefinition>(Path.Combine(testResourcesPath, "gamedef-test.xml"));

            int[] handSizes = gd.GetHandSizes();
            Assert.AreEqual(new int [] { 2, 5, 6, 7 }, handSizes);
        }
コード例 #16
0
        public void Test_CompareS()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml"));
            ChanceTree ct1 = CreateChanceTreeByGameDef.Create(gd);
            ChanceTree ct2 = CreateChanceTreeByGameDef.Create(gd);

            CompareChanceTrees.CompareS(ct1, ct2);
        }
コード例 #17
0
        static void SaveActionTree()
        {
            Console.WriteLine("Writing opponent action tree to {0} ...", _cmdLine.oppActionTreeFile);

            XmlWriterSettings xws = new XmlWriterSettings();

            xws.Indent = false;
            XmlSerializerExt.Serialize(_oppActionTree, _cmdLine.oppActionTreeFile, xws);
        }
コード例 #18
0
        /// <summary>
        /// Plays the following scenario:
        /// 1. Prepares chance abstractions.
        /// 2. Computes a eq-strategy by EqLp.
        /// 3. Computes a BR on the eq strategies.
        /// 4. Runs a session with 2 instances of Patience, one is playing eq, the other br.
        /// 5. Compares actual game result with the predicted game value.
        /// The test is trying to reuse chance abstractions and merge strategies for different positions
        /// if the abstraction is the same.
        /// <param name="baseDir">The function copies all config files from _testResourceDir/baseDir
        /// to _outDir/baseDir-eq and _outDir/baseDir-br, all intermediate files are also created here.</param>
        /// </summary>
        void PlayEqVsBr(string [] bucketizerStrings, int sessionGamesCount, int sessionRepetitionCount, double relativeTolerance)
        {
            Console.WriteLine("Run eq vs eq for chance abstractions:");
            for (int p = 0; p < bucketizerStrings.Length; ++p)
            {
                Console.WriteLine("pos: {0} bucket string: {1}", p, bucketizerStrings[0]);
            }

            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/${0}", "leduc-he.gamedef.xml"));

            string runDir = PrepareRunDir("EqVsBr_Leduc");

            IChanceAbstraction [] chanceAbstractions = PrepareConfigsAndChanceAbstractions(runDir, bucketizerStrings);
            double []             brValues           = new double[gd.MinPlayers];
            SolveGame(runDir, gd, chanceAbstractions, brValues);

            Console.WriteLine("Values of BR strategies:");
            for (int p = 0; p < brValues.Length; ++p)
            {
                Console.WriteLine("pos: {0} val: {1:0.00} mb0/g", p, brValues[p] * 1000);
            }

            // To tell the bots where the configs are:
            Props.Global.Set("dev.TestRunDir", runDir);

            runDir = CopyDirForEachBot(runDir, gd.MinPlayers);
            // Now runDir is eq dir.

            _actualResult = new TotalResult {
                Name = "Actual result"
            };

            string             ssConfigFile = Path.Combine(runDir, "ss.xml");
            SessionSuiteRunner runner       = new SessionSuiteRunner();

            runner.Configuration = XmlSerializerExt.Deserialize <SessionSuiteCfg>(ssConfigFile);
            runner.Configuration.Sessions[0].GamesCount  = sessionGamesCount;
            runner.Configuration.Sessions[0].RepeatCount = sessionRepetitionCount;
            runner.IsLoggingEnabled = false;
            runner.OnGameEnd       += new SessionSuiteRunner.OnGameEndHandler(runner_OnGameEnd);
            runner.Run();

            _actualResult.Print(Console.Out);

            for (int p = 0; p < gd.MinPlayers; ++p)
            {
                double expectedResult = brValues[p] * 1000;
                double actualResult   = _actualResult.Players["Patience-Br"].Rate(p);
                double epsilon        = Math.Abs(expectedResult * relativeTolerance);
                Assert.AreEqual(expectedResult, actualResult, epsilon);
            }

            // We can use the files created in other tests.
            //DeleteBotDirs(runDir);
        }
コード例 #19
0
        public void Test_GetAbstractCard()
        {
            Props parameters            = XmlSerializerExt.Deserialize <Props>(Path.Combine(_testResDir, "ca-hssd-ahvo-km.xml"));
            HsSdAhvoKMeansAdaptiveCa ca = CalculateCa(parameters, new int[] { 0, 5000, 5000, 5000 }, 1);

            VerifyPreflopPockets(ca);

            DeckDescriptor dd = StdDeck.Descriptor;

            int[] hand;

            // In comments there are normalized values to verify in debugger.

            #region Preflop bucket 7 (AA)

            //------------------------------------------------------------
            //	0.61537	0.42559	0.09124
            hand = dd.GetIndexes("Ac As Kh 5h 2d");
            Assert.AreEqual(3, ca.GetAbstractCard(hand, hand.Length));

            //	0.63778	0.43364	0.35852
            hand = dd.GetIndexes("Ad As 7s 7h 5s");
            Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length));

            #endregion

            #region Preflop bucket 7 (AA), flop bucket 4

            hand = dd.GetIndexes("Ac Ah Td Jh Js 5h");
            Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length - 1));
            // 0.647707503 0.222747622 0.335863970
            Assert.AreEqual(6, ca.GetAbstractCard(hand, hand.Length));

            hand = dd.GetIndexes("Ad Ah 5d 5s Ks 2d");
            Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length - 1));
            // 0.642999891 0.228836240 0.187371225
            Assert.AreEqual(7, ca.GetAbstractCard(hand, hand.Length));

            #endregion

            #region Preflop bucket 7 (AA), flop bucket 4, turn bucket 6

            hand = dd.GetIndexes("Ac Ad 2h Qd Qh 3s 2s");
            Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length - 2));
            Assert.AreEqual(6, ca.GetAbstractCard(hand, hand.Length - 1));
            // 0.20689665	0.00000000	0.44819598
            Assert.AreEqual(1, ca.GetAbstractCard(hand, hand.Length));

            hand = dd.GetIndexes("Ad Ah Qd Th Td 7c Jd");
            Assert.AreEqual(4, ca.GetAbstractCard(hand, hand.Length - 2));
            Assert.AreEqual(6, ca.GetAbstractCard(hand, hand.Length - 1));
            // 0.22068975	0.00000000	0.16117185
            Assert.AreEqual(2, ca.GetAbstractCard(hand, hand.Length));

            #endregion
        }
コード例 #20
0
        private static void Run()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            MainWindow mw = new MainWindow();

            mw.Player  = CreatePlayer();
            mw.GameDef = XmlSerializerExt.Deserialize <GameDefinition>(_cmdLine.GameDef);
            Application.Run(mw);
        }
コード例 #21
0
        public void Test_LeducHe()
        {
            _gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/leduc-he.gamedef.xml"));
            ChanceTree ct = CreateChanceTreeByGameDef.Create(_gd);

            _verifyLeaf = VerifyLeaf_LeducHe;
            DoVerifyChanceTree(ct);
            Assert.AreEqual(2, ct.CalculateRoundsCount());
        }
コード例 #22
0
        ///<summary>
        ///<para>Parameters:</para>
        ///<para>IsCreatingClusterTree: (bool, optional, default: false). Indicates that the object is created to create a cluster tree.</para>
        ///<para>ClusterTreeFile: (string, required). File with the cluster tree. Is ignored during cluster tree creation.</para>
        ///<para>MinBucketCounts: (string, required) minimal number of buckets for each round, one-space separated.</para>
        ///<para>MaxBucketCounts: (string, required) maximal number of buckets for each round, one-space separated.</para>
        ///<para>ClusterSizes#: (string, optional, default: 1e-9 1e-9 1e-9 1e-9) for each dimension: space separated lengths of one cluster for each round.
        ///Value for preflop is ignored. For each round the min. number of clusters of all dimesions will be taken.
        ///Zero-cluster sizes are exclued from the calculatíon.</para>
        ///<para>KMeansStages: (int, required)  number of k-means stages.</para>
        ///<para>Pockets#: (string, required) preflop pockets for bucket #.</para>
        ///<para>NormalizeHandValues: (bool, optional, default: false)  normalizes values for each coordinate so that they are in  [0..1].</para>
        ///<para>PrintHands: (bool, optional, default: false)  print sampled hands.</para>
        ///<para>PrintHandValues: (bool, optional, default: false)  for cluster tree creation: if true, prints values for each hand.</para>
        ///</summary>
        public KMeansAdaptiveCaBase(int dim, Props parameters)
        {
            Dim        = dim;
            Parameters = parameters;

            _deck = XmlSerializerExt.Deserialize <DeckDescriptor>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metagame/${0}", "stddeck.xml"));

            bool isCreatingClusterTree = bool.Parse(Parameters.GetDefault("IsCreatingClusterTree", "false"));

            _printHandValues     = bool.Parse(Parameters.GetDefault("PrintHandValues", "false"));
            _printHands          = bool.Parse(Parameters.GetDefault("PrintHands", "false"));
            _normalizeHandValues = bool.Parse(Parameters.GetDefault("NormalizeHandValues", "false"));


            MaxBucketCounts = ParseBucketsString(Parameters.Get("MaxBucketCounts"));
            MinBucketCounts = ParseBucketsString(Parameters.Get("MinBucketCounts"));

            if (MinBucketCounts[0] != MaxBucketCounts[0])
            {
                throw new ApplicationException(string.Format("Max and min preflop bucket counts must be equal, was: {0}, {1}",
                                                             MinBucketCounts[0], MaxBucketCounts[0]));
            }

            ClusterSizes = new double[Dim][];
            for (int d = 0; d < Dim; ++d)
            {
                ClusterSizes[d] = ParseDoubles(Parameters.GetDefault("ClusterSizes" + d.ToString(), "1e-9 1e-9 1e-9 1e-9"));
            }

            _pfPocketCa = new PreflopPocketCA(parameters, MaxBucketCounts[0]);

            if (_pfPocketCa.PocketKindToAbstrCard == null)
            {
                throw new ApplicationException("Preflop pockets must be specified manually");
            }

            _kmParameters.SetDefaultTerm();
            _kmParameters.dim       = Dim;
            _kmParameters.term_st_a = int.Parse(Parameters.Get("KMeansStages"));
            _kmParameters.term_st_b = _kmParameters.term_st_c = _kmParameters.term_st_d = 0;
            _kmParameters.seed      = 1;


            if (!isCreatingClusterTree)
            {
                string clusterTreeFile = Parameters.Get("ClusterTreeFile");
                if (!File.Exists(clusterTreeFile))
                {
                    throw new ApplicationException(string.Format("Cluster tree file '{0}' does not exist", clusterTreeFile));
                }
                _clusterTree = ClusterTree.Read(clusterTreeFile);
            }
        }
コード例 #23
0
        public void Test_FindNode()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml"));
            StrategyTree st = TreeHelper.CreateStrategyTree(gd, 0);

            Assert.AreEqual(3, st.FindNode("0dJ", gd.DeckDescr));
            Assert.AreEqual(11, st.FindNode("0dJ 0p1 1p1", gd.DeckDescr));
            Assert.AreEqual(13, st.FindNode("0dQ 0p0", gd.DeckDescr));
            Assert.AreEqual(16, st.FindNode("0d1 0p0 1p1 0p0", null));
        }
コード例 #24
0
 public void ConstructFromXml(ConstructFromXmlParams parameters)
 {
     if (GameDefinitionFile != null)
     {
         string gdFile = GameDefinitionFile.Get(parameters.Local);
         if (gdFile != "")
         {
             GameDefinition = XmlSerializerExt.Deserialize <GameDefinition>(gdFile);
         }
     }
 }
コード例 #25
0
            public GameDefParams(FictitiousPlay_Test test, string gameDefFile, double epsilon)
            {
                Epsilon = epsilon;

                GameDef = XmlSerializerExt.Deserialize <GameDefinition>(Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/${0}", gameDefFile));

                Name = GameDef.Name;

                ChanceTree = CreateChanceTreeByGameDef.Create(GameDef);
                ActionTree = CreateActionTreeByGameDef.Create(GameDef);
            }
コード例 #26
0
        public void Test_LoadFromXml()
        {
            string testResourcesPath = UTHelperPrivate.GetTestResourcesPath();

            Profile p =
                XmlSerializerExt.Deserialize <Profile>(Path.Combine(testResourcesPath, "Profile_Test-profile1.xml"));

            Assert.AreEqual("pvalue1", p.Properties.Get("pvar1"));
            Assert.AreEqual("pvalue2", p.Properties.Get("pvar2"));
            Assert.IsTrue(p.Properties.XmlMergeWithGlobal);
        }
コード例 #27
0
ファイル: Props_Test.cs プロジェクト: ivan-alles/poker-acpc
        public void Test_XmlSerialize()
        {
            // Just print xml to console, no checks for now.
            Props p = new Props();

            p.Set("p1", "val1");
            XmlSerializerExt.Serialize(p, Console.Out);
            p.XmlMergeWithGlobal = false;
            Console.WriteLine();
            XmlSerializerExt.Serialize(p, Console.Out);
        }
        public void Test_LeducHe()
        {
            GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/leduc-he.gamedef.xml"));

            for (int pos = 0; pos < gd.MinPlayers; ++pos)
            {
                StrategyTree st = TreeHelper.CreateStrategyTree(gd, pos);
                Assert.AreEqual(st.PlayersCount, gd.MinPlayers);
                Assert.AreEqual(723, st.NodesCount);
            }
        }
コード例 #29
0
        ///<summary>
        ///<para>Parameters:</para>
        ///<para>IsCreatingClusterTree: (bool, optional, default: false). Indicates that the object is created to create a cluster tree.</para>
        ///<para>ClusterTreeFile: (string, required). File with the cluster tree. Is ignored during cluster tree creation.</para>
        ///<para>MinBucketCounts: (string, required) minimal number of buckets for each round, one-space separated.</para>
        ///<para>MaxBucketCounts: (string, required) maximal number of buckets for each round, one-space separated.</para>
        ///<para>ClusterSizes: (string, required)  for each round: space separated HS range for one cluster. Value for preflop is ignored.</para>
        ///<para>Pockets#: (string, required) preflop pockets for bucket #.</para>
        ///<para>PrintHandValues: (bool, optional)  for cluster tree creation: if true, prints values for each hand.</para>
        ///</summary>
        public HsRangeAdaptiveCa(Props parameters)
        {
            Parameters = parameters;

            _deck = XmlSerializerExt.Deserialize <DeckDescriptor>(
                Props.Global.Expand("${bds.DataDir}ai.pkr.metagame/${0}", "stddeck.xml"));

            bool isCreatingClusterTree = false;

            if (!string.IsNullOrEmpty(Parameters.Get("IsCreatingClusterTree")))
            {
                isCreatingClusterTree = bool.Parse(Parameters.Get("IsCreatingClusterTree"));
            }

            _printHandValues = false;
            if (!string.IsNullOrEmpty(Parameters.Get("PrintHandValues")))
            {
                _printHandValues = bool.Parse(Parameters.Get("PrintHandValues"));
            }


            MaxBucketCounts = ParseBucketsString(Parameters.Get("MaxBucketCounts"));
            MinBucketCounts = ParseBucketsString(Parameters.Get("MinBucketCounts"));

            if (MinBucketCounts[0] != MaxBucketCounts[0])
            {
                throw new ApplicationException(string.Format("Max and min preflop bucket counts must be equal, was: {0}, {1}",
                                                             MinBucketCounts[0], MaxBucketCounts[0]));
            }

            ClusterSizes = ParseDoubles(Parameters.Get("ClusterSizes"));

            _pfPocketCa = new PreflopPocketCA(parameters, MaxBucketCounts[0]);

            if (_pfPocketCa.PocketKindToAbstrCard == null)
            {
                throw new ApplicationException("Preflop pockets must be specified manually");
            }

            if (!isCreatingClusterTree)
            {
                string clusterTreeFile = Parameters.Get("ClusterTreeFile");
                if (!File.Exists(clusterTreeFile))
                {
                    throw new ApplicationException(string.Format("Cluster tree file '{0}' does not exist", clusterTreeFile));
                }
                _clusterTree = ClusterTree.Read(clusterTreeFile);
            }

            string shortDescription = Parameters.Get("ShortDescription") ?? "";

            Name = "HE-HSRA-" + shortDescription + "-" + Parameters.Get("MaxBucketCounts").Replace(" ", "x");
        }
コード例 #30
0
        public void Test_SD3_UnnormalizedAdaptive()
        {
            Props parameters = XmlSerializerExt.Deserialize <Props>(Path.Combine(_testResDir, "ca-hssd-km.xml"));

            parameters.Set("SdKind", "Sd3");
            parameters.Set("NormalizeHandValues", "false");
            parameters.Set("MinBucketCounts", "8 10 10 1");
            parameters.Set("MaxBucketCounts", "8 10 10 4");
            parameters.Set("ClusterSizes0", "0 0.05 0.05 0.05");
            parameters.Set("ClusterSizes1", "0 2 2 0");


            HsSdKMeansAdaptiveCa ca = CalculateCa(parameters, new int[] { 0, 5000, 5000, 200 }, 1);

            VerifyPreflopPockets(ca);

            DeckDescriptor dd = StdDeck.Descriptor;

            int[] hand;

            // In comments there are normalized values.

            #region Preflop bucket 3 (87s)

            //------------------------------------------------------------

            // 0.572431087493896 0.380353838205338
            hand = dd.GetIndexes("7d 8d 5d 5h 4d");
            Assert.AreEqual(5, ca.GetAbstractCard(hand, hand.Length));

            // 0.57322484254837 0.173631072044373
            hand = dd.GetIndexes("7c 8c 7s 2s As");
            Assert.AreEqual(6, ca.GetAbstractCard(hand, hand.Length));

            //------------------------------------------------------------
            #endregion

            #region Buckets 4,9,9 (adapted to one cluster, make sure min and max hs go to the same bucket 0)

            // Min hs
            // 0.953535377979279 0
            hand = dd.GetIndexes("5h 5s 3s 5c 3d 2c 3c");
            Assert.AreEqual(0, ca.GetAbstractCard(hand, hand.Length));


            // Max hs
            //  1 0
            hand = dd.GetIndexes("5h 5s 3d 5d 5c Jc 2h");
            Assert.AreEqual(0, ca.GetAbstractCard(hand, hand.Length));

            //------------------------------------------------------------
            #endregion
        }
コード例 #31
0
ファイル: XmlUtil.cs プロジェクト: tomochandv/Test
        public static object LoadObject(Type objectType, string filePath, out string resultText)
        {
            object result = null;

            XmlSerializerExt xs = new XmlSerializerExt(objectType);
            using (XmlTextReader xtr = new XmlTextReader(filePath))
            {
                result = xs.DeserializeWithEvents(xtr);
                resultText = xs.DeserializationResultText;

            }

            return result;
        }