New utility methods to retrieve the total number of penalty (or solo) points for a player

This commit is contained in:
Olivier Teulière 2012-04-30 08:29:38 +02:00
parent 572d172640
commit 6ba32f4835
2 changed files with 44 additions and 0 deletions

View file

@ -29,6 +29,7 @@
#include "turn.h"
#include "history.h"
#include "encoding.h"
#include "settings.h"
#include "debug.h"
@ -82,6 +83,7 @@ void Player::removeLastTurn()
m_history.removeLastTurn();
}
unsigned Player::getWarningsNb() const
{
unsigned total = 0;
@ -92,6 +94,39 @@ unsigned Player::getWarningsNb() const
return total;
}
int Player::getPenaltyPoints() const
{
int total = 0;
for (unsigned i = 0; i < m_history.getSize(); ++i)
{
total += m_history.getTurn(i).getPenaltyPoints();
}
// Add penalties due to warnings
unsigned warningsNb = getWarningsNb();
int limit = Settings::Instance().getInt("arbitration.warnings-limit");
if ((int)warningsNb > limit)
{
int penaltiesPoints =
Settings::Instance().getInt("arbitration.default-penalty");
total -= penaltiesPoints * (warningsNb - limit);
}
return total;
}
int Player::getSoloPoints() const
{
int total = 0;
for (unsigned i = 0; i < m_history.getSize(); ++i)
{
total += m_history.getTurn(i).getSoloPoints();
}
return total;
}
wstring Player::toString() const
{
wstring res = L"Player ";

View file

@ -82,6 +82,15 @@ public:
/// Return the total number of warnings received
unsigned getWarningsNb() const;
/**
* Return the total number of penalties received
* (including the penalties due to warnings)
*/
int getPenaltyPoints() const;
/// Return the total number of solo points received
int getSoloPoints() const;
/**************************
* Accessors for the score of the player
**************************/