2005-02-05 12:14:56 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (C) 2005 Eliot
|
|
|
|
* Authors: Olivier Teuliere <ipkiss@via.ecp.fr>
|
|
|
|
*
|
|
|
|
* 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
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef _DUPLICATE_H_
|
|
|
|
#define _DUPLICATE_H_
|
|
|
|
|
|
|
|
#include "game.h"
|
|
|
|
|
|
|
|
using std::string;
|
2006-01-22 13:23:52 +01:00
|
|
|
using std::wstring;
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
|
2005-03-27 19:30:48 +02:00
|
|
|
/**
|
|
|
|
* This class handles the logic specific to a duplicate game.
|
|
|
|
* The trick in this mode is that the players will not necessarily play they
|
|
|
|
* word always in the same order, so we need to implement a "synchronization":
|
|
|
|
* - when a human player wants to play a word, he plays it, and its score
|
|
|
|
* and rack are updated. He cannot change his word afterwards.
|
|
|
|
* - if there is still a human player who has not played for the current
|
|
|
|
* turn, we wait for him
|
|
|
|
* - if all the human players have played, it's the turn to the AI players
|
|
|
|
* (currently handled in a loop, but we could imagine that they are running
|
|
|
|
* in their own thread).
|
|
|
|
* - once all the players have played, we can really end the turn:
|
|
|
|
* the best word is played on the board, the history of the game is
|
|
|
|
* updated, and the new rack is chosen.
|
|
|
|
*
|
|
|
|
* AI players play after human ones, because with the current implementation
|
|
|
|
* of the interfaces it is too easy for a player to see the rack of other
|
|
|
|
* players, and in particular a human player could take advantage of that to
|
|
|
|
* have more clues about the best word.
|
|
|
|
* TODO: better isolation of the players...
|
|
|
|
*/
|
2005-02-05 12:14:56 +01:00
|
|
|
class Duplicate: public Game
|
|
|
|
{
|
2005-02-24 09:06:24 +01:00
|
|
|
friend class GameFactory;
|
2005-02-05 12:14:56 +01:00
|
|
|
public:
|
|
|
|
virtual GameMode getMode() const { return kDUPLICATE; }
|
2005-02-09 23:33:56 +01:00
|
|
|
virtual string getModeAsString() const { return "Duplicate"; }
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
/*************************
|
|
|
|
* Game handling
|
|
|
|
*************************/
|
|
|
|
virtual int start();
|
|
|
|
virtual int setRackRandom(int, bool, set_rack_mode);
|
2006-01-22 13:23:52 +01:00
|
|
|
virtual int play(const wstring &iCoord, const wstring &iWord);
|
2005-02-05 12:14:56 +01:00
|
|
|
virtual int endTurn();
|
2005-03-29 08:56:06 +02:00
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
int setPlayer(int);
|
2005-02-12 19:54:57 +01:00
|
|
|
// 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();
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
private:
|
2005-02-24 09:06:24 +01:00
|
|
|
// Private constructor and destructor to force using the GameFactory class
|
|
|
|
Duplicate(const Dictionary &iDic);
|
|
|
|
virtual ~Duplicate();
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
void playRound(const Round &iRound, int n);
|
|
|
|
int endTurnForReal();
|
|
|
|
void end();
|
2005-03-27 23:45:04 +02:00
|
|
|
void duplicateAI(int n);
|
2005-02-12 19:54:57 +01:00
|
|
|
|
|
|
|
// m_hasPlayed[p] is true iff player p has played for this turn
|
|
|
|
map<int, bool> m_hasPlayed;
|
2005-02-05 12:14:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _DUPLICATE_H_ */
|
2006-01-01 20:49:35 +01:00
|
|
|
|
|
|
|
/// Local Variables:
|
|
|
|
/// mode: c++
|
|
|
|
/// mode: hs-minor
|
|
|
|
/// c-basic-offset: 4
|
|
|
|
/// indent-tabs-mode: nil
|
|
|
|
/// End:
|