ColorRace/tests/LoduGameMode.cpp
2026-08-05 07:10:27 +02:00

38 lines
1.4 KiB
C++

#include "gtest/gtest.h"
//
// Created by sebastian on 05.08.26.
//
#include "helpers/SequenceDiceSource.h"
#include "ludo/LudoGameMode.h"
TEST(LudoGameMode, SecondSixMovesOutOfBlockedEntry) {
ludo::LudoGameMode mode({0});
mode.setDiceSource(std::make_unique<SequenceDiceSource>(std::vector<int>{6, 6}));
mode.sendCommand(ludo::RollDiceCommand{0});
mode.pollEvents(); // Events des ersten Wurfs verwerfen, nicht Teil dieser Prüfung
ASSERT_EQ(mode.getCurrentPlayer(), 0u);
ASSERT_EQ(mode.getState().getPhase(), ludo::TurnPhase::AwaitingRoll);
mode.sendCommand(ludo::RollDiceCommand{0});
mode.pollEvents(); // Events des zweiten Wurfs verwerfen
ASSERT_EQ(mode.getState().getPhase(), ludo::TurnPhase::AwaitingPieceSelection);
auto movable = mode.getMoveablePieceIndices(ludo::PlayerColor::Red, mode.getState().getDiceValue());
ASSERT_EQ(movable.size(), 1u);
ASSERT_EQ(movable[0], 0);
mode.sendCommand(ludo::MovePieceCommand{0, 0});
auto events = mode.pollEvents(); // jetzt NUR die Events dieses einen Commands
ASSERT_FALSE(events.empty());
auto* moved = std::get_if<ludo::PieceMovedEvent>(&events.front());
ASSERT_NE(moved, nullptr);
EXPECT_EQ(moved->fromPosition, 0);
EXPECT_EQ(moved->toPosition, 6);
EXPECT_FALSE(moved->captured);
const auto& piece = mode.getState().getPieces()[0];
EXPECT_EQ(piece.state, ludo::PieceState::OnTrack);
EXPECT_EQ(piece.position, 6);
}