summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--common/action.h9
-rw-r--r--server/standard.cpp40
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(&current_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target << std::endl;
+ std::cout << std::ctime(&current_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(&current_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target << std::endl;
+ std::cout << std::ctime(&current_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(&current_time) << " Player: " << temp_action.player << " Can do action: " << temp_action.type << " On target: " << temp_action.target << std::endl;
+ std::cout << std::ctime(&current_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(&current_time) << " Player: " << action.player << " Did action: " << action.type << " On target: " << action.target << std::endl;
+ std::cout << std::ctime(&current_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;