mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-29 20:34:56 +01:00
Duplicate: assign a "no move" pseudo-move to all players when starting a turn
This commit is contained in:
parent
196e02f9ad
commit
0b3120a792
3 changed files with 15 additions and 45 deletions
|
@ -44,47 +44,6 @@ Arbitration::Arbitration(const GameParams &iParams)
|
|||
}
|
||||
|
||||
|
||||
void Arbitration::start()
|
||||
{
|
||||
ASSERT(getNPlayers(), "Cannot start a game without any player");
|
||||
|
||||
// Arbitrary player, since they should all have the same rack
|
||||
m_currPlayer = 0;
|
||||
|
||||
// Complete the racks
|
||||
try
|
||||
{
|
||||
// Reset the master move
|
||||
setMasterMove(Move());
|
||||
|
||||
const PlayedRack &newRack =
|
||||
helperSetRackRandom(getHistory().getCurrentRack(), true, RACK_NEW);
|
||||
setGameAndPlayersRack(newRack);
|
||||
|
||||
// Assign a "no move" pseudo-move to all the players.
|
||||
// This avoids the need to distinguish between "has not played yet"
|
||||
// and "has played with no move".
|
||||
// This is also practical to know at which turn the warnings, penalties
|
||||
// and solos should be assigned.
|
||||
BOOST_FOREACH(Player *player, m_players)
|
||||
{
|
||||
Command *pCmd = new PlayerMoveCmd(*player, Move(), true);
|
||||
pCmd->setHumanIndependent(!player->isHuman());
|
||||
accessNavigation().addAndExecute(pCmd);
|
||||
}
|
||||
}
|
||||
catch (EndGameException &e)
|
||||
{
|
||||
endGame();
|
||||
return;
|
||||
}
|
||||
|
||||
// Little hack to handle duplicate games with only AI players.
|
||||
// This will have no effect when there is at least one human player
|
||||
tryEndTurn();
|
||||
}
|
||||
|
||||
|
||||
void Arbitration::setRackRandom()
|
||||
{
|
||||
undoCurrentRack();
|
||||
|
|
|
@ -38,8 +38,6 @@ class Arbitration: public Duplicate
|
|||
friend class GameFactory;
|
||||
public:
|
||||
|
||||
virtual void start();
|
||||
|
||||
/**
|
||||
* Complete (or reset) the rack randomly.
|
||||
* @exception EndGameException if it is impossible to complete the rack
|
||||
|
|
|
@ -227,7 +227,7 @@ void Duplicate::recordPlayerMove(Player &ioPlayer, const Move &iMove)
|
|||
{
|
||||
// Replace the player move
|
||||
LOG_DEBUG("Replacing move for player " << ioPlayer.getId());
|
||||
if (!getNavigation().isLastTurn())
|
||||
if (!isArbitration && !getNavigation().isLastTurn())
|
||||
throw GameException("Cannot add a command to an old turn");
|
||||
Command *pCmd = new PlayerMoveCmd(ioPlayer, iMove, isArbitration);
|
||||
pCmd->setHumanIndependent(!ioPlayer.isHuman());
|
||||
|
@ -379,7 +379,8 @@ bool Duplicate::hasPlayed(unsigned iPlayerId) const
|
|||
MatchingPlayer predicate(iPlayerId);
|
||||
const PlayerMoveCmd *cmd =
|
||||
getNavigation().getCurrentTurn().findMatchingCmd<PlayerMoveCmd>(predicate);
|
||||
return cmd != 0 && cmd->isExecuted();
|
||||
return cmd != 0 && cmd->isExecuted() &&
|
||||
cmd->getMove().getType() != Move::NO_MOVE;
|
||||
}
|
||||
|
||||
|
||||
|
@ -416,6 +417,18 @@ void Duplicate::setGameAndPlayersRack(const PlayedRack &iRack)
|
|||
Command *pCmd = new PlayerRackCmd(*player, iRack);
|
||||
accessNavigation().addAndExecute(pCmd);
|
||||
}
|
||||
|
||||
// Assign a "no move" pseudo-move to all the players.
|
||||
// This avoids the need to distinguish between "has not played yet"
|
||||
// and "has played with no move".
|
||||
// This is also practical to know at which turn the warnings, penalties
|
||||
// and solos should be assigned.
|
||||
BOOST_FOREACH(Player *player, m_players)
|
||||
{
|
||||
Command *pCmd = new PlayerMoveCmd(*player, Move(), true);
|
||||
pCmd->setHumanIndependent(!player->isHuman());
|
||||
accessNavigation().addAndExecute(pCmd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue