summaryrefslogtreecommitdiff
path: root/server/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'server/game.cpp')
-rw-r--r--server/game.cpp67
1 files changed, 49 insertions, 18 deletions
diff --git a/server/game.cpp b/server/game.cpp
index 6b0b275..5827565 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -192,7 +192,7 @@ void Game::handle_action_draw(Action action) {
case Action::Tsumo: {
players[current_player].declare_tsumo();
- round_end();
+ round_end(Tsumo);
} break;
case Action::Riichi: {
@@ -283,7 +283,7 @@ void Game::handle_action_discard(Action action, int player) {
// Check if the wall has run out.
if(wall.remaining() <= 14) {
- round_end();
+ round_end(Draw);
break;
}
@@ -313,7 +313,7 @@ void Game::handle_action_discard(Action action, int player) {
case Action::Ron: {
players[preceding_action_owner].declare_ron(players[current_player].claim());
- round_end();
+ round_end(Ron);
} break;
// Will never occur on discard:
@@ -325,25 +325,56 @@ void Game::handle_action_discard(Action action, int player) {
}
}
-void Game::round_end() {
+void Game::round_end(Endcondition end) {
Message::RoundEnd::p msg = make_shared<Message::RoundEnd>();
- // Did anybody win?
- for(int i = 0; i < 4; i++) {
- if(players[current_player + i].won) {
- Player& player = players[current_player + i];
-
- msg->hand = player.hand;
-
- msg->yakus = player.won_han;
-
- msg->total_han = player.won_value.han();
- msg->total_fu = player.won_value.fu_rounded();
- msg->won = player.won_value.ron_east();
-
+ switch(end) {
+ case Draw:
+ msg->total_han = msg->total_fu = msg->won = 0;
+ break;
+
+ case Tsumo: {
+ Player& player = players[current_player];
+
+ msg->hand = player.hand;
+
+ msg->yakus = player.won_han;
+
+ msg->total_han = player.won_value.han();
+ msg->total_fu = player.won_value.fu_rounded();
+
+ if(current_player == round_num) {
+ msg->won = 3 * player.won_value.tsumo_east();
+ } else {
+ msg->won = player.won_value.tsumo_east() + 2 * player.won_value.tsumo();
+ }
+ } break;
+
+ case Ron:
+ for(int i = 0; i < 4; i++) {
+ if(players[current_player + i].won) {
+ Player& player = players[current_player + i];
+
+ msg->hand = player.hand;
+
+ msg->yakus = player.won_han;
+
+ msg->total_han = player.won_value.han();
+ msg->total_fu = player.won_value.fu_rounded();
+
+ if(current_player + i == round_num) {
+ msg->won = player.won_value.ron_east();
+ } else {
+ msg->won = player.won_value.ron();
+ }
+
+ // TODO: Support multiple wins.
+ break;
+ }
+ }
break;
- }
}
+
round_num++;
if(!round_num) {