2005-02-05 12:14:56 +01:00
|
|
|
/*****************************************************************************
|
2008-01-08 14:52:32 +01:00
|
|
|
* Eliot
|
|
|
|
* Copyright (C) 2004-2007 Olivier Teulière & Antoine Fraboulet
|
|
|
|
* Authors: Olivier Teulière <ipkiss @@ gmail.com>
|
|
|
|
* Antoine Fraboulet <antoine.fraboulet @@ free.fr>
|
2005-02-05 12:14:56 +01:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2005-10-23 16:53:42 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-02-05 12:14:56 +01:00
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "tile.h"
|
|
|
|
#include "rack.h"
|
|
|
|
#include "pldrack.h"
|
|
|
|
#include "round.h"
|
|
|
|
#include "results.h"
|
|
|
|
#include "board.h"
|
|
|
|
#include "player.h"
|
2005-11-06 15:53:15 +01:00
|
|
|
#include "turn.h"
|
2005-12-26 22:18:21 +01:00
|
|
|
#include "history.h"
|
2006-01-22 13:23:52 +01:00
|
|
|
#include "encoding.h"
|
2012-04-30 08:29:38 +02:00
|
|
|
#include "settings.h"
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
2005-11-06 00:57:41 +01:00
|
|
|
|
2012-02-18 22:26:52 +01:00
|
|
|
INIT_LOGGER(game, Player);
|
|
|
|
|
|
|
|
|
2008-01-28 20:17:33 +01:00
|
|
|
Player::Player()
|
2012-03-19 12:39:13 +01:00
|
|
|
: m_id(0), m_score(0), m_tableNb(0)
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-03-19 12:39:13 +01:00
|
|
|
void Player::setId(unsigned iId)
|
|
|
|
{
|
|
|
|
m_id = iId;
|
|
|
|
// Default table nb, equal to the player ID + 1
|
|
|
|
if (m_tableNb == 0)
|
|
|
|
m_tableNb = iId + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 23:33:56 +01:00
|
|
|
const PlayedRack & Player::getCurrentRack() const
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2005-12-26 22:18:21 +01:00
|
|
|
return m_history.getCurrentRack();
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-09 23:33:56 +01:00
|
|
|
void Player::setCurrentRack(const PlayedRack &iPld)
|
|
|
|
{
|
2005-12-26 22:18:21 +01:00
|
|
|
m_history.setCurrentRack(iPld);
|
2005-02-09 23:33:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
const PlayedRack & Player::getLastRack() const
|
|
|
|
{
|
2005-12-26 22:18:21 +01:00
|
|
|
return m_history.getPreviousTurn().getPlayedRack();
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
const Move & Player::getLastMove() const
|
2005-02-05 12:14:56 +01:00
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
return m_history.getPreviousTurn().getMove();
|
2005-02-05 12:14:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-27 02:06:54 +01:00
|
|
|
void Player::removeLastTurn()
|
|
|
|
{
|
2008-01-08 14:52:32 +01:00
|
|
|
// Remove points of the last turn
|
|
|
|
addPoints(- m_history.getPreviousTurn().getMove().getScore());
|
2005-12-27 02:06:54 +01:00
|
|
|
m_history.removeLastTurn();
|
|
|
|
}
|
2005-12-26 23:52:38 +01:00
|
|
|
|
2012-04-30 08:29:38 +02:00
|
|
|
|
2012-04-22 22:30:53 +02:00
|
|
|
unsigned Player::getWarningsNb() const
|
|
|
|
{
|
|
|
|
unsigned total = 0;
|
|
|
|
for (unsigned i = 0; i < m_history.getSize(); ++i)
|
|
|
|
{
|
|
|
|
total += m_history.getTurn(i).getWarningsNb();
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
2012-04-30 08:29:38 +02:00
|
|
|
|
|
|
|
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 =
|
2012-10-05 12:52:42 +02:00
|
|
|
Settings::Instance().getInt("arbitration.penalty-value");
|
2012-04-30 08:29:38 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-05 18:19:06 +02:00
|
|
|
int Player::getEndGamePoints() const
|
|
|
|
{
|
|
|
|
int total = 0;
|
|
|
|
for (unsigned i = 0; i < m_history.getSize(); ++i)
|
|
|
|
{
|
|
|
|
total += m_history.getTurn(i).getEndGamePoints();
|
|
|
|
}
|
|
|
|
return total;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-10-05 16:49:58 +02:00
|
|
|
int Player::getTotalScore() const
|
|
|
|
{
|
2012-10-05 18:19:06 +02:00
|
|
|
return m_score + getSoloPoints() + getPenaltyPoints() + getEndGamePoints();
|
2012-10-05 16:49:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-01-22 13:23:52 +01:00
|
|
|
wstring Player::toString() const
|
2005-12-26 23:52:38 +01:00
|
|
|
{
|
2008-11-23 09:18:03 +01:00
|
|
|
wstring res = L"Player ";
|
2006-01-22 13:23:52 +01:00
|
|
|
|
|
|
|
wchar_t buff[6];
|
2008-11-23 09:18:03 +01:00
|
|
|
_swprintf(buff, 5, L"%d\n", m_id);
|
|
|
|
res += wstring(buff);
|
2006-01-22 13:23:52 +01:00
|
|
|
res += m_history.toString() + L"\n";
|
2008-11-23 09:18:03 +01:00
|
|
|
res += L"score ";
|
|
|
|
_swprintf(buff, 5, L"%d\n", m_score);
|
2006-01-22 13:23:52 +01:00
|
|
|
res += wstring(buff);
|
2005-12-26 23:52:38 +01:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|