Ejemplo n.º 1
0
        public void MakeMove(Position origin, Position destination)
        {
            Piece catchedPiece = ExecuteMove(origin, destination);

            if (InCheck(currentPlayer))
            {
                undoMove(origin, destination, catchedPiece);
                throw new BoardException("Você não pode se colocar em Xeque");
            }
            Piece p = Bd.Piece(destination);

            //# Jogada especial promoção
            if (p is Pawn)
            {
                if ((p.Color == Color.White && destination.Linha == 0) || (p.Color == Color.Black && destination.Linha == 7))
                {
                    p = Bd.GetPiece(destination);
                    pieces.Remove(p);
                    Piece queen = new Queen(Bd, p.Color);
                    Bd.PutPiece(queen, destination);
                    pieces.Add(queen);
                }
            }
            if (InCheck(adversaryColor(currentPlayer)))
            {
                Check = true;
            }
            else
            {
                Check = false;
            }
            if (TestMate(adversaryColor(currentPlayer)))
            {
                Finished = true;
            }
            else
            {
                shift++;
                ChangePlayer();
            }


            //#Jogada especial enPassant
            if (p is Pawn && (destination.Linha == origin.Linha - 2 || destination.Linha == origin.Linha + 2))
            {
                vulnerableEnPassant = p;
            }
            else
            {
                vulnerableEnPassant = null;
            }
        }
Ejemplo n.º 2
0
        public Piece ExecuteMove(Position origin, Position destination)
        {
            Piece p = Bd.GetPiece(origin);

            p.AddQtMovies();
            Piece catchedPiece = Bd.GetPiece(destination);

            Bd.PutPiece(p, destination);
            if (catchedPiece != null)
            {
                catched.Add(catchedPiece);
            }

            //#Jogada especial Roque pequeno
            if (p is King && destination.Coluna == origin.Coluna + 2)
            {
                Position tOrigin      = new Position(origin.Linha, origin.Coluna + 3);
                Position tDestination = new Position(origin.Linha, origin.Coluna + 1);
                Piece    T            = Bd.GetPiece(tOrigin);
                T.AddQtMovies();
                Bd.PutPiece(T, tDestination);
            }
            //#Jogada especial Roque Grande
            if (p is King && destination.Coluna == origin.Coluna - 2)
            {
                Position tOrigin      = new Position(origin.Linha, origin.Coluna - 4);
                Position tDestination = new Position(origin.Linha, origin.Coluna - 1);
                Piece    T            = Bd.GetPiece(tOrigin);
                T.AddQtMovies();
                Bd.PutPiece(T, tDestination);
            }
            //#Jogada especial enPassant
            if (p is Pawn)
            {
                if (origin.Coluna != destination.Coluna && catchedPiece == null)
                {
                    Position posP;
                    if (p.Color == Color.White)
                    {
                        posP = new Position(destination.Linha + 1, destination.Coluna);
                    }
                    else
                    {
                        posP = new Position(destination.Linha - 1, destination.Coluna);
                    }
                    catchedPiece = Bd.GetPiece(posP);
                    catched.Add(catchedPiece);
                }
            }
            return(catchedPiece);
        }
Ejemplo n.º 3
0
        private void undoMove(Position origin, Position destination, Piece catchedPiece)
        {
            Piece p = Bd.GetPiece(destination);

            p.DecrementQtMovies();
            if (catchedPiece != null)
            {
                Bd.PutPiece(catchedPiece, destination);
                catched.Remove(catchedPiece);
            }
            Bd.PutPiece(p, origin);

            //#Jogada especial Roque pequeno
            if (p is King && destination.Coluna == origin.Coluna + 2)
            {
                Position tOrigin      = new Position(origin.Linha, origin.Coluna + 3);
                Position tDestination = new Position(origin.Linha, origin.Coluna + 1);
                Piece    T            = Bd.GetPiece(tOrigin);
                T.DecrementQtMovies();
                Bd.PutPiece(T, tDestination);
            }
            //#Jogada especial Roque grande
            if (p is King && destination.Coluna == origin.Coluna - 2)
            {
                Position tOrigin      = new Position(origin.Linha, origin.Coluna - 4);
                Position tDestination = new Position(origin.Linha, origin.Coluna - 1);
                Piece    T            = Bd.GetPiece(tOrigin);
                T.DecrementQtMovies();
                Bd.PutPiece(T, tDestination);
            }
            //#Jogada especial En Passant
            if (p is Pawn)
            {
                if (origin.Coluna != destination.Coluna && catchedPiece == vulnerableEnPassant)
                {
                    Piece    pawn = Bd.GetPiece(destination);
                    Position posP;
                    if (p.Color == Color.White)
                    {
                        posP = new Position(3, destination.Coluna);
                    }
                    else
                    {
                        posP = new Position(4, destination.Coluna);
                    }
                    Bd.PutPiece(pawn, posP);
                }
            }
        }
Ejemplo n.º 4
0
 public void PutNewPiece(char coluna, int linha, Piece piece)
 {
     Bd.PutPiece(piece, new ChessPosition(coluna, linha).ToPosition());
     pieces.Add(piece);
 }