public static StrategyTree CreateStrategyTree(GameDefinition gd, int pos) { ChanceTree ct = CreateChanceTreeByGameDef.Create(gd); ChanceTree pct = ExtractPlayerChanceTree.ExtractS(ct, 0); ActionTree at = CreateActionTreeByGameDef.Create(gd); StrategyTree st = CreateStrategyTreeByChanceAndActionTrees.CreateS(pct, at); return(st); }
/// <summary> /// Create initial snapshot. /// To simplify the algo, we have a precondition: it always solves from a snapshot. /// For the case there is no snapshot this function creates a new one. /// </summary> private void CreateNewSnapshot() { if (IsVerbose) { Console.WriteLine("Creating initial snapshot {0}", _curSnapshotInfo.BaseDir); } // Creates strategies for each player and saves them. _pt = CreateStrategyTreeByChanceAndActionTrees.CreateS(_init.PlayerCt, _at); for (int p = 0; p < _playersCount; ++p) { SetInitialStrategy(p); } // Todo: no saving now //_pt.Write(_curSnapshotInfo.StrategyFile); // Do it at the end, where all snapshot-related fields are initialized. //SaveSnapshotAuxData(); }
public OcfrParams(GameValue_Test test, string name, string gameDefFile, IChanceAbstraction[] abstractions, string[] ocfrFiles, double[] expectedResult, double epsilon) { Epsilon = epsilon; ExpectedResult = expectedResult; GameDef = XmlSerializerExt.Deserialize <GameDefinition>( Props.Global.Expand("${bds.DataDir}ai.pkr.metastrategy/${0}", gameDefFile)); Name = name; OcfrFiles = new string[GameDef.MinPlayers].Fill(i => Path.Combine(test._testResDir, ocfrFiles[i])); if (abstractions == null) { ChanceTree = CreateChanceTreeByGameDef.Create(GameDef); } else { ChanceTree = CreateChanceTreeByAbstraction.CreateS(GameDef, abstractions); } //VisChanceTree.Show(ChanceTree, Path.Combine(test._outDir, String.Format("{0}-c.gv", GameDef.Name))); ActionTree = CreateActionTreeByGameDef.Create(GameDef); StrategyTrees = new StrategyTree[GameDef.MinPlayers]; for (int p = 0; p < GameDef.MinPlayers; ++p) { ChanceTree pct = ExtractPlayerChanceTree.ExtractS(ChanceTree, p); StrategyTrees[p] = CreateStrategyTreeByChanceAndActionTrees.CreateS(pct, ActionTree); OpenCfrStrategyConverter conv = new OpenCfrStrategyConverter { GameDef = GameDef, HeroPosition = p, SourceFile = OcfrFiles[p], Strategy = StrategyTrees[p], ChanceAbstraction = abstractions == null ? null : abstractions[p] }; conv.Convert(); //VisStrategyTree.Show(StrategyTrees[p], Path.Combine(test._outDir, String.Format("{0}-str-{1}.gv", GameDef.Name, p))); } }
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); ActionTree at = CreateActionTreeByGameDef.Create(gd); StrategyTree [] playerTrees = new StrategyTree[2]; for (int p = 0; p < 2; ++p) { ChanceTree pct = ExtractPlayerChanceTree.ExtractS(ct, p); StrategyTree st = CreateStrategyTreeByChanceAndActionTrees.CreateS(pct, at); playerTrees[p] = st; VisStrategyTree.Show(st, Path.Combine(_outDir, string.Format("pt-{0}.gv", p))); } }
private static bool ProcessStrategyTree() { StrategyTree tree; if (_cmdLine.Input != "") { if (_inputFormat == ".dat") { tree = UFTree.Read <StrategyTree>(_cmdLine.Input); } else if (_inputFormat == ".txt") { tree = DumpStrategyTree.FromTxt(_cmdLine.Input); } else { Console.Error.WriteLine("Unsupported input format '{0}' for tree kind '{1}'", _inputFormat, _cmdLine.TreeKind); return(false); } } else { ActionTree at = CreateActionTreeByGameDef.Create(_gd); ChanceTree ct = CreateChanceTreeByGameDef.Create(_gd); ChanceTree pct = ExtractPlayerChanceTree.ExtractS(ct, _cmdLine.Position); tree = CreateStrategyTreeByChanceAndActionTrees.CreateS(pct, at); } if (_outputFormat == ".gv") { using (TextWriter w = new StreamWriter(File.Open(_cmdLine.Output, FileMode.Create))) { VisStrategyTree vis = new VisStrategyTree { Output = w }; if (_gd != null) { vis.CardNames = _gd.DeckDescr.CardNames; } if (_cmdLine.ClearExpr) { vis.ShowExpr.Clear(); } vis.ShowExprFromString(_cmdLine.ShowExpr); vis.PruneIfExt = (t, n, s, d) => s[d].Round > _cmdLine.MaxRound; vis.MatchPath = _cmdLine.MatchPath; vis.Show(tree, _cmdLine.Root); } } else if (_outputFormat == ".xml") { using (TextWriter w = new StreamWriter(File.Open(_cmdLine.Output, FileMode.Create))) { XmlWriterSettings settings = new XmlWriterSettings(); settings.Encoding = Encoding.ASCII; settings.Indent = true; using (XmlWriter xmlWriter = XmlWriter.Create(w, settings)) { StrategyTreeToXml xmlizer = new StrategyTreeToXml { Output = xmlWriter }; if (_cmdLine.ClearExpr) { xmlizer.ShowExpr.Clear(); } xmlizer.ShowExprFromString(_cmdLine.ShowExpr); xmlizer.Convert(tree); } } } else if (_outputFormat == ".dat") { tree.Write(_cmdLine.Output); } else if (_outputFormat == ".txt") { DumpStrategyTree.ToTxt(tree, _cmdLine.Output); } else { Console.Error.WriteLine("Unsupported ouput format '{0}' for tree kind '{1}'", _outputFormat, _cmdLine.TreeKind); return(false); } return(true); }