UNPKG

@logic-pad/core

Version:
26 lines (25 loc) 834 B
import BTModule, { BTTile, colorToBTTile, } from '../data.js'; export default class CellCountBTModule extends BTModule { instr; constructor(instr) { super(); 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 }; } }