The constuctors of the players now take as argument the ID of the player

This commit is contained in:
Olivier Teulière 2005-11-06 17:13:45 +00:00
parent 9e5b6e8ebf
commit 777a6a5e8c
8 changed files with 25 additions and 22 deletions

View file

@ -26,8 +26,8 @@
#include "ai_percent.h" #include "ai_percent.h"
AIPercent::AIPercent(float iPercent) AIPercent::AIPercent(int iId, float iPercent)
: m_percent(iPercent) : AIPlayer(iId), m_percent(iPercent)
{ {
// Ensure the decimal value of the percentage is between 0 and 1 // Ensure the decimal value of the percentage is between 0 and 1
if (m_percent < 0) if (m_percent < 0)

View file

@ -38,7 +38,7 @@ class AIPercent: public AIPlayer
{ {
public: public:
/// Constructor, taking the percentage (0.0 <= iPercent <= 1.0) /// Constructor, taking the percentage (0.0 <= iPercent <= 1.0)
AIPercent(float iPercent); AIPercent(int iId, float iPercent);
virtual ~AIPercent() {} virtual ~AIPercent() {}
/** /**

View file

@ -84,7 +84,7 @@ public:
protected: protected:
/// This class is a pure interface, forbid any direct instanciation /// This class is a pure interface, forbid any direct instanciation
AIPlayer() {} AIPlayer(int iId): Player(iId) {}
}; };
#endif #endif

View file

@ -781,13 +781,14 @@ int Game::getNHumanPlayers() const
void Game::addHumanPlayer() 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() void Game::addAIPlayer()
{ {
m_players.push_back(new AIPercent(0)); m_players.push_back(new AIPercent(getNPlayers(), 0));
} }

View file

@ -29,8 +29,9 @@
#include "debug.h" #include "debug.h"
Player::Player() Player::Player(int iId)
{ {
m_id = iId;
m_score = 0; m_score = 0;
} }
@ -73,8 +74,7 @@ const Round & Player::getLastRound() const
*/ */
void Player::endTurn(const Round &iRound, int iTurn) void Player::endTurn(const Round &iRound, int iTurn)
{ {
// FIXME: the number of the player is wrong here! m_history.push_back(new Turn(iTurn, m_id, m_pldrack, iRound));
m_history.push_back(new Turn(iTurn, iTurn, m_pldrack, iRound));
Rack rack; Rack rack;
m_pldrack.getRack(rack); m_pldrack.getRack(rack);

View file

@ -33,7 +33,7 @@ class Turn;
class Player class Player
{ {
public: public:
Player(); Player(int iId);
virtual ~Player(); virtual ~Player();
// Pseudo RTTI // Pseudo RTTI
@ -64,6 +64,9 @@ public:
void endTurn(const Round &iRound, int iTurn); void endTurn(const Round &iRound, int iTurn);
private: private:
/// ID of the player
int m_id;
/// Score of the player /// Score of the player
int m_score; int m_score;
@ -84,7 +87,7 @@ private:
class HumanPlayer: public Player class HumanPlayer: public Player
{ {
public: public:
HumanPlayer() {} HumanPlayer(int iId): Player(iId) {}
virtual ~HumanPlayer() {} virtual ~HumanPlayer() {}
// Pseudo RTTI // Pseudo RTTI

View file

@ -30,9 +30,9 @@
#include "turn.h" #include "turn.h"
Turn::Turn(int iNum, int iPlayer, Turn::Turn(int iNum, int iPlayerId,
const PlayedRack& iPldRack, const Round& iRound) 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; pldrack = iOther.pldrack;
round = iOther.round; round = iOther.round;
} }
#endif
string Turn::toString(bool iShowExtraSigns) const string Turn::toString(bool iShowExtraSigns) const
{ {
#if 0
string rs = ""; string rs = "";
if (iShowExtraSigns) if (iShowExtraSigns)
{ {
@ -57,8 +55,8 @@ string Turn::toString(bool iShowExtraSigns) const
} }
rs = rs + m_pldrack.toString() + " " + m_round.toString(); rs = rs + m_pldrack.toString() + " " + m_round.toString();
return rs; return rs;
#endif
} }
#endif
/// Local Variables: /// Local Variables:

View file

@ -30,29 +30,30 @@
class Turn class Turn
{ {
public: public:
// Turn(); Turn(int iNum, int iPlayerId,
Turn(int iNum, int iPlayer,
const PlayedRack& iPldRack, const Round& iRound); const PlayedRack& iPldRack, const Round& iRound);
virtual ~Turn() {}; virtual ~Turn() {};
#if 0 #if 0
void setNum(int iNum) { m_num = iNum; } 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 setPlayedRack(const PlayedRack& iPldRack) { m_pldrack = iPldRack; }
void setRound(const Round& iRound) { m_round = iRound; } void setRound(const Round& iRound) { m_round = iRound; }
#endif #endif
int getNum() const { return m_num; } 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 PlayedRack& getPlayedRack() const { return m_pldrack; }
const Round& getRound() const { return m_round; } 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; string toString(bool iShowExtraSigns = false) const;
#endif
private: private:
int m_num; int m_num;
int m_player; int m_playerId;
PlayedRack m_pldrack; PlayedRack m_pldrack;
Round m_round; Round m_round;