Sort the training results using the dictionary order as alphabetical order

This commit is contained in:
Olivier Teulière 2009-07-03 23:00:12 +00:00
parent 08c9816d32
commit bb13f634b3
2 changed files with 15 additions and 14 deletions

View file

@ -32,9 +32,9 @@
#include "debug.h" #include "debug.h"
bool wcharCompare(wchar_t c1, wchar_t c2) bool tileCompare(const Tile &t1, const Tile &t2)
{ {
return towlower(c1) < towlower(c2); return t1.toCode() < t2.toCode();
} }
struct less_points : public binary_function<const Round&, const Round&, bool> struct less_points : public binary_function<const Round&, const Round&, bool>
@ -48,23 +48,23 @@ struct less_points : public binary_function<const Round&, const Round&, bool>
return false; return false;
else else
{ {
// If the scores are equal, sort alphabetically, ignoring // If the scores are equal, sort alphabetically (i.e. in the
// the case // order of the letters in the dictionary), ignoring the case
const wstring &s1 = r1.getWord(); const wstring &s1 = r1.getWord();
const wstring &s2 = r2.getWord(); const wstring &s2 = r2.getWord();
if (std::lexicographical_compare(s1.begin(), if (std::lexicographical_compare(r1.getTiles().begin(),
s1.end(), r1.getTiles().end(),
s2.begin(), r2.getTiles().begin(),
s2.end(), r2.getTiles().end(),
wcharCompare)) tileCompare))
{ {
return true;; return true;;
} }
else if (std::lexicographical_compare(s2.begin(), else if (std::lexicographical_compare(r2.getTiles().begin(),
s2.end(), r2.getTiles().end(),
s1.begin(), r1.getTiles().begin(),
s1.end(), r1.getTiles().end(),
wcharCompare)) tileCompare))
{ {
return false; return false;
} }

View file

@ -75,6 +75,7 @@ public:
unsigned int getWordLen() const { return m_word.size(); } unsigned int getWordLen() const { return m_word.size(); }
int getPoints() const { return m_points; } int getPoints() const { return m_points; }
int getBonus() const { return m_bonus; } int getBonus() const { return m_bonus; }
const vector<Tile> &getTiles() const { return m_word; }
/************************* /*************************
* Coordinates * Coordinates