Exemple #1
0
        private static ResultBoards GetPossibleBoards(ChessPieceColor movingSide, Board examineBoard)
        {
            //We are going to store our result boards here
            resultBoards = new ResultBoards
            {
                Positions = new List <Board>()
            };

            for (byte x = 0; x < 64; x++)
            {
                Square sqr = examineBoard.Squares[x];

                //Make sure there is a piece on the square
                if (sqr.Piece == null)
                {
                    continue;
                }

                //Make sure the color is the same color as the one we are moving.
                if (sqr.Piece.PieceColor != movingSide)
                {
                    continue;
                }

                //For each valid move for this piece
                foreach (byte dst in sqr.Piece.ValidMoves)
                {
                    //We make copies of the board and move so that we can move it without effecting the parent board
                    Board board = examineBoard.FastBoardCopy();

                    //Make move so we can examine it
                    board.MovePiece(x, dst, ChessPieceType.Queen);

                    //We Generate Valid Moves for Board
                    board.GenerateValidMoves();


                    if (board.BlackCheck && movingSide == ChessPieceColor.Black)
                    {
                        continue;
                    }
                    if (board.WhiteCheck && movingSide == ChessPieceColor.White)
                    {
                        continue;
                    }

                    //We calculate the board score
                    board.EvaluateBoardScore();

                    //Invert Score to support Negamax
                    board.Score = SideToMoveScore(board.Score, GetOppositeColor(movingSide));

                    resultBoards.Positions.Add(board);
                }
            }

            return(resultBoards);
        }
Exemple #2
0
        public void InitiateBoard(string fen)
        {
            ChessBoard = new Board(fen);

            if (!string.IsNullOrEmpty(fen))
            {
                GenerateValidMoves();
                ChessBoard.EvaluateBoardScore();
            }
        }
Exemple #3
0
        public void Undo()
        {
            if (UndoChessBoard != null)
            {
                PieceTakenRemove(ChessBoard.LastMove);
                PieceTakenRemove(PreviousChessBoard.LastMove);

                ChessBoard      = new Board(UndoChessBoard);
                CurrentGameBook = UndoGameBook.MakeClone();

                ChessBoard.GenerateValidMoves();
                ChessBoard.EvaluateBoardScore();
            }
        }
Exemple #4
0
 public int EvaluateBoardScore() => ChessBoard.EvaluateBoardScore();
Exemple #5
0
        private ResultBoards GetSortValidMoves()
        {
            ResultBoards succ = new ResultBoards { Positions = new List<Board>(30) };

            piecesRemaining = 0;

#if (USETPL)
            Parallel.For(0,64, (ii) =>
#else
            for (byte ii = 0; ii < 64; ii++)
#endif
            {
                byte x = (byte)ii;
                Square sqr = Squares[x];

                //Make sure there is a piece on the square
                if (sqr.Piece == null)
#if (USETPL)
                    return;
#else
                    continue;
#endif

                piecesRemaining++;

                //Make sure the color is the same color as the one we are moving.
                if (sqr.Piece.PieceColor != WhoseMove)
#if (USETPL)
                    return;
#else
                    continue;
#endif

                    //For each valid move for this piece
                foreach (byte dst in sqr.Piece.ValidMoves)
                {
                    //We make copies of the board and move so that we can move it without effecting the parent board
                    Board board = FastBoardCopy();

                    //Make move so we can examine it
                    board.MovePiece(x, dst, ChessPieceType.Queen);

                    //We Generate Valid Moves for Board
                    board.GenerateValidMoves();

                    //Invalid Move
                    if (board.WhiteCheck && WhoseMove == ChessPieceColor.White)
                    {
                        continue;
                    }

                    //Invalid Move
                    if (board.BlackCheck && WhoseMove == ChessPieceColor.Black)
                    {
                        continue;
                    }

                    //We calculate the board score
                    board.EvaluateBoardScore();

                    //Invert Score to support Negamax
                    board.Score = SideToMoveScore(board.Score, board.WhoseMove);

                    succ.Positions.Add(board);
                }

            }