2022-09-01 21:51:48 +02:00
|
|
|
import set from Grid.Util;
|
2022-10-02 22:22:23 +02:00
|
|
|
import * as Hypothesis from Solver.Hypothesis;
|
2022-09-01 21:51:48 +02:00
|
|
|
import * as Inclusion from Solver.Inclusion;
|
|
|
|
import * as SingleCell from Solver.SingleCell;
|
|
|
|
import * as State from Solver.State;
|
|
|
|
import * as Strategy from Solver.Strategy;
|
2022-07-31 16:32:24 +02:00
|
|
|
|
|
|
|
return {
|
2022-09-01 21:51:48 +02:00
|
|
|
rate: rate,
|
|
|
|
solve: solve,
|
|
|
|
findNextStep: findNextStep
|
2022-07-31 16:32:24 +02:00
|
|
|
};
|
|
|
|
|
2022-09-01 21:51:48 +02:00
|
|
|
function solve(coloring) {
|
|
|
|
var solvingState = State.start(coloring);
|
|
|
|
var stuck = false;
|
|
|
|
while(!stuck && solvingState.missing.size() > 0) {
|
|
|
|
Strategy.execute(
|
|
|
|
findNextStep(solvingState),
|
|
|
|
applyStep(solvingState),
|
|
|
|
function() {console.log('Solver is stuck'); stuck = true;}
|
2022-07-31 16:32:24 +02:00
|
|
|
);
|
|
|
|
}
|
2022-09-01 21:51:48 +02:00
|
|
|
return solvingState.constellation;
|
2022-07-31 16:32:24 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 21:51:48 +02:00
|
|
|
function rate(coloring) {
|
2022-07-31 16:32:24 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 21:51:48 +02:00
|
|
|
function findNextStep(solvingState) {
|
|
|
|
return Strategy.tryEach([
|
|
|
|
Inclusion.find(solvingState),
|
2022-10-02 22:22:23 +02:00
|
|
|
SingleCell.find(solvingState),
|
|
|
|
Hypothesis.find(solvingState)
|
2022-09-01 21:51:48 +02:00
|
|
|
]);
|
2022-07-31 16:32:24 +02:00
|
|
|
}
|
|
|
|
|
2022-09-01 21:51:48 +02:00
|
|
|
function applyStep(solvingState) {
|
|
|
|
return function(step) {
|
|
|
|
console.log(step);
|
|
|
|
['empty', 'star'].forEach(function(attribute) {
|
|
|
|
if(step[attribute] != undefined) {
|
2022-10-23 23:13:49 +02:00
|
|
|
//step[attribute].iter(State.setCells(solvingState, attribute == 'star'));
|
|
|
|
State.setCells(solvingState, attribute == 'star', step[attribute]);
|
|
|
|
// ?? why is curryfication needed above ? State.setCells(solvingState, attribute == 'star', step[attribute]);
|
2022-07-31 16:32:24 +02:00
|
|
|
}
|
2022-09-01 21:51:48 +02:00
|
|
|
});
|
|
|
|
};
|
2022-07-31 16:32:24 +02:00
|
|
|
}
|