Ejemplo n.º 1
0
        // To match my version of TicTacToe (testing, playing AI vs AI, Human vs AI)
        public Cell MakeMove(Board board, int depthRecursion, CancellationToken token = default(CancellationToken))
        {
            Cell aiMove;

            // If CancellationToken is not null, pass it to the MinMax.NextMove()
            if (token != CancellationToken.None)
            {
                aiMove = minMaxAlg.NextMove(board, depthRecursion, token);
            }
            else            // no CancellationToken, Player can't stop AI from calculating the move.
            {
                aiMove = minMaxAlg.NextMove(board, depthRecursion);
            }


            return(aiMove);
        }
Ejemplo n.º 2
0
        // To match my version of TicTacToe (testing, playing AI vs AI, Human vs AI)
        public Cell MakeMove(Board board, int depthRecursion, CancellationToken token = default(CancellationToken))
        {
            Cell aiMove;

            if (board.rows * board.columns - board.remainingQtyMovesForGame == 0)            // 1st move in game
            {
                // AIPlayer takes center, this option never happens.
            }
            else if (board.rows * board.columns - board.remainingQtyMovesForGame == 1)           // 2nd move in game
            {
                // 1st move was made by opponent, so update with 'true'
                UpdateBattleFieldLimits(board, true);
            }
            else            // 3rd and after move in game
            {
                UpdateBattleFieldLimits(board, false);
            }

            BattleField = MakeBattleField(board);

            // If CancellationToken is not null, pass it to the MinMax.NextMove()
            if (token != CancellationToken.None)
            {
                aiMove = minMaxAlg.NextMove(BattleField, depthRecursion, token);
            }
            else            // no CancellationToken, Player can't stop AI from calculating the move.
            {
                aiMove = minMaxAlg.NextMove(BattleField, depthRecursion);
            }

            // Convert BattleField coords to board coords
            aiMove = CoordsBFtoMainBoard(aiMove);

            // Updating borders for BattleField
            UpdateBattleFieldLimits(board, false);

            return(aiMove);
        }