UNPKG

@logic-pad/core

Version:
31 lines (30 loc) 998 B
import BTModule, { BTTile, colorToBTTile, } from '../data.js'; export default class CellCountBTModule extends BTModule { constructor(instr) { super(); Object.defineProperty(this, "instr", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.instr = instr; } checkGlobal(grid) { const color = colorToBTTile(this.instr.color); let colored = 0; let possible = 0; for (let y = 0; y < grid.height; y++) { for (let x = 0; x < grid.width; x++) { const tile = grid.getTile(x, y); if (tile === color) colored += 1; else if (tile === BTTile.Empty) possible += 1; } } if (colored > this.instr.count || colored + possible < this.instr.count) return false; return { tilesNeedCheck: null, ratings: null }; } }