示例#1
0
        public Piece ExecuteMoviment(Position origin, Position destiny)
        {
            Piece p = BoardOfMatch.RemovePiece(origin);

            p.IncrementManyMoves();
            Piece takenPiece = BoardOfMatch.RemovePiece(destiny);

            BoardOfMatch.PutPiece(p, destiny);
            if (takenPiece != null)
            {
                CapturedPieces.Add(takenPiece);
            }

            // #SpecialPlay

            // Castle Kingside
            if (p is King && destiny.Column == origin.Column + 2)
            {
                Position originOfRook  = new Position(origin.Line, origin.Column + 3);
                Position destinyOfRook = new Position(origin.Line, origin.Column + 1);

                Piece rook = BoardOfMatch.RemovePiece(originOfRook);
                rook.IncrementManyMoves();
                BoardOfMatch.PutPiece(rook, destinyOfRook);
            }

            // Castle Queenside
            if (p is King && destiny.Column == origin.Column - 2)
            {
                Position originOfRook  = new Position(origin.Line, origin.Column - 4);
                Position destinyOfRook = new Position(origin.Line, origin.Column - 1);

                Piece rook = BoardOfMatch.RemovePiece(originOfRook);
                rook.IncrementManyMoves();
                BoardOfMatch.PutPiece(rook, destinyOfRook);
            }

            // EnPassant
            if (p is Pawn)
            {
                if (origin.Column != destiny.Column && takenPiece == null)
                {
                    Position posPawn;
                    if (p.Color == Color.White)
                    {
                        posPawn = new Position(destiny.Line + 1, destiny.Column);
                    }
                    else
                    {
                        posPawn = new Position(destiny.Line - 1, destiny.Column);
                    }
                    takenPiece = BoardOfMatch.RemovePiece(posPawn);
                    CapturedPieces.Add(takenPiece);
                }
            }
            return(takenPiece);
        }
示例#2
0
        public void PerformPlay(Position origin, Position destiny)
        {
            Piece takenPiece = ExecuteMoviment(origin, destiny);

            if (IsTheKingInCheck(ActualPlayer))
            {
                UndoMoviment(origin, destiny, takenPiece);
                throw new BoardException("[ERROR] Can't put yourself in check");
            }

            Piece p = BoardOfMatch.UniquePiece(destiny);

            // #SpecialPlay upgrade
            if (p is Pawn)
            {
                if ((p.Color == Color.White && destiny.Line == 0) || (p.Color == Color.Black && destiny.Line == 7))
                {
                    p = BoardOfMatch.RemovePiece(destiny);
                    Pieces.Remove(p);

                    Piece queen = new Queen(p.Color, BoardOfMatch);
                    BoardOfMatch.PutPiece(queen, destiny);

                    Pieces.Add(queen);
                }
            }

            if (IsTheKingInCheck(AdversaryColor(ActualPlayer)))
            {
                Check = true;
            }
            else
            {
                Check = false;
            }

            if (IsCheckmate(AdversaryColor(ActualPlayer)))
            {
                Ended = true;
            }
            else
            {
                Turn++;
                ChangePlayer();
            }

            // #SpecialPlay
            // EnPassant
            if (p is Pawn && (destiny.Line == origin.Line - 2 || destiny.Line == origin.Line + 2))
            {
                VulnerableEnPassant = p;
            }
            else
            {
                VulnerableEnPassant = null;
            }
        }
示例#3
0
        public void UndoMoviment(Position origin, Position destiny, Piece takenPiece)
        {
            Piece p = BoardOfMatch.RemovePiece(destiny);

            p.DecrementManyMoves();
            if (takenPiece != null)
            {
                BoardOfMatch.PutPiece(takenPiece, destiny);
                CapturedPieces.Remove(takenPiece);
            }
            BoardOfMatch.PutPiece(p, origin);


            // #SpecialMove
            // Castle Kingside
            if (p is King && destiny.Column == origin.Column + 2)
            {
                Position originOfRook  = new Position(origin.Line, origin.Column + 3);
                Position destinyOfRook = new Position(origin.Line, origin.Column + 1);

                Piece rook = BoardOfMatch.RemovePiece(destinyOfRook);
                rook.DecrementManyMoves();
                BoardOfMatch.PutPiece(rook, originOfRook);
            }

            // Castle Queenside
            if (p is King && destiny.Column == origin.Column - 2)
            {
                Position originOfRook  = new Position(origin.Line, origin.Column - 4);
                Position destinyOfRook = new Position(origin.Line, origin.Column - 1);

                Piece rook = BoardOfMatch.RemovePiece(destinyOfRook);
                rook.IncrementManyMoves();
                BoardOfMatch.PutPiece(rook, originOfRook);
            }

            // EnPassant
            if (p is Pawn)
            {
                if (origin.Column != destiny.Column && takenPiece == VulnerableEnPassant)
                {
                    Piece    pawn = BoardOfMatch.RemovePiece(destiny);
                    Position posPawn;
                    if (p.Color == Color.White)
                    {
                        posPawn = new Position(3, destiny.Column);
                    }
                    else
                    {
                        posPawn = new Position(4, destiny.Column);
                    }
                    BoardOfMatch.PutPiece(pawn, posPawn);
                }
            }
        }
示例#4
0
 public void PutNewPiece(char column, int line, Piece piece)
 {
     BoardOfMatch.PutPiece(piece, new ChessPosition(column, line).ToPosition());
     Pieces.Add(piece);
 }