Skip to content

Commit a080041

Browse files
committed
better use of atLeast_ (yellow char)
1 parent e7a5cde commit a080041

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

resolver.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,19 @@ class Wordle {
5656
std::array<bool, 26> letters_;
5757
};
5858
std::array<Letters, N> word_;
59-
Letters atLeast_;
59+
std::array<Letters, N> atLeast_;
6060
std::vector<std::string> allowWord_;
6161
std::vector<std::string> allWord_;
6262
};
6363

6464
template <std::size_t N>
6565
Wordle<N>::Wordle(const std::string& allowPath, const std::string& allPath)
6666
: word_ {}
67-
, atLeast_ { false }
67+
, atLeast_ {}
6868
, allowWord_ { loadList(allowPath) }
6969
, allWord_ { loadList(allPath) }
7070
{
71+
atLeast_.fill(false);
7172
debug << "allowWord size: " << allowWord_.size() << '\n';
7273
}
7374

@@ -90,8 +91,9 @@ std::array<uint, 26> Wordle<N>::histogramLetter()
9091
res.fill(0);
9192
for (const auto& word : allowWord_) {
9293
Letters onlyOnce {};
93-
for (char c : word) {
94-
if (atLeast_.contains(c)) // TODO: rework at least in order to take into account position
94+
for (std::size_t i = 0; i < N; ++i) {
95+
char c = word[i];
96+
if (atLeast_[i].contains(c))
9597
continue;
9698
onlyOnce.unset(c);
9799
}
@@ -145,13 +147,13 @@ std::string Wordle<N>::discoverLetter()
145147
template <std::size_t N>
146148
std::pair<std::string, bool> Wordle<N>::nextWord()
147149
{
150+
if (allowWord_.size() == 1)
151+
return { allowWord_[0], true };
148152
if (allowWord_.size() < 10) {
149153
for (const auto& word : allowWord_) {
150154
debug << "maybe: " << word << '\n';
151155
}
152156
}
153-
if (allowWord_.size() == 1)
154-
return { allowWord_[0], true };
155157
return { discoverLetter(), false };
156158
}
157159

@@ -166,9 +168,9 @@ void Wordle<N>::validWord(const std::string& word, const std::string& input)
166168
}
167169
} else if (input[i] == 'y') {
168170
word_[i].unset(c);
169-
atLeast_.set(c);
171+
atLeast_[i].set(c);
170172
} else if (input[i] == 'g') {
171-
atLeast_.set(c);
173+
atLeast_[i].is(c);
172174
word_[i].is(c);
173175
} else {
174176
throw "invalid input";

0 commit comments

Comments
 (0)