コード例 #1
0
        private void UndoMove(Position source, Position target, Piece capturedPiece)
        {
            ChessPiece p = (ChessPiece)Board.RemovePiece(target);

            p.DecreaseMoveCount();
            Board.PlacePiece(p, source);

            if (capturedPiece != null)
            {
                Board.PlacePiece(capturedPiece, target);
                CapturedPieces.Remove(capturedPiece);
                PiecesOnTheBoard.Add(capturedPiece);
            }

            //SpecialMove Castling KingSide Rook
            if (p is King && target.Column == source.Column + 2)
            {
                Position   sourceRook = new Position(source.Row, source.Column + 3);
                Position   targetRook = new Position(source.Row, source.Column + 1);
                ChessPiece rook       = (ChessPiece)Board.RemovePiece(targetRook);
                Board.PlacePiece(rook, sourceRook);
                rook.DecreaseMoveCount();
            }
            //SpecialMove Castling QueenSide Rook
            if (p is King && target.Column == source.Column - 2)
            {
                Position   sourceRook = new Position(source.Row, source.Column - 4);
                Position   targetRook = new Position(source.Row, source.Column - 1);
                ChessPiece rook       = (ChessPiece)Board.RemovePiece(targetRook);
                Board.PlacePiece(rook, sourceRook);
                rook.DecreaseMoveCount();
            }

            //SpecialMove EnPassant
            if (p is Pawn)
            {
                if (source.Column != target.Column && capturedPiece == EnPassantVulnerable)
                {
                    ChessPiece pawn = (ChessPiece)Board.RemovePiece(target);
                    Position   pawnPosition;
                    if (p.Color == Color.White)
                    {
                        pawnPosition = new Position(3, target.Column);
                    }
                    else
                    {
                        pawnPosition = new Position(3, target.Column);
                    }
                    Board.PlacePiece(pawn, pawnPosition);
                }
            }
        }
コード例 #2
0
        public ChessPiece ReplacePromotedPiece(String type)
        {
            if (Promoted == null)
            {
                throw new ApplicationException("There is no piece to be promoted.\n");
            }
            if (!type.Equals("B") && !type.Equals("N") && !type.Equals("R") && !type.Equals("Q"))
            {
                return(Promoted);
            }

            Position promotedPosition = Promoted.GetChessPosition().ToPosition();
            Piece    promoted         = Board.RemovePiece(promotedPosition);

            PiecesOnTheBoard.Remove(promoted);

            ChessPiece newPiece = NewPiece(type, Promoted.Color);

            Board.PlacePiece(newPiece, promotedPosition);
            PiecesOnTheBoard.Add(newPiece);

            return(newPiece);
        }
コード例 #3
0
 private void PlaceNewPiece(char column, int row, ChessPiece piece)
 {
     Board.PlacePiece(piece, new ChessPosition(column, row).ToPosition());
     PiecesOnTheBoard.Add(piece);
 }