public bool PlayGame(bool addToGameStats = true, bool debug = false)
        {
            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 (debug)
                    {
                        Console.WriteLine("Turn " + game.Turn);
                    }

                    if (game.Turn >= maxTurns)
                    {
                        break;
                    }

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

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

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

                    if (debug)
                    {
                        Console.WriteLine(playertask);
                    }
                    game.Process(playertask);
                }
            }
            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 || (game.Turn >= maxTurns && repeatDraws))
            {
                return(false);
            }

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

            player1.FinalizeGame();
            player2.FinalizeGame();
            return(true);
        }
Example #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);
        }
Example #3
0
        public bool PlayGame(bool addToGameStats = true, bool debug = false)
        {
            SabberStoneCore.Model.Game game = new SabberStoneCore.Model.Game(gameConfig, setupHeroes);
            //var 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() };
            bool        printGame = false;

            game.StartGame();
            if (gameConfig.SkipMulligan == false)
            {
                var originalStartingPlayer  = game.CurrentPlayer;
                var originalStartinOpponent = game.CurrentOpponent;

                game.CurrentPlayer = originalStartingPlayer;
                currentAgent       = gameConfig.StartPlayer == 1 ? player1 : player2;
                poGame             = new POGame(game, debug);
                playertask         = currentAgent.GetMove(poGame);
                game.Process(playertask);

                game.CurrentPlayer = originalStartinOpponent;
                currentAgent       = gameConfig.StartPlayer == 1 ? player2 : player1;
                poGame             = new POGame(game, debug);
                playertask         = currentAgent.GetMove(poGame);
                game.Process(playertask);

                game.CurrentPlayer = originalStartingPlayer;
                game.MainReady();
            }
#if DEBUG
            try
            {
#endif
            while (game.State != State.COMPLETE && game.State != State.INVALID)
            {
                //if (debug)
                //Console.WriteLine("Turn " + game.Turn);
                if (printGame)
                {
                    //Console.WriteLine(MCGS.SabberHelper.SabberUtils.PrintGame(game));
                    printGame = false;
                }

                if (game.Turn >= maxTurns)
                {
                    break;
                }

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

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

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

                if (debug)
                {
                    //Console.WriteLine(playertask);
                }

                if (playertask.PlayerTaskType == PlayerTaskType.END_TURN)
                {
                    printGame = true;
                }

                game.Process(playertask);
            }
#if DEBUG
        }

        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);
            }
        }
#endif

            if (game.State == State.INVALID || (game.Turn >= maxTurns && repeatDraws))
            {
                return(false);
            }

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

            player1.FinalizeGame();
            player2.FinalizeGame();
            return(true);
        }
Example #4
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() };
            var         cursorPosition = Console.CursorLeft;

            game.StartGame();
            try
            {
                while (game.State != State.COMPLETE && game.State != State.INVALID)
                {
                    var        player        = game.CurrentPlayer == game.Player1 ? "Player1" : "Player2";
                    Controller currentPlayer = game.CurrentPlayer;

                    if (debug)
                    {
                        Console.WriteLine("---------------------------------------------------");
                        Console.WriteLine("Turn {0}. {1}:[{2}/{3}]", game.Turn, player, currentPlayer.RemainingMana, currentPlayer.BaseMana);
                    }
                    else
                    {
                        Console.CursorLeft = cursorPosition;
                        Console.Write(new string(' ', Console.BufferWidth - (cursorPosition + 1)));
                        Console.CursorLeft = cursorPosition;
                        Console.Write(" Turn {0}. {1}:[{2}/{3}]", game.Turn, player, currentPlayer.RemainingMana, currentPlayer.BaseMana);
                    }

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

                    var turnWatch = new Stopwatch();
                    turnWatch.Start();
                    currentStopwatch.Start();
                    playertask = currentAgent.GetMove(poGame);
                    currentStopwatch.Stop();
                    turnWatch.Stop();
                    if (debug)
                    {
                        Console.WriteLine("Elapsed seconds for {0} : {1}", player, turnWatch.Elapsed.TotalSeconds);
                    }
                    game.CurrentPlayer.Game   = game;
                    game.CurrentOpponent.Game = game;

                    if (debug)
                    {
                        Console.WriteLine(playertask.FullPrint());
                    }
                    game.Process(playertask);
                }
            }
            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);
        }