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; import * as Strategy from Solver.Strategy; return { rate: rate, solve: solve, findNextStep: findNextStep }; 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;} ); } return solvingState.constellation; } function rate(coloring) { } function findNextStep(solvingState) { return Strategy.tryEach([ Inclusion.find(solvingState), SingleCell.find(solvingState), Hypothesis.find(solvingState) ]); } function applyStep(solvingState) { return function(step) { console.log(step); ['empty', 'star'].forEach(function(attribute) { if(step[attribute] != undefined) { //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]); } }); }; }