@@ -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
6464template <std::size_t N>
6565Wordle<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()
145147template <std::size_t N>
146148std::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