Dead code removal service
This commit is contained in:
parent
ee3aa889b8
commit
d8cebb863f
1 changed files with 9 additions and 12 deletions
21
solver.cpp
21
solver.cpp
|
@ -15,7 +15,7 @@ bool Solver::all_are_consistent(vector<int> supposed_sequence) {
|
||||||
|
|
||||||
// Try all remaining sequences
|
// Try all remaining sequences
|
||||||
vector<int> Solver::brute_force(vector<vector<int>> *possibilities, vector<int> *chosen, int index) {
|
vector<int> Solver::brute_force(vector<vector<int>> *possibilities, vector<int> *chosen, int index) {
|
||||||
vector<int> r = vector<int>(N, -1);
|
vector<int> r(N, -1);
|
||||||
if(index == N) {
|
if(index == N) {
|
||||||
if(all_are_consistent(*chosen))
|
if(all_are_consistent(*chosen))
|
||||||
r = *chosen;
|
r = *chosen;
|
||||||
|
@ -38,6 +38,7 @@ int Solver::get_weight(vector<int> guess) {
|
||||||
// Get weight
|
// Get weight
|
||||||
for(auto hist : history) {
|
for(auto hist : history) {
|
||||||
// TODO get worst-case weight
|
// TODO get worst-case weight
|
||||||
|
// Possibly get how many sequences it eliminates
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -47,11 +48,13 @@ Weighed_guess Solver::minimax(vector<vector<int>> *possibilities, vector<int> *c
|
||||||
// If complete guess, get weight and return
|
// If complete guess, get weight and return
|
||||||
if(index == N)
|
if(index == N)
|
||||||
return {get_weight(*chosen), *chosen};
|
return {get_weight(*chosen), *chosen};
|
||||||
// Get max-weighted child
|
|
||||||
|
// Get max-weighted children
|
||||||
Weighed_guess r = {-2, {}};
|
Weighed_guess r = {-2, {}};
|
||||||
for(int col : (*possibilities)[index]) {
|
for(int col : (*possibilities)[index]) {
|
||||||
chosen->push_back(col);
|
chosen->push_back(col);
|
||||||
Weighed_guess r2 = minimax(possibilities, chosen, index+1);
|
auto r2 = minimax(possibilities, chosen, index+1);
|
||||||
|
|
||||||
if(r2.weight > r.weight || r.weight == -2)
|
if(r2.weight > r.weight || r.weight == -2)
|
||||||
r = r2;
|
r = r2;
|
||||||
chosen->pop_back();
|
chosen->pop_back();
|
||||||
|
@ -61,9 +64,10 @@ Weighed_guess Solver::minimax(vector<vector<int>> *possibilities, vector<int> *c
|
||||||
|
|
||||||
// Guessing
|
// Guessing
|
||||||
vector<int> Solver::guess() {
|
vector<int> Solver::guess() {
|
||||||
// TODO make it smart
|
|
||||||
auto possibilities = known.list_all_possibilities();
|
auto possibilities = known.list_all_possibilities();
|
||||||
auto chosen = vector<int>(0);
|
auto chosen = vector<int>(0);
|
||||||
|
|
||||||
|
// TODO make it smart
|
||||||
return brute_force(&possibilities, &chosen, 0);
|
return brute_force(&possibilities, &chosen, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,14 +125,6 @@ vector<bool> Solver::extract_info(Historic_guess hist) {
|
||||||
auto guess = cleaned.guess;
|
auto guess = cleaned.guess;
|
||||||
auto response = cleaned.response;
|
auto response = cleaned.response;
|
||||||
|
|
||||||
bool something = false;
|
|
||||||
for(int n = 0; n < N; n++)
|
|
||||||
if(guess[n] > -1)
|
|
||||||
something = true;
|
|
||||||
|
|
||||||
if(!something)
|
|
||||||
return {false, false};
|
|
||||||
|
|
||||||
// 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 < N; n++)
|
for(int n = 0; n < N; n++)
|
||||||
|
@ -195,6 +191,7 @@ void Solver::learn(vector<int> guess, Response response) {
|
||||||
// Learn from previous guesses
|
// Learn from previous guesses
|
||||||
for(int i = 0; i < history.size(); i++) {
|
for(int i = 0; i < history.size(); i++) {
|
||||||
auto info = extract_info(history[i]);
|
auto info = extract_info(history[i]);
|
||||||
|
|
||||||
if(!info[0]) {
|
if(!info[0]) {
|
||||||
// If there is nothing left to learn from the guess
|
// If there is nothing left to learn from the guess
|
||||||
history.erase(history.begin()+i);
|
history.erase(history.begin()+i);
|
||||||
|
|
Loading…
Reference in a new issue