Arbitration: allow ending the turn even if some players have no assigned move

This commit is contained in:
Olivier Teulière 2012-03-14 21:08:09 +01:00
parent bfab57f6ac
commit 3a8ac20a0a
2 changed files with 28 additions and 15 deletions

View file

@ -18,6 +18,7 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*****************************************************************************/
#include <boost/foreach.hpp>
#include <algorithm> // For transform
#include <cwctype> // For towupper
@ -115,9 +116,18 @@ void Arbitration::finalizeTurn()
{
m_results.clear();
// FIXME arbitration begin
// Assign a default empty move to the human players which have
// not played yet, to be able to end the turn.
BOOST_FOREACH(Player *player, m_players)
{
if (player->isHuman() && !hasPlayed(player->getId()))
{
LOG_INFO("Assigning a default move to player " << player->getId());
recordPlayerMove(*player, Move());
}
}
tryEndTurn();
// FIXME arbitration end
}

View file

@ -945,31 +945,34 @@ QString ArbitrationWidget::formatMove(const Move &iMove) const
void ArbitrationWidget::endTurn()
{
QSet<unsigned int> notPlayerIdSet;
unsigned int nbPlayers = m_game->getNbPlayers();
for (unsigned int i = 0; i < nbPlayers; ++i)
{
if (!m_game->hasPlayed(i) && m_game->getPlayer(i).isHuman())
notPlayerIdSet.insert(i);
}
if (!notPlayerIdSet.empty())
{
notifyProblem(_q("All the players must have an assigned move before ending the turn."));
return;
}
if (m_game->duplicateGetMasterMove().getType() != Move::VALID_ROUND)
{
notifyProblem(_q("You must select a master move before ending the turn."));
return;
}
bool allPlayed = true;
for (unsigned int i = 0; i < m_game->getNbPlayers(); ++i)
{
if (!m_game->hasPlayed(i) && m_game->getPlayer(i).isHuman())
allPlayed = false;
}
if (!allPlayed)
{
QString msg = _q("Some player(s) have no assigned move. "
"If you continue, they will be assigned a \"(NO MOVE)\" "
"pseudo-move, but you will be able to change that later.");
if (!QtCommon::requestConfirmation(msg))
return;
}
m_addedMoves.clear();
emit notifyInfo(_q("New turn started"));
m_game->removeTestRound();
m_game->arbitrationFinalizeTurn();
// FIXME: shouldn't be done here
setEnabled(!m_game->isFinished());
emit gameUpdated();