Exemple #1
0
        private Piece MovePiece(Position from, Position to)
        {
            Piece piece = Board.RemovePiece(from);

            piece.AddMovesQuantity();
            Piece capturedPiece = Board.RemovePiece(to);

            Board.AddPiece(to, piece);

            if (capturedPiece != null)
            {
                _capturedPieces.Add(capturedPiece);
            }

            //#jogadaespecial roque pequeno
            if (piece is King && to.Column == from.Column + 2)
            {
                Position rookPositionFrom = new Position(from.Row, from.Column + 3);
                Position rookPositionTo   = new Position(from.Row, from.Column + 1);
                MovePiece(rookPositionFrom, rookPositionTo);
            }

            //#jogadaespecial roque grande
            if (piece is King && to.Column == from.Column - 2)
            {
                Position rookPositionFrom = new Position(from.Row, from.Column - 4);
                Position rookPositionTo   = new Position(from.Row, from.Column - 1);
                MovePiece(rookPositionFrom, rookPositionTo);
            }

            //#jogadaespecial en passant
            if (piece is Pawn)
            {
                if (from.Column != to.Column && capturedPiece == null)
                {
                    Position piecePosition;
                    if (piece.Color == Color.White)
                    {
                        piecePosition = new Position(to.Row + 1, to.Column);
                    }
                    else
                    {
                        piecePosition = new Position(to.Row - 1, to.Column);
                    }

                    capturedPiece = Board.RemovePiece(piecePosition);
                    _capturedPieces.Add(capturedPiece);
                }
            }

            return(capturedPiece);
        }