UNPKG

@logic-pad/core

Version:
132 lines (131 loc) 3.79 kB
import { ConfigType } from '../config.js'; import GridData from '../grid.js'; import { State, Mode } from '../primitives.js'; import CustomIconSymbol from '../symbols/customIconSymbol.js'; import Rule from './rule.js'; class ForesightRule extends Rule { /** * **Foresight: Show hints** */ constructor(count, regenInterval, startFull, solvePath = []) { super(); Object.defineProperty(this, "count", { enumerable: true, configurable: true, writable: true, value: count }); Object.defineProperty(this, "regenInterval", { enumerable: true, configurable: true, writable: true, value: regenInterval }); Object.defineProperty(this, "startFull", { enumerable: true, configurable: true, writable: true, value: startFull }); Object.defineProperty(this, "solvePath", { enumerable: true, configurable: true, writable: true, value: solvePath }); this.count = count; this.regenInterval = regenInterval; this.startFull = startFull; this.solvePath = solvePath; } get id() { return `foresight`; } get explanation() { return `*Foresight:* Show hints`; } get visibleWhenSolving() { return false; } get configs() { return ForesightRule.CONFIGS; } createExampleGrid() { return ForesightRule.EXAMPLE_GRID; } get searchVariants() { return ForesightRule.SEARCH_VARIANTS; } validateGrid(_grid) { return { state: State.Incomplete }; } get necessaryForCompletion() { return false; } get isSingleton() { return true; } modeVariant(mode) { // foresight is disabled in perfection mode if (mode === Mode.Perfection) { return null; } return this; } copyWith({ count, regenInterval, startFull, solvePath, }) { return new ForesightRule(count ?? this.count, regenInterval ?? this.regenInterval, startFull ?? this.startFull, solvePath ?? this.solvePath); } } Object.defineProperty(ForesightRule, "EXAMPLE_GRID", { enumerable: true, configurable: true, writable: true, value: Object.freeze(GridData.create(['.']).addSymbol(new CustomIconSymbol('', GridData.create([]), 0, 0, 'MdRemoveRedEye'))) }); Object.defineProperty(ForesightRule, "CONFIGS", { enumerable: true, configurable: true, writable: true, value: Object.freeze([ { type: ConfigType.Number, default: 5, min: 1, field: 'count', description: 'Foresight count', configurable: true, }, { type: ConfigType.Number, default: 30, min: 1, field: 'regenInterval', description: 'Regen Interval (seconds)', configurable: true, }, { type: ConfigType.Boolean, default: false, field: 'startFull', description: 'Start with full foresight', configurable: true, }, { type: ConfigType.SolvePath, default: [], field: 'solvePath', description: 'Intended solve path', configurable: true, }, ]) }); Object.defineProperty(ForesightRule, "SEARCH_VARIANTS", { enumerable: true, configurable: true, writable: true, value: [ new ForesightRule(5, 30, false).searchVariant(), ] }); export default ForesightRule; export const instance = new ForesightRule(5, 30, false);