From 34e376a4908f8f2235d28314c4f779bbd1d09389 Mon Sep 17 00:00:00 2001 From: Vegard Storheil Eriksen Date: Fri, 3 Dec 2010 10:33:05 +0100 Subject: Use PlayerState and GameState in Message::RoundState. --- common/message.h | 57 ++++++++----------------------------------------------- server/client.cpp | 6 +++--- server/client.h | 8 +++----- server/game.cpp | 16 ++++++++++++---- server/game.h | 7 +++---- server/player.cpp | 14 ++++++++++---- 6 files changed, 39 insertions(+), 69 deletions(-) diff --git a/common/message.h b/common/message.h index 0380b3e..1574838 100644 --- a/common/message.h +++ b/common/message.h @@ -12,6 +12,7 @@ using boost::dynamic_pointer_cast; #include "action.h" #include "tile.h" +#include "state.h" namespace Message { namespace Types { @@ -157,71 +158,29 @@ namespace Message { public: typedef boost::shared_ptr p; - // Player contents. - struct Player { - //! Concealed tiles in hand. - Tiles hand; - //! Open tiles in hand. - Tilegroups open; - //! Discarded tiles. - Tiles pond; - - //! Riichi declared? - bool riichi; - - //! Player's score - int score; - - //! Seat wind. - int wind; - - template - void serialize(Archive & ar, const unsigned int v) { - ar & hand; - ar & open; - ar & pond; - } - }; - RoundState() : Base(Types::RoundState) {} - RoundState(const Player& pl_d, const Player& pl_r, const Player& pl_u, const Player& pl_l, const Tiles& d, const Actions& a, int p) - : Base(Types::RoundState), dora(d), possible_actions(a), current_player(p) { + RoundState(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a) + : Base(Types::RoundState), game(g), possible_actions(a) { players[0] = pl_d; players[1] = pl_r; players[2] = pl_u; players[3] = pl_l; } - //! Players. - Player players[4]; + //! Player states. + PlayerState players[4]; - //! List of dora/kandora. - Tiles dora; + //! Game state. + GameState game; //! List of actions client must return one of. Actions possible_actions; - //! Current player, relative to client. 0 = self, 1 = shimocha and so on. - int current_player; - - //! Round (prevalent) wind. - int round_wind; - - //! Round number (of this wind). - int round_number; - - //! Count of riichi sticks on table (current and leftovers). - int riichibou; - - //! Count of honba sticks on table (indicating renchan). - int honba; - template void serialize(Archive & ar, const unsigned int v) { ar & players; - ar & dora; + ar & game; ar & possible_actions; - ar & current_player; } }; diff --git a/server/client.cpp b/server/client.cpp index 1fbef6d..0d0b0ba 100644 --- a/server/client.cpp +++ b/server/client.cpp @@ -104,8 +104,8 @@ void Client::round_start() { connection->send(make_shared()); } -void Client::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a, int p) { - connection->send(make_shared(pl_d, pl_r, pl_u, pl_l, d, a, p)); +void Client::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a) { + connection->send(make_shared(pl_d, pl_r, pl_u, pl_l, g, a)); } void Client::round_end(boost::function callback) { @@ -133,7 +133,7 @@ void ClientDumb::round_start() { } -void ClientDumb::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a, int p) { +void ClientDumb::round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a) { } diff --git a/server/client.h b/server/client.h index add78f0..3455056 100644 --- a/server/client.h +++ b/server/client.h @@ -25,10 +25,8 @@ class ClientBase { //! Notify client of a round start. virtual void round_start() = 0; - typedef Message::RoundState::Player PlayerState; - //! Send round state. - virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a, int p) = 0; + virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a) = 0; //! Send round end. virtual void round_end(boost::function callback) = 0; @@ -83,7 +81,7 @@ class Client : public ClientBase, public boost::enable_shared_from_this virtual void round_start(); //! Send round state. - virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a, int p); + virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a); //! Send round end. virtual void round_end(boost::function callback); @@ -102,7 +100,7 @@ class ClientDumb : public ClientBase { virtual void round_start(); - virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const Tiles& d, const Actions& a, int p); + virtual void round_state(const PlayerState& pl_d, const PlayerState& pl_r, const PlayerState& pl_u, const PlayerState& pl_l, const GameState& g, const Actions& a); virtual void round_end(boost::function callback); diff --git a/server/game.cpp b/server/game.cpp index 628a966..b0739cb 100644 --- a/server/game.cpp +++ b/server/game.cpp @@ -116,7 +116,7 @@ void Game::round_update_draw() { // Construct and send state to each client. PlayerNum player = 0; do { - Player::State state[4]; + PlayerState state[4]; state[0] = players[player].get_state(); state[1] = players[player + 1].get_state_filtered(); @@ -128,7 +128,11 @@ void Game::round_update_draw() { a = possible_actions; } - players[player].client->round_state(state[0], state[1], state[2], state[3], dora, a, current_player - player); + GameState gstate; + gstate.dora = dora; + gstate.current_player = current_player - player; + + players[player].client->round_state(state[0], state[1], state[2], state[3], gstate, a); } while(++player); // Await action from client. @@ -143,7 +147,7 @@ void Game::round_update_discard() { // Construct and send state to each client. PlayerNum player = 0; do { - Player::State state[4]; + PlayerState state[4]; state[0] = players[player].get_state(); state[1] = players[player + 1].get_state_filtered(); @@ -157,7 +161,11 @@ void Game::round_update_discard() { } } - players[player].client->round_state(state[0], state[1], state[2], state[3], dora, a, current_player - player); + GameState gstate; + gstate.dora = dora; + gstate.current_player = current_player - player; + + players[player].client->round_state(state[0], state[1], state[2], state[3], gstate, a); } while(++player); preceding_action = Action::Pass; diff --git a/server/game.h b/server/game.h index 1de6c73..b0ec4a2 100644 --- a/server/game.h +++ b/server/game.h @@ -9,6 +9,7 @@ #include "wall.h" #include "client.h" #include "../common/action.h" +#include "../common/state.h" #include "../common/cyclicint.h" class Game : public boost::enable_shared_from_this { @@ -34,13 +35,11 @@ class Game : public boost::enable_shared_from_this { //! Prepare for a new round. void round_start(); - typedef Client::PlayerState State; - //! Get a state snapshot. - State get_state(); + PlayerState get_state(); //! Get a state snapshot, with concealed tiles filtered. - State get_state_filtered(); + PlayerState get_state_filtered(); //! Get possible actions after a draw. Actions get_actions_draw(); diff --git a/server/player.cpp b/server/player.cpp index 554084d..6673937 100644 --- a/server/player.cpp +++ b/server/player.cpp @@ -13,13 +13,19 @@ void Game::Player::round_start() { client->round_start(); } -Game::Player::State Game::Player::get_state() { - State state = {hand, open, pond}; +PlayerState Game::Player::get_state() { + Tilegroups h = open; + h.insert(h.begin(), hand); + + PlayerState state = {h, pond}; return state; } -Game::Player::State Game::Player::get_state_filtered() { - State state = {hand, open, pond}; +PlayerState Game::Player::get_state_filtered() { + Tilegroups h = open; + h.insert(h.begin(), hand); + + PlayerState state = {h, pond}; return state; } -- cgit v1.2.3