mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2024-11-17 07:48:27 +01:00
Handling of which player has played is only done in the Duplicate class now
(since the other modes do not need this)
This commit is contained in:
parent
d41530c496
commit
cf94b4e015
6 changed files with 53 additions and 52 deletions
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2005 Eliot
|
||||
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: duplicate.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
* $Id: duplicate.cpp,v 1.3 2005/02/12 18:54:57 ipkiss Exp $
|
||||
*
|
||||
* 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
|
||||
|
@ -125,7 +125,7 @@ int Duplicate::start()
|
|||
m_players[i]->setCurrentRack(pld);
|
||||
}
|
||||
/* Nobody has played yet in this round */
|
||||
m_players[i]->setStatus(Player::TO_PLAY);
|
||||
m_hasPlayed[i] = false;
|
||||
}
|
||||
|
||||
/* Next turn */
|
||||
|
@ -153,8 +153,7 @@ int Duplicate::endTurn()
|
|||
int i;
|
||||
for (i = 0; i < getNPlayers(); i++)
|
||||
{
|
||||
if (m_players[i]->isHuman() &&
|
||||
m_players[i]->getStatus() == Player::TO_PLAY)
|
||||
if (m_players[i]->isHuman() && !m_hasPlayed[i])
|
||||
{
|
||||
/* A human player has not played... */
|
||||
m_currPlayer = i;
|
||||
|
@ -198,7 +197,7 @@ void Duplicate::playRound(const Round &iRound, int n)
|
|||
player->addPoints(iRound.getPoints());
|
||||
player->endTurn(iRound, getNRounds());
|
||||
|
||||
player->setStatus(Player::PLAYED);
|
||||
m_hasPlayed[n] = true;
|
||||
}
|
||||
|
||||
|
||||
|
@ -243,7 +242,7 @@ int Duplicate::endTurnForReal()
|
|||
m_players[i]->setCurrentRack(pld);
|
||||
}
|
||||
/* Nobody has played yet in this round */
|
||||
m_players[i]->setStatus(Player::TO_PLAY);
|
||||
m_hasPlayed[i] = false;
|
||||
}
|
||||
|
||||
/* XXX: Little hack to handle the games with only AI players.
|
||||
|
@ -272,3 +271,29 @@ int Duplicate::setPlayer(int n)
|
|||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void Duplicate::prevHumanPlayer()
|
||||
{
|
||||
if (getNHumanPlayers() == 0)
|
||||
return;
|
||||
// FIXME: possible infinite loop...
|
||||
do
|
||||
{
|
||||
prevPlayer();
|
||||
} while (!m_players[m_currPlayer]->isHuman() ||
|
||||
m_hasPlayed[m_currPlayer]);
|
||||
}
|
||||
|
||||
|
||||
void Duplicate::nextHumanPlayer()
|
||||
{
|
||||
if (getNHumanPlayers() == 0)
|
||||
return;
|
||||
// FIXME: possible infinite loop...
|
||||
do
|
||||
{
|
||||
nextPlayer();
|
||||
} while (!m_players[m_currPlayer]->isHuman() ||
|
||||
m_hasPlayed[m_currPlayer]);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2005 Eliot
|
||||
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: duplicate.h,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
* $Id: duplicate.h,v 1.3 2005/02/12 18:54:57 ipkiss Exp $
|
||||
*
|
||||
* 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
|
||||
|
@ -51,6 +51,10 @@ public:
|
|||
virtual int play(const string &iCoord, const string &iWord);
|
||||
virtual int endTurn();
|
||||
int setPlayer(int);
|
||||
// Switch to the previous human player who has not played yet
|
||||
void prevHumanPlayer();
|
||||
// Switch to the next human player who has not played yet
|
||||
void nextHumanPlayer();
|
||||
|
||||
private:
|
||||
|
||||
|
@ -58,6 +62,9 @@ private:
|
|||
int endTurnForReal();
|
||||
void end();
|
||||
int duplicateAI(int n);
|
||||
|
||||
// m_hasPlayed[p] is true iff player p has played for this turn
|
||||
map<int, bool> m_hasPlayed;
|
||||
};
|
||||
|
||||
#endif /* _DUPLICATE_H_ */
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
|
||||
* Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: game.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
* $Id: game.cpp,v 1.3 2005/02/12 18:54:57 ipkiss Exp $
|
||||
*
|
||||
* 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
|
||||
|
@ -288,7 +288,14 @@ Game * Game::load(FILE *fin, const Dictionary &iDic)
|
|||
{
|
||||
// We don't really know whose turn it is, but at least we know that
|
||||
// the game was saved while a human was to play.
|
||||
pGame->nextHumanPlayer();
|
||||
for (int i = 0; i < pGame->getNPlayers(); i++)
|
||||
{
|
||||
if (pGame->m_players[i]->isHuman())
|
||||
{
|
||||
pGame->m_currPlayer = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return pGame;
|
||||
}
|
||||
|
@ -299,7 +306,7 @@ void Game::save(ostream &out) const
|
|||
const string decal = " ";
|
||||
// "Header" of the game
|
||||
out << IDENT_STRING << endl << endl;
|
||||
out << "Game type: " << getModeAsString();
|
||||
out << "Game type: " << getModeAsString() << endl;
|
||||
for (int i = 0; i < getNPlayers(); i++)
|
||||
{
|
||||
out << "Player " << i << ": ";
|
||||
|
@ -902,30 +909,6 @@ void Game::nextPlayer()
|
|||
}
|
||||
|
||||
|
||||
void Game::prevHumanPlayer()
|
||||
{
|
||||
if (getNHumanPlayers() == 0)
|
||||
return;
|
||||
do
|
||||
{
|
||||
prevPlayer();
|
||||
} while (!m_players[m_currPlayer]->isHuman() ||
|
||||
m_players[m_currPlayer]->getStatus() != Player::TO_PLAY);
|
||||
}
|
||||
|
||||
|
||||
void Game::nextHumanPlayer()
|
||||
{
|
||||
if (getNHumanPlayers() == 0)
|
||||
return;
|
||||
do
|
||||
{
|
||||
nextPlayer();
|
||||
} while (!m_players[m_currPlayer]->isHuman() ||
|
||||
m_players[m_currPlayer]->getStatus() != Player::TO_PLAY);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* This function checks whether it is legal to play the given word at the
|
||||
* given coordinates. If so, the function fills a Round object, also given as
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
|
||||
* Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: game.h,v 1.4 2005/02/09 22:33:56 ipkiss Exp $
|
||||
* $Id: game.h,v 1.5 2005/02/12 18:54:57 ipkiss Exp $
|
||||
*
|
||||
* 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
|
||||
|
@ -204,10 +204,6 @@ public:
|
|||
string getPlayerRack(int) const;
|
||||
|
||||
int currPlayer() const { return m_currPlayer; }
|
||||
// Return the previous human player who has not played yet
|
||||
void prevHumanPlayer();
|
||||
// Return the next human player who has not played yet
|
||||
void nextHumanPlayer();
|
||||
|
||||
/*************************
|
||||
* Game handling
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2004-2005 Eliot
|
||||
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: player.cpp,v 1.2 2005/02/09 22:33:56 ipkiss Exp $
|
||||
* $Id: player.cpp,v 1.3 2005/02/12 18:54:57 ipkiss Exp $
|
||||
*
|
||||
* 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
|
||||
|
@ -31,8 +31,7 @@
|
|||
|
||||
Player::Player(bool iHuman):
|
||||
m_human(iHuman),
|
||||
m_score(0),
|
||||
m_status(TO_PLAY)
|
||||
m_score(0)
|
||||
{
|
||||
// Start with an empty rack
|
||||
m_playedRacks.push_back(new PlayedRack());
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 2004-2005 Eliot
|
||||
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
||||
*
|
||||
* $Id: player.h,v 1.3 2005/02/09 22:33:56 ipkiss Exp $
|
||||
* $Id: player.h,v 1.4 2005/02/12 18:54:57 ipkiss Exp $
|
||||
*
|
||||
* 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
|
||||
|
@ -58,13 +58,6 @@ public:
|
|||
**************************/
|
||||
void endTurn(const Round &iRound, int iTurn);
|
||||
|
||||
/**************************
|
||||
*
|
||||
**************************/
|
||||
typedef enum {PLAYED, TO_PLAY} play_status;
|
||||
void setStatus(play_status iStatus) { m_status = iStatus; }
|
||||
play_status getStatus() const { return m_status; }
|
||||
|
||||
/**************************
|
||||
* AI (Artificial Intelligence) handling
|
||||
* The int argument of Player_ai_search() is the 'turn' number
|
||||
|
@ -105,8 +98,6 @@ private:
|
|||
bool m_human;
|
||||
// Score of the player
|
||||
int m_score;
|
||||
// Play status (XXX: only used by duplicate mode currently)
|
||||
play_status m_status;
|
||||
|
||||
// History of the racks and rounds for the player
|
||||
vector<PlayedRack *> m_playedRacks;
|
||||
|
|
Loading…
Reference in a new issue