From 9cbfcb9ef2dac318288b7ffef2aabf0e26f8b134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Atle=20Hellvik=20Havs=C3=B8?= Date: Mon, 22 Nov 2010 18:14:29 +0100 Subject: Made server respond to Action::Chi messages. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Atle Hellvik Havsø --- server/game.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file 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 #include +#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(); } -- cgit v1.2.3