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); } }
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); }
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); }
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); }
public void Test_Convert() { GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>( Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/leduc-he.gamedef.xml")); string testDir = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly()); ChanceTree ct1 = CreateChanceTreeByGameDef.Create(gd); // DumpChanceTree.ToTxt(ct1, Console.Out); MemoryStream ms = new MemoryStream(); using (TextWriter tw = new StreamWriter(ms)) { DumpChanceTree.ToTxt(ct1, tw); } byte[] buf = ms.ToArray(); ms = new MemoryStream(buf); ChanceTree ct2; using (TextReader tr = new StreamReader(ms)) { ct2 = DumpChanceTree.FromTxt(tr); } Assert.AreEqual(ct1.Version, ct2.Version); Assert.AreEqual(ct1.NodesCount, ct2.NodesCount); int roundsCount = ct1.CalculateRoundsCount(); double[] potShare1 = new double[ct1.PlayersCount]; double[] potShare2 = new double[ct1.PlayersCount]; for (Int64 n = 0; n < ct2.NodesCount; ++n) { Assert.AreEqual(ct1.GetDepth(n), ct2.GetDepth(n)); Assert.AreEqual(ct1.Nodes[n].Position, ct2.Nodes[n].Position); Assert.AreEqual(ct1.Nodes[n].Card, ct2.Nodes[n].Card); Assert.AreEqual(ct1.Nodes[n].Probab, ct2.Nodes[n].Probab); if (ct1.GetDepth(n) == ct1.PlayersCount * roundsCount) { UInt16 [] activePlayerMasks = ActivePlayers.Get(ct1.PlayersCount, 2, ct1.PlayersCount); foreach (UInt16 ap in activePlayerMasks) { ct1.Nodes[n].GetPotShare(ap, potShare1); ct2.Nodes[n].GetPotShare(ap, potShare2); Assert.AreEqual(potShare1, potShare2); } } } }
public void Test_Compare() { GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>( Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml")); string testDir = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly()); string strFile = Path.Combine(testDir, "eq-KunhPoker-0-s.xml"); StrategyTree st0 = XmlToStrategyTree.Convert(strFile, gd.DeckDescr); StrategyTree st1 = XmlToStrategyTree.Convert(strFile, gd.DeckDescr); CompareStrategyTrees comparer = new CompareStrategyTrees { IsVerbose = true }; comparer.Compare(st0, st1); for (int p = 0; p < 2; ++p) { Assert.AreEqual(0, comparer.SumProbabDiff[p]); Assert.AreEqual(0, comparer.MaxProbabDiff[p]); Assert.AreEqual(0, comparer.AverageProbabDiff[p]); Assert.AreEqual(13, comparer.PlayerNodesCount[p]); } // Now change a probability Assert.IsTrue(st0.Nodes[4].Probab <= 0.9); Assert.IsTrue(st0.Nodes[9].Probab >= 0.1); st0.Nodes[4].Probab += 0.1; st0.Nodes[9].Probab -= 0.1; comparer.Compare(st0, st1); Assert.AreEqual(0.2, comparer.SumProbabDiff[0], 1e-8); Assert.AreEqual(0.1, comparer.MaxProbabDiff[0], 1e-8); Assert.AreEqual(0.2 / 13, comparer.AverageProbabDiff[0], 1e-8); Assert.AreEqual(13, comparer.PlayerNodesCount[0]); Assert.AreEqual(0, comparer.SumProbabDiff[1]); Assert.AreEqual(0, comparer.MaxProbabDiff[1]); Assert.AreEqual(0, comparer.AverageProbabDiff[1]); Assert.AreEqual(13, comparer.PlayerNodesCount[1]); }
public void Test_Convert() { GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>( Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml")); string testDir = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly()); string xmlFile = Path.Combine(testDir, "eq-KunhPoker-0-s.xml"); StrategyTree st1 = XmlToStrategyTree.Convert(xmlFile, gd.DeckDescr); //StrategyTreeDump.ToTxt(st1, Console.Out); MemoryStream ms = new MemoryStream(); using (TextWriter tw = new StreamWriter(ms)) { DumpStrategyTree.ToTxt(st1, tw); } byte[] buf = ms.ToArray(); ms = new MemoryStream(buf); StrategyTree st2; using (TextReader tr = new StreamReader(ms)) { st2 = DumpStrategyTree.FromTxt(tr); } Assert.AreEqual(st1.Version, st2.Version); Assert.AreEqual(st1.NodesCount, st2.NodesCount); for (Int64 n = 0; n < st2.NodesCount; ++n) { Assert.AreEqual(st1.GetDepth(n), st2.GetDepth(n)); Assert.AreEqual(st1.Nodes[n].Position, st2.Nodes[n].Position); Assert.AreEqual(st1.Nodes[n].IsDealerAction, st2.Nodes[n].IsDealerAction); if (st1.Nodes[n].IsDealerAction) { Assert.AreEqual(st1.Nodes[n].Card, st2.Nodes[n].Card); } else { Assert.AreEqual(st1.Nodes[n].Amount, st2.Nodes[n].Amount); Assert.AreEqual(st1.Nodes[n].Probab, st2.Nodes[n].Probab); } } }
public void Test_Game() { string testResourcesPath = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly()); instance = this; SessionSuiteRunner = new SessionSuiteRunner(); SessionSuiteRunner.Configuration = XmlSerializerExt.Deserialize <SessionSuiteCfg>( Path.Combine(testResourcesPath, "SessionSuiteRunner_Test_2Players.Sessions.xml")); SessionSuiteRunner.Run(); int totalCardsCount = CalculateTotalCardsCount(); for (int p = 0; p < 2; ++p) { Assert.AreEqual(1, _players[p].OnGameBeginCount); Assert.AreEqual(1, _players[p].OnGameEndCount); } // Guest player did not play. Assert.AreEqual(0, _players[2].OnGameBeginCount); Assert.AreEqual(0, _players[2].OnGameEndCount); }
public void Test_Kuhn() { GameDefinition gd = XmlSerializerExt.Deserialize <GameDefinition>( Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/kuhn.gamedef.xml")); string testDir = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly()); string xmlFile = Path.Combine(testDir, "eq-KunhPoker-0-s.xml"); StrategyTree st = XmlToStrategyTree.Convert(xmlFile, gd.DeckDescr); // Do some random checks Assert.AreEqual(false, st.Nodes[4].IsDealerAction); Assert.AreEqual(0, st.Nodes[4].Position); Assert.AreEqual(0.666666666666667, st.Nodes[4].Probab); Assert.AreEqual(false, st.Nodes[6].IsDealerAction); Assert.AreEqual(1, st.Nodes[6].Position); Assert.AreEqual(1, st.Nodes[6].Amount); Assert.AreEqual(true, st.Nodes[12].IsDealerAction); Assert.AreEqual(0, st.Nodes[12].Position); Assert.AreEqual(1, st.Nodes[12].Card); }
// Naming convention: // Log file : baseName.log // Zipped log file: baseName.zip // Session suite : baseName-ss.xml void Replay(string baseName) { string testResourcesPath = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly()); string tempDir = Path.GetTempPath(); string configZip = Path.Combine(testResourcesPath, baseName + ".zip"); FastZip fz = new FastZip(); fz.ExtractZip(configZip, tempDir, FastZip.Overwrite.Always, null, "", "", true); string origLogPath = Path.Combine(tempDir, baseName + ".log"); string ssConfigFile = Path.Combine(testResourcesPath, baseName + "-ss.xml"); _ssRunner = new SessionSuiteRunner(); _ssRunner.Configuration = XmlSerializerExt.Deserialize <SessionSuiteCfg>(ssConfigFile); _ssRunner.IsLoggingEnabled = true; _ssRunner.LogDir = tempDir; // Replace XML path to the log being replayed with the actual path from the temp directory. _ssRunner.Configuration.Sessions[0].ReplayFrom = origLogPath; for (int p = 0; p < _ssRunner.Configuration.LocalPlayers.Length; ++p) { _ssRunner.Configuration.LocalPlayers[p].CreationParameters.Set("ReplayFrom", origLogPath); } _ssRunner.Run(); string hint; bool comparisonResult = GameLogComparer.Compare(_ssRunner.Configuration.Sessions[0].ReplayFrom.Get(Props.Global), _ssRunner.CurrentLogFile, out hint, int.MaxValue); Console.WriteLine("Original log:" + _ssRunner.Configuration.Sessions[0].ReplayFrom); Console.WriteLine("Replayed log:" + _ssRunner.CurrentLogFile); Console.WriteLine(hint); Assert.IsTrue(comparisonResult); }
public void Test_XmlSerialization() { SessionSuiteCfg ssc1 = new SessionSuiteCfg(); string testResDir = UTHelper.GetTestResourceDir(Assembly.GetExecutingAssembly()); ssc1.Name = "Suite1"; ssc1.LocalPlayers = new LocalPlayerCfg[2] { new LocalPlayerCfg { Assembly = "Players.dll", Type = "SuperBot", Name = "SuperBot1", CreationParameters = new string[] { "Param1", "1" } }, new LocalPlayerCfg { Assembly = "Players.dll", Type = "PuperBot", Name = "PuperBot1", CreationParameters = new Dictionary <string, string> { { "Param1", "2" } } } }; ssc1.Sessions = new SessionCfg[2] { new SessionCfg("Ring Game", SessionKind.RingGame, testResDir + "SessionSuiteCfg_Test.Gamedef1.xml"), new SessionCfg("Ring Game With Seat Permutation", SessionKind.RingGameWithSeatPermutations, testResDir + "SessionSuiteCfg_Test.Gamedef1.xml") }; ssc1.Sessions[0].GamesCount = 1000; ssc1.Sessions[0].Players = new PlayerSessionCfg[] { new PlayerSessionCfg { Name = "SuperBot1", SessionParameters = new Dictionary <string, string> { { "p1", "v1" } } }, new PlayerSessionCfg { Name = "PuperBot1", SessionParameters = new Dictionary <string, string> { { "p1", "v1" } } } }; ssc1.Sessions[1].GamesCount = 100; ssc1.Sessions[1].Players = new PlayerSessionCfg[] { new PlayerSessionCfg { Name = "SuperBot1", SessionParameters = new Dictionary <string, string> { { "p1", "v1" } } }, new PlayerSessionCfg { Name = "PuperBot1", SessionParameters = new Dictionary <string, string> { { "p1", "v1" } } } }; StringBuilder sb = new StringBuilder(); using (TextWriter tw = new StringWriter(sb)) { ssc1.XmlSerialize(tw); } Console.WriteLine(sb.ToString()); SessionSuiteCfg rc2; using (TextReader textReader = new StringReader(sb.ToString())) { XmlSerializerExt.Deserialize(out rc2, textReader); } Assert.IsNotNull(rc2); }