public static void TestPOGameMyAgent(int count, CardClass player, CardClass opponent, List <Card> playerDeck, List <Card> opponentDeck, AbstractAgent opponentAgent) { Console.WriteLine("Setup gameConfig"); var gameConfig = new GameConfig() { StartPlayer = -1, Player1HeroClass = player, Player2HeroClass = opponent, Player1Deck = playerDeck, Player2Deck = opponentDeck, FillDecks = false, Shuffle = true, Logging = true }; Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new MCTSAgent(); AbstractAgent player2 = opponentAgent; var gameHandler = new POGameHandler(gameConfig, player1, player2, repeatDraws: false); Console.WriteLine("Simulate Games"); gameHandler.PlayGames(nr_of_games: count, addResultToGameStats: true, debug: false); GameStats gameStats = gameHandler.getGameStats(); Console.WriteLine(player + " vs " + opponent); gameStats.printResults(); Console.WriteLine("Test successful"); }
public void processMatchup(EvaluationTask task) { Console.WriteLine($"Thread {Thread.CurrentThread.ManagedThreadId}, evaluates games {task.game_number + 1} of " + $"({this.agents[task.idx_player_1].AgentAuthor}, {this.agents[task.idx_player_2].AgentAuthor}), " + $"({this.decks[task.idx_deck_1].deckname}, {this.decks[task.idx_deck_2].deckname})"); AbstractAgent player1 = Activator.CreateInstance(agents[task.idx_player_1].AgentClass) as AbstractAgent; AbstractAgent player2 = Activator.CreateInstance(agents[task.idx_player_2].AgentClass) as AbstractAgent; GameConfig gameConfig = new GameConfig { StartPlayer = 1, Player1HeroClass = decks[task.idx_deck_1].cardclass, Player2HeroClass = decks[task.idx_deck_2].cardclass, Player1Deck = decks[task.idx_deck_1].cards, Player2Deck = decks[task.idx_deck_1].cards, }; GameStats gameStats = null; while (gameStats == null || (gameStats.PlayerA_Wins == 1) == (gameStats.PlayerB_Wins == 1)) { var gameHandler = new POGameHandler(gameConfig, player1, player2); gameHandler.PlayGames(1); gameStats = gameHandler.getGameStats(); } results[task.idx_player_1, task.idx_player_2, task.idx_deck_1, task.idx_deck_2].addResult( gameStats.PlayerA_Wins == 1, gameStats.PlayerB_Wins == 1, gameStats.PlayerA_Exceptions == 1, gameStats.PlayerB_Exceptions == 1 ); }
private void RunMatches(TyDeckHeroPair p1Deck, TyDeckHeroPair p2Deck, int number, int startPlayer) { GameConfig gameConfig = new GameConfig { StartPlayer = startPlayer, Player1HeroClass = p1Deck.GetHeroClass(), Player1Deck = p1Deck.GetDeck(), Player2HeroClass = p2Deck.GetHeroClass(), Player2Deck = p2Deck.GetDeck(), FillDecks = true, Logging = false }; var gameHandler = new POGameHandler(gameConfig, _agent0, _agent1, debug: _debug); gameHandler.PlayGames(number); GameStats gameStats = gameHandler.getGameStats(); _totalPlays += gameStats.GamesPlayed; _agent0Wins += gameStats.PlayerA_Wins; _agent1Wins += gameStats.PlayerB_Wins; }
private static void Main(string[] args) { Console.WriteLine("Setup gameConfig"); //todo: rename to Main GameConfig gameConfig = new GameConfig { StartPlayer = 1, Player1HeroClass = CardClass.MAGE, Player2HeroClass = CardClass.MAGE, FillDecks = true, Logging = false }; Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new FaceHunter(); AbstractAgent player2 = new FaceHunter(); var gameHandler = new POGameHandler(gameConfig, player1, player2, debug: true); Console.WriteLine("PlayGame"); //gameHandler.PlayGame(); gameHandler.PlayGames(10); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); Console.WriteLine("Test successful"); Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine("Setup gameConfig"); //todo: rename to Main GameConfig gameConfig = new GameConfig { StartPlayer = 2, Player1HeroClass = CardClass.DRUID, Player2HeroClass = CardClass.WARLOCK, Player1Deck = Decks.MidrangeJadeShaman, Player2Deck = Decks.RenoKazakusMage, FillDecks = true, SkipMulligan = true, }; Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new RandomAgentLateEnd(); AbstractAgent player2 = new Gandalf(); var gameHandler = new POGameHandler(gameConfig, player1, player2, debug: true); Console.WriteLine("PlayGame"); gameHandler.PlayGame(); //gameHandler.PlayGames (100); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); Console.WriteLine("Test successful"); Console.ReadLine(); }
private static void Main() { Console.WriteLine("Setup gameConfig"); var gameConfig = new GameConfig() { StartPlayer = 1, // line for deck selection in here Player1HeroClass = CardClass.WARRIOR, Player2HeroClass = CardClass.WARRIOR, FillDecks = true, Shuffle = true, Logging = false }; Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new GreedyAgent(); AbstractAgent player2 = new MyAgent(); var gameHandler = new POGameHandler(gameConfig, player1, player2, repeatDraws: false); Console.WriteLine("Simulate Games"); //gameHandler.PlayGame(); gameHandler.PlayGames(nr_of_games: 100, addResultToGameStats: true, debug: false); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); Console.WriteLine("Test successful"); Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine("Setup gameConfig"); //todo: rename to Main GameConfig gameConfig = new GameConfig { StartPlayer = 1, Player1HeroClass = CardClass.WARRIOR, // <- put your hero class here Player2HeroClass = CardClass.WARRIOR, Player1Deck = Decks.AggroPirateWarrior, // <- put your new deck here Player2Deck = Decks.AggroPirateWarrior, FillDecks = true, Logging = false }; Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new MyMCTS_Agent(); AbstractAgent player2 = new SaliMCTS(); var gameHandler = new POGameHandler(gameConfig, player1, player2, debug: true); Console.WriteLine("PlayGame"); //gameHandler.PlayGame(); gameHandler.PlayGames(totalgames); //30模50場66%,20模50場74%,15模50場82%,15模擬1000場70% GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); Console.WriteLine(now_games); Console.WriteLine("Test successful"); Console.ReadLine(); }
public static void TestPOGame() { Console.WriteLine("Setup gameConfig"); var gameConfig = new GameConfig() { StartPlayer = 1, Player1HeroClass = CardClass.MAGE, Player2HeroClass = CardClass.MAGE, Player1Deck = Decks.RenoKazakusMage, Player2Deck = Decks.RenoKazakusMage, FillDecks = false, Shuffle = true, Logging = false }; Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new GreedyAgent(); AbstractAgent player2 = new GreedyAgent(); var gameHandler = new POGameHandler(gameConfig, player1, player2, repeatDraws: false); Console.WriteLine("Simulate Games"); //gameHandler.PlayGame(); gameHandler.PlayGames(nr_of_games: 1000, addResultToGameStats: true, debug: false); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); Console.WriteLine("Test successful"); Console.ReadLine(); }
private List <double[]> Evaluate(List <double[]> pop) { foreach (var item in pop) { item[item.Length - 1] = 0; } foreach (var player1 in pop) { AbstractAgent agent1 = new GreedyAgent(); AbstractAgent agent2 = new KISSBot(); Random rnd = new Random(Guid.NewGuid().GetHashCode()); var gameHandler1 = new POGameHandler(gameConfig1, agent1, agent2, repeatDraws: false); var gameHandler2 = new POGameHandler(gameConfig2, agent1, agent2, repeatDraws: false); var gameHandler3 = new POGameHandler(gameConfig3, agent1, agent2, repeatDraws: false); //gameHandler.PlayGame(debug: true); gameHandler1.PlayGames(nr_of_games: _numGames, addResultToGameStats: true, debug: false); gameHandler2.PlayGames(nr_of_games: _numGames, addResultToGameStats: true, debug: false); gameHandler3.PlayGames(nr_of_games: _numGames, addResultToGameStats: true, debug: false); player1[player1.Length - 1] += gameHandler1.getGameStats().PlayerB_Wins; player1[player1.Length - 1] += gameHandler2.getGameStats().PlayerB_Wins; player1[player1.Length - 1] += gameHandler3.getGameStats().PlayerB_Wins; } return(pop.OrderByDescending(x => x[x.Length - 1]).ToList()); }
private static void Main(string[] args) { Console.WriteLine("Setup gameConfig"); //todo: rename to Main GameConfig[] gameConfig = { SHAMAN_SHAMAN, SHAMAN_MAGE, SHAMAN_WAR, MAGE_SHAMAN, MAGE_MAGE, MAGE_WAR, WAR_SHAMAN, WAR_MAGE, WAR_WAR }; foreach (var config in gameConfig) { foreach (AbstractAgent opponent in new AbstractAgent[] { new RandomAgent(), new RandomAgentLateEnd(), new FaceHunter() }) { Console.WriteLine("Playing {0} vs {1} against {2}", config.Player1HeroClass, config.Player2HeroClass, opponent.GetType()); AbstractAgent player1 = new SimpleBalanceAgentDepthCards(); var gameHandler = new POGameHandler(config, player1, opponent, debug: false); //gameHandler.PlayGame(); gameHandler.PlayGames(100); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); Console.WriteLine("Test successful"); } } Console.ReadLine(); }
public static void TestPOGame(int numberOfRuns, int startPlayer, AbstractAgent p1, AbstractAgent p2, CardClass p1HeroClass, CardClass p2HeroClass, List <Card> p1Deck, List <Card> p2Deck, bool train = false) { Console.WriteLine("Setup gameConfig"); var gameConfig = new GameConfig() { StartPlayer = startPlayer, Player1HeroClass = p1HeroClass, Player2HeroClass = p2HeroClass, Player1Deck = p1Deck, Player2Deck = p2Deck, FillDecks = false, Shuffle = true, Logging = true }; Console.WriteLine("Setup POGameHandler"); var gameHandler = new POGameHandler(gameConfig, p1, p2, repeatDraws: false); Console.WriteLine("Simulate Games"); //gameHandler.PlayGame(); gameHandler.PlayGames(nr_of_games: numberOfRuns, addResultToGameStats: true, debug: false); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); Console.WriteLine("Writing results to the file"); //TODO: write the results here String wins = ""; for (int i = 0; i < gameStats.PlayerA_Wins; i++) { wins += "1"; } for (int i = 0; i < numberOfRuns - gameStats.PlayerA_Wins; i++) { wins += "2"; } //write the results if (train) { string outputFile = "/home/tobias/Develop/Java/CrushingBots/data/TRAINING_results.txt"; using (StreamWriter sw = File.AppendText(outputFile)) { sw.Write(wins); } Console.WriteLine("Test successful"); //Console.ReadLine(); } Console.WriteLine("Test successful"); //Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine("Setup gameConfig"); //todo: rename to Main /*GameConfig gameConfig = new GameConfig * { * StartPlayer = 1, * Player1HeroClass = CardClass.MAGE, * Player2HeroClass = CardClass.SHAMAN, * FillDecks = false, * Logging = false, * Player1Deck = Decks.RenoKazakusMage, * Player2Deck = Decks.MidrangeJadeShaman //RenoKazakusMage * }; * * * /*foreach (Card c in Cards.All) * { * Console.WriteLine(c.Name); * }*/ GameConfig gameConfig = gameConfigCoevoluationary(args); Console.WriteLine("Setup POGameHandler"); AbstractAgent player1agent = new ParametricGreedyAgent(); ((ParametricGreedyAgent)player1agent).setAgeintWeightsFromString(args[2]); AbstractAgent player2agent = new ParametricGreedyAgent(); ((ParametricGreedyAgent)player2agent).setAgeintWeightsFromString(args[5]); POGameHandler gameHandler = new POGameHandler(gameConfig, player1agent, player2agent, debug: false); gameConfig.StartPlayer = -1; //Pick random start player Console.WriteLine("STARTING GAMES"); int numGames = Int32.Parse(args[6]); gameHandler.PlayGames(numGames); GameStats gameStats = gameHandler.getGameStats(); //gameStats.printResults(); int p1wins = gameStats.PlayerA_Wins; int p2wins = gameStats.PlayerB_Wins; Console.WriteLine(p1wins + " " + p2wins + " " + numGames + " " + gameStats.PlayerA_TurnsToWin + " " + gameStats.PlayerA_TurnsToLose + " " + gameStats.PlayerA_HealthDifferenceWinning + " " + gameStats.PlayerA_HealthDifferenceLosing ); //Console.ReadLine(); }
/// <summary> /// plays the game, a function to reduce repeated code. /// </summary> /// <param name="gameConfig"></param> /// <param name="player1"></param> /// <param name="player2"></param> internal static void playGame(GameConfig gameConfig, AbstractAgent player1, AbstractAgent player2) { var gameHandler = new POGameHandler(gameConfig, player1, player2, debug: false); gameHandler.PlayGames(100); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); }
// check the best normal deck public static double Benchmark2(double[] X) { SetCoef(X); List <List <Card> > decks = MyDecks.Instance().GetMyDecks(); List <CardClass> heros = MyDecks.Instance().GetMyHeros(); for (int i = 40; i < 60; i++) { for (int j = 0; j < decks.Count; j++) { //todo: rename to Main GameConfig gameConfig = new GameConfig { StartPlayer = 1, Player1HeroClass = heros[i], Player2HeroClass = heros[j], FillDecks = false, Logging = false, Player1Deck = decks[i], Player2Deck = decks[j] }; //Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new UCTHunter(); AbstractAgent player2 = new UCTHunter(); var gameHandler = new POGameHandler(gameConfig, player1, player2, debug: false); //Console.WriteLine("PlayGame"); gameHandler.PlayGames(3); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); double winRate = (double)gameStats.PlayerA_Wins / (double)gameStats.GamesPlayed; Log.Instance("coef3.txt").Append(heros[i].ToString() + " " + i.ToString() + ":" + heros[j].ToString() + " " + winRate.ToString()); //double expectedMin = 1; //return Math.Pow(winRate - expectedMin, 2); } } return(0.0); }
/// <summary> /// Decks to choose from: /// Decks.AggroPirateWarrior /// Decks.RenoKazakusMage /// Decks.MidrangeJadeShaman /// Rules: /// - an Agent class that inherist from Abstract Agent /// - supporting files of up to 1GB(please contact us in case you need to load a bigger database or something like an extremely large Neural Network) /// - the agent needs to finish the whole turn with a time limit of 75 seconds.Execution times for returned moves are removed from the time being used by the agent.In case the submitted agent exceeds this limit, it will lose the game. /// /// </summary> /// <param name="args"></param> private static void Main(string[] args) { int numberOfGamesGames = 100; int filesToWrite = 1; var Rnd = new Random(); var watch = System.Diagnostics.Stopwatch.StartNew(); int exceptioncounter = 0; int turnsPlayed = 0; for (int k = 0; k < filesToWrite; k++) { for (int i = 0; i < numberOfGamesGames; i++) { //Console.WriteLine("Setup gameConfig"); try { GameConfig gameConfig = new GameConfig { StartPlayer = -1, Player1HeroClass = CardClass.WARRIOR, Player2HeroClass = CardClass.WARRIOR, Player1Deck = Decks.AggroPirateWarrior, Player2Deck = Decks.AggroPirateWarrior, Logging = false }; AbstractAgent player1 = new MyAgent(); gameConfig.Player1Name = "Player1"; AbstractAgent player2 = new RandomAgentLateEnd(); gameConfig.Player2Name = "Player2"; var gameHandler = new POGameHandler(gameConfig, player1, player2, debug: false); gameHandler.PlayGames(5, true); turnsPlayed += gameHandler.getGameStats().TurnsPlayed; } catch { exceptioncounter++; Console.Write("Ex:" + exceptioncounter + " "); i--; } if (i % 100 == 0 && i != 0) { Console.WriteLine("\t" + watch.Elapsed.TotalMinutes.ToString("F2") + "min \t\tCount:" + i); } } Console.WriteLine("Done Turns:" + turnsPlayed); } Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine("Setup gameConfig"); //todo: rename to Main /*GameConfig gameConfig = new GameConfig * { * StartPlayer = 1, * Player1HeroClass = CardClass.MAGE, * Player1Deck = Decks.RenoKazakusMage, * // Player1Deck = Decks.AggroPirateWarrior, * // Player1Deck = Decks.MidrangeJadeShaman, * Player2HeroClass = CardClass.MAGE, * Player2Deck = Decks.RenoKazakusMage, * // Player2Deck = Decks.AggroPirateWarrior, * // Player2Deck = Decks.MidrangeJadeShaman, * FillDecks = true, * Logging = true * };*/ int numberOfFights = 10; int gamesPerFight = 100; for (int i = 0; i < numberOfFights; i++) { Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new Galahad(); AbstractAgent player2 = GetRandomAgent(); Console.WriteLine("Fight " + i + " out of " + numberOfFights + " ==> " + player1.ToString() + " vs. " + player2.ToString()); GameConfig randomGameConfig = GetRandomGameConfig(); Console.WriteLine(randomGameConfig.Player1HeroClass.ToString() + " vs. " + randomGameConfig.Player2HeroClass.ToString()); var gameHandler = new POGameHandler(GetRandomGameConfig(), player1, player2, debug: true); gameHandler.PlayGames(gamesPerFight); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); Console.WriteLine(randomGameConfig.Player1HeroClass.ToString() + " vs. " + randomGameConfig.Player2HeroClass.ToString()); player1.FinalizeAgent(); } Console.WriteLine("Test successful"); Process.Start(@"powershell", $@"-c (New-Object Media.SoundPlayer 'E:\music\sampleTracks\taylor_swift_goat.wav').PlaySync();"); Console.ReadLine(); }
public static void AgentDuel(int count, PlayableAgent player, PlayableAgent opponent, bool saveLogs = false) { Console.WriteLine("Setup gameConfig"); var gameConfig = new GameConfig() { StartPlayer = -1, Player1HeroClass = player.AgentClass, Player2HeroClass = opponent.AgentClass, Player1Deck = player.Deck, Player2Deck = opponent.Deck, FillDecks = false, Shuffle = true, Logging = true }; //Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = player.Agent; AbstractAgent player2 = opponent.Agent; var gameHandler = new POGameHandler(gameConfig, player1, player2, repeatDraws: false); Console.WriteLine("Simulate Games"); gameHandler.PlayGames(nr_of_games: count, addResultToGameStats: true, debug: false); GameStats gameStats = gameHandler.getGameStats(); if (saveLogs) { try { string path = "log.txt"; using (StreamWriter sw = File.CreateText(path)) { gameStats.GameInfoLogs.ForEach(log => log.ForEach(logEntry => sw.WriteLine(logEntry))); } } catch (Exception e) { Console.WriteLine(e); } } Console.WriteLine(player.AgentClass + " vs " + opponent.AgentClass); gameStats.printResults(); Console.WriteLine("Duel successful"); }
public static void TestPOGame() { Console.WriteLine("Setup gameConfig"); var gameConfig = new GameConfig() { //WARLOCK,WARRIOR //ZooLock,AggroPirateWarrior StartPlayer = 1, Player1HeroClass = CardClass.WARRIOR, Player2HeroClass = CardClass.HUNTER, //Player2HeroClass = CardClass.WARRIOR, Player1Deck = Decks.AggroPirateWarrior, Player2Deck = Decks.MidrangeSecretHunter, //Player2Deck = Decks.AggroPirateWarrior, FillDecks = false, Shuffle = true, Logging = true }; Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new AIAgents.Dog.Dog(); //AbstractAgent player1 = new AIAgents.BetaStone.BetaStone(); //AbstractAgent player1 = new DynamicLookaheadAgent(); //AbstractAgent player1 = new GreedyAgent(); //AbstractAgent player2 = new AIAgents.BetaStone.BetaStone(); //AbstractAgent player2 = new AIAgents.Dog.Dog(); AbstractAgent player2 = new DynamicLookaheadAgent(); //AbstractAgent player2 = new GreedyAgent(); var gameHandler = new POGameHandler(gameConfig, player1, player2, repeatDraws: false); Console.WriteLine("Simulate Games"); //gameHandler.PlayGame(); gameHandler.PlayGames(nr_of_games: 10, addResultToGameStats: true, debug: false); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); Console.WriteLine("Test successful"); Console.ReadLine(); }
private static void testWeights(Dictionary <string, CardClass> classMap, Dictionary <string, List <Card> > deckMap, List <string> deckList, List <double> weights) { Console.WriteLine("Simulate Games"); Random r = new Random(); double wins = 0.0; double losses = 0.0; double numGames = 3000; for (int i = 0; i < numGames; i++) { string p1Deck = deckList[r.Next(deckList.Count)]; string p2Deck = deckList[r.Next(deckList.Count)]; var gameConfig = new GameConfig() { StartPlayer = r.Next(2) + 1, Player1HeroClass = classMap.GetValueOrDefault(p1Deck, CardClass.MAGE), Player2HeroClass = classMap.GetValueOrDefault(p2Deck, CardClass.ROGUE), Player1Deck = deckMap.GetValueOrDefault(p1Deck, Decks.RenoKazakusMage), Player2Deck = deckMap.GetValueOrDefault(p2Deck, Decks.MiraclePirateRogue), FillDecks = true, Shuffle = true, Logging = false }; AbstractAgent player1 = new GreedyAgent(); AbstractAgent player2 = new NNAgent(weights); Console.WriteLine("Game " + i + " " + p1Deck + " " + p2Deck); var gameHandler = new POGameHandler(gameConfig, player1, player2, repeatDraws: false); gameHandler.PlayGames(nr_of_games: 1, addResultToGameStats: true, debug: false); GameStats gameStats = gameHandler.getGameStats(); wins += gameStats.PlayerB_Wins; losses += gameStats.PlayerA_Wins; } Console.WriteLine("Bot winrate: " + (wins / (wins + losses))); Console.WriteLine("Wins: " + wins); Console.WriteLine("Losses: " + losses); Console.WriteLine("Draws: " + (numGames - (wins + losses))); }
public static double Benchmark(double[] X) { // create random coef run 10 times and get the win rate SetCoef(X); //todo: rename to Main GameConfig gameConfig = new GameConfig { StartPlayer = 1, Player1HeroClass = CardClass.MAGE, Player2HeroClass = CardClass.MAGE, FillDecks = true, Logging = false, }; //Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new FaceHunter(); AbstractAgent player2 = new UCTHunter(); var gameHandler = new POGameHandler(gameConfig, player1, player2, debug: false); //Console.WriteLine("PlayGame"); gameHandler.PlayGames(20); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); //Console.WriteLine("Setup gameConfig"); double winRate = (double)gameStats.PlayerB_Wins / (double)gameStats.GamesPlayed; var str = new StringBuilder(); Log.Instance("coef.txt").Append(FullPrintCoef(winRate)); double expectedMin = 1; return(Math.Pow(winRate - expectedMin, 2)); }
private static void runSimulation(Dictionary <string, CardClass> classMap, Dictionary <string, List <Card> > deckMap, List <string> deckList) { int numGames = 3000; Random r = new Random(); Console.WriteLine("Simulate Games"); List <List <double> > games = new List <List <double> >(); for (int i = 0; i < numGames; i++) { double max = 10; double min = -10; List <double> randWeights = Enumerable.Range(0, 24) // create sequence of 100 elements .Select(_ => r.NextDouble() * (max - min) + min) // for each element select random value .ToList(); // convert to array. string p1Deck = deckList[r.Next(deckList.Count)]; string p2Deck = deckList[r.Next(deckList.Count)]; var gameConfig = new GameConfig() { StartPlayer = r.Next(2) + 1, Player1HeroClass = classMap.GetValueOrDefault(p1Deck, CardClass.MAGE), Player2HeroClass = classMap.GetValueOrDefault(p2Deck, CardClass.ROGUE), Player1Deck = deckMap.GetValueOrDefault(p1Deck, Decks.RenoKazakusMage), Player2Deck = deckMap.GetValueOrDefault(p2Deck, Decks.MiraclePirateRogue), FillDecks = true, Shuffle = true, Logging = false }; AbstractAgent player1 = new RandomAgent(); AbstractAgent player2 = new NNAgent(randWeights); Console.WriteLine("Game " + i + " " + p1Deck + " " + p2Deck); var gameHandler = new POGameHandler(gameConfig, player1, player2, repeatDraws: false); gameHandler.PlayGames(nr_of_games: 1, addResultToGameStats: true, debug: false); GameStats gameStats = gameHandler.getGameStats(); // gameStats.printResults(); randWeights.Add(gameStats.PlayerB_Wins); games.Add(randWeights); // Console.WriteLine(String.Join(",", randWeights.Select(p=>p.ToString()).ToArray())); } StringBuilder sb = new StringBuilder(); if (!File.Exists(@"hsdata.csv")) { sb.Append("HERO_HEALTH_REDUCED,HERO_ATTACK_REDUCED,WEAPON_DURABILITY_REDUCED,MINION_HEALTH_REDUCED,MINION_ATTACK_REDUCED,MINION_KILLED,MINION_APPEARED,SECRET_REMOVED,MANA_REDUCED,M_HEALTH,M_ATTACK,M_HAS_CHARGE,M_HAS_DEAHTRATTLE,M_HAS_DIVINE_SHIELD,M_HAS_LIFE_STEAL,M_HAS_STEALTH,M_HAS_TAUNT,M_HAS_WINDFURY,M_IS_RUSH,M_MANA_COST,M_POISONOUS,M_SILENCED,M_SUMMONED,M_CANT_BE_TARGETED_BY_SPELLS,RESULT\r\n"); } for (int i = 0; i < games.Count(); i++) { for (int j = 0; j < games[0].Count(); j++) { sb.Append((j == 0 ? "" : ",") + games[i][j]); } sb.AppendLine(); } File.AppendAllText(@"hsdata.csv", sb.ToString()); Console.WriteLine("Simulation successful"); Console.ReadLine(); }
private int Stage4(int nLeagues) { Console.WriteLine("Stage " + 4 + " start:"); for (int i = 0; i < nLeagues; i++) { foreach (AgentTournament agent in agents) { foreach (AgentTournament agent2 in agents) { foreach (deck deck in decks) { foreach (deck deck2 in decks) { if (!deck.Equals(deck2) && !agent.agentAI.Equals(agent2.agentAI)) { GameConfig gameConfig = new GameConfig { StartPlayer = 1, Player1HeroClass = deck.heroClass, Player2HeroClass = deck2.heroClass, FillDecks = false, Logging = false, FillDecksPredictably = true, History = false }; gameConfig.Player1Deck = deck.deckList; gameConfig.Player2Deck = deck2.deckList; var gameHandler = new POGameHandler(gameConfig, agent.agentAI, agent2.agentAI, debug: false); Console.WriteLine("PlayGame " + getAgentName(agent) + " using " + getDeckName(deck.deckList) + " vs " + getAgentName(agent2) + " using " + getDeckName(deck2.deckList)); gameHandler.PlayGames(1); GameStats gameStats = gameHandler.getGameStats(); if (gameStats.PlayerA_Wins == 1) { agent.leagueWins++; } else { agent2.leagueWins++; } agent.leagueTurns += gameStats.Turns; agent2.leagueTurns += gameStats.Turns; writer.AppendLine(4 + "," + i + "," + getAgentName(agent) + "," + getDeckName(deck.deckList) + "," + getAgentName(agent2) + "," + getDeckName(deck2.deckList) + "," + gameStats.PlayerA_Wins + "," + gameStats.Turns); Console.WriteLine(gameStats.PlayerA_Wins + " vs " + gameStats.PlayerB_Wins); Console.WriteLine(); } } } } } Console.WriteLine(".................."); Console.WriteLine(" League Ended "); Console.WriteLine(".................."); int leagueGamesPlayed = 0; foreach (AgentTournament a in agents) { leagueGamesPlayed += a.leagueWins; a.stageWins += a.leagueWins; a.stageTurns += a.leagueTurns; } resultsLeague.Append(4 + "," + i + ","); foreach (AgentTournament a in agents) { resultsLeague.Append(a.leagueWins + ","); } resultsLeague.Append(leagueGamesPlayed + ","); foreach (AgentTournament a in agents) { resultsLeague.Append(a.leagueTurns + ","); } resultsLeague.AppendLine(); Console.WriteLine("Total games played in this league " + leagueGamesPlayed + "\n"); foreach (AgentTournament a in agents) { Console.WriteLine("League " + i + getAgentName(a) + " win percentage " + a.leagueWins / (float)leagueGamesPlayed); a.leagueWins = 0; a.leagueTurns = 0; } } Console.WriteLine("====================="); Console.WriteLine("====================="); int totalGamesPlayed = 0; foreach (AgentTournament a in agents) { totalGamesPlayed += a.stageWins; a.finalWins += a.stageWins; a.finalTurns += a.stageTurns; } resultsStage.Append(4 + ","); foreach (AgentTournament a in agents) { resultsStage.Append(a.stageWins + ","); } resultsStage.Append(totalGamesPlayed + ","); foreach (AgentTournament a in agents) { resultsStage.Append(a.stageTurns + ","); } resultsStage.AppendLine(); Console.WriteLine("Number of games played: " + totalGamesPlayed); foreach (AgentTournament a in agents) { Console.WriteLine(getAgentName(a) + " win percentage " + a.stageWins / (float)totalGamesPlayed); a.stageWins = 0; a.stageTurns = 0; } return(totalGamesPlayed); }
private static void Main() { Console.WriteLine("Setup gameConfig"); double[] values = new double[] { 41.9584023938321, 20.9314780959075, 42.5709950325876, 29.2160915509873, 3.02713018633757, 39.1902154319408, 16.5569344163206, 41.7280641359873, 25.5307942824582, 44.74108665634, 26.4395090874469, 34.6203779911717 }; //var gameConfig = new GameConfig() //{ // StartPlayer = 1, // Player1HeroClass = CardClass.SHAMAN, // Player2HeroClass = CardClass.SHAMAN, // Player1Deck = Decks.MidrangeJadeShaman, // Player2Deck = Decks.MidrangeJadeShaman, // FillDecks = true, // Shuffle = true, // Logging = false, // History = true //}; //EA ea = new EA(100, 0.1f, 6, 10, 4, 12); //var result = ea.StartEA(); //Console.WriteLine("Values"); //foreach (var item in result) //{ // Console.WriteLine(String.Join(',', item)); //} Console.WriteLine("Setup POGameHandler"); AbstractAgent player1 = new GreedyAgent(); AbstractAgent player2 = new KISSBot(); Random rnd = new Random(Guid.NewGuid().GetHashCode()); GameConfig gameConfig1 = new GameConfig() { StartPlayer = 1, Player1HeroClass = CardClass.SHAMAN, Player2HeroClass = CardClass.SHAMAN, Player1Deck = Decks.MidrangeJadeShaman, Player2Deck = Decks.MidrangeJadeShaman, FillDecks = true, Shuffle = true, Logging = false, History = true }; GameConfig gameConfig2 = new GameConfig() { StartPlayer = 1, Player1HeroClass = CardClass.MAGE, Player2HeroClass = CardClass.MAGE, Player1Deck = Decks.RenoKazakusMage, Player2Deck = Decks.RenoKazakusMage, FillDecks = true, Shuffle = true, Logging = false, History = true }; GameConfig gameConfig3 = new GameConfig() { StartPlayer = 1, Player1HeroClass = CardClass.WARRIOR, Player2HeroClass = CardClass.WARRIOR, Player1Deck = Decks.AggroPirateWarrior, Player2Deck = Decks.AggroPirateWarrior, FillDecks = true, Shuffle = true, Logging = false, History = true }; Console.WriteLine("Simulate Games"); var gameHandler1 = new POGameHandler(gameConfig1, player2, player1, repeatDraws: false); var gameHandler11 = new POGameHandler(gameConfig1, player1, player2, repeatDraws: false); var gameHandler2 = new POGameHandler(gameConfig2, player2, player1, repeatDraws: false); var gameHandler21 = new POGameHandler(gameConfig2, player1, player2, repeatDraws: false); var gameHandler3 = new POGameHandler(gameConfig3, player2, player1, repeatDraws: false); var gameHandler31 = new POGameHandler(gameConfig3, player1, player2, repeatDraws: false); //gameHandler11.PlayGame(debug: true); //gameHandler11.getGameStats().printResults(); gameHandler1.PlayGames(nr_of_games: 100, addResultToGameStats: true, debug: false); gameHandler1.getGameStats().printResults(); gameHandler11.PlayGames(nr_of_games: 100, addResultToGameStats: true, debug: false); gameHandler11.getGameStats().printResults(); gameHandler2.PlayGames(nr_of_games: 100, addResultToGameStats: true, debug: false); gameHandler2.getGameStats().printResults(); gameHandler21.PlayGames(nr_of_games: 100, addResultToGameStats: true, debug: false); gameHandler21.getGameStats().printResults(); gameHandler3.PlayGames(nr_of_games: 100, addResultToGameStats: true, debug: false); gameHandler3.getGameStats().printResults(); gameHandler31.PlayGames(nr_of_games: 100, addResultToGameStats: true, debug: false); gameHandler31.getGameStats().printResults(); Console.ReadLine(); }
private static void Main(string[] args) { Console.WriteLine("Setup gameConfig"); AbstractAgent agent1 = null; AbstractAgent agent2 = null; if (args[0].Equals("EVA")) { Console.WriteLine("EVA loaded for agent 1"); agent1 = new EVA(); ((EVA)agent1).InitializeAgent(); } else if (args[0].Equals("AlvaroAgent")) { agent1 = new AlvaroAgent(); ((AlvaroAgent)agent1).InitializeAgent(); } if (args[3].Equals("EVA")) { Console.WriteLine("EVA loaded for agent 2"); agent2 = new EVA(); ((EVA)agent2).InitializeAgent(); } else if (args[3].Equals("AlvaroAgent")) { agent2 = new AlvaroAgent(); ((AlvaroAgent)agent2).InitializeAgent(); } Console.WriteLine("Agents loaded!"); var gameConfig = new GameConfig() { StartPlayer = -1, // set to -1 should randomize starting player every game // Player1HeroClass = CardClass.MAGE, // Player2HeroClass = CardClass.MAGE, FillDecks = true, Shuffle = true, Logging = false, Player1HeroClass = stringToCardClass(args[2]), Player2HeroClass = stringToCardClass(args[5]), // FillDecks = false, // Logging = false, Player1Deck = stringToDeck(args[1]), Player2Deck = stringToDeck(args[4]) //RenoKazakusMage }; int numGames = Int32.Parse(args[6]); Console.WriteLine("Setup POGameHandler"); var gameHandler = new POGameHandler(gameConfig, agent1, agent2, repeatDraws: false); Console.WriteLine("Simulate Games"); //gameHandler.PlayGame(); gameHandler.PlayGames(nr_of_games: numGames, addResultToGameStats: true, debug: false); GameStats gameStats = gameHandler.getGameStats(); gameStats.printResults(); Console.WriteLine("Player 1: " + args[0] + " with deck " + args[1]); Console.WriteLine("Player 2: " + args[3] + " with deck " + args[4]); Console.WriteLine("Test successful"); // Console.ReadLine(); }