summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authorAtle Hellvik Havsø <atle@havso.net>2010-11-22 16:07:21 +0100
committerAtle Hellvik Havsø <atle@havso.net>2010-11-22 16:07:21 +0100
commit696c8689e6362093026c34d340f6d987749ec8fd (patch)
tree93160ba40e02d0059df94d0b68cac4b010ac0b98 /server
parent6cb21cf5b8c45f1308d37483fa85006c1b57f467 (diff)
The "Chi" mechanism now works.
Signed-off-by: Atle Hellvik Havsø <atle@havso.net>
Diffstat (limited to 'server')
-rw-r--r--server/game.cpp64
1 files changed, 45 insertions, 19 deletions
diff --git a/server/game.cpp b/server/game.cpp
index 50f6241..6ae899c 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -125,7 +125,7 @@ void Game::round_update() {
draw_phase = false;
} else {
//We chwck to see if player can chi from last discard
- Tile* temp_tile = &game_state.players[current_player].pond.back();
+
int temp_next_player;
if (current_player == 3) {
@@ -134,24 +134,33 @@ void Game::round_update() {
temp_next_player = current_player + 1;
}
- Tiles* hand = &game_state.players[temp_next_player].hand;
+ Tiles* pond = &game_state.players[current_player].pond;
+ Tile temp_tile = pond->back();
Tiles::iterator it;
Tile* tile_2u = NULL;
Tile* tile_1u = NULL;
Tile* tile_1o = NULL;
Tile* tile_2o = NULL;
unsigned int count = 0, tile_2u_id,tile_1u_id,tile_1o_id,tile_2o_id;
- for(it = hand->begin(); it != hand->end(); ++it) {
- if(it->type == (temp_tile->type-2)) {
+ Tile::Type check_tile;
+ for(it = game_state.players[temp_next_player].hand.begin(); it != game_state.players[temp_next_player].hand.end(); ++it) {
+ check_tile = Tile::Type(temp_tile.type - 2);
+ if(it->type == check_tile) {
tile_2u = &(*it);
tile_2u_id = count;
- } else if(it->type == (temp_tile->type-1)) {
+ }
+ check_tile = Tile::Type(temp_tile.type - 1);
+ if(it->type == check_tile) {
tile_1u = &(*it);
tile_1u_id = count;
- } else if(it->type == (temp_tile->type+1)) {
+ }
+ check_tile = Tile::Type(temp_tile.type + 1);
+ if(it->type == check_tile) {
tile_1o = &(*it);
tile_1o_id = count;
- } else if(it->type == (temp_tile->type+2)) {
+ }
+ check_tile = Tile::Type(temp_tile.type + 2);
+ if(it->type == check_tile) {
tile_2o = &(*it);
tile_2o_id = count;
}
@@ -164,21 +173,22 @@ void Game::round_update() {
chi = false;
//Make sure we have a chi within the same series.
if(tile_2u->type <= Tile::Man_7 && tile_2u->type >= Tile::Man_1) {
- if(temp_tile->type <= Tile::Man_9 && temp_tile->type >= Tile::Man_3) {
+ if(temp_tile.type <= Tile::Man_9 && temp_tile.type >= Tile::Man_3) {
chi = true;
}
} else if(tile_2u->type <= Tile::Pin_7 && tile_2u->type >= Tile::Pin_1) {
- if(temp_tile->type <= Tile::Pin_9 && temp_tile->type >= Tile::Pin_3) {
+ if(temp_tile.type <= Tile::Pin_9 && temp_tile.type >= Tile::Pin_3) {
chi = true;
}
} else if(tile_2u->type <= Tile::Sou_1 && tile_2u->type >= Tile::Sou_1) {
- if(temp_tile->type <= Tile::Sou_9 && temp_tile->type >= Tile::Sou_3) {
+ if(temp_tile.type <= Tile::Sou_9 && temp_tile.type >= Tile::Sou_3) {
chi = true;
}
}
if(chi) {
temp_action.player = temp_next_player;
temp_action.target = tile_2u_id;
+ temp_action.type = Action::Chi;
game_state.possible_actions.push_back(temp_action);
#ifdef DEBUG
@@ -209,7 +219,15 @@ void Game::round_update() {
if(chi) {
temp_action.player = temp_next_player;
temp_action.target = 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;
+
+ #endif
}
}
@@ -217,15 +235,15 @@ void Game::round_update() {
Action temp_action;
chi = false;
//Make sure we have a chi within the same series.
- if(temp_tile->type <= Tile::Man_7 && temp_tile->type >= Tile::Man_1) {
+ if(temp_tile.type <= Tile::Man_7 && temp_tile.type >= Tile::Man_1) {
if(tile_2o->type <= Tile::Man_9 && tile_2o->type >= Tile::Man_3) {
chi = true;
}
- } else if(temp_tile->type <= Tile::Pin_7 && temp_tile->type >= Tile::Pin_1) {
+ } else if(temp_tile.type <= Tile::Pin_7 && temp_tile.type >= Tile::Pin_1) {
if(tile_2o->type <= Tile::Pin_9 && tile_2o->type >= Tile::Pin_3) {
chi = true;
}
- } else if(temp_tile->type <= Tile::Sou_1 && temp_tile->type >= Tile::Sou_1) {
+ } else if(temp_tile.type <= Tile::Sou_1 && temp_tile.type >= Tile::Sou_1) {
if(tile_2o->type <= Tile::Sou_9 && tile_2o->type >= Tile::Sou_3) {
chi = true;
}
@@ -233,7 +251,15 @@ void Game::round_update() {
if(chi) {
temp_action.player = temp_next_player;
temp_action.target = 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;
+
+ #endif
}
}
@@ -253,24 +279,24 @@ void Game::round_update() {
players[3]->round_state(game_state);
// Only implemented discard so far, so only current player that needs to be able to do a action.
- char smart = 0x0000;
+ char smart = 0;
for(Actions::iterator it = game_state.possible_actions.begin(); it != game_state.possible_actions.end(); ++it) {
- smart = smart | (1 << it->player);
+ smart = smart | (0x0001 << it->player);
}
- if(smart & 0x0001) {
+ if(smart & 1) {
num_player_actions++;
players[0]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
}
- if(smart & 0x0010) {
+ if(smart & 2) {
num_player_actions++;
players[1]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
}
- if(smart & 0x0100) {
+ if(smart & 4) {
num_player_actions++;
players[2]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
}
- if(smart & 0x1000) {
+ if(smart & 8) {
num_player_actions++;
players[3]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
}