From 1c8a6840e6bc9cb1fa641d0ef2fe88ede5551373 Mon Sep 17 00:00:00 2001 From: sebastian Date: Wed, 5 Aug 2026 18:42:01 +0200 Subject: [PATCH] UPD: Move isBlockedByOwnPiece to LudoRules --- game/src/ludo/LudoGameMode.cpp | 13 ++----------- game/src/ludo/LudoGameMode.h | 3 --- game/src/ludo/gameMode/LudoRules.cpp | 9 +++++++++ game/src/ludo/gameMode/LudoRules.h | 2 ++ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/game/src/ludo/LudoGameMode.cpp b/game/src/ludo/LudoGameMode.cpp index a8f15ba..01b2b84 100644 --- a/game/src/ludo/LudoGameMode.cpp +++ b/game/src/ludo/LudoGameMode.cpp @@ -79,7 +79,7 @@ void ludo::LudoGameMode::handle(const RollDiceCommand &command) { if (m_gameState.m_diceValue == 6) { if (auto homeIndex = findLowestHomeSlotPiece(getColorOf(command.player))) { - if (!isBlockedByOwnPiece(getColorOf(command.player), PieceState::OnTrack, getEntryOffset(getColorOf(command.player)))) { + if (!LudoRules::isBlockedByOwnPiece(m_gameState, getColorOf(command.player), PieceState::OnTrack, getEntryOffset(getColorOf(command.player)))) { autoReleasePiece(*homeIndex); finishTurn(); return; @@ -165,7 +165,7 @@ std::vector ludo::LudoGameMode::getMoveablePieceIndices(PlayerColor color, continue; } - if (!isBlockedByOwnPiece(color, dest.state, dest.position)) { + if (!LudoRules::isBlockedByOwnPiece(m_gameState, color, dest.state, dest.position)) { moveablePieceIndices.push_back(i); } } @@ -196,15 +196,6 @@ int ludo::LudoGameMode::getEntryOffset(PlayerColor color) { return static_cast(color) * 10; } -bool ludo::LudoGameMode::isBlockedByOwnPiece(PlayerColor owner, PieceState state, int position) const { - for (const auto& piece : m_gameState.getPieces()) { - if (piece.color == owner && piece.state == state && piece.position == position) { - return true; - } - } - return false; -} - void ludo::LudoGameMode::publishEvent(LudoEvent event) { m_pendingEvents.push_back(event); m_eventBus.publish(event); diff --git a/game/src/ludo/LudoGameMode.h b/game/src/ludo/LudoGameMode.h index 16261fd..b358223 100644 --- a/game/src/ludo/LudoGameMode.h +++ b/game/src/ludo/LudoGameMode.h @@ -60,9 +60,6 @@ namespace ludo { int rollDice(); std::unique_ptr m_diceSource; - - [[nodiscard]] bool isBlockedByOwnPiece(PlayerColor owner, PieceState state, int position) const; - void publishEvent(LudoEvent event); }; } diff --git a/game/src/ludo/gameMode/LudoRules.cpp b/game/src/ludo/gameMode/LudoRules.cpp index 55537fb..80ad78f 100644 --- a/game/src/ludo/gameMode/LudoRules.cpp +++ b/game/src/ludo/gameMode/LudoRules.cpp @@ -35,3 +35,12 @@ std::optional ludo::LudoRules::computeDestination(const LudoG } return std::nullopt; } + +bool ludo::LudoRules::isBlockedByOwnPiece(const LudoGameState &state, PlayerColor owner, PieceState pieceState, int position) { + for (const auto& piece : state.getPieces()) { + if (piece.color == owner && piece.state == pieceState && piece.position == position) { + return true; + } + } + return false; +} diff --git a/game/src/ludo/gameMode/LudoRules.h b/game/src/ludo/gameMode/LudoRules.h index b1e255d..1d1cd6c 100644 --- a/game/src/ludo/gameMode/LudoRules.h +++ b/game/src/ludo/gameMode/LudoRules.h @@ -26,6 +26,8 @@ namespace ludo { static std::optional computeDestination(const LudoGameState& state, const Piece& piece, int diceValue); + static bool isBlockedByOwnPiece(const LudoGameState& state, PlayerColor owner, PieceState pieceState, int position); + };