예제 #1
0
 public CheckersBoardView()
 {
     _selectedPositions = new JavaList <object>();
     _boardGameEngine   = new CheckersBoardGameEngine();
     _checkersMinimax   = new CheckersMinimax(_boardGameEngine);
     ResetBoard();
 }
예제 #2
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);
        }
예제 #3
0
        private int GetCurrentPlayerStrength(CheckersBoardGameEngine boardGameEngine)
        {
            var colorForce = 0;
            var enemyForce = 0;

            int colorKing = _computerPieceColor == CheckersBoardGameEngine.WhitePiece ? CheckersBoardGameEngine.WhiteKingPiece : CheckersBoardGameEngine.BlackKing;

            try
            {
                for (var i = 0; i < 32; i++)
                {
                    int piece = boardGameEngine.GetPieceAtPosition(i);

                    if (piece != CheckersBoardGameEngine.EmptyPiece)
                    {
                        if (piece == _computerPieceColor || piece == colorKing)
                        {
                            colorForce += GetPieceStrength(piece, i);
                        }
                        else
                        {
                            enemyForce += GetPieceStrength(piece, i);
                        }
                    }
                }
            }
            catch (InvalidBoardCoordinateException ex)
            {
                Debug.WriteLine(ex.StackTrace);
                Application.Exit();
            }

            return(colorForce - enemyForce);
        }
예제 #4
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);
        }
예제 #5
0
 public CheckersMinimax(CheckersBoardGameEngine gameBoardGameEngine)
 {
     _currentBoardGameEngine = gameBoardGameEngine;
     _computerPieceColor     = CheckersBoardGameEngine.BlackPiece;
 }
예제 #6
0
 private bool TreeCutOffTest(CheckersBoardGameEngine boardGameEngine, int minimaxTreeDepth)
 {
     return(minimaxTreeDepth > DefaultMinimaxTreeDepth || boardGameEngine.IsGameOver());
 }