From e8d0db8b1da5a16fad2c990cd12d4eabc6f245f8 Mon Sep 17 00:00:00 2001 From: Tissevert Date: Sun, 2 Oct 2022 22:22:23 +0200 Subject: [PATCH] [WIP, BROKEN] Plug the stub for the Hypothesis solver to show how it'll be used --- js/Solver.js | 5 +++-- js/Solver/Hypothesis.js | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 js/Solver/Hypothesis.js diff --git a/js/Solver.js b/js/Solver.js index 2520121..d17bd44 100644 --- a/js/Solver.js +++ b/js/Solver.js @@ -1,5 +1,5 @@ -import * as CellSet from Geometry.CellSet; import set from Grid.Util; +import * as Hypothesis from Solver.Hypothesis; import * as Inclusion from Solver.Inclusion; import * as SingleCell from Solver.SingleCell; import * as State from Solver.State; @@ -30,7 +30,8 @@ function rate(coloring) { function findNextStep(solvingState) { return Strategy.tryEach([ Inclusion.find(solvingState), - SingleCell.find(solvingState) + SingleCell.find(solvingState), + Hypothesis.find(solvingState) ]); } diff --git a/js/Solver/Hypothesis.js b/js/Solver/Hypothesis.js new file mode 100644 index 0000000..3b696ae --- /dev/null +++ b/js/Solver/Hypothesis.js @@ -0,0 +1,21 @@ +import perimeter from Solver.SingleCell; +import * as State from Solver.State; + +return { + find: find +}; + +function find(solvingState) { + solvingState.missing.map(f(solvingState)) +}; + +function f(solvingState) { + return function(cell) { + var forked = State.fork(solvingState); + State.set(forked, cell, true); + } +} + +function checkContradiction(beforeState, afterState, cell) { + //TODO has one cellSet (color, row, column) become empty ? if it doesn't contain cell, it's a contradiction +}