2005-02-05 12:14:56 +01:00
|
|
|
/*****************************************************************************
|
|
|
|
* Copyright (C) 1999-2005 Eliot
|
|
|
|
* Authors: Antoine Fraboulet <antoine.fraboulet@free.fr>
|
|
|
|
* 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
|
|
|
*****************************************************************************/
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
|
|
#ifndef _GAME_H_
|
|
|
|
#define _GAME_H_
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
#include "bag.h"
|
|
|
|
#include "board.h"
|
2004-04-08 11:43:06 +02:00
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
class Player;
|
|
|
|
class PlayedRack;
|
|
|
|
class Round;
|
|
|
|
class Rack;
|
2005-11-06 00:22:41 +01:00
|
|
|
class Turn;
|
2005-02-05 12:14:56 +01:00
|
|
|
typedef struct _Dictionary * Dictionary;
|
2004-04-08 11:43:06 +02:00
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
using namespace std;
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
/*************************
|
|
|
|
* Ident string used to identify saved Eliot games
|
|
|
|
*************************/
|
|
|
|
#define IDENT_STRING "Eliot"
|
2004-04-08 11:43:06 +02:00
|
|
|
|
2005-03-27 19:30:48 +02:00
|
|
|
/**
|
|
|
|
* Parent class of all the Game types.
|
|
|
|
* It offers the common attributes (Board, Bag, etc...) as well as useful
|
|
|
|
* "helper" methods to factorize some code.
|
|
|
|
*/
|
2005-02-05 12:14:56 +01:00
|
|
|
class Game
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
Game(const Dictionary &iDic);
|
|
|
|
virtual ~Game();
|
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
/// Game mode: each one of these modes is implemented in an inherited class
|
2005-02-05 12:14:56 +01:00
|
|
|
enum GameMode
|
|
|
|
{
|
|
|
|
kTRAINING,
|
|
|
|
kFREEGAME,
|
|
|
|
kDUPLICATE
|
|
|
|
};
|
|
|
|
virtual GameMode getMode() const = 0;
|
2005-02-09 23:33:56 +01:00
|
|
|
virtual string getModeAsString() const = 0;
|
2005-02-05 12:14:56 +01:00
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
/// Game variant: it slightly modifies the rules of the game
|
|
|
|
enum GameVariant
|
|
|
|
{
|
|
|
|
kNONE, // Normal game rules
|
|
|
|
kJOKER // Joker game
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Accessors for the variant of the game.
|
|
|
|
* The variant can be changed during a game without any problem
|
|
|
|
* (though it seems rather useless...)
|
|
|
|
*/
|
|
|
|
void setVariant(GameVariant iVariant) { m_variant = iVariant; }
|
|
|
|
GameVariant getVariant() const { return m_variant; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dictionary associated with the game.
|
|
|
|
* The dictionary can be changed during a game without problem
|
|
|
|
*/
|
|
|
|
const Dictionary & getDic() const { return *m_dic; }
|
|
|
|
void setDic(const Dictionary &iDic) { m_dic = &iDic; }
|
|
|
|
|
2005-11-05 16:48:59 +01:00
|
|
|
const Board& getBoard() const { return m_board; }
|
|
|
|
const Bag& getBag() const { return m_bag; }
|
2005-11-06 02:05:06 +01:00
|
|
|
const Player& getPlayer(int iNum) const;
|
|
|
|
const Turn& getTurn(int iNum) const;
|
2005-11-05 16:48:59 +01:00
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
/**
|
|
|
|
* Saved games handling.
|
2005-02-05 12:14:56 +01:00
|
|
|
*
|
|
|
|
* load() returns the loaded game, or NULL if there was a problem
|
|
|
|
* load() might need some more work to be robust enough to
|
|
|
|
* handle "hand written" files
|
2005-03-29 00:07:22 +02:00
|
|
|
*/
|
2005-02-05 12:14:56 +01:00
|
|
|
static Game * load(FILE *fin, const Dictionary &iDic);
|
|
|
|
void save(ostream &out) const;
|
|
|
|
|
|
|
|
/*************************
|
|
|
|
* Playing the game
|
2005-11-06 00:22:41 +01:00
|
|
|
* the int parameter should be 0 <= int < getNTurns
|
2005-02-05 12:14:56 +01:00
|
|
|
*************************/
|
|
|
|
int back(int);
|
|
|
|
|
|
|
|
/*************************
|
|
|
|
* Set the rack for searching
|
|
|
|
*
|
|
|
|
* The int parameter is a boolean, if this parameter
|
|
|
|
* set the rack will check that there are at least
|
|
|
|
* 2 vowels and 2 consonants before the round 15.
|
|
|
|
*
|
|
|
|
* The setrackmanual parameter string has to contain
|
|
|
|
* 'a' <= char <= 'z' or 'A' <= char <= 'Z' or '?'
|
|
|
|
*
|
|
|
|
* return value
|
|
|
|
* 0 : the rack has been set
|
|
|
|
* 1 : the bag does not contain enough tiles
|
|
|
|
* 2 : the rack check was set on and failed
|
|
|
|
* 3 : the rack cannot be completed (Game_*_setrackrandom only)
|
|
|
|
*************************/
|
2005-02-26 23:57:34 +01:00
|
|
|
static const int RACK_SIZE;
|
2005-11-06 02:05:06 +01:00
|
|
|
enum set_rack_mode {RACK_ALL, RACK_NEW};
|
2005-02-05 12:14:56 +01:00
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
/**
|
|
|
|
* Methods to access already played words.
|
2005-11-06 00:22:41 +01:00
|
|
|
* The int parameter should be 0 <= int < getNTurns()
|
2005-03-29 00:07:22 +02:00
|
|
|
*/
|
2005-11-06 00:22:41 +01:00
|
|
|
int getNTurns() const { return m_history.size(); }
|
2005-02-05 12:14:56 +01:00
|
|
|
string getPlayedRack(int) const;
|
|
|
|
string getPlayedWord(int) const;
|
|
|
|
string getPlayedCoords(int num) const;
|
|
|
|
int getPlayedPoints(int) const;
|
|
|
|
int getPlayedBonus(int) const;
|
|
|
|
int getPlayedPlayer(int) const;
|
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
/**
|
|
|
|
* Methods to access players.
|
2005-03-27 19:30:48 +02:00
|
|
|
* The int parameter should be 0 <= int < getNPlayers()
|
2005-03-29 00:07:22 +02:00
|
|
|
*/
|
2005-02-05 12:14:56 +01:00
|
|
|
int getNPlayers() const { return m_players.size(); }
|
|
|
|
int getNHumanPlayers() const;
|
2005-03-03 23:14:41 +01:00
|
|
|
virtual void addHumanPlayer();
|
2005-03-27 19:30:48 +02:00
|
|
|
// TODO: Ability to specify which kind of AI player is wanted
|
2005-03-03 23:14:41 +01:00
|
|
|
virtual void addAIPlayer();
|
2005-04-20 22:58:51 +02:00
|
|
|
string getPlayerRack(int, bool = false) const;
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
int currPlayer() const { return m_currPlayer; }
|
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
/**
|
2005-02-05 12:14:56 +01:00
|
|
|
* Game handling
|
2005-03-29 00:07:22 +02:00
|
|
|
*/
|
2005-02-05 12:14:56 +01:00
|
|
|
virtual int start() = 0;
|
|
|
|
virtual int setRackRandom(int, bool, set_rack_mode) = 0;
|
|
|
|
virtual int play(const string &iCoord, const string &iWord) = 0;
|
|
|
|
virtual int endTurn() = 0;
|
|
|
|
|
|
|
|
protected:
|
2005-03-29 00:07:22 +02:00
|
|
|
/// All the players, indexed by their ID
|
2005-02-05 12:14:56 +01:00
|
|
|
vector<Player*> m_players;
|
2005-03-29 00:07:22 +02:00
|
|
|
/// ID of the "current" player
|
2005-02-05 12:14:56 +01:00
|
|
|
int m_currPlayer;
|
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
// TODO: check what should be private and what should be protected
|
2005-02-05 12:14:56 +01:00
|
|
|
// private:
|
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
/// Variant
|
|
|
|
GameVariant m_variant;
|
|
|
|
|
|
|
|
/// Dictionary currently associated to the game
|
2005-02-05 12:14:56 +01:00
|
|
|
const Dictionary * m_dic;
|
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
/// Bag
|
2005-02-05 12:14:56 +01:00
|
|
|
Bag m_bag;
|
2005-03-29 00:07:22 +02:00
|
|
|
|
|
|
|
/// Board
|
2005-02-05 12:14:56 +01:00
|
|
|
Board m_board;
|
|
|
|
|
2005-03-29 00:07:22 +02:00
|
|
|
/**
|
|
|
|
* History of the game.
|
2005-11-06 00:22:41 +01:00
|
|
|
* The vector is indexed by the number of turns in the game
|
2005-03-29 00:07:22 +02:00
|
|
|
*/
|
2005-11-06 00:22:41 +01:00
|
|
|
vector<Turn*> m_history;
|
2005-02-05 12:14:56 +01:00
|
|
|
|
|
|
|
int m_points;
|
|
|
|
|
|
|
|
bool m_finished;
|
|
|
|
|
|
|
|
/*********************************************************
|
|
|
|
* Helper functions
|
|
|
|
*********************************************************/
|
|
|
|
|
2005-03-27 19:30:48 +02:00
|
|
|
int helperPlayRound(const Round &iRound);
|
|
|
|
int helperSetRackRandom(int p, bool iCheck, set_rack_mode mode);
|
|
|
|
int helperSetRackManual(int p, bool iCheck, const string &iLetters);
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
void prevPlayer();
|
|
|
|
void nextPlayer();
|
|
|
|
bool rackInBag(const Rack &iRack, const Bag &iBag) const;
|
|
|
|
void realBag(Bag &iBag) const;
|
|
|
|
int checkPlayedWord(const string &iCoord,
|
|
|
|
const string &iWord, Round &oRound);
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* _GAME_H_ */
|