add missing game_state.cpp file
This commit is contained in:
parent
5b0834bc22
commit
1266791750
1 changed files with 60 additions and 0 deletions
60
src/game_state.cpp
Normal file
60
src/game_state.cpp
Normal file
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue