2005-02-05 12:14:56 +01:00
|
|
|
|
/*****************************************************************************
|
2008-01-08 14:52:32 +01:00
|
|
|
|
* Eliot
|
2012-10-07 16:25:41 +02:00
|
|
|
|
* Copyright (C) 2005-2012 Antoine Fraboulet & Olivier Teuli<EFBFBD>re
|
2008-01-08 14:52:32 +01:00
|
|
|
|
* Authors: Antoine Fraboulet <antoine.fraboulet @@ free.fr>
|
|
|
|
|
* Olivier Teuli<EFBFBD>re <ipkiss @@ gmail.com>
|
2005-02-05 12:14:56 +01:00
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
2009-11-29 17:01:31 +01:00
|
|
|
|
#ifndef RESULTS_H_
|
|
|
|
|
#define RESULTS_H_
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
2005-02-05 12:14:56 +01:00
|
|
|
|
#include <vector>
|
2009-01-22 19:30:22 +01:00
|
|
|
|
#include <map>
|
2005-02-17 21:01:59 +01:00
|
|
|
|
#include "round.h"
|
2012-02-18 22:26:52 +01:00
|
|
|
|
#include "logging.h"
|
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
|
|
|
|
|
2008-01-08 14:52:32 +01:00
|
|
|
|
class Dictionary;
|
2005-02-17 21:01:59 +01:00
|
|
|
|
class Board;
|
|
|
|
|
class Rack;
|
2013-01-17 18:39:03 +01:00
|
|
|
|
class Bag;
|
2005-02-17 21:01:59 +01:00
|
|
|
|
|
|
|
|
|
|
2005-03-27 19:30:48 +02:00
|
|
|
|
/**
|
2009-01-22 19:30:22 +01:00
|
|
|
|
* This abstract class defines the interface to perform a search on the board
|
|
|
|
|
* for a given rack, and it offers accessors to the resulting rounds.
|
|
|
|
|
* Not all the rounds found by the search are necessarily kept, it depends
|
|
|
|
|
* on the implementation (see below in the file for the various
|
|
|
|
|
* implementations).
|
|
|
|
|
*
|
|
|
|
|
* After the search, the rounds are sorted by decreasing number of points,
|
|
|
|
|
* then by alphabetical order (case insensitive), then by coordinates,
|
|
|
|
|
* then by alphabetical order again (case sensitive this time).
|
2005-03-27 19:30:48 +02:00
|
|
|
|
*/
|
2005-02-05 12:14:56 +01:00
|
|
|
|
class Results
|
|
|
|
|
{
|
2012-02-18 22:26:52 +01:00
|
|
|
|
DEFINE_LOGGER();
|
2005-02-05 12:14:56 +01:00
|
|
|
|
public:
|
2010-01-28 23:24:11 +01:00
|
|
|
|
virtual ~Results() {}
|
2009-01-22 19:30:22 +01:00
|
|
|
|
unsigned int size() const { return m_rounds.size(); }
|
2008-01-08 14:52:32 +01:00
|
|
|
|
const Round & get(unsigned int) const;
|
2013-01-16 11:09:28 +01:00
|
|
|
|
bool isEmpty() const { return m_rounds.empty(); }
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
2009-01-22 19:30:22 +01:00
|
|
|
|
/**
|
|
|
|
|
* Perform a search on the board. Every time a word is found,
|
|
|
|
|
* the add() method will be called. At the end of the search,
|
|
|
|
|
* results are sorted.
|
|
|
|
|
*/
|
|
|
|
|
virtual void search(const Dictionary &iDic, const Board &iBoard,
|
|
|
|
|
const Rack &iRack, bool iFirstWord) = 0;
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
2009-01-22 19:30:22 +01:00
|
|
|
|
/** Add a round */
|
|
|
|
|
virtual void add(const Round &iRound) = 0;
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
2009-01-22 19:30:22 +01:00
|
|
|
|
/** Clear the stored rounds, and get ready for a new search */
|
|
|
|
|
virtual void clear() = 0;
|
|
|
|
|
|
|
|
|
|
protected:
|
2005-02-05 12:14:56 +01:00
|
|
|
|
vector<Round> m_rounds;
|
2009-01-22 19:30:22 +01:00
|
|
|
|
void sort();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This implementation keeps only the rounds corresponding to the best score.
|
|
|
|
|
* If there are several rounds with the same score, they are all kept.
|
|
|
|
|
* All other rounds are ignored.
|
|
|
|
|
*/
|
|
|
|
|
class BestResults: public Results
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
BestResults();
|
|
|
|
|
virtual void search(const Dictionary &iDic, const Board &iBoard,
|
|
|
|
|
const Rack &iRack, bool iFirstWord);
|
|
|
|
|
virtual void clear();
|
|
|
|
|
virtual void add(const Round &iRound);
|
2008-01-08 14:52:32 +01:00
|
|
|
|
|
2009-01-22 19:30:22 +01:00
|
|
|
|
private:
|
|
|
|
|
int m_bestScore;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This implementation finds the best score possible, and keeps only
|
|
|
|
|
* the rounds whose score is closest to (but not lower than) the given
|
|
|
|
|
* percentage of the best score.
|
|
|
|
|
* All the rounds with this closest score are kept, rounds with a different
|
|
|
|
|
* score are ignored.
|
|
|
|
|
*/
|
|
|
|
|
class PercentResults: public Results
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
/** The percentage is given as a float between 0 (0%) and 1 (100%) */
|
|
|
|
|
PercentResults(float iPercent);
|
|
|
|
|
virtual void search(const Dictionary &iDic, const Board &iBoard,
|
|
|
|
|
const Rack &iRack, bool iFirstWord);
|
|
|
|
|
virtual void clear();
|
|
|
|
|
virtual void add(const Round &iRound);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const float m_percent;
|
|
|
|
|
int m_bestScore;
|
|
|
|
|
int m_minScore;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This implementation keeps the N best rounds, N being the given limit.
|
|
|
|
|
* All other rounds are ignored.
|
|
|
|
|
* In the special case where the limit is 0, all rounds are kept (but you can
|
|
|
|
|
* expect the sorting of the rounds to be much slower...)
|
|
|
|
|
*/
|
|
|
|
|
class LimitResults: public Results
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
LimitResults(int iLimit);
|
|
|
|
|
virtual void search(const Dictionary &iDic, const Board &iBoard,
|
|
|
|
|
const Rack &iRack, bool iFirstWord);
|
|
|
|
|
virtual void clear();
|
|
|
|
|
virtual void add(const Round &iRound);
|
|
|
|
|
|
|
|
|
|
void setLimit(int iNewLimit) { m_limit = iNewLimit; }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
int m_limit;
|
|
|
|
|
map<int, int> m_scoresCount;
|
|
|
|
|
int m_total;
|
|
|
|
|
int m_minScore;
|
2005-02-05 12:14:56 +01:00
|
|
|
|
};
|
2004-04-08 11:43:06 +02:00
|
|
|
|
|
2013-01-17 18:39:03 +01:00
|
|
|
|
/**
|
|
|
|
|
* This implementation starts with finding the rounds corresponding to the best
|
|
|
|
|
* score, like BestResults would do.
|
|
|
|
|
* After that, it uses a series of heuristics to identify the round which
|
|
|
|
|
* be best as "master move" in a duplicate game.
|
|
|
|
|
* All other rounds are discarded, so the size() method will always
|
|
|
|
|
* return 0 (if no round can be played at all) or 1.
|
|
|
|
|
*/
|
|
|
|
|
class MasterResults: public Results
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
MasterResults(const Bag &iBag);
|
|
|
|
|
virtual void search(const Dictionary &iDic, const Board &iBoard,
|
|
|
|
|
const Rack &iRack, bool iFirstWord);
|
|
|
|
|
virtual void clear();
|
|
|
|
|
virtual void add(const Round &iRound);
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
const Bag &m_bag;
|
|
|
|
|
BestResults m_bestResults;
|
|
|
|
|
};
|
|
|
|
|
|
2004-04-08 11:43:06 +02:00
|
|
|
|
#endif
|
2005-12-26 22:22:21 +01:00
|
|
|
|
|