Move solving logic to a separate class
This commit is contained in:
parent
3dc9f04650
commit
dd89c1fd6c
4 changed files with 40 additions and 8 deletions
20
solver/solver.cpp
Normal file
20
solver/solver.cpp
Normal 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();
|
||||
}
|
||||
14
solver/solver.h
Normal file
14
solver/solver.h
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
#pragma once
|
||||
|
||||
#include "puzzle.h"
|
||||
|
||||
class Solver {
|
||||
public:
|
||||
Solver(std::string puzz_string);
|
||||
bool Solve();
|
||||
std::string State();
|
||||
std::string StateUrl();
|
||||
|
||||
private:
|
||||
Puzzle puzzle_;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue