TurnData: remove the m_playerId member

This commit is contained in:
Olivier Teulière 2013-01-16 14:40:34 +01:00
parent 7f3f29df31
commit cdcb5c25b7
13 changed files with 18 additions and 36 deletions

View file

@ -21,7 +21,6 @@
#include <sstream> #include <sstream>
#include "cmd/game_move_cmd.h" #include "cmd/game_move_cmd.h"
#include "player.h"
#include "game_params.h" #include "game_params.h"
#include "game.h" #include "game.h"
#include "rack.h" #include "rack.h"
@ -31,11 +30,9 @@
INIT_LOGGER(game, GameMoveCmd); INIT_LOGGER(game, GameMoveCmd);
GameMoveCmd::GameMoveCmd(Game &ioGame, const Move &iMove, GameMoveCmd::GameMoveCmd(Game &ioGame, const Move &iMove)
unsigned int iPlayerId)
: m_game(ioGame), m_move(iMove), : m_game(ioGame), m_move(iMove),
m_moveRack(ioGame.getHistory().getCurrentRack()), m_moveRack(ioGame.getHistory().getCurrentRack())
m_playerId(iPlayerId)
{ {
setAutoExecutable(false); setAutoExecutable(false);
} }
@ -48,7 +45,7 @@ void GameMoveCmd::doExecute()
// History of the game // History of the game
History &history = m_game.accessHistory(); History &history = m_game.accessHistory();
history.playMove(m_playerId, m_move, newRack); history.playMove(m_move, newRack);
// Points // Points
m_game.addPoints(m_move.getScore()); m_game.addPoints(m_move.getScore());

View file

@ -46,14 +46,12 @@ class GameMoveCmd: public Command
DEFINE_LOGGER(); DEFINE_LOGGER();
public: public:
GameMoveCmd(Game &ioGame, const Move &iMove, GameMoveCmd(Game &ioGame, const Move &iMove);
unsigned int iPlayerId);
virtual wstring toString() const; virtual wstring toString() const;
// Getters // Getters
const Move & getMove() const { return m_move; } const Move & getMove() const { return m_move; }
unsigned int getPlayerId() const { return m_playerId; }
protected: protected:
virtual void doExecute(); virtual void doExecute();
@ -64,7 +62,6 @@ class GameMoveCmd: public Command
Move m_move; Move m_move;
Round m_round; Round m_round;
PlayedRack m_moveRack; PlayedRack m_moveRack;
unsigned int m_playerId;
void playRound(); void playRound();
void unplayRound(); void unplayRound();

View file

@ -44,7 +44,7 @@ void PlayerMoveCmd::doExecute()
const PlayedRack &newRack = Move::ComputeRackForMove(m_originalRack, m_move); const PlayedRack &newRack = Move::ComputeRackForMove(m_originalRack, m_move);
// Update the history and rack of the player // Update the history and rack of the player
m_player.accessHistory().playMove(m_player.getId(), m_move, newRack); m_player.accessHistory().playMove(m_move, newRack);
} }

View file

@ -311,7 +311,7 @@ void Duplicate::endTurn()
// Play the master word on the board // Play the master word on the board
// We assign it to player 0 arbitrarily (this is only used // We assign it to player 0 arbitrarily (this is only used
// to retrieve the rack, which is the same for all players...) // to retrieve the rack, which is the same for all players...)
Command *pCmd = new GameMoveCmd(*this, m_masterMove, REF_PLAYER_ID); Command *pCmd = new GameMoveCmd(*this, m_masterMove);
accessNavigation().addAndExecute(pCmd); accessNavigation().addAndExecute(pCmd);
// Change the turn after doing all the game changes. // Change the turn after doing all the game changes.

View file

@ -153,7 +153,7 @@ int FreeGame::endTurn()
const Move &move = getCurrentPlayer().getLastMove(); const Move &move = getCurrentPlayer().getLastMove();
// Update the game // Update the game
Command *pCmd = new GameMoveCmd(*this, move, m_currPlayer); Command *pCmd = new GameMoveCmd(*this, move);
accessNavigation().addAndExecute(pCmd); accessNavigation().addAndExecute(pCmd);
// Complete the rack for the player that just played // Complete the rack for the player that just played

View file

@ -96,14 +96,12 @@ bool History::beforeFirstRound() const
} }
void History::playMove(unsigned int iPlayer, void History::playMove(const Move &iMove,
const Move &iMove,
const PlayedRack &iNewRack) const PlayedRack &iNewRack)
{ {
TurnData * current_turn = m_history.back(); TurnData * current_turn = m_history.back();
// Set the number and the round // Set the number and the round
current_turn->setPlayer(iPlayer);
current_turn->setMove(iMove); current_turn->setMove(iMove);
// Create a new turn // Create a new turn
@ -125,11 +123,10 @@ void History::removeLastTurn()
delete t; delete t;
} }
#ifdef BACK_REMOVE_RACK_NEW_PART
// Now we have the previous played round in back() // Now we have the previous played round in back()
TurnData *t = m_history.back(); TurnData *t = m_history.back();
t->setPlayer(0);
//t->setRound(Round()); //t->setRound(Round());
#ifdef BACK_REMOVE_RACK_NEW_PART
t->getPlayedRound().setNew(Rack()); t->getPlayedRound().setNew(Rack());
#endif #endif
} }

View file

@ -83,8 +83,7 @@ public:
bool beforeFirstRound() const; bool beforeFirstRound() const;
/// Update the history with the given move and complete the turn. /// Update the history with the given move and complete the turn.
void playMove(unsigned int player, const Move &iMove, void playMove(const Move &iMove, const PlayedRack &iNewRack);
const PlayedRack &iNewRack);
/// Remove last turn /// Remove last turn
void removeLastTurn(); void removeLastTurn();

View file

@ -180,7 +180,7 @@ void Topping::endTurn()
{ {
// Play the top move on the board // Play the top move on the board
const Move &move = getTopMove(); const Move &move = getTopMove();
Command *pCmd = new GameMoveCmd(*this, move, m_currPlayer); Command *pCmd = new GameMoveCmd(*this, move);
accessNavigation().addAndExecute(pCmd); accessNavigation().addAndExecute(pCmd);
accessNavigation().newTurn(); accessNavigation().newTurn();

View file

@ -145,7 +145,7 @@ void Training::endTurn()
move = getMoveFromMasterGame(); move = getMoveFromMasterGame();
else else
move = m_players[m_currPlayer]->getLastMove(); move = m_players[m_currPlayer]->getLastMove();
Command *pCmd = new GameMoveCmd(*this, move, m_currPlayer); Command *pCmd = new GameMoveCmd(*this, move);
accessNavigation().addAndExecute(pCmd); accessNavigation().addAndExecute(pCmd);
accessNavigation().newTurn(); accessNavigation().newTurn();
} }

View file

@ -30,15 +30,13 @@ INIT_LOGGER(game, TurnData);
// FIXME: move set to an arbitrary one (no move). It would be better to get rid of this // FIXME: move set to an arbitrary one (no move). It would be better to get rid of this
// constructor completely // constructor completely
TurnData::TurnData() TurnData::TurnData()
: m_playerId(0), m_warningsNb(0), : m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
{ {
} }
TurnData::TurnData(unsigned int iPlayerId, const PlayedRack& iPldRack, TurnData::TurnData(const PlayedRack& iPldRack, const Move& iMove)
const Move& iMove) : m_pldrack(iPldRack), m_move(iMove),
: m_playerId(iPlayerId), m_pldrack(iPldRack), m_move(iMove),
m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0) m_warningsNb(0), m_penaltyPoints(0), m_soloPoints(0), m_endGamePoints(0)
{ {
} }

View file

@ -42,10 +42,8 @@ class TurnData
DEFINE_LOGGER(); DEFINE_LOGGER();
public: public:
TurnData(); TurnData();
TurnData(unsigned int iPlayerId, TurnData(const PlayedRack& iPldRack, const Move& iMove);
const PlayedRack& iPldRack, const Move& iMove);
void setPlayer(unsigned int iPlayerId) { m_playerId = iPlayerId; }
void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; } void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; }
void setMove(const Move& iMove) { m_move = iMove; } void setMove(const Move& iMove) { m_move = iMove; }
// Setters for events (warnings, penalties, solos, end game primes) // Setters for events (warnings, penalties, solos, end game primes)
@ -54,7 +52,6 @@ public:
void addSoloPoints(int iPoints) { m_soloPoints += iPoints; } void addSoloPoints(int iPoints) { m_soloPoints += iPoints; }
void addEndGamePoints(int iPoints) { m_endGamePoints += iPoints; } void addEndGamePoints(int iPoints) { m_endGamePoints += iPoints; }
unsigned int getPlayer() const { return m_playerId; }
const PlayedRack& getPlayedRack() const { return m_pldrack; } const PlayedRack& getPlayedRack() const { return m_pldrack; }
const Move& getMove() const { return m_move; } const Move& getMove() const { return m_move; }
// Getters for events (warnings, penalties, solos, end game primes) // Getters for events (warnings, penalties, solos, end game primes)
@ -66,7 +63,6 @@ public:
wstring toString() const; wstring toString() const;
private: private:
unsigned int m_playerId;
PlayedRack m_pldrack; PlayedRack m_pldrack;
Move m_move; Move m_move;
int m_warningsNb; int m_warningsNb;

View file

@ -412,8 +412,7 @@ void XmlReader::endElement(const string& namespaceURI,
else if (tag == "GameMove") else if (tag == "GameMove")
{ {
const Move &move = buildMove(*m_game, m_attributes, false); const Move &move = buildMove(*m_game, m_attributes, false);
Player &p = getPlayer(m_players, m_attributes["playerId"], tag); GameMoveCmd *cmd = new GameMoveCmd(*m_game, move);
GameMoveCmd *cmd = new GameMoveCmd(*m_game, move, p.getId());
m_game->accessNavigation().addAndExecute(cmd); m_game->accessNavigation().addAndExecute(cmd);
} }

View file

@ -251,9 +251,8 @@ void XmlWriter::write(const Game &iGame, const string &iFileName)
else if (dynamic_cast<const GameMoveCmd*>(cmd)) else if (dynamic_cast<const GameMoveCmd*>(cmd))
{ {
const GameMoveCmd *moveCmd = static_cast<const GameMoveCmd*>(cmd); const GameMoveCmd *moveCmd = static_cast<const GameMoveCmd*>(cmd);
unsigned int id = moveCmd->getPlayerId();
out << indent; out << indent;
writeMove(out, moveCmd->getMove(), "GameMove", id); writeMove(out, moveCmd->getMove(), "GameMove", -1);
out << endl; out << endl;
} }
else if (dynamic_cast<const MasterMoveCmd*>(cmd)) else if (dynamic_cast<const MasterMoveCmd*>(cmd))