public ActionResult Mark(int row, int column, string botName, string state)
        {
            Game game = new Game();

            game.Board.Deserialize(state);

            game.Mark(row, column);

            if (game.IsOver)
            {
                return(this.RedirectToAction("GameOver", new { state = game.Board.Serialize() }));
            }

            IBot bot;

            switch (botName)
            {
            case "RandomBot": bot = new RandomBot(); break;

            case "MinMaxBot": bot = new MinMaxBot(); break;

            default: throw new ArgumentException("Unsupported bot!");
            }

            Tuple <int, int> move = bot.GetMove(game.Copy());

            game.Mark(move.Item1, move.Item2);

            if (game.IsOver)
            {
                return(this.RedirectToAction("GameOver", new { state = game.Board.Serialize() }));
            }

            return(this.RedirectToAction("Play", new { botName = botName, state = game.Board.Serialize() }));
        }
Example #2
0
        public IActionResult Mark(int row, int column)
        {
            Game game = this.SessionGet <Game>(this.SessionGameKey);

            game.Mark(row, column);

            if (!game.IsOver)
            {
                IBot bot;
                switch (this.SessionGet <string>(this.SessionBotKey))
                {
                case "RandomBot": bot = new RandomBot(); break;

                case "MinMaxBot": bot = new MinMaxBot(); break;

                default: throw new ArgumentException("Unsupported bot!");
                }

                Tuple <int, int> move = bot.GetMove(game.Copy());
                game.Mark(move.Item1, move.Item2);
            }

            this.SessionSet(this.SessionGameKey, game);

            return(this.RedirectToAction("Show"));
        }