diff options
-rw-r--r-- | server/game.cpp | 47 |
1 files changed, 37 insertions, 10 deletions
diff --git a/server/game.cpp b/server/game.cpp index 6ae899c..a02dc7b 100644 --- a/server/game.cpp +++ b/server/game.cpp @@ -80,7 +80,8 @@ void Game::round_start() { } void Game::round_update() { - + + char smart = 0; // We're in the draw_phase whenever a player draws a tile from the wall if(draw_phase) { // If the wall is empty (Contains only 14 tiles) when we enter draw phase the round is over. @@ -123,6 +124,7 @@ void Game::round_update() { // Enter the discard phase next loop; draw_phase = false; + smart = smart | (1 << current_player); } else { //We chwck to see if player can chi from last discard @@ -263,26 +265,49 @@ void Game::round_update() { } } - - //Go back into draw_phase0 draw_phase = true; // Not implemented yet - + for(Actions::iterator it = game_state.possible_actions.begin(); it != game_state.possible_actions.end(); ++it) { + smart = smart | (0x0001 << it->player); + } + + if(smart & 1) { + Action pass; + pass.type = Action::Pass; + pass.player = 0; + game_state.possible_actions.push_back(pass); + } + if(smart & 2) { + Action pass; + pass.type = Action::Pass; + pass.player = 1; + game_state.possible_actions.push_back(pass); + } + if(smart & 4) { + Action pass; + pass.type = Action::Pass; + pass.player = 2; + game_state.possible_actions.push_back(pass); + } + if(smart & 8) { + Action pass; + pass.type = Action::Pass; + pass.player = 3; + game_state.possible_actions.push_back(pass); + } } + // Send the updates state to the players - players[0]->round_state(game_state); players[1]->round_state(game_state); players[2]->round_state(game_state); players[3]->round_state(game_state); + // Only implemented discard so far, so only current player that needs to be able to do a action. - char smart = 0; - for(Actions::iterator it = game_state.possible_actions.begin(); it != game_state.possible_actions.end(); ++it) { - smart = smart | (0x0001 << it->player); - } + if(smart & 1) { num_player_actions++; @@ -400,8 +425,10 @@ void Game::handle_action(Action action) { position++; } if (!positions.empty()) { + int found = 0; for(std::vector<int>::iterator it = positions.begin(); it != positions.end(); ++it) { - game_state.possible_actions.erase(game_state.possible_actions.begin() + *it); + game_state.possible_actions.erase(game_state.possible_actions.begin() + (*it - found)); + found++; } } |