Пример #1
0
        public IActionResult Index()
        {
            TicTacToe ticTacToe = TicTacToe.Instance;

            ticTacToe.ClearBoard();

            TicTacToeBot  bot  = TicTacToeBot.Instance;
            TicTacToeUser user = TicTacToeUser.Instance;

            bot.SetTicTacToe(ticTacToe);
            user.SetTicTacToe(ticTacToe);

            // switch starting
            if (ticTacToe.IsPlayerStarting == true)
            {
                ticTacToe.IsPlayerStarting = false;
                // bot first move
                AlphaBetaPruning alphaBetaPruning = new AlphaBetaPruning(ticTacToe.ticTacToeBoard, ticTacToe.Level);
                Tuple <int, int> xy = alphaBetaPruning.BestMove();
                bot.MakeMove(xy.Item1, xy.Item2);
            }
            else
            {
                ticTacToe.IsPlayerStarting = true;
            }

            return(View(ticTacToe));
        }
Пример #2
0
        public IActionResult NextMove(IFormCollection formCollection)
        {
            TicTacToe        ticTacToe        = TicTacToe.Instance;
            TicTacToeChecker ticTacToeChecker = new TicTacToeChecker();
            TicTacToeBot     bot  = TicTacToeBot.Instance;
            TicTacToeUser    user = TicTacToeUser.Instance;

            // setting level
            ticTacToe.Level = int.Parse(formCollection["Level"]);

            string place = formCollection["Button"];
            int    userX = int.Parse(place[0].ToString());
            int    userY = int.Parse(place[1].ToString());

            // user
            user.MakeMove(userX, userY);
            //
            ticTacToeChecker.CheckGameStatus(ticTacToe);

            if (ticTacToe.GameStatus == GameStatus.InProgress)
            {
                // bot
                AlphaBetaPruning alphaBetaPruning = new AlphaBetaPruning(ticTacToe.ticTacToeBoard, ticTacToe.Level);
                Tuple <int, int> xy = alphaBetaPruning.BestMove();
                bot.MakeMove(xy.Item1, xy.Item2);
                //
                ticTacToeChecker.CheckGameStatus(ticTacToe);

                if (ticTacToe.GameStatus != GameStatus.InProgress)
                {
                    ticTacToeChecker.CheckGameStatusAndGivePoint(ticTacToe);
                }
            }
            else
            {
                ticTacToeChecker.CheckGameStatusAndGivePoint(ticTacToe);
            }

            return(View("Index", ticTacToe));
        }