コード例 #1
0
            public double simulation(Node node)
            {
                var validOpts     = node.state.Simulate(node.state.CurrentPlayer.Options()).Where(x => x.Value != null);
                var choosenAction = validOpts.RandomElement(Rnd);
                int reward        = 0;

                int panic = 0;

                while (choosenAction.Key.PlayerTaskType != PlayerTaskType.END_TURN && reward != int.MaxValue && reward != int.MinValue)
                {
                    panic += 1;
                    if (panic >= 100)
                    {
                        //Console.Write("panic!!!!! sim\n");
                        break;
                    }
                    validOpts     = choosenAction.Value.Simulate(choosenAction.Value.CurrentPlayer.Options()).Where(x => x.Value != null);
                    choosenAction = validOpts.RandomElement(Rnd);

                    MidRangeScore rater = new MidRangeScore {
                        Controller = choosenAction.Value.CurrentPlayer
                    };
                    reward = rater.Rate();

                    if (_watch.ElapsedMilliseconds >= MAX_TURN_TIME_MS)
                    {
                        break;
                    }
                }

                return((double)reward);
            }
コード例 #2
0
        public static void OneTurn()
        {
            var game = new Game(
                new GameConfig()
            {
                StartPlayer      = 1,
                Player1Name      = "FitzVonGerald",
                Player1HeroClass = CardClass.WARRIOR,
                Player1Deck      = Decks.RenoKazakusMage,
                Player2Name      = "RehHausZuckFuchs",
                Player2HeroClass = CardClass.SHAMAN,
                Player2Deck      = Decks.RenoKazakusMage,
                FillDecks        = false,
                Shuffle          = false,
                SkipMulligan     = false
            });

            game.Player1.BaseMana = 10;
            game.StartGame();

            var aiPlayer1 = new MidRangeScore();
            var aiPlayer2 = new AggroScore();

            game.Process(ChooseTask.Mulligan(game.Player1, aiPlayer1.MulliganRule().Invoke(game.Player1.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList())));
            game.Process(ChooseTask.Mulligan(game.Player2, aiPlayer2.MulliganRule().Invoke(game.Player2.Choice.Choices.Select(p => game.IdEntityDic[p]).ToList())));

            game.MainReady();

            while (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);
                    if (game.CurrentPlayer.Choice != null)
                    {
                        break;
                    }
                }
            }

            Console.WriteLine(game.Player1.HandZone.FullPrint());
            Console.WriteLine(game.Player1.BoardZone.FullPrint());
        }
コード例 #3
0
            public void expansion(Node node)
            {
                if (!node.childNodes.Any())
                {
                    var possibleActions = node.state.Simulate(node.state.CurrentPlayer.Options()).Where(x => x.Value != null);

                    foreach (KeyValuePair <PlayerTask, POGame> actionState in possibleActions)
                    {
                        if (actionState.Key.PlayerTaskType == PlayerTaskType.END_TURN)
                        {
                            continue;
                        }
                        Node appnode = new Node();
                        appnode.state      = actionState.Value;
                        appnode.nodeAction = actionState.Key;
                        appnode.parent     = node;
                        MidRangeScore rater = new MidRangeScore {
                            Controller = actionState.Value.CurrentPlayer
                        };
                        appnode.Q = rater.Rate();
                        node.childNodes.Add(appnode);
                    }
                }
            }
コード例 #4
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);
        }
コード例 #5
0
ファイル: Program.cs プロジェクト: jojo1023/SabberStone
        public static void FullGame()
        {
            var game = new Game(
                new GameConfig()
            {
                StartPlayer      = 1,
                Player1Name      = "FitzVonGerald",
                Player1HeroClass = CardClass.WARRIOR,
                Player1Deck      = Decks.AggroPirateWarrior,
                Player2Name      = "RehHausZuckFuchs",
                Player2HeroClass = CardClass.SHAMAN,
                Player2Deck      = Decks.MidrangeJadeShaman,
                FillDecks        = false,
                Shuffle          = true,
                SkipMulligan     = false
            });

            game.StartGame();

            var aiPlayer1 = new AggroScore();
            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());

            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);
                        if (game.CurrentPlayer.Choice != null)
                        {
                            Console.WriteLine($"* Recaclulating 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($"* Recaclulating due to a final solution ...");
                            break;
                        }
                    }
                }
            }
            Console.WriteLine($"Game: {game.State}, Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState}");
        }
コード例 #6
0
        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
        public override PlayerTask GetMove(POGame poGame)
        {
            Controller player = poGame.CurrentPlayer;

            // Implement a simple Mulligan Rule
            if (player.MulliganState == Mulligan.INPUT)
            {
                List <int> mulligan = new MidRangeScore().MulliganRule().Invoke(player.Choice.Choices.Select(p => poGame.getGame().IdEntityDic[p]).ToList());
                switch (poGame.CurrentPlayer.HeroClass)
                {
                case CardClass.SHAMAN: goto case CardClass.HUNTER;

                case CardClass.PALADIN: goto case CardClass.HUNTER;

                case CardClass.DRUID: goto case CardClass.HUNTER;

                case CardClass.HUNTER:
                    mulligan = new CustomMidrangeScoreHempel {
                        Controller = player
                    }.MulliganRule().Invoke(player.Choice.Choices.Select(p => poGame.getGame().IdEntityDic[p]).ToList());
                    weights = new double[3] {
                        1.0, 1.0, 1.0
                    };
                    break;

                case CardClass.ROGUE: goto case CardClass.WARRIOR;

                case CardClass.WARLOCK: goto case CardClass.WARRIOR;

                case CardClass.WARRIOR:
                    mulligan = new CustomAggroScoreHempel {
                        Controller = player
                    }.MulliganRule().Invoke(player.Choice.Choices.Select(p => poGame.getGame().IdEntityDic[p]).ToList());
                    weights = new double[3] {
                        1.0, 0.3, 0.7
                    };
                    break;

                case CardClass.PRIEST: goto case CardClass.MAGE;

                case CardClass.MAGE:
                    mulligan = new CustomScore {
                        Controller = player
                    }.MulliganRule().Invoke(player.Choice.Choices.Select(p => poGame.getGame().IdEntityDic[p]).ToList());
                    weights = new double[3] {
                        0.5, 1.0, 1.0
                    };
                    break;

                default:
                    mulligan = new CustomMidrangeScoreHempel {
                        Controller = player
                    }.MulliganRule().Invoke(player.Choice.Choices.Select(p => poGame.getGame().IdEntityDic[p]).ToList());
                    weights = new double[3] {
                        1.0, 1.0, 1.0
                    };
                    break;
                }
                return(ChooseTask.Mulligan(player, mulligan));
            }

            if (newTurn)
            {
                var tree = new Tree(poGame, weights);
                newTurn = false;
                tree.GetNext();
                TaskList = new Stack <PlayerTask>();
                TaskList = tree.BestEndNode.GetTaskList();
            }

            if (TaskList.Any())
            {
                return(TaskList.Pop());
            }
            else
            {
                newTurn = true;
                return(player.Options().FindLast(x => x.PlayerTaskType == PlayerTaskType.END_TURN) ?? player.Options().First());
            }
        }