mirror of
git://git.savannah.nongnu.org/eliot.git
synced 2025-01-13 20:03:23 +01:00
MoveSelector: add a new heuristic (deactivated for now)
This commit is contained in:
parent
80fa47d71b
commit
075dbaa2fb
3 changed files with 38 additions and 2 deletions
|
@ -21,13 +21,22 @@
|
|||
#include "move_selector.h"
|
||||
#include "round.h"
|
||||
#include "results.h"
|
||||
#include "bag.h"
|
||||
|
||||
#include "dic.h"
|
||||
#include "debug.h"
|
||||
|
||||
|
||||
INIT_LOGGER(game, MoveSelector);
|
||||
|
||||
#define PLAYED_JOKER (-1000)
|
||||
#define EXTENSION_1 50
|
||||
|
||||
|
||||
MoveSelector::MoveSelector(const Bag &iBag, const Dictionary &iDic)
|
||||
: m_bag(iBag), m_dic(iDic)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Round MoveSelector::selectMaster(const BestResults &iResults) const
|
||||
|
@ -60,7 +69,12 @@ int MoveSelector::evalScore(const Round &iRound) const
|
|||
{
|
||||
int score = 0;
|
||||
score += evalForJokersInRack(iRound);
|
||||
// TODO: more heuristics
|
||||
// Deactivated for now, as it breaks a few non-regression tests,
|
||||
// and I don't have time to fix them at the moment... :)
|
||||
#if 0
|
||||
score += evalForExtensions(iRound);
|
||||
#endif
|
||||
// TODO: add more heuristics
|
||||
return score;
|
||||
}
|
||||
|
||||
|
@ -71,3 +85,17 @@ int MoveSelector::evalForJokersInRack(const Round &iRound) const
|
|||
}
|
||||
|
||||
|
||||
int MoveSelector::evalForExtensions(const Round &iRound) const
|
||||
{
|
||||
// Find front and back extensions to the given round
|
||||
const wstring &roundWord = iRound.getWord();
|
||||
vector<wdstring> results;
|
||||
m_dic.searchRacc(roundWord, results);
|
||||
|
||||
// Give a bonus for each extension
|
||||
// TODO: it would be better to give a bonus only for extensions
|
||||
// corresponding to letters still in the bag...
|
||||
return results.size() * EXTENSION_1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,6 +25,8 @@
|
|||
|
||||
class Round;
|
||||
class BestResults;
|
||||
class Bag;
|
||||
class Dictionary;
|
||||
|
||||
|
||||
/**
|
||||
|
@ -37,6 +39,9 @@ class MoveSelector
|
|||
{
|
||||
DEFINE_LOGGER();
|
||||
public:
|
||||
|
||||
MoveSelector(const Bag &iBag, const Dictionary &iDic);
|
||||
|
||||
/**
|
||||
* Return a move to be used as "master move" in a duplicate game.
|
||||
* The method takes the given moves and tries to find the optimal move,
|
||||
|
@ -51,9 +56,12 @@ public:
|
|||
Round selectMaster(const BestResults &iResults) const;
|
||||
|
||||
private:
|
||||
const Bag &m_bag;
|
||||
const Dictionary &m_dic;
|
||||
|
||||
int evalScore(const Round &iRound) const;
|
||||
int evalForJokersInRack(const Round &iRound) const;
|
||||
int evalForExtensions(const Round &iRound) const;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -326,7 +326,7 @@ void MasterResults::search(const Dictionary &iDic, const Board &iBoard,
|
|||
return;
|
||||
|
||||
// Find the best round, according to the heuristics in MoveSelector
|
||||
MoveSelector selector;
|
||||
MoveSelector selector(m_bag, iDic);
|
||||
const Round &round = selector.selectMaster(m_bestResults);
|
||||
m_rounds.push_back(round);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue