UNPKG

@logic-pad/core

Version:
40 lines (39 loc) 1.09 kB
import { Color } from '../primitives.js'; import Rule from './rule.js'; export default class CellCountPerZoneRule extends Rule { color; get configExplanation() { return 'Use the zone tool to define areas on the grid.'; } /** * @param color - The color of the cells to count. */ constructor(color) { super(); this.color = color; this.color = color; } getZoneCounts(grid) { let complete = true; const zones = grid.reduceByZone((zone, tile, x, y) => { zone.positions.push({ x, y }); if (tile.color === this.color) { zone.completed++; } else if (tile.color === Color.Gray) { zone.possible++; complete = false; } return zone; }, () => ({ positions: [], completed: 0, possible: 0, })); return { zones, complete }; } withColor(color) { return this.copyWith({ color }); } } export const instance = undefined;