diff --git a/game/move_selector.cpp b/game/move_selector.cpp index 17e22c3..20a29f0 100644 --- a/game/move_selector.cpp +++ b/game/move_selector.cpp @@ -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 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; +} + + diff --git a/game/move_selector.h b/game/move_selector.h index 2ec957e..76a463c 100644 --- a/game/move_selector.h +++ b/game/move_selector.h @@ -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; }; diff --git a/game/results.cpp b/game/results.cpp index 4d0fb21..204f5de 100644 --- a/game/results.cpp +++ b/game/results.cpp @@ -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); }