From beb11579e012a2570f883d4bf37bb4f2b407d0f9 Mon Sep 17 00:00:00 2001 From: Paolo Capriotti Date: Wed, 25 Jul 2007 15:35:01 +0200 Subject: [PATCH] Removed Q_ASSERT macros in Position, as in #26. --- src/variants/xchess/position.h | 38 +++++++++++++------------------------- 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/src/variants/xchess/position.h b/src/variants/xchess/position.h index 784d987..aabe3fd 100644 --- a/src/variants/xchess/position.h +++ b/src/variants/xchess/position.h @@ -370,17 +370,18 @@ void Position::executeCaptureOn(const Point& point) { template void Position::basicMovePiece(const M& move) { P p = m_board[move.from]; - Q_ASSERT(p); - - m_board[move.to] = p; - m_board[move.from] = Piece(); + if (p) { + m_board[move.to] = p; + m_board[move.from] = Piece(); + } } template void Position::basicDropPiece(P* piece, const Point& to) { - Q_ASSERT(piece); - m_board[to] = *piece; - switchTurn(); + if (piece) { + m_board[to] = *piece; + switchTurn(); + } } template @@ -407,7 +408,7 @@ bool Position::pseudolegal(M& move) const { if (!valid(move.from)) return false; if (!valid(move.to)) return false; P piece = m_board[move.from]; - Q_ASSERT(piece); + if (!piece) return false; Color thisTurn = piece.color(); Color otherTurn = P::oppositeColor(thisTurn); if (piece && (turn() == thisTurn)) { @@ -435,8 +436,9 @@ bool Position::pseudolegal(M& move) const { template typename P::Color Position::moveTurn(const M& move) const { P piece = m_board[move.from]; - Q_ASSERT(piece); - return piece.color(); + if (piece) { + return piece.color(); + } } template @@ -689,7 +691,7 @@ void Position::dump() const { template void Position::move(const M& move) { P piece = m_board[move.from]; - Q_ASSERT(piece); + if (!piece) return; Color color = piece.color(); typename P::Type type = piece.type(); @@ -715,26 +717,12 @@ void Position::move(const M& move) { else if (move.type() == M::KingSideCastling) { Point rookSquare = move.to + Point(1,0); Point rookDestination = move.from + Point(1,0); - - P rook = m_board[rookSquare]; - - Q_ASSERT(rook); - Q_ASSERT(rook.type() == ROOK); - Q_UNUSED(rook); - basicMovePiece(M(rookSquare, rookDestination)); } else if (move.type() == M::QueenSideCastling) { Point rookSquare = move.to - Point(2,0); Point rookDestination = move.from - Point(1,0); - - P rook = m_board[rookSquare]; - - Q_ASSERT(rook); - Q_ASSERT(rook.type() == ROOK); - Q_UNUSED(rook); - basicMovePiece(M(rookSquare, rookDestination)); } } -- 2.11.4.GIT