// determine the "fitness" of the deck by its performance against the control deck public static double EvaluateFitness(List <Card> deck) { var watch = Stopwatch.StartNew(); var gameConfig = new GameConfig() { StartPlayer = 1, Player1Name = "P1", Player1HeroClass = hero, Player1Deck = deck, Player2Name = "P2", Player2HeroClass = CardClass.WARRIOR, Player2Deck = Decks.AggroPirateWarrior, FillDecks = false, Shuffle = true, SkipMulligan = false, Logging = false, History = false }; int player_wins = 0; int control_wins = 0; // simulate games between the member deck and the control deck, tracking wins // most efficient performance seems to be 1 game / thread per core Parallel.For(0, games, options, i => { var game = new Game(gameConfig); game.StartGame(); var aiPlayer1 = new ControlScore(); var aiPlayer2 = new AggroScore(); List <int> mulligan1 = aiPlayer1.MulliganRule().Invoke(game.Player1.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList()); List <int> mulligan2 = aiPlayer2.MulliganRule().Invoke(game.Player2.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList()); game.Process(ChooseTask.Mulligan(game.Player1, mulligan1)); game.Process(ChooseTask.Mulligan(game.Player2, mulligan2)); game.MainReady(); try { while (game.State != State.COMPLETE) { //Console.WriteLine($"Hero[P1]: {game.Player1.Hero.Health} / Hero[P2]: {game.Player2.Hero.Health}"); while (game.State == State.RUNNING && game.CurrentPlayer == game.Player1) { List <OptionNode> solutions = OptionNode.GetSolutions(game, game.Player1.Id, aiPlayer1, 10, 500); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); foreach (PlayerTask task in solution) { //Console.WriteLine(task.FullPrint()); game.Process(task); if (game.CurrentPlayer.Choice != null) { break; } } } while (game.State == State.RUNNING && game.CurrentPlayer == game.Player2) { List <OptionNode> solutions = OptionNode.GetSolutions(game, game.Player2.Id, aiPlayer2, 10, 500); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); foreach (PlayerTask task in solution) { //Console.WriteLine(task.FullPrint()); game.Process(task); if (game.CurrentPlayer.Choice != null) { break; } } } } if (game.Player1.PlayState == PlayState.WON) { Interlocked.Increment(ref player_wins); } else if (game.Player2.PlayState == PlayState.WON) { Interlocked.Increment(ref control_wins); } } catch (Exception e) { Console.WriteLine($"Exception caught: {e}"); Console.WriteLine("Composition of offending deck:"); foreach (Card card in deck) { Console.WriteLine($"{card.ToString()}"); } Console.WriteLine("Awarding win to opponent."); Interlocked.Increment(ref control_wins); } Console.WriteLine($"Player 1 Wins: {player_wins} / Player 2 Wins: {control_wins}"); }); watch.Stop(); Console.WriteLine(""); Console.WriteLine($"{games} games took {watch.ElapsedMilliseconds / 1000 / 60} minutes!"); Console.WriteLine($"Player 1 (Population) {player_wins * 100 / games}% vs. Player 2 (Control) {control_wins * 100 / games}%!"); Console.WriteLine(""); return(player_wins * 100 / games); }
//the game we need public static string FullGame(List <Card> player1Deck, int where, List <Card> player2Deck, string gameLogAddr) { string logsbuild = ""; var game = new Game( new GameConfig() { StartPlayer = 1, Player1Name = "FitzVonGerald", Player1HeroClass = CardClass.DRUID, Player1Deck = player1Deck,//Decks.AggroPirateWarrior, Player2Name = "RehHausZuckFuchs", Player2HeroClass = CardClass.SHAMAN, Player2Deck = player2Deck, FillDecks = false, Shuffle = true, SkipMulligan = false }); game.StartGame(); var aiPlayer1 = new ControlScore(); var aiPlayer2 = new MidRangeScore(); List <int> mulligan1 = aiPlayer1.MulliganRule().Invoke(game.Player1.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList()); List <int> mulligan2 = aiPlayer2.MulliganRule().Invoke(game.Player2.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList()); logsbuild += $"Player1: Mulligan {string.Join(",", mulligan1)}"; logsbuild += "\n"; logsbuild += $"Player2: Mulligan {string.Join(",", mulligan2)}"; logsbuild += "\n"; // Console.WriteLine($"Player1: Mulligan {string.Join(",", mulligan1)}"); //Console.WriteLine($"Player2: Mulligan {string.Join(",", mulligan2)}"); game.Process(ChooseTask.Mulligan(game.Player1, mulligan1)); game.Process(ChooseTask.Mulligan(game.Player2, mulligan2)); game.MainReady(); while (game.State != State.COMPLETE) { // Console.WriteLine("here:" + where); logsbuild += $"Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState} - " + $"ROUND {(game.Turn + 1) / 2} - {game.CurrentPlayer.Name}" + "\n"; logsbuild += $"Hero[P1]: {game.Player1.Hero.Health} / Hero[P2]: {game.Player2.Hero.Health}" + "\n"; logsbuild += "\n"; //Console.WriteLine($"Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState} - " + // $"ROUND {(game.Turn + 1) / 2} - {game.CurrentPlayer.Name}");//I get round number here, can cut it off right here //Console.WriteLine($"Hero[P1]: {game.Player1.Hero.Health} / Hero[P2]: {game.Player2.Hero.Health}"); //Console.WriteLine(""); while (game.State == State.RUNNING && game.CurrentPlayer == game.Player1) { logsbuild += $"* Calculating solutions *** Player 1 ***" + "\n"; // Console.WriteLine($"* Calculating solutions *** Player 1 ***");//player 1's turn List <OptionNode> solutions = OptionNode.GetSolutions(game, game.Player1.Id, aiPlayer1, maxDepth, maxWidth); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); //Console.WriteLine($"- Player 1 - <{game.CurrentPlayer.Name}> ---------------------------"); logsbuild += $"- Player 1 - <{game.CurrentPlayer.Name}> ---------------------------" + "\n"; foreach (PlayerTask task in solution) { logsbuild += task.FullPrint() + "\n"; // Console.WriteLine(task.FullPrint());//important focus point for you. test this by first uncommenting it string printedTask = task.FullPrint(); //CONNOR CODE if (printedTask.IndexOf("play") != -1) //CONNOR CODE { //CONNOR CODE string card = task.Source.ToString(); //CONNOR CODE //Console.WriteLine("Play: " + printedTask); //ADDITION: if the tast is PlayCardTask, this code runs //Console.WriteLine("Card is: " + card);//CONNOR CODE CalculateFreqs(card);//CONNOR CODE //CalculateTotalFreqs(card, cardStatistics);//CONNOR CODE }//CONNOR CODE else//CONNOR CODE {//CONNOR CODE // Console.WriteLine("Else: " + printedTask);//CONNOR CODE }//CONNOR CODE game.Process(task); if (game.CurrentPlayer.Choice != null) { logsbuild += $"* Recaclulating due to a final solution ..." + "\n"; // Console.WriteLine($"* Recaclulating due to a final solution ..."); break; } } }//hello hell0 hello is there anybody in there? Now that you can hear it // GC.Collect(); // Random mode for Player 2 // Console.WriteLine($"- Player 2 - <{game.CurrentPlayer.Name}> ---------------------------");//player 2's turn logsbuild += $"- Player 2 - <{game.CurrentPlayer.Name}> ---------------------------" + "\n"; while (game.State == State.RUNNING && game.CurrentPlayer == game.Player2) { //var options = game.Options(game.CurrentPlayer); //var option = options[Rnd.Next(options.Count)]; //Log.Info($"[{option.FullPrint()}]"); //game.Process(option); // Console.WriteLine($"* Calculating solutions *** Player 2 ***"); logsbuild += $"* Calculating solutions *** Player 2 ***" + "\n"; List <OptionNode> solutions = OptionNode.GetSolutions(game, game.Player2.Id, aiPlayer2, maxDepth, maxWidth); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); // Console.WriteLine($"- Player 2 - <{game.CurrentPlayer.Name}> ---------------------------"); logsbuild += $"- Player 2 - <{game.CurrentPlayer.Name}> ---------------------------" + "\n"; foreach (PlayerTask task in solution) { // Console.WriteLine(task.FullPrint());//this is what you neeed to focus on right here logsbuild += task.FullPrint() + "\n"; game.Process(task); if (game.CurrentPlayer.Choice != null) { // Console.WriteLine($"* Recaclulating due to a final solution ..."); logsbuild += $"* Recaclulating due to a final solution ..." + "\n"; break; } } } GC.Collect(); } //Console.WriteLine($"Game: {game.State}, Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState}"); int healthdiff = game.Player1.Hero.Health - game.Player2.Hero.Health; logsbuild += "Game: {game.State}, Player1: " + game.Player1.PlayState + " / Player2:" + game.Player2.PlayState + "healthdiff:" + healthdiff + "& turns:" + game.Turn; using (StreamWriter tw = File.AppendText(gameLogAddr)) { tw.WriteLine(logsbuild); tw.Close(); } return("Game: {game.State}, Player1: " + game.Player1.PlayState + " / Player2:" + game.Player2.PlayState + "healthdiff:" + healthdiff + "& turns:" + game.Turn); }
public static void FullGame() { var game = new Game( new GameConfig() { StartPlayer = 1, Player1Name = "YiLingShu", Player1HeroClass = CardClass.MAGE, Player1Deck = Decks.RenoKazakusMage, Player2Name = "GouZei", Player2HeroClass = CardClass.MAGE, Player2Deck = Decks.RenoKazakusMage, FillDecks = false, Shuffle = true, SkipMulligan = false, History = false }); game.StartGame(); var aiPlayer1 = new ControlScore(); var aiPlayer2 = new ControlScore(); List <int> mulligan1 = aiPlayer1.MulliganRule().Invoke(game.Player1.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList()); List <int> mulligan2 = aiPlayer2.MulliganRule().Invoke(game.Player2.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList()); Console.WriteLine($"Player1: Mulligan {String.Join(",", mulligan1)}"); Console.WriteLine($"Player2: Mulligan {String.Join(",", mulligan2)}"); game.Process(ChooseTask.Mulligan(game.Player1, mulligan1)); game.Process(ChooseTask.Mulligan(game.Player2, mulligan2)); game.MainReady(); while (game.State != State.COMPLETE) { Console.WriteLine(""); Console.WriteLine($"Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState} - " + $"ROUND {(game.Turn + 1) / 2} - {game.CurrentPlayer.Name}"); Console.WriteLine($"Hero[P1]: {game.Player1.Hero.Health} / Hero[P2]: {game.Player2.Hero.Health}"); Console.WriteLine(""); while (game.State == State.RUNNING && game.CurrentPlayer == game.Player1) { Console.WriteLine($"* Calculating solutions *** Player 1 ***"); List <OptionNode> solutions = OptionNode.GetSolutions(game, game.Player1.Id, aiPlayer1, 10, 500); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); Console.WriteLine($"- Player 1 - <{game.CurrentPlayer.Name}> ---------------------------"); foreach (PlayerTask task in solution) { Console.WriteLine(task.FullPrint()); game.Process(task); break; if (game.CurrentPlayer.Choice != null) { Console.WriteLine($"* Recalculating due to a final solution ..."); break; } } } // Random mode for Player 2 Console.WriteLine($"- Player 2 - <{game.CurrentPlayer.Name}> ---------------------------"); while (game.State == State.RUNNING && game.CurrentPlayer == game.Player2) { //var options = game.Options(game.CurrentPlayer); //var option = options[Rnd.Next(options.Count)]; //Log.Info($"[{option.FullPrint()}]"); //game.Process(option); Console.WriteLine($"* Calculating solutions *** Player 2 ***"); List <OptionNode> solutions = OptionNode.GetSolutions(game, game.Player2.Id, aiPlayer2, 10, 500); var solution = new List <PlayerTask>(); solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution); Console.WriteLine($"- Player 2 - <{game.CurrentPlayer.Name}> ---------------------------"); foreach (PlayerTask task in solution) { Console.WriteLine(task.FullPrint()); game.Process(task); if (game.CurrentPlayer.Choice != null) { Console.WriteLine($"* Recalculating due to a final solution ..."); break; } } } } Console.WriteLine($"Game: {game.State}, Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState}"); }