Move solving logic to a separate class

This commit is contained in:
Drew Galbraith 2023-05-03 23:56:29 -07:00
parent 3dc9f04650
commit dd89c1fd6c
4 changed files with 40 additions and 8 deletions

20
solver/solver.cpp Normal file
View file

@ -0,0 +1,20 @@
#include "solver.h"
#include <sstream>
Solver::Solver(std::string string) : puzzle_(Puzzle::FromString(string)) {}
bool Solver::Solve() {
while (puzzle_.ApplyNextStep()) {
}
return puzzle_.IsSolved();
}
std::string Solver::State() { return puzzle_.CurrentState(); }
std::string Solver::StateUrl() {
std::ostringstream stream;
stream << "https://tiramisu.one/sudoku.html?p=" << puzzle_.CurrentState()
<< "&m=" << puzzle_.PencilMarkState();
return stream.str();
}