private void EvaluatePopulation() { Scores = new Dictionary <Individual, int>(); for (int i = 0; i < Population.Count; i++) { Scores.Add(Population[i], 0); } for (int i = 0; i < Population.Count - 1; i++) { for (int j = i + 1; j < Population.Count; j++) { var individual1 = Population[i]; var individual2 = Population[2]; var game = new LocalGame(); int result = game.PlayGame(individual1.Player(), individual2.Player()); if (result == 1) { Scores[individual1]++; Scores[individual2]--; } else if (result == 2) { Scores[individual2]++; Scores[individual1]--; } } } }
public static void StartLocalGame(Kingdom kingdom) { if (App.Context.CurrentGame != null) { App.Context.CurrentGame.CancelGame(); } Game game = new LocalGame(App.Context); App.Context.CurrentGame = game; game.GamePageModel.Kingdom = kingdom; game.PlayGame(); App.RootFrame.Navigate(typeof(GamePage)); game.ExitingGame += game_ExitingGame; }
public void PlayBotGames(string[] args) { var localGame = new LocalGame { Verbose = args.Contains(VerboseArg) }; string gamesToPlayString = args.Where(gtp => gtp.StartsWith(GamesToPlayArg)) .Select(gtp => gtp.Substring(GamesToPlayArg.Length)).FirstOrDefault(); GamesToPlay = gamesToPlayString == null ? 100 : int.Parse(gamesToPlayString); int[] results = { 0, 0, 0 }; var player1 = new Player { Strategy = new AlphaBetaStrategy(new SimpleEvaluator(), 3) }; var player2 = new Player { Strategy = new AlphaBetaStrategy(new SimpleEvaluator(), 4) }; for (int gamesPlayed = 0; gamesPlayed < GamesToPlay; gamesPlayed++) { if (gamesPlayed % GameGroupSize == 0) { Console.WriteLine($"Playing next {GameGroupSize} games now @ game{gamesPlayed}"); } int result = localGame.PlayGame(player1, player2); results[result]++; } Console.WriteLine($"Draws: {results[0]}"); Console.WriteLine($"Player 1 wins(avg t= {player1.TimesPerMove.Average()}): {results[1]}"); Console.WriteLine($"Player 2 wins(avg t= {player2.TimesPerMove.Average()}: {results[2]}"); Console.WriteLine("All games played..."); }