예제 #1
0
파일: Computer.cs 프로젝트: Miha-I/checkers
        private int maxMove(CheckersBoard board, int depth, int alpha, int beta)
        {
            if (cutOffTest(board, depth))
            {
                return(eval(board));
            }


            List          sucessors;
            List          move;
            CheckersBoard nextBoard;
            int           value;

            sucessors = board.legalMoves();
            while (mayPlay(sucessors))
            {
                move      = (List)sucessors.pop_front();
                nextBoard = (CheckersBoard)board.clone();
                nextBoard.move(move);
                value = minMove(nextBoard, depth + 1, alpha, beta);

                if (value > alpha)
                {
                    alpha = value;
                }

                if (alpha > beta)
                {
                    return(beta);
                }
            }
            return(alpha);
        }
예제 #2
0
파일: Computer.cs 프로젝트: Miha-I/checkers
        private List minimax(CheckersBoard board)
        {
            List          sucessors;
            List          move, bestMove = null;
            CheckersBoard nextBoard;
            int           value, maxValue = Int32.MinValue;

            sucessors = board.legalMoves();
            while (mayPlay(sucessors))
            {
                move      = (List)sucessors.pop_front();
                nextBoard = (CheckersBoard)board.clone();
                nextBoard.move(move);
                value = minMove(nextBoard, 1, maxValue, Int32.MaxValue);

                if (value > maxValue)
                {
                    maxValue = value;
                    bestMove = move;
                }
            }
            return(bestMove);
        }