Solver should remember, how long the sequence is

This commit is contained in:
Matúš Púll 2024-11-04 19:06:36 +01:00
parent 245324d9c3
commit 61d53d7700

View file

@ -3,11 +3,12 @@
class Solver {
Game known;
int N, M;
vector<Historic_guess> history = {};
vector<int> sequence;
public:
Solver(int p_N, int p_M) : known({p_N, p_M}) {
sequence = vector<int>(p_N, -1);
Solver(int p_N, int p_M) : N(p_N), M(p_M), known({p_N, p_M}) {
sequence = vector<int>(N, -1);
}
// Guessing
@ -22,7 +23,7 @@ public:
}
Historic_guess clean(Historic_guess hist) {
// 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]) {
hist.guess[n] = -1;
hist.response[1] -= 1;
@ -30,10 +31,10 @@ public:
}
// 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)
continue;
for(int i = 0; i < known.N; i++) {
for(int i = 0; i < N; i++) {
if(i == n)
continue;
if(known.final_color(i) == hist.guess[n]) {
@ -46,8 +47,8 @@ public:
return hist;
}
vector<vector<int>> get_positions_of_colors(vector<int> guess) {
auto positions_of_colors = vector<vector<int>>(known.M, vector<int>(0));
for(int n = 0; n < known.N; n++)
auto positions_of_colors = vector<vector<int>>(M, vector<int>(0));
for(int n = 0; n < N; n++)
if(guess[n] > -1)
positions_of_colors[guess[n]].push_back(n);
return positions_of_colors;
@ -58,7 +59,7 @@ public:
auto positions_of_colors = get_positions_of_colors(guess);
// 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;
for(int n : positions_of_colors[col])
if(known.can(n, col))
@ -68,12 +69,12 @@ public:
}
}
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]))
known.must_be(n, guess[n]);
}
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)
known.cannot_be(n, guess[n]);
}
@ -85,7 +86,7 @@ public:
void all_are_here(vector<int> 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())
known.empty_color(col);
}
@ -101,7 +102,7 @@ public:
// Get number of colors, that can be on their positions
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]))
possible_count++;
@ -134,7 +135,7 @@ public:
}
// All guessed colors are in the sequence
if(response[0] + response[1] == known.N)
if(response[0] + response[1] == N)
all_are_here(guess);
return something_to_learn;