Constellations/js/Solver/State.js

39 lines
948 B
JavaScript
Raw Permalink Normal View History

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);
}