1
Fork 0
This repository has been archived on 2025-04-09. You can view files and clone it, but cannot push or open issues or pull requests.
puzzle-wuzzle-generator/include/solver.hpp
2014-02-13 22:03:39 +01:00

35 lines
668 B
C++

#pragma once
#include "clusters.hpp"
#include <deque>
template <typename Field>
struct Solution {
std::deque<typename Field::Position> taps;
};
template <typename Field>
auto solve_impl(Field const & field, Solution<Field> & s){
for(auto&& p : field.all_positions()){
if(!field.empty(p)) goto analyse;
}
return true;
analyse:
for(auto&& c : all_clusters(field)){
if(c.size() < 3) continue;
auto new_field = make_empty(field, c);
if(solve_impl(new_field, s)) {
s.taps.push_front(*c.begin());
return true;
}
}
return false;
}
template <typename Field>
auto solve(Field const & field){
Solution<Field> s;
solve_impl(field, s);
return s;
}