summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/game.cpp58
1 files changed, 41 insertions, 17 deletions
diff --git a/server/game.cpp b/server/game.cpp
index 1806e25..cdfaf4f 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -60,7 +60,7 @@ void Game::round_start() {
game_state.players[player_num].hand.push_back(wall.take_one());
}
- current_player = 0;
+ current_player = 3;
num_player_actions = 0;
draw_phase = true;
@@ -70,7 +70,24 @@ void Game::round_start() {
void Game::round_update() {
+
if ( draw_phase ) {
+
+
+
+
+ if ( current_player == 3) {
+ current_player = 0;
+ } else {
+ current_player++;
+ }
+ #ifdef DEBUG
+
+ std::cout << "Next players turn: " << current_player << std::endl;
+
+ #endif
+
+
// Is the wall empty? Then the round is over and we have a draw
if (wall.is_done()) {
round_end();
@@ -92,37 +109,46 @@ void Game::round_update() {
// TODO
// Add code for calculation of possible chi, pon, kan and ron.
-
- // Update who the current player is.
- if ( current_player == 3) {
- current_player = 0;
- } else {
- current_player++;
- }
}
// Send RoundState, inkl. liste av mulige actions.
- players[0]->round_state(game_state);
- players[1]->round_state(game_state);
- players[2]->round_state(game_state);
- players[3]->round_state(game_state);
-
+ for(int i = 0; i <= 3; i++) {
+ if ( i != current_player ) {
+ State send_state = game_state;
+
+ send_state.possible_actions.clear();
+
+ players[i]->round_state(send_state);
+ } else {
+ players[i]->round_state(game_state);
+ #ifdef DEBUG
+ std::cout << "Waiting for action from player: " << i << std::endl;
+ #endif
+ }
+ }
// Kall player->get_action(handle_action) for hver spiller som har actions, om ingen kan gjøre noe så blir
// det neste spiller sin tur.
+ draw_phase = !draw_phase;
if(num_player_actions) {
- draw_phase = !draw_phase;
players[current_player]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
} else {
- draw_phase = true;
round_update();
}
}
void Game::handle_action(Action action) {
+
+ #ifdef DEBUG
+
+ std::cout << "Player: " << action.player << " Did action: " << action.type << " On target: " << action.target << std::endl;
+
+
+ #endif
+
switch ( action.type ) {
case Action::Pass: {
@@ -179,8 +205,6 @@ void Game::handle_action(Action action) {
if (num_player_actions == 0) {
// TODO
// Add code for when someone has done a chi, pon, ron and kan.
-
-
round_update();
}
}