Exemplo n.º 1
0
        private JavaList <object> GetComputerMinimaxMovements(CheckersBoardGameEngine boardGameEngine)
        {
            JavaList <object> bestMove = null;
            int maxValue = int.MinValue;

            var sucessors = boardGameEngine.FindAllLegalMovesForCurrentPlayer();

            while (IsValidMove(sucessors))
            {
                var move      = (JavaList <object>)sucessors.pop_front();
                var nextBoard = boardGameEngine.Clone();

                nextBoard.ApplyMove(move);
                var value = PlayerMinMove(nextBoard, 1, maxValue, int.MaxValue);

                if (value > maxValue)
                {
                    Debug.WriteLine("Max value : " + value + " at depth : 0");
                    maxValue = value;
                    bestMove = move;
                }
            }

            Debug.WriteLine("Move value selected : " + maxValue + " at depth : 0");

            return(bestMove);
        }
Exemplo n.º 2
0
        private int PlayerMaxMove(CheckersBoardGameEngine boardGameEngine, int minimaxTreeDepth, int alphaCutOff, int betaCutOff)
        {
            if (TreeCutOffTest(boardGameEngine, minimaxTreeDepth))
            {
                return(GetCurrentPlayerStrength(boardGameEngine));
            }

            Debug.WriteLine("Max node at depth : " + minimaxTreeDepth + " with alpha : " + alphaCutOff +
                            " beta : " + betaCutOff);

            var sucessors = boardGameEngine.FindAllLegalMovesForCurrentPlayer();

            while (IsValidMove(sucessors))
            {
                var move      = (JavaList <object>)sucessors.pop_front();
                var nextBoard = boardGameEngine.Clone();
                nextBoard.ApplyMove(move);
                var value = PlayerMinMove(nextBoard, minimaxTreeDepth + 1, alphaCutOff, betaCutOff);

                if (value > alphaCutOff)
                {
                    alphaCutOff = value;
                    Debug.WriteLine("Max value : " + value + " at depth : " + minimaxTreeDepth);
                }

                if (alphaCutOff > betaCutOff)
                {
                    Debug.WriteLine("Max value with prunning : " + betaCutOff + " at depth : " + minimaxTreeDepth);
                    Debug.WriteLine(sucessors.Count + " sucessors left");
                    return(betaCutOff);
                }
            }

            Debug.WriteLine("Max value selected : " + alphaCutOff + " at depth : " + minimaxTreeDepth);
            return(alphaCutOff);
        }