private static void PlayIAMain(params AIRule[] ias) { Game2048 game = new Game2048(); AI.AI ia = new AI.AI(ias); ShowGrid(game); var result = ia.PlayGame(game, () => { ShowGrid(game); System.Threading.Thread.Sleep(75); }).Item1; if (result == GameResult.Loss) { ShowGrid(game); Console.WriteLine(); Console.WriteLine("You loose you dumb !"); Console.WriteLine(); Console.ReadKey(); } else if (result == GameResult.Win) { ShowGrid(game); Console.WriteLine(); Console.WriteLine("Congratulations, you won .... A COCONUT !"); Console.WriteLine(); } Console.WriteLine("Press any key to leave !"); }
private static void PlayIAStatsMain(params AIRule[] rules) { string text = string.Format("Running 1000 tests with selected AI : {0}", rules.Aggregate("", (x, y) => x + y.GetType().Name + " (" + y.Coefficient + "),")); Console.WriteLine(text); List <GameResult> results = new List <GameResult>(); List <int> scores = new List <int>(); List <int> bests = new List <int>(); AI.AI ai = new AI.AI(rules); Parallel.For(0, 1000, (i) => { Game2048 game = new Game2048(); var res = ai.PlayGame(game, () => { }); results.Add(res.Item1); scores.Add(game.Score); bests.Add(game.ShowBoard.Max(Game2048.SIZE)); }); Console.WriteLine("Results : "); var wins = results.Count(x => x == GameResult.Win); Console.WriteLine(" - {0} win and {1} losses.", wins, 1000 - wins); Console.WriteLine(" - {0} average score, {1} best, {2} worst.", scores.Average(), scores.Max(), scores.Min()); Console.WriteLine(" - {0} average best tile, {1} best, {2} worst.", bests.Average(), bests.Max(), bests.Min()); Console.WriteLine(); Console.WriteLine(); }