logik/solver.hpp
2024-11-03 10:55:37 +01:00

85 lines
1.7 KiB
C++

#pragma once
#include <vector>
#include <iostream>
using std::vector;
using std::cout;
struct Game {
int N, M;
// Table of NxM saying which position can hold which color
vector<vector<bool>> possible;
// Searched sequence
vector<int> sequence;
Game(int p_N, int p_M) : N(p_N), M(p_M) {
possible = vector<vector<bool>>(N, vector<bool>(M, 1));
sequence = vector<int>(N, -1);
}
// Learning functions
void cannot_be(int n, int col) {
possible[n][col] = false;
}
void must_be(int must_n, int col) {
for(int n = 0; n < N; n++)
if(n != must_n)
possible[n][col] = 0;
}
void empty_color(int col) {
for(int n = 0; n < N; n++)
possible[n][col] = 0;
}
void print() {
cout << " ";
for(int col = 0; col < M; col++)
cout << col;
cout << std::endl;
for(int i = 0; i < N; i++) {
cout << i;
for(auto col : possible[i])
cout << col;
cout << std::endl;;
}
}
};
class Solver {
Game known;
vector<vector<int>> history = {};
public:
Solver(int p_N, int p_M) : known({p_N, p_M}) {}
vector<int> guess() {
// TODO
return {};
}
void learn_back(vector<int> guess) {
// TODO
}
void learn(vector<int> guess, vector<int> response) {
// Reduce color positions
if(response[0] == 0 && response[1] == 0) {
for(int col : guess)
known.empty_color(col);
}
else if(response[1] == 0) {;
for(int n = 0; n < known.N; n++)
known.cannot_be(n, guess[n]);
}
else if(response[0] == 0) {
// TODO if somewhere, then at least here
}
else {
// TODO nonzero / nonzero
}
// Learn from previous guesses
for(vector<int> past_guess : history)
learn_back(past_guess);
history.push_back(guess);
}
void print() {
known.print();
}
};