ai_player.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002  * Copyright (C) 2005 Eliot
00003  * Authors: Olivier Teuliere  <ipkiss@via.ecp.fr>
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018  *****************************************************************************/
00019 
00020 #ifndef _AI_PLAYER_H_
00021 #define _AI_PLAYER_H_
00022 
00023 #include "player.h"
00024 
00025 class Round;
00026 class Board;
00027 class Tile;
00028 typedef struct _Dictionary * Dictionary;
00029 
00030 /**
00031  * This class is a pure interface, that must be implemented by all the AI
00032  * (Artificial Intelligence) players
00033  *
00034  * Note: we could implement various strategies (some of which are already
00035  * implemented):
00036  *   - best: play the word with the best score (current default implementation)
00037  *   - second: play the word with the second best score (strictly lower than
00038  *        the best one)
00039  *   - random: randomly choose one of the possible words
00040  *   - handicap(p): in the array of the n possible words (sorted by
00041  *        decreasing scores), play the word number i, where i/n is nearest
00042  *        from a predefined percentage p.
00043  *        So 'handicap(0)' should be equivalent to 'best'.
00044  *        This strategy should make an interesting opponent, because you can
00045  *        adapt it to your level, with a careful choice of the p value.
00046  *
00047  * In fact, instead of working on the score of the words, these strategies
00048  * could work on any other value. In particular, some heuristics could
00049  * modulate the score with a value indicating the openings offered by the
00050  * word (if a word makes accessible a "word counts triple" square, it is
00051  * less interesting than another word with the same score or even with a
00052  * slightly lower score, but which does not offer such a square).
00053  *
00054  * More evolved heuristics could even take into account the remaining
00055  * letters in the bag to guess the 'statistical rack' of the opponent, and
00056  * play a word both maximizing the score and minimizing the opponent's
00057  * score...
00058  * Hmmm... i don't think this one will be implemented in a near future :)
00059  **************************/
00060 class AIPlayer: public Player
00061 {
00062 public:
00063     virtual ~AIPlayer() {}
00064 
00065     /// No human here. Trespassers will be shot!
00066     virtual bool isHuman() const { return false; }
00067 
00068     /**
00069      * This method does the actual computation. It will be called before any
00070      * of the following methods, so it must prepare everything for them.
00071      */
00072     virtual void compute(const Dictionary &iDic, Board &iBoard, int turn) = 0;
00073     /**
00074      * Return true when the AI wants to change letters instead of playing a
00075      * word.
00076      * Should return false in duplicate mode, as it is not allowed to change
00077      * letters.
00078      */
00079     virtual bool changesLetters() const = 0;
00080     /// Return the round played by the AI (if changesLetters() returns false)
00081     virtual const Round & getChosenRound() const = 0;
00082     /// Get the letters to change (if changesLetters() returns true)
00083     virtual vector<Tile> getChangedLetters() const = 0;
00084 
00085 protected:
00086     /// This class is a pure interface, forbid any direct instanciation
00087     AIPlayer(int iId): Player(iId) {}
00088 };
00089 
00090 #endif
00091 
00092 /// Local Variables:
00093 /// mode: c++
00094 /// mode: hs-minor
00095 /// c-basic-offset: 4
00096 /// indent-tabs-mode: nil
00097 /// End:

Generated on Thu Dec 29 02:01:14 2005 for Eliot by  doxygen 1.4.5