Ejemplo n.º 1
0
 public void GivenTheAITournamentResultIsAsTheFollowing(Table table)
 {
     _tournamentResult = new TournamentResult();
     foreach (var row in table.Rows)
     {
         string raw = row["Round Result"];
         IEnumerable<int> scores = raw.Split('-').Select(int.Parse);
         var roundResult = new RoundResult(
             scores.First(),
             scores.First() == 10,
             scores.Skip(1));
         Assert.AreEqual(int.Parse(row["Expected Score"]), roundResult.RoundTotalScore);
         _tournamentResult.AddRound(roundResult);
     }
 }
Ejemplo n.º 2
0
 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
 }