summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtle Hellvik Havsø <atle@havso.net>2010-11-22 18:14:29 +0100
committerAtle Hellvik Havsø <atle@havso.net>2010-11-22 18:14:55 +0100
commit9cbfcb9ef2dac318288b7ffef2aabf0e26f8b134 (patch)
tree3d367a6a8c4c6d1a08945c670481ed62b814a182
parent6b76b7542a49dd6382fdfa1a37c85712a8249b86 (diff)
Made server respond to Action::Chi messages.
Signed-off-by: Atle Hellvik Havsø <atle@havso.net>
-rw-r--r--server/game.cpp55
1 files changed, 51 insertions, 4 deletions
diff --git a/server/game.cpp b/server/game.cpp
index a02dc7b..8e6f358 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -6,6 +6,8 @@
#include <algorithm>
#include <ctime>
+#include "../common/set.h"
+
bool MyDataSortPredicate(const Tile& d1, const Tile& d2)
{
@@ -71,10 +73,10 @@ void Game::round_start() {
std::sort(game_state.players[3].hand.begin(),game_state.players[3].hand.end(), MyDataSortPredicate);
-
- current_player = 3;
- num_player_actions = 0;
- draw_phase = true;
+ most_value_action.type = Action::Pass;
+ current_player = 3;
+ num_player_actions = 0;
+ draw_phase = true;
round_update();
}
@@ -435,6 +437,51 @@ void Game::handle_action(Action action) {
//When everyone has done their action we empty the list (just to be sure) and then do a round_update()
if(num_player_actions == 0) {
game_state.possible_actions.empty();
+
+ if(most_value_action.type != Action::Pass) {
+ switch (most_value_action.type) {
+ case Action::Chi: {
+ Set chi;
+ Tile left_tile = game_state.players[current_player].pond.back();
+ left_tile.rotated = true;
+ chi.add_tile(left_tile);
+
+ Tile middle_tile = game_state.players[action.player].hand[action.target];
+ chi.add_tile(middle_tile);
+
+ Tile right_tile;
+ if(Tile::Type(game_state.players[action.player].hand[action.target].type + 1) == left_tile.type) {
+ right_tile = game_state.players[action.player].hand[action.target + 2];
+ } else {
+ right_tile = game_state.players[action.player].hand[action.target + 1];
+ }
+ chi.add_tile(right_tile);
+
+ game_state.players[action.player].open.push_back(chi);
+ game_state.players[action.player].hand.erase(game_state.players[action.player].hand.begin() + action.target);
+ game_state.players[action.player].hand.erase(game_state.players[action.player].hand.begin() + action.target);
+
+
+ } break;
+
+ case Action::Pon: {
+
+ } break;
+
+ case Action::Kan: {
+
+ } break;
+
+ case Action::Ron: {
+
+ } break;
+
+ default: break;
+ }
+
+ most_value_action.type = Action::Pass;
+ }
+
round_update();
}