コード例 #1
0
 public string debugManaCostOption(PlayerTask o)
 {
     if (o.HasSource)
     {
         return(o.Source.Card.Cost.ToString());
     }
     else             //if (o.PlayerTaskType == PlayerTaskType.HERO_POWER)
     {
         Console.WriteLine("getting mana debug: " + o.ToString());
         return(" Nan");
     }
     return(" Nan");            // HeroPower is not caught
 }
コード例 #2
0
        public bool PlayGame(bool addToGameStats = true)
        {
            Game game = new Game(gameConfig, setupHeroes);

            player1.InitializeGame();
            player2.InitializeGame();

            AbstractAgent currentAgent;
            Stopwatch     currentStopwatch;
            POGame        poGame;
            PlayerTask    playertask = null;

            Stopwatch[] watches = new[] { new Stopwatch(), new Stopwatch() };

            game.StartGame();
            try
            {
                while (game.State != State.COMPLETE && game.State != State.INVALID)
                {
                    if (gameConfig.Logging)
                    {
                        game.Log(LogLevel.INFO, BlockType.SCRIPT, "POGameHandler", "Turn " + game.Turn);
                    }

                    currentAgent = game.CurrentPlayer == game.Player1 ? player1 : player2;
                    Controller currentPlayer = game.CurrentPlayer;
                    currentStopwatch = game.CurrentPlayer == game.Player1 ? watches[0] : watches[1];
                    poGame           = new POGame(game, gameConfig.Logging);

                    currentStopwatch.Start();
                    playertask = currentAgent.GetMove(poGame);
                    currentStopwatch.Stop();

                    game.CurrentPlayer.Game   = game;
                    game.CurrentOpponent.Game = game;

                    if (gameConfig.Logging)
                    {
                        game.Log(LogLevel.INFO, BlockType.SCRIPT, "POGameHandler", playertask.ToString());
                    }
                    game.Process(playertask);
                    ShowLog(game, gameConfig, LogLevel.WARNING);
                }
            }
            catch (Exception e)
            //Current Player loses if he throws an exception
            {
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                game.State = State.COMPLETE;
                game.CurrentPlayer.PlayState   = PlayState.CONCEDED;
                game.CurrentOpponent.PlayState = PlayState.WON;

                if (addToGameStats && game.State != State.INVALID)
                {
                    gameStats.registerException(game, e);
                }
            }

            if (game.State == State.INVALID)
            {
                return(false);
            }

            if (addToGameStats)
            {
                gameStats.addGame(game, watches);
            }

            player1.FinalizeGame();
            player2.FinalizeGame();
            return(true);
        }
コード例 #3
0
 public Task SendPlayerTaskAsync(Player player, PlayerTask task, params string[] args) => SendAsync("task", new PlayerTaskRequest(player, task.ToString(), args));