예제 #1
0
 private int checkWinner()
 {
     if (OMinimax.getScore(board, true, false) >= OMinimax.getWinScore())
     {
         return(1);
     }
     if (OMinimax.getScore(board, false, true) >= OMinimax.getWinScore())
     {
         return(2);
     }
     return(0);
 }
예제 #2
0
        public void run()
        {
            //Clear Console and draw board
            board.BoardDraw();
            // AI 1 LOGIC
            // using Minimax and alpha beta pruning algorithms calculate and return coordinates
            int[] aiMove = aiX.calculateNextMove(minimaxDepth);
            //Check if it is tie
            if (aiMove == null)
            {
                Console.WriteLine("No possible moves left. Game Over.");

                gameFinished = true;
                return;
            }


            // Place a [0] to the found cell.
            playMove(aiMove[1], aiMove[0], true);

            board.BoardDraw();

            Console.WriteLine("[0]: " + OMinimax.getScore(board, true, true) + " [X]: " + OMinimax.getScore(board, false, true));


            // Check if the last move ends the game.
            winner = checkWinner();

            if (winner == 1)
            {
                Console.WriteLine("AI1 [0] WON!");

                gameFinished = true;
                return;
            }

            // Make the AI instance calculate a move.
            int[] aiMove2 = aiO.calculateNextMove(minimaxDepth);

            if (aiMove2 == null)
            {
                Console.WriteLine("No possible moves left. Game Over.");

                gameFinished = true;
                return;
            }


            // Place a [X] to the found cell.
            playMove(aiMove2[1], aiMove2[0], false);

            board.BoardDraw();

            Console.WriteLine("Black: " + OMinimax.getScore(board, true, true) + " White: " + OMinimax.getScore(board, false, true));

            winner = checkWinner();

            if (winner == 2)
            {
                Console.WriteLine("AI2 [X] WON!");

                gameFinished = true;
                return;
            }

            if (board.generateMoves().Count == 0)
            {
                Console.WriteLine("No possible moves left. Game Over.");

                gameFinished = true;
                return;
            }

            isAi1Turn = true;
        }