Пример #1
0
        public static void RunQuickMatch()
        {
            var game = new SabberStoneState(new SabberStoneCore.Model.Game(new GameConfig {
                StartPlayer      = 1,
                Player1Name      = Constants.SABBERSTONE_GAMECONFIG_PLAYER1_NAME,
                Player1HeroClass = CardClass.HUNTER,
                Player1Deck      = Decks.GetRandomTournamentDeck(),
                Player2Name      = Constants.SABBERSTONE_GAMECONFIG_PLAYER2_NAME,
                Player2HeroClass = CardClass.HUNTER,
                Player2Deck      = Decks.GetRandomTournamentDeck(),
                FillDecks        = false,
                Shuffle          = true,
                SkipMulligan     = false,
                History          = false
            }));

            // Create two bots to play
            var bot1 = BotFactory.CreateSabberStoneBot(BotSetupType.RandomBot, game.Player1);
            var bot2 = BotFactory.CreateSabberStoneBot(BotSetupType.RandomBot, game.Player2);

            game.Game.StartGame();

            game.Game.Process(MulliganStrategySabberStone.DefaultMulligan(game.Game.Player1));
            game.Game.Process(MulliganStrategySabberStone.DefaultMulligan(game.Game.Player2));

            game.Game.MainReady();

            while (game.Game.State != State.COMPLETE)
            {
                Console.WriteLine("");
                Console.WriteLine($"TURN {(game.Game.Turn + 1) / 2} - {game.Game.CurrentPlayer.Name}");
                Console.WriteLine($"Hero[P1] {game.Player1.Hero} HP: {game.Player1.Hero.Health} / Hero[P2] {game.Player2.Hero} HP: {game.Player2.Hero.Health}");
                Console.WriteLine($"- {game.Game.CurrentPlayer.Name} Action ----------------------------");

                // Ask the bot to act.
                var action = game.Game.CurrentPlayer.Id == game.Player1.Id ? bot1.Act(game) : bot2.Act(game);

                // Check if the action is valid
                if (action == null || !action.IsComplete())
                {
                    continue;
                }

                // Process the tasks in the action
                foreach (var item in action.Tasks)
                {
                    // Process the task
                    Console.WriteLine(item.Task.FullPrint());
                    game.Game.Process(item.Task);
                }
            }

            Console.WriteLine($"Game: {game.Game.State}, Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState}");
        }
        /// <summary>
        /// Runs a game of this match with the specified index.
        /// </summary>
        /// <param name="gameIndex">The index of the game that should be run.</param>
        public void RunGame(int gameIndex)
        {
            Console.WriteLine($"{DateTime.Now:T} -> Starting Game {gameIndex+1} of {NumberOfGames}");
            try {
                var timer = Stopwatch.StartNew();

                // Alternate which player starts.
                var config = GetTournamentConfiguration();
                config.StartPlayer = gameIndex % 2 + 1;

                // Create a new game with the cloned configuration.
                var game = new SabberStoneState(new SabberStoneCore.Model.Game(config));

                // Set up the bots with their Controller from the created game.
                Bots[0].SetController(game.Player1);
                Bots[1].SetController(game.Player2);

                // Get the game ready.
                game.Game.StartGame();
                MatchStatistics.NewGameStarted(gameIndex + 1, game.Game.FirstPlayer.Name);

                // Default mulligan for each player.
                game.Game.Process(MulliganStrategySabberStone.DefaultMulligan(game.Game.Player1));
                game.Game.Process(MulliganStrategySabberStone.DefaultMulligan(game.Game.Player2));

                game.Game.MainReady();

                // Play out the game.
                while (game.Game.State != State.COMPLETE)
                {
                    if (_printToConsole)
                    {
                        Console.WriteLine("");
                    }
                    if (_printToConsole)
                    {
                        Console.WriteLine($"*TURN {(game.Game.Turn + 1) / 2} - {game.Game.CurrentPlayer.Name}");
                    }
                    if (_printToConsole)
                    {
                        Console.WriteLine($"*Hero[P1] {game.Player1.Hero} HP: {game.Player1.Hero.Health} / Hero[P2] {game.Player2.Hero} HP: {game.Player2.Hero.Health}");
                    }

                    // Play out the current player's turn until they pass.
                    if (game.Game.CurrentPlayer.Id == Bots[0].PlayerID())
                    {
                        PlayPlayerTurn(game, Bots[0]);
                    }
                    else if (game.Game.CurrentPlayer.Id == Bots[1].PlayerID())
                    {
                        PlayPlayerTurn(game, Bots[1]);
                    }
                }

                if (_printToConsole)
                {
                    Console.WriteLine($"*Game: {game.Game.State}, Player1: {game.Player1.PlayState} / Player2: {game.Player2.PlayState}");
                    Console.WriteLine($"*Game lasted {timer.Elapsed:g}");
                }

                // Create game data.
                MatchStatistics.EndCurrentGame(game);
            }
            catch (Exception e) {
                Console.WriteLine($"ERROR: Exception thrown during game {gameIndex+1}");
                WriteExceptionToFile(e);
            }
        }