Solver should remember, how long the sequence is
This commit is contained in:
parent
245324d9c3
commit
61d53d7700
1 changed files with 14 additions and 13 deletions
27
solver.hpp
27
solver.hpp
|
@ -3,11 +3,12 @@
|
||||||
|
|
||||||
class Solver {
|
class Solver {
|
||||||
Game known;
|
Game known;
|
||||||
|
int N, M;
|
||||||
vector<Historic_guess> history = {};
|
vector<Historic_guess> history = {};
|
||||||
vector<int> sequence;
|
vector<int> sequence;
|
||||||
public:
|
public:
|
||||||
Solver(int p_N, int p_M) : known({p_N, p_M}) {
|
Solver(int p_N, int p_M) : N(p_N), M(p_M), known({p_N, p_M}) {
|
||||||
sequence = vector<int>(p_N, -1);
|
sequence = vector<int>(N, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Guessing
|
// Guessing
|
||||||
|
@ -22,7 +23,7 @@ public:
|
||||||
}
|
}
|
||||||
Historic_guess clean(Historic_guess hist) {
|
Historic_guess clean(Historic_guess hist) {
|
||||||
// The in-place colors we know
|
// The in-place colors we know
|
||||||
for(int n = 0; n < known.N; n++) {
|
for(int n = 0; n < N; n++) {
|
||||||
if(known.final_color(n) == hist.guess[n]) {
|
if(known.final_color(n) == hist.guess[n]) {
|
||||||
hist.guess[n] = -1;
|
hist.guess[n] = -1;
|
||||||
hist.response[1] -= 1;
|
hist.response[1] -= 1;
|
||||||
|
@ -30,10 +31,10 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// The out-of-place colors we know
|
// The out-of-place colors we know
|
||||||
for(int n = 0; n < known.N; n++) {
|
for(int n = 0; n < N; n++) {
|
||||||
if(hist.guess[n] == -1)
|
if(hist.guess[n] == -1)
|
||||||
continue;
|
continue;
|
||||||
for(int i = 0; i < known.N; i++) {
|
for(int i = 0; i < N; i++) {
|
||||||
if(i == n)
|
if(i == n)
|
||||||
continue;
|
continue;
|
||||||
if(known.final_color(i) == hist.guess[n]) {
|
if(known.final_color(i) == hist.guess[n]) {
|
||||||
|
@ -46,8 +47,8 @@ public:
|
||||||
return hist;
|
return hist;
|
||||||
}
|
}
|
||||||
vector<vector<int>> get_positions_of_colors(vector<int> guess) {
|
vector<vector<int>> get_positions_of_colors(vector<int> guess) {
|
||||||
auto positions_of_colors = vector<vector<int>>(known.M, vector<int>(0));
|
auto positions_of_colors = vector<vector<int>>(M, vector<int>(0));
|
||||||
for(int n = 0; n < known.N; n++)
|
for(int n = 0; n < N; n++)
|
||||||
if(guess[n] > -1)
|
if(guess[n] > -1)
|
||||||
positions_of_colors[guess[n]].push_back(n);
|
positions_of_colors[guess[n]].push_back(n);
|
||||||
return positions_of_colors;
|
return positions_of_colors;
|
||||||
|
@ -58,7 +59,7 @@ public:
|
||||||
auto positions_of_colors = get_positions_of_colors(guess);
|
auto positions_of_colors = get_positions_of_colors(guess);
|
||||||
|
|
||||||
// If color isn't here, it can't be in the sequence
|
// If color isn't here, it can't be in the sequence
|
||||||
for(int col = 0; col < known.M; col++) {
|
for(int col = 0; col < M; col++) {
|
||||||
int possible_count = 0;
|
int possible_count = 0;
|
||||||
for(int n : positions_of_colors[col])
|
for(int n : positions_of_colors[col])
|
||||||
if(known.can(n, col))
|
if(known.can(n, col))
|
||||||
|
@ -68,12 +69,12 @@ public:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void here(vector<int> guess) {
|
void here(vector<int> guess) {
|
||||||
for(int n = 0; n < known.N; n++)
|
for(int n = 0; n < N; n++)
|
||||||
if(guess[n] > -1 && known.can(n, guess[n]))
|
if(guess[n] > -1 && known.can(n, guess[n]))
|
||||||
known.must_be(n, guess[n]);
|
known.must_be(n, guess[n]);
|
||||||
}
|
}
|
||||||
void not_here(vector<int> guess) {
|
void not_here(vector<int> guess) {
|
||||||
for(int n = 0; n < known.N; n++)
|
for(int n = 0; n < N; n++)
|
||||||
if(guess[n] > -1)
|
if(guess[n] > -1)
|
||||||
known.cannot_be(n, guess[n]);
|
known.cannot_be(n, guess[n]);
|
||||||
}
|
}
|
||||||
|
@ -85,7 +86,7 @@ public:
|
||||||
void all_are_here(vector<int> guess) {
|
void all_are_here(vector<int> guess) {
|
||||||
auto positions_of_colors = get_positions_of_colors(guess);
|
auto positions_of_colors = get_positions_of_colors(guess);
|
||||||
|
|
||||||
for(int col = 0; col < known.M; col++) {
|
for(int col = 0; col < M; col++) {
|
||||||
if(!positions_of_colors[col].size())
|
if(!positions_of_colors[col].size())
|
||||||
known.empty_color(col);
|
known.empty_color(col);
|
||||||
}
|
}
|
||||||
|
@ -101,7 +102,7 @@ public:
|
||||||
|
|
||||||
// Get number of colors, that can be on their positions
|
// Get number of colors, that can be on their positions
|
||||||
int possible_count = 0;
|
int possible_count = 0;
|
||||||
for(int n = 0; n < known.N; n++)
|
for(int n = 0; n < N; n++)
|
||||||
if(guess[n] > -1 && known.can(n, guess[n]))
|
if(guess[n] > -1 && known.can(n, guess[n]))
|
||||||
possible_count++;
|
possible_count++;
|
||||||
|
|
||||||
|
@ -134,7 +135,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
// All guessed colors are in the sequence
|
// All guessed colors are in the sequence
|
||||||
if(response[0] + response[1] == known.N)
|
if(response[0] + response[1] == N)
|
||||||
all_are_here(guess);
|
all_are_here(guess);
|
||||||
|
|
||||||
return something_to_learn;
|
return something_to_learn;
|
||||||
|
|
Loading…
Reference in a new issue