diff options
author | John Fultz <jfultz@wolfram.com> | 2017-08-14 11:31:36 -0500 |
---|---|---|
committer | John Fultz <jfultz@wolfram.com> | 2017-08-14 11:31:36 -0500 |
commit | e23f1b73d77f5cc80ba9ef07d9877111b4ded349 (patch) | |
tree | 4d08a5966fb4dc640517379e494e2be8bf93f9ea /evaluator.cpp | |
parent | e985f7f07f91e172061c9c99bf68770c5e785d66 (diff) |
Fixes #50 and related non-English strategy issues.
Specifically...
* Bogowin was only being used for English-like dictionaries.
I suppose the bogowin numbers might change a bit from
dictionary to dictionary, but I think it's quite plausible that
the numbers are similar for all dictionaries.
* This fixes bogowin always returning 100 or 0.
* Make the strategy code more fine-grained, so that if it
has some strategy files and not others, it will use what it
has. JKB recommended a long time ago that I add a generic
worths file to give the blank a high worth, but it wasn't being
used because most languages didn't also have a syn2 or
a superleaves. Now it will. Also, the vowel-consonant
balance computations don't use any strategy files at all,
but they were also being skipped if you didn't have every
single strategy file. Oops.
* The strategy computations would sometimes do
unexpected things if the leaves weren't alphabetized.
They now look at the alphabetized version of the leave.
* A couple more conversions to ranged-for loops.
Diffstat (limited to 'evaluator.cpp')
-rw-r--r-- | evaluator.cpp | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/evaluator.cpp b/evaluator.cpp index 1a05fbc..faace6a 100644 --- a/evaluator.cpp +++ b/evaluator.cpp @@ -72,35 +72,33 @@ double ScorePlusLeaveEvaluator::sharedConsideration(const GamePosition &position double ScorePlusLeaveEvaluator::leaveValue(const LetterString &leave) const { - if (!QUACKLE_STRATEGY_PARAMETERS->isInitialized()) - return 0; - LetterString alphabetized = String::alphabetize(leave); - if (QUACKLE_STRATEGY_PARAMETERS->superleave(alphabetized)) + if (QUACKLE_STRATEGY_PARAMETERS->hasSuperleaves() && QUACKLE_STRATEGY_PARAMETERS->superleave(alphabetized)) return QUACKLE_STRATEGY_PARAMETERS->superleave(alphabetized); double value = 0; - double synergy = 0; - LetterString uniqleave; - - const LetterString::const_iterator leaveEnd(leave.end()); if (!leave.empty()) { - for (LetterString::const_iterator leaveIt = leave.begin(); leaveIt != leaveEnd; ++leaveIt) - value += QUACKLE_STRATEGY_PARAMETERS->tileWorth(*leaveIt); + double synergy = 0; + LetterString uniqleave; + + if (QUACKLE_STRATEGY_PARAMETERS->hasWorths()) + for (const auto& leaveIt : leave) + value += QUACKLE_STRATEGY_PARAMETERS->tileWorth(leaveIt); - for (unsigned int i = 0; i < leave.length() - 1; ++i) - if (leave[i] == leave[i + 1]) - value += QUACKLE_STRATEGY_PARAMETERS->syn2(leave[i], leave[i]); + if (QUACKLE_STRATEGY_PARAMETERS->hasSyn2()) + for (unsigned int i = 0; i < alphabetized.length() - 1; ++i) + if (alphabetized[i] == alphabetized[i + 1]) + value += QUACKLE_STRATEGY_PARAMETERS->syn2(alphabetized[i], alphabetized[i]); - uniqleave += leave[0]; - for (unsigned int i = 1; i < leave.length(); ++i) - if (uniqleave[uniqleave.length() - 1] != leave[i]) - uniqleave += leave[i]; + uniqleave += alphabetized[0]; + for (unsigned int i = 1; i < alphabetized.length(); ++i) + if (uniqleave[uniqleave.length() - 1] != alphabetized[i]) + uniqleave += alphabetized[i]; - if (uniqleave.length() >= 2) + if (uniqleave.length() >= 2 && QUACKLE_STRATEGY_PARAMETERS->hasSyn2()) { for (unsigned int i = 0; i < uniqleave.length() - 1; ++i) for (unsigned int j = i + 1; j < uniqleave.length(); ++j) @@ -126,11 +124,11 @@ double ScorePlusLeaveEvaluator::leaveValue(const LetterString &leave) const int vowels = 0; int cons = 0; - for (LetterString::const_iterator leaveIt = leave.begin(); leaveIt != leaveEnd; ++leaveIt) + for (const auto& leaveIt : leave) { - if (*leaveIt != QUACKLE_BLANK_MARK) + if (leaveIt != QUACKLE_BLANK_MARK) { - if (QUACKLE_ALPHABET_PARAMETERS->isVowel(*leaveIt)) + if (QUACKLE_ALPHABET_PARAMETERS->isVowel(leaveIt)) vowels++; else cons++; |