From fb11c1db15f839c7777b159b30111311a4faa35b Mon Sep 17 00:00:00 2001 From: Yann Dirson Date: Mon, 6 Aug 2007 22:37:31 +0200 Subject: [PATCH] Deal with non-promotable shogi pieces. --- src/hlvariant/shogi/gamestate.h | 12 ++++++++++++ src/hlvariant/shogi/legalitycheck.h | 2 +- src/hlvariant/shogi/serializer.h | 2 +- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/hlvariant/shogi/gamestate.h b/src/hlvariant/shogi/gamestate.h index 2984de0..d580d67 100644 --- a/src/hlvariant/shogi/gamestate.h +++ b/src/hlvariant/shogi/gamestate.h @@ -48,6 +48,7 @@ public: virtual void basicMove(const Move& m); virtual void captureOn(const Point& p); virtual bool promotionZone(typename Piece::Color player, const Point& p) const; + virtual bool canPromote(const Piece& p) const; virtual void setTurn(typename Piece::Color color); virtual typename Piece::Color previousTurn() const; @@ -115,6 +116,17 @@ bool GameState::promotionZone(typename Piece::Color player, const P } template +bool GameState::canPromote(const Piece& p) const { + if (p.promoted()) + return false; + + if ((p.type() == Piece::KING) || (p.type() == Piece::GOLD)) + return false; + else + return true; +} + +template bool GameState::operator==(const GameState& other) const { return m_turn == other.m_turn && m_board == other.m_board; diff --git a/src/hlvariant/shogi/legalitycheck.h b/src/hlvariant/shogi/legalitycheck.h index 34fc699..621c52e 100644 --- a/src/hlvariant/shogi/legalitycheck.h +++ b/src/hlvariant/shogi/legalitycheck.h @@ -154,7 +154,7 @@ bool LegalityCheck::pseudolegal(Move& move) const { else { Piece piece = m_state.board().get(move.from()); if (piece != Piece() && getMoveType(piece, move)) { - if (!piece.promoted() && + if (m_state.canPromote(piece) && (m_state.promotionZone(piece.color(), move.to()) || m_state.promotionZone(piece.color(), move.from()))) move.setType(Move::PROMOTION); diff --git a/src/hlvariant/shogi/serializer.h b/src/hlvariant/shogi/serializer.h index 7c4f647..5c863bb 100644 --- a/src/hlvariant/shogi/serializer.h +++ b/src/hlvariant/shogi/serializer.h @@ -143,7 +143,7 @@ QString Serializer::serialize(const Move& move, const GameState& if (move.promoteTo() != -1) res += "+"; // if it is a refused promotion - else if (!piece.promoted() && + else if (ref.canPromote(piece) && move.drop() == Piece() && ref.promotionZone(ref.turn(), move.to())) { res += "="; -- 2.11.4.GIT