public static void RunAITournament(int numPlayers, int round) { DateTime startTime = DateTime.Now; var stats = new Dictionary<string, TournamentPlayerStats>(); var simplexLearnedScores = SimplexLearnedScores.Load(SimplexLearning.FileName); ColorConsole.WriteLine(ConsoleColor.Cyan, "Loaded parameters: {0}", simplexLearnedScores); for (int i = 1; i <= round; ++i) { var game = new Game.Game((new SettlerBoardConstructor()).ConstructBoard(), numPlayers); game.Round = i; var improvedEmmAiPlayerNormal = new ImprovedEMN(new GameScores()); var improvedEmmAiPlayerExpansion = new ImprovedEMN(simplexLearnedScores); var players = new IPlayer[numPlayers]; players.Fill(improvedEmmAiPlayerNormal); players[RandomGenerator.Next(numPlayers)] = improvedEmmAiPlayerExpansion; for (int j = 0; j < numPlayers; ++j) { string name = players[j].Name; if (!stats.ContainsKey(name)) { stats[name] = new TournamentPlayerStats { PlayerName = name }; } } var controller = new GameController(new ConsoleViewer(), game, false, players); int winnerIndex = controller.Run(); TournamentPlayerStats stat = stats[players[winnerIndex].Name]; ColorConsole.WriteLine(ConsoleColor.Yellow, ">>> University {0}, AI player '{1}' has won. <<<", controller.Game.GetUniversityByIndex(winnerIndex).Color, stat.PlayerName ); stat.HasWon(); foreach (TournamentPlayerStats statForPrint in stats.Values) { statForPrint.PrintToConsole(); } ColorConsole.WriteLine(ConsoleColor.Green, "Total time taken: " + (DateTime.Now - startTime)); } }
public static void PlayGame() { while (true) { var game = new Game.Game((new SettlerBoardConstructor()).ConstructBoard(), 4); IPlayer improvedEMM_AIPlayer = new ImprovedEMN(new GameScores()); var players = new IPlayer[4]; players.Fill(improvedEMM_AIPlayer); players[RandomGenerator.Next(4)] = _humanConsolePlayer; var controller = new GameController(new ConsoleViewer(), game, true, players); _humanConsolePlayer.GameController = controller; controller.Run(); Console.WriteLine("Try again? y/n"); ConsoleKeyInfo key = Console.ReadKey(); Console.WriteLine(); if (key.KeyChar == 'n') { break; } } }
private double RunTournament(double[] values) { DateTime startedTime = DateTime.Now; _learnedScores.FromResult(values); var stats = new Dictionary<string, TournamentPlayerStats>(); const int numPlayers = 2; int round = 0; var tournamentResult = new TournamentResult(); int challengerIndex = 0; while (round < _roundsToWinInTournament) { ++round; challengerIndex = (challengerIndex + 1) % numPlayers; var game = new Game.Game(_boardConstructor.ConstructBoard(), numPlayers) {Round = round}; var _improvedEMM_AIPlayer_normal = new ImprovedEMN(new GameScores()); var _improvedEMM_AIPlayer_expansion = new ImprovedEMN(_learnedScores); var players = new IPlayer[numPlayers]; players.Fill(_improvedEMM_AIPlayer_normal); players[challengerIndex] = _improvedEMM_AIPlayer_expansion; for (var j = 0; j < numPlayers; ++j) { var name = players[j].Name; if (!stats.ContainsKey(name)) { stats[name] = new TournamentPlayerStats { PlayerName = name }; } } var controller = new GameController(_gameViewer, game, false, players); var winnerIndex = controller.Run(); var stat = stats[players[winnerIndex].Name]; ColorConsole.WriteLine(ConsoleColor.Yellow, ">>> University {0}, AI player '{1}' has won. <<<", controller.Game.GetUniversityByIndex(winnerIndex).Color, stat.PlayerName ); stat.HasWon(); var challengerUni = game.GetUniversityByIndex(challengerIndex); tournamentResult.AddRound( new RoundResult(game.GetScore(challengerUni), winnerIndex == challengerIndex, game.Universities.Where(u => u != challengerUni).Select(game.GetScore) )); foreach (var statForPrint in stats.Values) { statForPrint.PrintToConsole(); } } var totalScore = tournamentResult.CalculateTotalScore(); LogInfo(_learnedScores.ToString()); _touranmentCount++; var remainingTimeSpan = GetEstimatedFinishedTime(); LogInfo("Got score: {0}. Challenger won {1} rounds. Time taken this tournament: {2}." + " Total time taken: {3}. Estimated finished time: {4} ({5} to go)", totalScore, tournamentResult.ChallengerWinningCount, DateTime.Now - startedTime, DateTime.Now - _learningStartedDT, DateTime.Now + remainingTimeSpan, remainingTimeSpan); return -totalScore; // return negative for function minimisation }