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_PERCENT_H_ 00021 #define _AI_PERCENT_H_ 00022 00023 #include "ai_player.h" 00024 #include "results.h" 00025 00026 /** 00027 * This kind of AI is parameterized by a percentage p. 00028 * The computation consists in finding all the N possible rounds for the 00029 * current rack/board, and sorting the list. 00030 * The chosen round is the n'th element of the sorted list, such that n/N 00031 * is closest to the percentage p. 00032 * A percentage of 0 should always return the best round (i.e. the one with 00033 * the highest score), while a percentage of 1 should return the worst one. 00034 * This kind of AI will never change letters (unless it cannot play anything, 00035 * in which case it just passes without changing letters). 00036 */ 00037 class AIPercent: public AIPlayer 00038 { 00039 public: 00040 /// Constructor, taking the percentage (0.0 <= iPercent <= 1.0) 00041 AIPercent(int iId, float iPercent); 00042 virtual ~AIPercent() {} 00043 00044 /** 00045 * This method does the actual computation. It will be called before any 00046 * of the following methods, so it must prepare everything for them. 00047 */ 00048 virtual void compute(const Dictionary &iDic, Board &iBoard, int turn); 00049 /// Return true when the AI wants to change letters instead of playing a word 00050 virtual bool changesLetters() const; 00051 /// Return the round played by the AI (if changesLetters() returns false) 00052 virtual const Round & getChosenRound() const; 00053 /// Get the letters to change (if changesLetters() returns true) 00054 virtual vector<Tile> getChangedLetters() const; 00055 00056 private: 00057 /// Percentage used for this player 00058 float m_percent; 00059 /// Container for all the found solutions 00060 Results m_results; 00061 }; 00062 00063 #endif 00064 00065 /// Local Variables: 00066 /// mode: c++ 00067 /// mode: hs-minor 00068 /// c-basic-offset: 4 00069 /// indent-tabs-mode: nil 00070 /// End: