diff --git a/src/game_state.cpp b/src/game_state.cpp new file mode 100644 index 0000000..4c5333f --- /dev/null +++ b/src/game_state.cpp @@ -0,0 +1,60 @@ +#include "game_state.h" + +namespace Hanabi { + + void Game::make_turn() + { + assert(next_action < actions.size()); + 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(); + } + } +}