2022-09-01 21:51:48 +02:00
|
|
|
import size from Config;
|
|
|
|
import {asAFunction, iter, square} from Grid.Util;
|
|
|
|
import {diagonal, zero} from Geometry.Vector;
|
2022-08-30 22:39:09 +02:00
|
|
|
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);
|
|
|
|
}
|