2023-11-11 12:40:36 +01:00
|
|
|
#include "game_state.h"
|
|
|
|
|
|
|
|
namespace Hanabi {
|
|
|
|
|
|
|
|
void Game::make_turn()
|
|
|
|
{
|
2023-11-11 13:29:55 +01:00
|
|
|
ASSERT(next_action < actions.size());
|
2023-11-11 12:40:36 +01:00
|
|
|
Card const next_draw = deck[deck.size() - state->draw_pile_size()];
|
|
|
|
state->rotate_next_draw(next_draw);
|
|
|
|
Action const & action = actions[next_action];
|
|
|
|
std::uint8_t index;
|
|
|
|
switch(action.type) {
|
|
|
|
case Hanabi::ActionType::color_clue:
|
|
|
|
case Hanabi::ActionType::rank_clue:
|
|
|
|
state->give_clue();
|
|
|
|
break;
|
|
|
|
case Hanabi::ActionType::discard:
|
|
|
|
index = state->find_card_in_hand(action.card);
|
|
|
|
ASSERT(index != std::uint8_t(-1));
|
|
|
|
state->discard(index);
|
|
|
|
break;
|
|
|
|
case Hanabi::ActionType::play:
|
|
|
|
index = state->find_card_in_hand(action.card);
|
|
|
|
ASSERT(index != std::uint8_t(-1));
|
|
|
|
state->play(index);
|
|
|
|
break;
|
|
|
|
case Hanabi::ActionType::vote_terminate_players:
|
|
|
|
case Hanabi::ActionType::vote_terminate:
|
|
|
|
case Hanabi::ActionType::end_game:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
++next_action;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::revert_turn()
|
|
|
|
{
|
|
|
|
state->revert();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::forward_until(size_t turn, size_t draw_pile_break)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < std::min(turn - 1, actions.size()); i++) {
|
|
|
|
if (state->draw_pile_size() == draw_pile_break) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
make_turn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::revert_until(size_t draw_pile_break)
|
|
|
|
{
|
|
|
|
while(state->draw_pile_size() < draw_pile_break) {
|
|
|
|
revert_turn();
|
|
|
|
}
|
|
|
|
while(state->last_action_type() == ActionType::clue)
|
|
|
|
{
|
|
|
|
revert_turn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|