private static PlayableAgent SetupPlayer() { StringBuilder help = new StringBuilder(); help.AppendLine("<---------- Player Setup ---------->"); help.AppendLine("Choose player deck and agent"); help.AppendLine("Available decks: AggroPirateWarrior, MidrangeBuffPaladin, MidrangeJadeShaman, MidrangeSecretHunter, " + "MiraclePirateRogue, RenoKazakusDragonPriest, RenoKazakusMage"); help.AppendLine("Available agents: RandomAgent, GreedyAgent, BeamSearchAgent, DynamicLookaheadAgent, MCTSAgent"); help.Append("Example: AggroPirateWarrior BeamSearchAgent"); string input = ReadFromConsole(help.ToString()); PlayableAgent agent = new PlayableAgent(); if (String.IsNullOrWhiteSpace(input)) { return(agent); } List <string> parsedInput = input.Split(' ').ToList(); if (parsedInput.Count >= 2) { agent.SetDeck(parsedInput[0]); var assembly = Assembly.GetExecutingAssembly(); try { var type = assembly.GetTypes() .First(t => t.Name == parsedInput[1]); if (parsedInput[1] == "MCTSAgent") { agent.Agent = GetParamsForAgent(); } else { AbstractAgent agentInstance = (AbstractAgent)Activator.CreateInstance(type); agent.Agent = agentInstance; } } catch (Exception e) { Console.WriteLine("Invalid agent name. Using default agent"); } } else { Console.WriteLine("Not enough parameters. Using default deck and agent."); } return(agent); }
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 void CharacterTakeOver(PlayableAgent player) { m_CharacterSelectionWindow.gameObject.SetActive(true); temp_character = player; }
private Vector2Int?SelectTargetForAttackFromPosition(List <PlayableAgent> Players, Vector2Int Pos) { if (!AbilitySystem.CanActivateAbilityByTag(MainAbility)) { return(null); } Vector2Int OriginalPosition = GridPos; GridPos = Pos; Grid.setOccupied((Vector3Int)OriginalPosition, false); Grid.setOccupied((Vector3Int)GridPos, true); PlayableAgent TargetAgent = null; foreach (PlayableAgent Player in Players) { // Can target if (AbilitySystem.CanActivateTargetAbilityByTag(MainAbility, Player.GridPos)) { // First if (TargetAgent == null) { TargetAgent = Player; } else { float BestDist = Vector2Int.Distance(GridPos, TargetAgent.GridPos); float NewDist = Vector2Int.Distance(GridPos, Player.GridPos); // Closest if (NewDist < BestDist) { TargetAgent = Player; } else if (NewDist == BestDist) { int BestHealth = TargetAgent.AbilitySystem.GetAttributeValue(Attribute.Health).Value; int NewHealth = Player.AbilitySystem.GetAttributeValue(Attribute.Health).Value; // Lowest health if (NewHealth < BestHealth) { TargetAgent = Player; } else if (BestHealth == NewHealth) { // First role if (Player.Role < TargetAgent.Role) { TargetAgent = Player; } } } } } } Grid.setOccupied((Vector3Int)GridPos, false); Grid.setOccupied((Vector3Int)OriginalPosition, true); GridPos = OriginalPosition; if (TargetAgent != null) { return(TargetAgent.GridPos); } return(null); }
private Vector2Int?BlobMoveTarget(List <PlayableAgent> Players) { Vector3Int OwnerPos = (Vector3Int)GridPos; PlayableAgent BestAgent = null; List <Vector3Int> BestPath = null; foreach (PlayableAgent Player in Players) { Vector3Int PlayerPos = (Vector3Int)Player.GridPos; Grid.setOccupied(PlayerPos, false); List <Vector3Int> Path = Grid.findPath(OwnerPos, PlayerPos); if (Path != null) { // First or closest if (BestPath == null || (Path.Count < BestPath.Count)) { BestPath = Path; BestAgent = Player; } else if (Path.Count == BestPath.Count) { int BestHealth = BestAgent.AbilitySystem.GetAttributeValue(Attribute.Health).Value; int NewHealth = Player.AbilitySystem.GetAttributeValue(Attribute.Health).Value; // Lowest health if (NewHealth < BestHealth) { BestPath = Path; BestAgent = Player; } else if (BestHealth == NewHealth) { // First role if (Player.Role < BestAgent.Role) { BestPath = Path; BestAgent = Player; } } } } Grid.setOccupied(PlayerPos, true); } Vector2Int?TargetPosition = null; if (BestPath != null) { for (int i = BestPath.Count - 1; i >= 0; i--) { if (AbilitySystem.CanActivateTargetAbilityByTag(TypeTag.MoveAbility, (Vector2Int)BestPath[i])) { TargetPosition = (Vector2Int)BestPath[i]; break; } } } return(TargetPosition); }
private static void MainLoop() { PlayableAgent player1 = new PlayableAgent(); PlayableAgent player2 = new PlayableAgent(); StringBuilder help = new StringBuilder(); bool exit = false; help.AppendLine("Use command 'player1' to setup first agent."); help.AppendLine("Use command 'player2' to setup second agent."); help.AppendLine("Use command 'play (count)' to start (count) number of simulations."); help.Append("Use command 'exit' to quit."); Console.WriteLine("Duels of Agents"); while (!exit) { string input = ReadFromConsole(help.ToString()); if (String.IsNullOrWhiteSpace(input)) { continue; } try { List <string> parsedInput = input.Split(' ').ToList(); switch (parsedInput[0]) { case "play": int count; if (parsedInput.Count < 2) { Console.WriteLine("Missing param"); continue; } if (Int32.TryParse(parsedInput[1], out count)) { string inp = ReadFromConsole("Save game log to file? (y/n)"); if (!String.IsNullOrWhiteSpace(inp) && inp.ToLower() == "y") { string path = "log.txt"; if (File.Exists(path)) { string inpt = ReadFromConsole("Will overwrite old log file. Do you agree? (y/n)"); AgentDuel(count, player1, player2, !String.IsNullOrWhiteSpace(inpt) && inpt.ToLower() == "y"); } else { AgentDuel(count, player1, player2, true); } } } else { Console.WriteLine(parsedInput[1] + " not valid."); } break; case "player1": player1 = SetupPlayer(); break; case "player2": player2 = SetupPlayer(); break; case "exit": exit = true; break; default: break; } } catch (Exception e) { //Console.WriteLine(e); } } }