summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/game.cpp131
-rw-r--r--server/game.h13
2 files changed, 108 insertions, 36 deletions
diff --git a/server/game.cpp b/server/game.cpp
index 3c695c4..bd4314e 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -35,20 +35,17 @@ void Game::handle_ready() {
void Game::round_start() {
players[0]->round_start();
+ players[0]->id = 0;
players[1]->round_start();
+ players[1]->id = 1;
players[2]->round_start();
+ players[2]->id = 2;
players[3]->round_start();
+ players[3]->id = 3;
- // Sett opp runden
+ // Sett opp runden sin state
game_state = make_shared<State>();
- east_action = false;
- west_action = false;
- south_action = false;
- north_action = false;
-
- num_player_actions = 0;
-
// Simulates drawing 4, 4 ,4 for each player
for (int player_num = 0; player_num < 4; player_num++) {
for (int i = 0; i < 3; i++) {
@@ -63,54 +60,124 @@ void Game::round_start() {
game_state->players[player_num].hand.push_back(wall.take_one());
}
- // Gives an extra tile to the first player (east)
- game_state->players[0].hand.push_back(wall.take_one());
-
- // Set the action that east can do.
- Action discard;
- discard.type = Action::Discard;
- game_state->possible_actions.push_back(discard);
-
- east_action = true;
- num_player_actions++;
+ current_player = 0;
+ num_player_actions = 0;
+ draw_phase = true;
round_update();
}
void Game::round_update() {
- // Send RoundState, inkl. liste av mulige actions.
+ if ( draw_phase ) {
+ game_state->players[current_player].hand.push_back(wall.take_one());
+
+ Action discard_action;
+ discard_action.type = Action::Discard;
+ discard_action.player = current_player;
+
+ game_state->possible_actions.push_back(discard_action);
+
+ // TODO
+ // Add code for calculation of possible riichi, tsumo, kan and draw
+
+ num_player_actions++;
+
+ draw_phase = false;
+
+ } else { // Run if we're in the discard phase
+
+
+
+
+ // Update who the current player is.
+ if ( current_player == 3) {
+ current_player = 0;
+ } else {
+ current_player++;
+ }
+
+ draw_phase = true;
+ }
+
+
+
+ // 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);
- // Kall player->get_action(handle_action) for hver spiller som har actions
- if (east_action) {
+ // 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.
+ if(num_player_actions) {
players[0]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ } else {
+ round_update();
}
+
+}
+
+void Game::handle_action(Action action) {
+ switch ( action.type ) {
+
+ case Action::Pass: {
+
+ } break;
+
+ case Action::Discard: {
+ game_state->players[current_player].pond.push_back(game_state->players[current_player].hand[action.target]);
+ game_state->players[current_player].hand.erase(game_state->players[current_player].hand.begin() + action.target);
+ } break;
+
+ case Action::Riichi: {
+
+ } break;
+
+ case Action::Chi: {
+ if(most_value_action.type != Action::Pon && most_value_action.type != Action::Kan && most_value_action.type != Action::Ron) {
+ most_value_action = action;
+ }
+ } break;
- if (west_action) {
- players[1]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ case Action::Pon: {
+ if(most_value_action.type != Action::Ron) {
+ most_value_action = action;
+ }
+ } break;
+
+ case Action::Kan: {
+
+ } break;
+
+ case Action::Ron: {
+
+ } break;
+
+ case Action::Tsumo: {
+
+ } break;
+
+ case Action::Draw: {
+
+ } break;
+
+ default:
+ break;
}
- if (south_action) {
- players[2]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
- }
- if (north_action) {
- players[3]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
- }
-}
-
-void Game::handle_action(Action action) {
+ num_player_actions--;
+
// Sjekk action, sjekk om endelig action er avgjort
// Oppdater state
// Evt. round_end()
if (num_player_actions == 0) {
round_update();
}
+
+
}
void Game::round_end() {
diff --git a/server/game.h b/server/game.h
index 634ea4d..3ed97e4 100644
--- a/server/game.h
+++ b/server/game.h
@@ -31,12 +31,17 @@ class Game : public boost::enable_shared_from_this<Game> {
//! The current state of the game
State::p game_state;
+ //! Current player, used when discarding etc
+ int current_player;
+
+ //! Are we in draw or discard phase?
+ bool draw_phase;
+
+ //! Number of players doing action
int num_player_actions;
- bool east_action;
- bool west_action;
- bool south_action;
- bool north_action;
+ //! Highest value action done
+ Action most_value_action;
//! Handle Ready message from player.
void handle_ready();