summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/SConstruct2
-rw-r--r--server/game.cpp146
2 files changed, 142 insertions, 6 deletions
diff --git a/server/SConstruct b/server/SConstruct
index ddf93ae..67bb36a 100644
--- a/server/SConstruct
+++ b/server/SConstruct
@@ -15,7 +15,7 @@ else:
env.Append(LIBS = ['boost_system', 'boost_serialization', 'pthread'])
if not GetOption('release'):
- env.Append(CPPFLAGS = ['-Wall', '-g'])
+ env.Append(CPPFLAGS = ['-Wall', '-g', '-D DEBUG'])
if GetOption('profiling'):
env.Append(CPPFLAGS = ['-pg'])
diff --git a/server/game.cpp b/server/game.cpp
index 49cfb0b..50f6241 100644
--- a/server/game.cpp
+++ b/server/game.cpp
@@ -6,6 +6,7 @@
#include <algorithm>
#include <ctime>
+
bool MyDataSortPredicate(const Tile& d1, const Tile& d2)
{
return d1.type < d2.type;
@@ -118,12 +119,127 @@ void Game::round_update() {
game_state.possible_actions.push_back(discard);
- num_player_actions++;
+ //num_player_actions++;
// Enter the discard phase next loop;
draw_phase = false;
} else {
- //Go back into draw_phase
+ //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) {
+ temp_next_player = 0;
+ } else {
+ temp_next_player = current_player + 1;
+ }
+
+ Tiles* hand = &game_state.players[temp_next_player].hand;
+ 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_2u = &(*it);
+ tile_2u_id = count;
+ } else if(it->type == (temp_tile->type-1)) {
+ tile_1u = &(*it);
+ tile_1u_id = count;
+ } else if(it->type == (temp_tile->type+1)) {
+ tile_1o = &(*it);
+ tile_1o_id = count;
+ } else if(it->type == (temp_tile->type+2)) {
+ tile_2o = &(*it);
+ tile_2o_id = count;
+ }
+ count++;
+ }
+
+ bool chi;
+ if(tile_2u && tile_1u) {
+ Action temp_action;
+ 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) {
+ 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) {
+ 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) {
+ chi = true;
+ }
+ }
+ if(chi) {
+ temp_action.player = temp_next_player;
+ temp_action.target = tile_2u_id;
+ 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
+ }
+ }
+
+ if(tile_1u && tile_1o) {
+ Action temp_action;
+ chi = false;
+ //Make sure we have a chi within the same series.
+ if(tile_1u->type <= Tile::Man_7 && tile_1u->type >= Tile::Man_1) {
+ if(tile_1o->type <= Tile::Man_9 && tile_1o->type >= Tile::Man_3) {
+ chi = true;
+ }
+ } else if(tile_1u->type <= Tile::Pin_7 && tile_1u->type >= Tile::Pin_1) {
+ if(tile_1o->type <= Tile::Pin_9 && tile_1o->type >= Tile::Pin_3) {
+ chi = true;
+ }
+ } else if(tile_1u->type <= Tile::Sou_1 && tile_1u->type >= Tile::Sou_1) {
+ if(tile_1o->type <= Tile::Sou_9 && tile_1o->type >= Tile::Sou_3) {
+ chi = true;
+ }
+ }
+ if(chi) {
+ temp_action.player = temp_next_player;
+ temp_action.target = tile_1u_id;
+ game_state.possible_actions.push_back(temp_action);
+ }
+ }
+
+ if(tile_1o && tile_2o) {
+ 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(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) {
+ 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) {
+ if(tile_2o->type <= Tile::Sou_9 && tile_2o->type >= Tile::Sou_3) {
+ chi = true;
+ }
+ }
+ if(chi) {
+ temp_action.player = temp_next_player;
+ temp_action.target = tile_1o_id;
+ game_state.possible_actions.push_back(temp_action);
+ }
+ }
+
+
+
+ //Go back into draw_phase0
draw_phase = true;
// Not implemented yet
@@ -137,9 +253,29 @@ 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.
- if(num_player_actions > 0) {
- players[current_player]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
- } else {
+ char smart = 0x0000;
+ for(Actions::iterator it = game_state.possible_actions.begin(); it != game_state.possible_actions.end(); ++it) {
+ smart = smart | (1 << it->player);
+ }
+
+ if(smart & 0x0001) {
+ num_player_actions++;
+ players[0]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ }
+ if(smart & 0x0010) {
+ num_player_actions++;
+ players[1]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ }
+ if(smart & 0x0100) {
+ num_player_actions++;
+ players[2]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ }
+ if(smart & 0x1000) {
+ num_player_actions++;
+ players[3]->get_action(boost::bind(&Game::handle_action, shared_from_this(), _1));
+ }
+
+ if(num_player_actions == 0) {
round_update();
}
}