diff options
author | Atle Hellvik Havsø <atle@havso.net> | 2010-11-23 15:08:48 +0100 |
---|---|---|
committer | Atle Hellvik Havsø <atle@havso.net> | 2010-11-23 15:08:48 +0100 |
commit | 0736e72be71331b843e2f49c3af0cb9071ee93ca (patch) | |
tree | 46102b3e2fcd6f54709de63ca5b5c562ccbc7a71 | |
parent | 0ef516444415729861681b91531322e4eb66dc78 (diff) |
Changed the target in action from 2 ints into a vector<int>. Making it easier to scale when we start with kan and riichi.
Signed-off-by: Atle Hellvik Havsø <atle@havso.net>
-rw-r--r-- | common/action.h | 9 | ||||
-rw-r--r-- | server/standard.cpp | 40 |
2 files changed, 23 insertions, 26 deletions
diff --git a/common/action.h b/common/action.h index c4237e6..5099e03 100644 --- a/common/action.h +++ b/common/action.h @@ -21,11 +21,9 @@ class Action { //! Type of action. Type type; - //! Target of action (if applicable). - int target; - //! Second target of action (if applicable) - int target2; - + //! Targets of action (if applicable). + std::vector<int> target; + //! Player doing this action int player; @@ -33,7 +31,6 @@ class Action { void serialize(Archive & ar, const unsigned int version) { ar & type; ar & target; - ar & target2; ar & player; } }; diff --git a/server/standard.cpp b/server/standard.cpp index 08012d1..015308d 100644 --- a/server/standard.cpp +++ b/server/standard.cpp @@ -149,14 +149,14 @@ State& Standard::round_update() { } if(chi) { temp_action.player = temp_next_player; - temp_action.target = tile_2u_id; - temp_action.target2 = tile_1u_id; + temp_action.target.push_back(tile_2u_id); + temp_action.target.push_back(tile_1u_id); temp_action.type = Action::Chi; game_state.possible_actions.push_back(temp_action); #ifdef DEBUG time_t current_time = std::time(0); - std::cout << std::ctime(¤t_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target << std::endl; + std::cout << std::ctime(¤t_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target[0] << std::endl; #endif } @@ -175,15 +175,15 @@ State& Standard::round_update() { } if(chi) { temp_action.player = temp_next_player; - temp_action.target = tile_1u_id; - temp_action.target2 = tile_1o_id; + temp_action.target.push_back(tile_1u_id); + temp_action.target.push_back(tile_1o_id); temp_action.type = Action::Chi; game_state.possible_actions.push_back(temp_action); #ifdef DEBUG time_t current_time = std::time(0); - std::cout << std::ctime(¤t_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target << std::endl; + std::cout << std::ctime(¤t_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target[0] << std::endl; #endif } @@ -202,15 +202,15 @@ State& Standard::round_update() { } if(chi) { temp_action.player = temp_next_player; - temp_action.target = tile_1o_id; - temp_action.target2 = tile_2o_id; + temp_action.target.push_back(tile_1o_id); + temp_action.target.push_back(tile_2o_id); temp_action.type = Action::Chi; game_state.possible_actions.push_back(temp_action); #ifdef DEBUG time_t current_time = std::time(0); - std::cout << std::ctime(¤t_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target << std::endl; + std::cout << std::ctime(¤t_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target[0] << std::endl; #endif } @@ -274,7 +274,7 @@ bool Standard::round_action(Action action) { #ifdef DEBUG time_t current_time = std::time(0); - std::cout << std::ctime(¤t_time) << " Player: " << action.player << " Did action: " << action.type << " On target: " << action.target << std::endl; + std::cout << std::ctime(¤t_time) << " Player: " << action.player << " Did action: " << action.type << " On target: " << action.target[0] << std::endl; #endif @@ -305,9 +305,9 @@ bool Standard::round_action(Action action) { } break; case Action::Discard: { - Tile discarded_tile = game_state.players[action.player].hand[action.target]; + Tile discarded_tile = game_state.players[action.player].hand[action.target[0]]; game_state.players[action.player].pond.push_back(discarded_tile); - 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[0]); } break; @@ -379,14 +379,14 @@ bool Standard::round_action(Action action) { left_tile.rotated = true; game_state.players[action.player].open.push_back(left_tile); - Tile middle_tile = game_state.players[action.player].hand[action.target]; - game_state.players[action.player].open.push_back(middle_tile); - - Tile right_tile = game_state.players[action.player].hand[action.target2]; - game_state.players[action.player].open.push_back(right_tile); - - 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.target2 - 1); + int count = 0; + for(std::vector<int>::iterator it = most_value_action.target.begin(); it != most_value_action.target.end(); ++it) { + Tile target_tile = game_state.players[action.player].hand[(*it) - count]; + game_state.players[action.player].open.push_back(target_tile); + game_state.players[action.player].hand.erase(game_state.players[action.player].hand.begin() + (*it) - count); + + count++; + } } break; |