Пример #1
0
        public static void TestFullGames()
        {
            int maxGames = 1000;
            int maxDepth = 10;
            int maxWidth = 14;

            int[] player1Stats = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
            int[] player2Stats = new int[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };

            var gameConfig = new GameConfig()
            {
                StartPlayer      = -1,
                Player1Name      = "FitzVonGerald",
                Player1HeroClass = CardClass.PALADIN,
                Player1Deck      = new List <Card>()
                {
                    Cards.FromName("Blessing of Might"),
                    Cards.FromName("Blessing of Might"),
                    Cards.FromName("Gnomish Inventor"),
                    Cards.FromName("Gnomish Inventor"),
                    Cards.FromName("Goldshire Footman"),
                    Cards.FromName("Goldshire Footman"),
                    Cards.FromName("Hammer of Wrath"),
                    Cards.FromName("Hammer of Wrath"),
                    Cards.FromName("Hand of Protection"),
                    Cards.FromName("Hand of Protection"),
                    Cards.FromName("Holy Light"),
                    Cards.FromName("Holy Light"),
                    Cards.FromName("Ironforge Rifleman"),
                    Cards.FromName("Ironforge Rifleman"),
                    Cards.FromName("Light's Justice"),
                    Cards.FromName("Light's Justice"),
                    Cards.FromName("Lord of the Arena"),
                    Cards.FromName("Lord of the Arena"),
                    Cards.FromName("Nightblade"),
                    Cards.FromName("Nightblade"),
                    Cards.FromName("Raid Leader"),
                    Cards.FromName("Raid Leader"),
                    Cards.FromName("Stonetusk Boar"),
                    Cards.FromName("Stonetusk Boar"),
                    Cards.FromName("Stormpike Commando"),
                    Cards.FromName("Stormpike Commando"),
                    Cards.FromName("Stormwind Champion"),
                    Cards.FromName("Stormwind Champion"),
                    Cards.FromName("Stormwind Knight"),
                    Cards.FromName("Stormwind Knight")
                },
                Player2Name      = "RehHausZuckFuchs",
                Player2HeroClass = CardClass.PALADIN,
                Player2Deck      = new List <Card>()
                {
                    Cards.FromName("Blessing of Might"),
                    Cards.FromName("Blessing of Might"),
                    Cards.FromName("Gnomish Inventor"),
                    Cards.FromName("Gnomish Inventor"),
                    Cards.FromName("Goldshire Footman"),
                    Cards.FromName("Goldshire Footman"),
                    Cards.FromName("Hammer of Wrath"),
                    Cards.FromName("Hammer of Wrath"),
                    Cards.FromName("Hand of Protection"),
                    Cards.FromName("Hand of Protection"),
                    Cards.FromName("Holy Light"),
                    Cards.FromName("Holy Light"),
                    Cards.FromName("Ironforge Rifleman"),
                    Cards.FromName("Ironforge Rifleman"),
                    Cards.FromName("Light's Justice"),
                    Cards.FromName("Light's Justice"),
                    Cards.FromName("Lord of the Arena"),
                    Cards.FromName("Lord of the Arena"),
                    Cards.FromName("Nightblade"),
                    Cards.FromName("Nightblade"),
                    Cards.FromName("Raid Leader"),
                    Cards.FromName("Raid Leader"),
                    Cards.FromName("Stonetusk Boar"),
                    Cards.FromName("Stonetusk Boar"),
                    Cards.FromName("Stormpike Commando"),
                    Cards.FromName("Stormpike Commando"),
                    Cards.FromName("Stormwind Champion"),
                    Cards.FromName("Stormwind Champion"),
                    Cards.FromName("Stormwind Knight"),
                    Cards.FromName("Stormwind Knight")
                },
                FillDecks    = false,
                Shuffle      = true,
                SkipMulligan = false,
                Logging      = false,
                History      = false
            };

            for (int i = 0; i < maxGames; i++)
            {
                var game = new Game(gameConfig);
                game.StartGame();

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

                while (game.State != State.COMPLETE)
                {
                    while (game.State == State.RUNNING && game.CurrentPlayer == game.Player1)
                    {
                        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);
                        foreach (PlayerTask task in solution)
                        {
                            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, maxDepth, maxWidth);
                        var solution = new List <PlayerTask>();
                        solutions.OrderByDescending(p => p.Score).First().PlayerTasks(ref solution);
                        foreach (PlayerTask task in solution)
                        {
                            game.Process(task);
                            if (game.CurrentPlayer.Choice != null)
                            {
                                break;
                            }
                        }
                    }
                }

                player1Stats[(int)game.Player1.PlayState]++;
                player2Stats[(int)game.Player2.PlayState]++;

                Console.WriteLine($"{i}.Game: {game.State}, Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState}");
            }

            Console.WriteLine($"Player1: {String.Join(",", player1Stats)}");
            Console.WriteLine($"Player2: {String.Join(",", player2Stats)}");
        }
Пример #2
0
		public static void FullGame()
		{
			var game = new Game(
				new GameConfig()
				{
					StartPlayer = 1,
					Player1Name = "FitzVonGerald",
					Player1HeroClass = CardClass.WARRIOR,
					Player1Deck = Decks.AggroPirateWarrior,
					Player2Name = "RehHausZuckFuchs",
					Player2HeroClass = CardClass.WARRIOR,
					Player2Deck = Decks.AggroPirateWarrior,
					FillDecks = false,
					Shuffle = true,
					SkipMulligan = false
				});
			game.StartGame();

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

			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}");
		}
        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);
        }