public override PlayerTask GetMove(POGame poGame)
        {
            var player = poGame.CurrentPlayer;

            // Implement a simple Mulligan Rule
            if (player.MulliganState == Mulligan.INPUT)
            {
                List <int> mulligan = new ControlScore().MulliganRule().Invoke(player.Choice.Choices.Select(p => poGame.getGame().IdEntityDic[p]).ToList());
                return(ChooseTask.Mulligan(player, mulligan));
            }

            // Apply MCTS and do the best move
            PlayerTask action = null;

            try
            {
                if (mcts)
                {
                    action = MCTS(poGame.getCopy());
                }
                else
                {
                    var legalMoves = poGame.Simulate(player.Options()).Where(x => x.Value != null);
                    return(legalMoves.Any() ?
                           legalMoves.OrderBy(x => Score(x.Value, player.PlayerId)).Last().Key :
                           player.Options().First(x => x.PlayerTaskType == PlayerTaskType.END_TURN));
                }
            }
            catch (NullReferenceException)
            {
                action = player.Options().First(x => x.PlayerTaskType == PlayerTaskType.END_TURN);
            }
            if (myDebug)
            {
                Console.WriteLine();
                Console.WriteLine(poGame.FullPrint());
                Console.WriteLine("Chose action: " + action);
            }
            return(action);
        }
Пример #2
0
 // Start is called before the first frame update
 private void Awake()
 {
     control = FindObjectOfType <ControlScore>();
     frog    = FindObjectOfType <FrogController>();
 }
Пример #3
0
        //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);
        }
Пример #4
0
        // 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);
        }
Пример #5
0
 // Start is called before the first frame update
 void Awake()
 {
     control = FindObjectOfType <ControlScore>();
 }
        public static string FullGame(string player1Class, string player1Strategy, List <Card> player1Deck, string player2Class, string player2Strategy, List <Card> player2Deck, ref string gameLogAddr)
        {
            string logsbuild = "";
            var    game      = getGame(player1Class, player1Deck, player2Class, player2Deck);

            game.StartGame();

            string startPlayer = game.CurrentPlayer.Name;
            object aiPlayer1   = new AggroScore();
            object aiPlayer2   = new AggroScore();

            switch (player1Strategy.ToLower())
            {
            case "control":
                aiPlayer1 = new ControlScore();
                break;

            case "fatigue":
                aiPlayer1 = new FatigueScore();
                break;

            case "midrange":
                aiPlayer1 = new MidRangeScore();
                break;

            case "ramp":
                aiPlayer1 = new RampScore();
                break;
            }
            switch (player2Strategy.ToLower())
            {
            case "control":
                aiPlayer2 = new ControlScore();
                break;

            case "fatigue":
                aiPlayer2 = new FatigueScore();
                break;

            case "midrange":
                aiPlayer2 = new MidRangeScore();
                break;

            case "ramp":
                aiPlayer2 = new RampScore();
                break;
            }

            List <int> mulligan1 = ((GamePlayer.Score.Score)aiPlayer1).MulliganRule().Invoke(game.Player1.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList());
            List <int> mulligan2 = ((GamePlayer.Score.Score)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";

            string hand_log      = "Hand<P1>,";
            string temp_hand_log = "";

            game.Process(ChooseTask.Mulligan(game.Player1, mulligan1));
            game.Process(ChooseTask.Mulligan(game.Player2, mulligan2));

            game.MainReady();

            while (game.State != State.COMPLETE)
            {
                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";
                for (int i = 0; i < game.Player1.HandZone.Count; i++)
                {
                    temp_hand_log = $"{game.Player1.HandZone[i]}";
                    hand_log     += temp_hand_log.Substring(1, temp_hand_log.Length - 1);
                    hand_log      = hand_log.Split2('[')[0] + ",";
                }
                logsbuild += "\n";

                //Console.WriteLine(logsbuild);
                //registerLogHandStats(logsbuild);

                while (game.State == State.RUNNING && game.CurrentPlayer == game.Player1)
                {
                    logsbuild += $"* Calculating solutions *** Player 1 ***" + "\n";

                    List <OptionNode> solutions = OptionNode.GetSolutions(game, game.Player1.Id, ((GamePlayer.Score.Score)aiPlayer1), maxDepth, maxWidth);
                    var solution = new List <PlayerTask>();
                    solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution);

                    logsbuild += $"- Player 1 - <{game.CurrentPlayer.Name}> ---------------------------" + "\n";
                    foreach (PlayerTask task in solution)
                    {
                        logsbuild += task.FullPrint() + "\n";

                        game.Process(task);
                        if (game.CurrentPlayer.Choice != null)
                        {
                            logsbuild += $"* Recaclulating due to a final solution ..." + "\n";
                            break;
                        }
                    }
                }

                logsbuild += $"- Player 2 - <{game.CurrentPlayer.Name}> ---------------------------" + "\n";
                while (game.State == State.RUNNING && game.CurrentPlayer == game.Player2)
                {
                    logsbuild += $"* Calculating solutions *** Player 2 ***" + "\n";
                    List <OptionNode> solutions = OptionNode.GetSolutions(game, game.Player2.Id, ((GamePlayer.Score.Score)aiPlayer2), maxDepth, maxWidth);
                    var solution = new List <PlayerTask>();
                    solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution);

                    logsbuild += $"- Player 2 - <{game.CurrentPlayer.Name}> ---------------------------" + "\n";
                    foreach (PlayerTask task in solution)
                    {
                        logsbuild += task.FullPrint() + "\n";
                        game.Process(task);
                        if (game.CurrentPlayer.Choice != null)
                        {
                            logsbuild += $"* Recaclulating due to a final solution ..." + "\n";
                            break;
                        }
                    }
                }
            }

            //hand_log = hand_log + "\n";
            //Console.WriteLine(hand_log);

            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;
            gameLogAddr = logsbuild + "\n" + hand_log;

            return("start player=" + startPlayer + ", Game: {game.State}, Player1: " + game.Player1.PlayState + " / Player2:" + game.Player2.PlayState + "healthdiff:" + healthdiff + "& turns:" + game.Turn);
        }
Пример #7
0
 void Awake()
 {
     estiro  = GetComponent <estirolengua>();
     control = FindObjectOfType <ControlScore>();
 }
        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}");
        }
Пример #9
0
 void Awake()
 {
     from    = FindObjectOfType <FrogController>();
     control = FindObjectOfType <ControlScore>();
 }