UPD: Move isBlockedByOwnPiece to LudoRules
This commit is contained in:
parent
7426374b00
commit
1c8a6840e6
@ -79,7 +79,7 @@ void ludo::LudoGameMode::handle(const RollDiceCommand &command) {
|
|||||||
|
|
||||||
if (m_gameState.m_diceValue == 6) {
|
if (m_gameState.m_diceValue == 6) {
|
||||||
if (auto homeIndex = findLowestHomeSlotPiece(getColorOf(command.player))) {
|
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);
|
autoReleasePiece(*homeIndex);
|
||||||
finishTurn();
|
finishTurn();
|
||||||
return;
|
return;
|
||||||
@ -165,7 +165,7 @@ std::vector<int> ludo::LudoGameMode::getMoveablePieceIndices(PlayerColor color,
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isBlockedByOwnPiece(color, dest.state, dest.position)) {
|
if (!LudoRules::isBlockedByOwnPiece(m_gameState, color, dest.state, dest.position)) {
|
||||||
moveablePieceIndices.push_back(i);
|
moveablePieceIndices.push_back(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -196,15 +196,6 @@ int ludo::LudoGameMode::getEntryOffset(PlayerColor color) {
|
|||||||
return static_cast<int>(color) * 10;
|
return static_cast<int>(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) {
|
void ludo::LudoGameMode::publishEvent(LudoEvent event) {
|
||||||
m_pendingEvents.push_back(event);
|
m_pendingEvents.push_back(event);
|
||||||
m_eventBus.publish(event);
|
m_eventBus.publish(event);
|
||||||
|
|||||||
@ -60,9 +60,6 @@ namespace ludo {
|
|||||||
int rollDice();
|
int rollDice();
|
||||||
std::unique_ptr<IDiceSource> m_diceSource;
|
std::unique_ptr<IDiceSource> m_diceSource;
|
||||||
|
|
||||||
|
|
||||||
[[nodiscard]] bool isBlockedByOwnPiece(PlayerColor owner, PieceState state, int position) const;
|
|
||||||
|
|
||||||
void publishEvent(LudoEvent event);
|
void publishEvent(LudoEvent event);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,3 +35,12 @@ std::optional<ludo::Destination> ludo::LudoRules::computeDestination(const LudoG
|
|||||||
}
|
}
|
||||||
return std::nullopt;
|
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;
|
||||||
|
}
|
||||||
|
|||||||
@ -26,6 +26,8 @@ namespace ludo {
|
|||||||
static std::optional<Destination> computeDestination(const LudoGameState& state,
|
static std::optional<Destination> computeDestination(const LudoGameState& state,
|
||||||
const Piece& piece, int diceValue);
|
const Piece& piece, int diceValue);
|
||||||
|
|
||||||
|
static bool isBlockedByOwnPiece(const LudoGameState& state, PlayerColor owner, PieceState pieceState, int position);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user