Beispiel #1
0
        public bool MovePiece(byte sourceColumn, byte sourceRow, byte destinationColumn, byte destinationRow)
        {
            byte srcPosition = (byte)(sourceColumn + (sourceRow * 8));
            byte dstPosition = (byte)(destinationColumn + (destinationRow * 8));

            Piece piece = ChessBoard.Squares[srcPosition].Piece;

            _previousChessBoard = new Board(ChessBoard);

            Board.MovePiece(ChessBoard, srcPosition, dstPosition, ChessPieceType.Queen);

            PieceMoveVaidation.GenerateValidMoves(ChessBoard);

            switch (piece.PieceColor)
            {
            //If there is a check in place, check if this is still true;
            case ChessPieceColor.White:
            {
                if (ChessBoard.WhiteCheck)
                {
                    //Invalid Move
                    ChessBoard = new Board(_previousChessBoard);
                    PieceMoveVaidation.GenerateValidMoves(ChessBoard);
                    return(false);
                }

                break;
            }

            case ChessPieceColor.Black:
            {
                if (ChessBoard.BlackCheck)
                {
                    //Invalid Move
                    ChessBoard = new Board(_previousChessBoard);
                    PieceMoveVaidation.GenerateValidMoves(ChessBoard);
                    return(false);
                }

                break;
            }

            default:
                throw new ArgumentOutOfRangeException("ChessPieceColor ", " is not valid");
            }

            return(true);
        }
Beispiel #2
0
 private void GenerateValidMoves()
 {
     PieceMoveVaidation.GenerateValidMoves(ChessBoard);
 }