From 777a6a5e8cc8b5dc7a37d06cc5960b81c95a580f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20Teuli=C3=A8re?= Date: Sun, 6 Nov 2005 17:13:45 +0000 Subject: [PATCH] The constuctors of the players now take as argument the ID of the player --- game/ai_percent.cpp | 4 ++-- game/ai_percent.h | 2 +- game/ai_player.h | 2 +- game/game.cpp | 5 +++-- game/player.cpp | 6 +++--- game/player.h | 7 +++++-- game/turn.cpp | 8 +++----- game/turn.h | 13 +++++++------ 8 files changed, 25 insertions(+), 22 deletions(-) diff --git a/game/ai_percent.cpp b/game/ai_percent.cpp index 45a7ddd..10bb55b 100644 --- a/game/ai_percent.cpp +++ b/game/ai_percent.cpp @@ -26,8 +26,8 @@ #include "ai_percent.h" -AIPercent::AIPercent(float iPercent) - : m_percent(iPercent) +AIPercent::AIPercent(int iId, float iPercent) + : AIPlayer(iId), m_percent(iPercent) { // Ensure the decimal value of the percentage is between 0 and 1 if (m_percent < 0) diff --git a/game/ai_percent.h b/game/ai_percent.h index b057f89..8a2e682 100644 --- a/game/ai_percent.h +++ b/game/ai_percent.h @@ -38,7 +38,7 @@ class AIPercent: public AIPlayer { public: /// Constructor, taking the percentage (0.0 <= iPercent <= 1.0) - AIPercent(float iPercent); + AIPercent(int iId, float iPercent); virtual ~AIPercent() {} /** diff --git a/game/ai_player.h b/game/ai_player.h index d917773..be7b01a 100644 --- a/game/ai_player.h +++ b/game/ai_player.h @@ -84,7 +84,7 @@ public: protected: /// This class is a pure interface, forbid any direct instanciation - AIPlayer() {} + AIPlayer(int iId): Player(iId) {} }; #endif diff --git a/game/game.cpp b/game/game.cpp index a724049..292d5f0 100644 --- a/game/game.cpp +++ b/game/game.cpp @@ -781,13 +781,14 @@ int Game::getNHumanPlayers() const void Game::addHumanPlayer() { - m_players.push_back(new HumanPlayer()); + // The ID of the player is its position in the m_players vector + m_players.push_back(new HumanPlayer(getNPlayers())); } void Game::addAIPlayer() { - m_players.push_back(new AIPercent(0)); + m_players.push_back(new AIPercent(getNPlayers(), 0)); } diff --git a/game/player.cpp b/game/player.cpp index 05a1d70..dc42c1d 100644 --- a/game/player.cpp +++ b/game/player.cpp @@ -29,8 +29,9 @@ #include "debug.h" -Player::Player() +Player::Player(int iId) { + m_id = iId; m_score = 0; } @@ -73,8 +74,7 @@ const Round & Player::getLastRound() const */ void Player::endTurn(const Round &iRound, int iTurn) { - // FIXME: the number of the player is wrong here! - m_history.push_back(new Turn(iTurn, iTurn, m_pldrack, iRound)); + m_history.push_back(new Turn(iTurn, m_id, m_pldrack, iRound)); Rack rack; m_pldrack.getRack(rack); diff --git a/game/player.h b/game/player.h index 550dced..9c510bd 100644 --- a/game/player.h +++ b/game/player.h @@ -33,7 +33,7 @@ class Turn; class Player { public: - Player(); + Player(int iId); virtual ~Player(); // Pseudo RTTI @@ -64,6 +64,9 @@ public: void endTurn(const Round &iRound, int iTurn); private: + /// ID of the player + int m_id; + /// Score of the player int m_score; @@ -84,7 +87,7 @@ private: class HumanPlayer: public Player { public: - HumanPlayer() {} + HumanPlayer(int iId): Player(iId) {} virtual ~HumanPlayer() {} // Pseudo RTTI diff --git a/game/turn.cpp b/game/turn.cpp index 9ef593e..6a2ecc9 100644 --- a/game/turn.cpp +++ b/game/turn.cpp @@ -30,9 +30,9 @@ #include "turn.h" -Turn::Turn(int iNum, int iPlayer, +Turn::Turn(int iNum, int iPlayerId, const PlayedRack& iPldRack, const Round& iRound) - : m_num(iNum), m_player(iPlayer), m_pldrack(iPldRack), m_round(iRound) + : m_num(iNum), m_playerId(iPlayerId), m_pldrack(iPldRack), m_round(iRound) { } @@ -44,12 +44,10 @@ void Turn::operator=(const Turn &iOther) pldrack = iOther.pldrack; round = iOther.round; } -#endif string Turn::toString(bool iShowExtraSigns) const { -#if 0 string rs = ""; if (iShowExtraSigns) { @@ -57,8 +55,8 @@ string Turn::toString(bool iShowExtraSigns) const } rs = rs + m_pldrack.toString() + " " + m_round.toString(); return rs; -#endif } +#endif /// Local Variables: diff --git a/game/turn.h b/game/turn.h index 6efdc59..eb629ae 100644 --- a/game/turn.h +++ b/game/turn.h @@ -30,29 +30,30 @@ class Turn { public: -// Turn(); - Turn(int iNum, int iPlayer, + Turn(int iNum, int iPlayerId, const PlayedRack& iPldRack, const Round& iRound); virtual ~Turn() {}; #if 0 void setNum(int iNum) { m_num = iNum; } - void setPlayer(int iPldRack) { m_player = iPldRack; } + void setPlayer(int iPlayerId) { m_playerId = iPlayerId; } void setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; } void setRound(const Round& iRound) { m_round = iRound; } #endif int getNum() const { return m_num; } - int getPlayer() const { return m_player; } + int getPlayer() const { return m_playerId; } const PlayedRack& getPlayedRack() const { return m_pldrack; } const Round& getRound() const { return m_round; } -// void operator=(const Turn &iOther); +#if 0 + void operator=(const Turn &iOther); string toString(bool iShowExtraSigns = false) const; +#endif private: int m_num; - int m_player; + int m_playerId; PlayedRack m_pldrack; Round m_round;