예제 #1
0
        public void MakeThePlay(Position origin, Position destination)
        {
            Piece CapturedPiece = RunMovement(origin, destination);

            if (IsItChecked(CurrentPlayer))
            {
                UndoMovement(origin, destination, CapturedPiece);
                throw new BoardException("You Can't put yourself in check!");
            }

            Piece p = Brd.Piece(destination);

            //#Special Play: Promotion
            if (p is Pawn)
            {
                if (p.Color == Color.White && destination.Row == 0 || p.Color == Color.Black && destination.Row == 7)
                {
                    p = Brd.RemovePiece(destination);
                    Pieces.Remove(p);
                    Piece queen = new Queen(Brd, p.Color);
                    Brd.PutPiece(queen, destination);
                    Pieces.Add(queen);
                }
            }


            if (IsItChecked(Opponent(CurrentPlayer)))
            {
                Check = true;
            }
            else
            {
                Check = false;
            }

            if (CheckmateTest(Opponent(CurrentPlayer)))
            {
                Finished = true;
            }
            else
            {
                Turn++;
                ChangePlayer();
            }

            //#Special Play: En Passant
            if (p is Pawn && destination.Row == origin.Row - 2 || destination.Row == origin.Row + 2)
            {
                VulnerableEnPassant = p;
            }
            else
            {
                VulnerableEnPassant = null;
            }
        }
예제 #2
0
        public Piece RunMovement(Position origin, Position destination)
        {
            Piece P = Brd.RemovePiece(origin);

            P.IncreaseMovementsQty();
            Piece CapturedPiece = Brd.RemovePiece(destination);

            Brd.PutPiece(P, destination);
            if (CapturedPiece != null)
            {
                Captured.Add(CapturedPiece);
            }

            //#Special Play: Castling short
            if (P is King && destination.Column == origin.Column + 2)
            {
                Position originR      = new Position(origin.Row, origin.Column + 3);
                Position destinationR = new Position(origin.Row, origin.Column + 1);
                Piece    R            = Brd.RemovePiece(originR);
                R.IncreaseMovementsQty();
                Brd.PutPiece(R, destinationR);
            }

            //#Special Play: Castling long
            if (P is King && destination.Column == origin.Column - 2)
            {
                Position originR      = new Position(origin.Row, origin.Column - 4);
                Position destinationR = new Position(origin.Row, origin.Column - 1);
                Piece    R            = Brd.RemovePiece(originR);
                R.IncreaseMovementsQty();
                Brd.PutPiece(R, destinationR);
            }

            //#Special Play: En Passant
            if (P is Pawn)
            {
                if (origin.Column != destination.Column && CapturedPiece == null)
                {
                    Position posP;
                    if (P.Color == Color.White)
                    {
                        posP = new Position(destination.Row + 1, destination.Column);
                    }
                    else
                    {
                        posP = new Position(destination.Row - 1, destination.Column);
                    }
                    CapturedPiece = Brd.RemovePiece(posP);
                    Captured.Add(CapturedPiece);
                }
            }

            return(CapturedPiece);
        }
예제 #3
0
        public void UndoMovement(Position origin, Position destination, Piece capturedPiece)
        {
            Piece P = Brd.RemovePiece(destination);

            P.DecreaseMovementsQty();
            if (capturedPiece != null)
            {
                Brd.PutPiece(capturedPiece, destination);
                Captured.Remove(capturedPiece);
            }
            Brd.PutPiece(P, origin);

            //#Special Play: Castling short
            if (P is King && destination.Column == origin.Column + 2)
            {
                Position originR      = new Position(origin.Row, origin.Column + 3);
                Position destinationR = new Position(origin.Row, origin.Column + 1);
                Piece    R            = Brd.RemovePiece(destinationR);
                R.DecreaseMovementsQty();
                Brd.PutPiece(R, originR);
            }

            //#Special Play: Castling long
            if (P is King && destination.Column == origin.Column - 2)
            {
                Position originR      = new Position(origin.Row, origin.Column - 4);
                Position destinationR = new Position(origin.Row, origin.Column - 1);
                Piece    R            = Brd.RemovePiece(destinationR);
                R.DecreaseMovementsQty();
                Brd.PutPiece(R, originR);
            }

            //#Special Play: En Passant
            if (P is Pawn)
            {
                if (origin.Column != destination.Column && capturedPiece == VulnerableEnPassant)
                {
                    Piece    pawn = Brd.RemovePiece(destination);
                    Position posP;
                    if (P.Color == Color.White)
                    {
                        posP = new Position(3, destination.Column);
                    }
                    else
                    {
                        posP = new Position(4, destination.Column);
                    }
                    Brd.PutPiece(pawn, posP);
                }
            }
        }