2022-08-30 22:39:09 +02:00
|
|
|
import * as CellSet from Geometry.CellSet;
|
2022-08-19 08:19:50 +02:00
|
|
|
import * as Strategy from Solver.Strategy;
|
2022-10-23 23:13:49 +02:00
|
|
|
import * as State from Solver.State;
|
2022-08-30 22:39:09 +02:00
|
|
|
import {diagonal, getColumn, getRow, plus} from Geometry.Vector;
|
2022-08-19 08:19:50 +02:00
|
|
|
|
|
|
|
return {
|
2022-10-02 22:17:27 +02:00
|
|
|
find: find,
|
2022-10-23 23:13:49 +02:00
|
|
|
getRange: getRange
|
2022-08-19 08:19:50 +02:00
|
|
|
};
|
|
|
|
|
2022-08-30 22:39:09 +02:00
|
|
|
function find(solvingState) {
|
2022-10-23 23:13:49 +02:00
|
|
|
return Strategy.tryEach(
|
|
|
|
State.zoneNames(solvingState).map(function(name) {
|
|
|
|
return Strategy.map(
|
|
|
|
stepOfCell(solvingState, name),
|
|
|
|
Strategy.tryEach(solvingState.zones[name].map(getSingleCellIn))
|
|
|
|
);
|
|
|
|
})
|
2022-08-19 08:19:50 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
function getSingleCellIn(cellSet) {
|
|
|
|
return function() {
|
|
|
|
if(cellSet.size() == 1) {
|
2022-08-30 22:39:09 +02:00
|
|
|
return cellSet.toList()[0];
|
2022-08-19 08:19:50 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-23 23:13:49 +02:00
|
|
|
function stepOfCell(solvingState, name) {
|
2022-09-01 21:51:48 +02:00
|
|
|
return function(cell) {
|
|
|
|
return {
|
|
|
|
reason: 'singleCell',
|
2022-10-23 23:13:49 +02:00
|
|
|
set: name,
|
|
|
|
empty: getRange(solvingState, cell),
|
2022-09-01 21:51:48 +02:00
|
|
|
star: new CellSet.CellSet(cell)
|
|
|
|
};
|
2022-08-19 08:19:50 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2022-10-23 23:13:49 +02:00
|
|
|
function getRange(solvingState, cell) {
|
2022-08-30 22:39:09 +02:00
|
|
|
var union = CellSet.union([
|
2022-10-23 23:13:49 +02:00
|
|
|
solvingState.zones.colors[solvingState.getColor(cell)],
|
|
|
|
solvingState.zones.rows[getRow(cell)],
|
|
|
|
solvingState.zones.columns[getColumn(cell)],
|
|
|
|
CellSet.rectangle(plus(cell, diagonal(-1)), diagonal(3))
|
|
|
|
.intersection(solvingState.missing)
|
2022-08-19 08:19:50 +02:00
|
|
|
]);
|
2022-08-30 22:39:09 +02:00
|
|
|
union.remove(cell);
|
|
|
|
return union;
|
2022-08-19 08:19:50 +02:00
|
|
|
}
|