void Initialize() { DateTime startTime = DateTime.Now; _at = ActionTree.Read <ActionTree>(ActionTreeFile); if (IsVerbose) { Console.WriteLine("Action tree: {0}", _at.Version.ToString()); } _init = new InitData(this); _playersCount = _at.PlayersCount; _epsilonLog = new List <EpsilonLogEntry>(); _snapshotSwitcher = new SnapshotSwitcher(OutputPath, GetSnapshotHeaderFileName(), SnapshotsCount); _curSnapshotInfo = new SnapshotInfo(_snapshotSwitcher.CurrentSnapshotPath, _playersCount); IterationCounts = new int[_playersCount]; LastBrValues = new double[_playersCount]; _ptExt = new Node[_playersCount][]; _rng = new System.Random(RngSeed); _mcDealer = new McDealer(GameDef, _rng); _hands = new int[_playersCount][].Fill(i => new int[_mcDealer.HandSize]); _handSizes = GameDef.GetHandSizes(); _oppGv = new double[_at.NodesCount]; bool isNewSnapshot = !_snapshotSwitcher.IsSnapshotAvailable; if (isNewSnapshot) { CreateNewSnapshot(); } //LoadSnapshot(); CreatePlayerTrees(); for (int p = 0; p < _playersCount; ++p) { if (TraceDir != null) { Vis.Show(this, p, GetTraceFileName(p, "tree", "init-pt", "gv")); } } if (TraceDir != null) { VisChanceTree.Show(_init.PlayerCt, GetTraceFileName(0, "pct", "", "gv")); } PrintInitDone(); // Clean-up _init = null; double time = (DateTime.Now - startTime).TotalSeconds; if (IsVerbose) { Console.WriteLine("Initialization done in {0:0.0} s", time); } }
static int Main(string[] args) { if (!Parser.ParseArgumentsWithUsage(args, _cmdLine)) { return(1); } if (_cmdLine.DebuggerLaunch) { Debugger.Launch(); } if (_cmdLine.DiagUnmanagedMemory) { UnmanagedMemory.IsDiagOn = true; Console.WriteLine("Unmanaged memory diagnostics is on"); } ActionTree at = ActionTree.Read <ActionTree>(_cmdLine.ActionTree); Console.WriteLine("Action tree: {0}", at.Version.ToString()); ChanceTree ct = ChanceTree.Read <ChanceTree>(_cmdLine.ChanceTree); Console.WriteLine("Chance tree: {0}", ct.Version.ToString()); StrategyTree oppSt = StrategyTree.Read <StrategyTree>(_cmdLine.OppStrategy); Console.WriteLine("Opp strategy: {0}", oppSt.Version.ToString()); // Create and configure Br solver Br br = new Br { HeroPosition = _cmdLine.HeroPosition, ChanceTree = ct, ActionTree = at, }; br.Strategies = new StrategyTree[ct.PlayersCount]; for (int opp = 0; opp < ct.PlayersCount; ++opp) { if (opp == _cmdLine.HeroPosition) { continue; } br.Strategies[opp] = oppSt; } DateTime startTime = DateTime.Now; // Solve Br br.Solve(); double time = (DateTime.Now - startTime).TotalSeconds; Console.WriteLine("Done in {0:0.0} s, BR value for hero pos {1}: {2}", time, br.HeroPosition, br.Value); string outFile = Path.Combine(Path.GetDirectoryName(_cmdLine.OppStrategy), Path.GetFileNameWithoutExtension(_cmdLine.OppStrategy)); outFile += "-br.dat"; Console.WriteLine("Writing br to {0}", outFile); br.Strategies[_cmdLine.HeroPosition].Write(outFile); return(0); }