import size from Config; import {asAFunction, iter, square} from Grid.Util; import {diagonal, zero} from Geometry.Vector; import * as CellSet from Geometry.CellSet; return { getCellSets: getCellSets, start: start }; function start(coloring) { var empty = Array.from({length: size}); return { constellation: square(size), getColor: asAFunction(coloring), missing: CellSet.rectangle(zero(), diagonal(size)), colorZones: getZones(coloring), rows: empty.map(function(_, i) {return CellSet.row(i);}), columns: empty.map(function(_, i) {return CellSet.column(i);}) }; } function getZones(grid) { var zones = Array.from({length: size}); iter(grid, function(color, cell) { if(zones[color] == undefined) { zones[color] = new CellSet.CellSet(); } zones[color].add(cell); }); return zones; } function getCellSets(solvingState) { return solvingState.colorZones .concat(solvingState.rows) .concat(solvingState.columns); }