//========================================================================== // start a new game internal void NewGame() { _polygame.NewBoard(ChooserKinds.Mcts, StepCount, MaxDepth); _polygame.Reseed(++Seed); TimePlayed = TimeSpan.Zero; UpdatePieces(); }
//========================================================================== internal void PlayTurns(int initseed, int ngames, int nsteps, int arandom, int brandom) { var maxdepth = 9; _out.WriteLine("\nPlay turns '{0}' seed={1} games={2} steps={3} maxdepth={4} random A={5} B={6}\n", Game.Title, initseed, ngames, nsteps, maxdepth, arandom, brandom); var score = new Dictionary <Pair <string, ResultKinds>, int>(); for (int seed = initseed; seed < initseed + ngames; seed++) { Game.Reseed(seed); Game.NewBoard(); if (Logger.Level >= 2) { ShowState(); } Game.StepCount = nsteps; Game.MaxDepth = maxdepth; var pick = 0; for (int moveno = 0; ; moveno++) { if (Game.GameResult != ResultKinds.None) { break; } // which to use? var nrandom = (Game.TurnPlayer == Game.FirstPlayer) ? arandom : brandom; // means get user input if (nrandom == -1) { ShowBoard(); ShowMoves(); do { pick = -1; var prompt = String.Format("[{0}] Your move (of {1}): ", Logger.Level, Game.LegalMoves.Count); var input = Program.GetInput(prompt, "|[rn]?[0-9]+"); if (input == "") { return; } if (input.StartsWith("n")) { Logger.Level = input.Substring(1).SafeIntParse() ?? Logger.Level; } else if (input == "r") { Game.NewBoard(); if (Logger.Level >= 2) { ShowState(); } moveno = 0; break; } else { pick = input.SafeIntParse() ?? -1; } } while (!(pick >= 0 && pick < Game.LegalMoves.Count)); } else if (moveno < nrandom) { pick = Game.NextRandom(Game.LegalMoves.Count); } else if (nsteps == 0) { pick = 0; } else { Game.UpdateChooser(); var done = Game.UpdateChooser(); Logger.WriteLine(3, "Update returns {0}", done); //if (moveno == 4) ShowTree(2); pick = Game.ChosenMove.Index; } if (pick >= 0) { Logger.WriteLine(1, "{0} make move {1} of {2}: {3}", Game.TurnPlayer, pick, Game.LegalMoves.Count, Game.GetLegalMove(pick).ToString("P")); Game.MakeMove(pick); } } var key = Pair.Create(Game.ResultPlayer, Game.GameResult); if (score.ContainsKey(key)) { score[key]++; } else { score[key] = 1; } _out.WriteLine("Seed {0} result {1} {2}", seed, Game.ResultPlayer, Game.GameResult); ShowBoard(); ShowPosition(); } foreach (var kvp in score) { _out.WriteLine("\nplayer={0} result={1} count={2}", kvp.Key.Item1, kvp.Key.Item2, kvp.Value); } }