@logic-pad/core 0.15.3 → 0.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1540,28 +1540,23 @@ declare global {
1540
1540
  copyWith({ pattern }: { pattern?: GridData }): this;
1541
1541
  withPattern(pattern: GridData): this;
1542
1542
  }
1543
- export declare class CellCountPerZoneRule extends Rule {
1543
+ export interface Zone {
1544
+ positions: Position$1[];
1545
+ completed: number;
1546
+ possible: number;
1547
+ }
1548
+ export type ZoneCounts = {
1549
+ zones: Zone[];
1550
+ complete: boolean;
1551
+ };
1552
+ export declare abstract class CellCountPerZoneRule extends Rule {
1544
1553
  readonly color: Color;
1545
- readonly title = 'Equal Count Per Zone';
1546
1554
  get configExplanation(): string;
1547
- private static readonly CONFIGS;
1548
- private static readonly EXAMPLE_GRID_LIGHT;
1549
- private static readonly EXAMPLE_GRID_DARK;
1550
- private static readonly EXAMPLE_GRID_GRAY;
1551
- private static readonly SEARCH_VARIANTS;
1552
1555
  /**
1553
- * **Zones of the same size have the same number of <color> cells.**
1554
- *
1555
1556
  * @param color - The color of the cells to count.
1556
1557
  */
1557
1558
  constructor(color: Color);
1558
- get id(): string;
1559
- get explanation(): string;
1560
- get configs(): readonly AnyConfig[] | null;
1561
- createExampleGrid(): GridData;
1562
- get searchVariants(): SearchVariant[];
1563
- validateGrid(grid: GridData): RuleState;
1564
- copyWith({ color }: { color?: Color }): this;
1559
+ protected getZoneCounts(grid: GridData): ZoneCounts;
1565
1560
  withColor(color: Color): this;
1566
1561
  }
1567
1562
  export declare class CellCountRule extends Rule {
@@ -1684,6 +1679,28 @@ declare global {
1684
1679
  }): this;
1685
1680
  get validateWithSolution(): boolean;
1686
1681
  }
1682
+ export declare class DifferentCountPerZoneRule extends CellCountPerZoneRule {
1683
+ readonly color: Color;
1684
+ readonly title = 'Different Count Per Zone';
1685
+ private static readonly CONFIGS;
1686
+ private static readonly EXAMPLE_GRID_LIGHT;
1687
+ private static readonly EXAMPLE_GRID_DARK;
1688
+ private static readonly EXAMPLE_GRID_GRAY;
1689
+ private static readonly SEARCH_VARIANTS;
1690
+ /**
1691
+ * **Zones of the same size have different numbers of <color> cells.**
1692
+ *
1693
+ * @param color - The color of the cells to count.
1694
+ */
1695
+ constructor(color: Color);
1696
+ get id(): string;
1697
+ get explanation(): string;
1698
+ get configs(): readonly AnyConfig[] | null;
1699
+ createExampleGrid(): GridData;
1700
+ get searchVariants(): SearchVariant[];
1701
+ validateGrid(grid: GridData): RuleState;
1702
+ copyWith({ color }: { color?: Color }): this;
1703
+ }
1687
1704
  export declare class ForesightRule extends Rule {
1688
1705
  readonly count: number;
1689
1706
  readonly regenInterval: number;
@@ -1905,6 +1922,28 @@ declare global {
1905
1922
  withColor(color: Color): this;
1906
1923
  withSize(size: number): this;
1907
1924
  }
1925
+ export declare class SameCountPerZoneRule extends CellCountPerZoneRule {
1926
+ readonly color: Color;
1927
+ readonly title = 'Equal Count Per Zone';
1928
+ private static readonly CONFIGS;
1929
+ private static readonly EXAMPLE_GRID_LIGHT;
1930
+ private static readonly EXAMPLE_GRID_DARK;
1931
+ private static readonly EXAMPLE_GRID_GRAY;
1932
+ private static readonly SEARCH_VARIANTS;
1933
+ /**
1934
+ * **Zones of the same size have the same number of <color> cells.**
1935
+ *
1936
+ * @param color - The color of the cells to count.
1937
+ */
1938
+ constructor(color: Color);
1939
+ get id(): string;
1940
+ get explanation(): string;
1941
+ get configs(): readonly AnyConfig[] | null;
1942
+ createExampleGrid(): GridData;
1943
+ get searchVariants(): SearchVariant[];
1944
+ validateGrid(grid: GridData): RuleState;
1945
+ copyWith({ color }: { color?: Color }): this;
1946
+ }
1908
1947
  export declare class SameShapeRule extends RegionShapeRule {
1909
1948
  readonly title = 'Same Shape Areas';
1910
1949
  private static readonly CONFIGS;
@@ -1,31 +1,23 @@
1
- import { AnyConfig } from '../config.js';
2
1
  import GridData from '../grid.js';
3
- import { Color, RuleState } from '../primitives.js';
4
- import Rule, { SearchVariant } from './rule.js';
5
- export default class CellCountPerZoneRule extends Rule {
2
+ import { Color, Position } from '../primitives.js';
3
+ import Rule from './rule.js';
4
+ export interface Zone {
5
+ positions: Position[];
6
+ completed: number;
7
+ possible: number;
8
+ }
9
+ export type ZoneCounts = {
10
+ zones: Zone[];
11
+ complete: boolean;
12
+ };
13
+ export default abstract class CellCountPerZoneRule extends Rule {
6
14
  readonly color: Color;
7
- readonly title = "Equal Count Per Zone";
8
15
  get configExplanation(): string;
9
- private static readonly CONFIGS;
10
- private static readonly EXAMPLE_GRID_LIGHT;
11
- private static readonly EXAMPLE_GRID_DARK;
12
- private static readonly EXAMPLE_GRID_GRAY;
13
- private static readonly SEARCH_VARIANTS;
14
16
  /**
15
- * **Zones of the same size have the same number of <color> cells.**
16
- *
17
17
  * @param color - The color of the cells to count.
18
18
  */
19
19
  constructor(color: Color);
20
- get id(): string;
21
- get explanation(): string;
22
- get configs(): readonly AnyConfig[] | null;
23
- createExampleGrid(): GridData;
24
- get searchVariants(): SearchVariant[];
25
- validateGrid(grid: GridData): RuleState;
26
- copyWith({ color }: {
27
- color?: Color;
28
- }): this;
20
+ protected getZoneCounts(grid: GridData): ZoneCounts;
29
21
  withColor(color: Color): this;
30
22
  }
31
- export declare const instance: CellCountPerZoneRule;
23
+ export declare const instance: undefined;
@@ -1,16 +1,12 @@
1
- import { ConfigType } from '../config.js';
2
1
  import { array } from '../dataHelper.js';
3
- import GridData, { NEIGHBOR_OFFSETS } from '../grid.js';
4
- import GridZones from '../gridZones.js';
5
- import { Color, State } from '../primitives.js';
2
+ import { NEIGHBOR_OFFSETS } from '../grid.js';
3
+ import { Color } from '../primitives.js';
6
4
  import Rule from './rule.js';
7
- class CellCountPerZoneRule extends Rule {
5
+ export default class CellCountPerZoneRule extends Rule {
8
6
  get configExplanation() {
9
7
  return 'Use the zone tool to define areas on the grid.';
10
8
  }
11
9
  /**
12
- * **Zones of the same size have the same number of <color> cells.**
13
- *
14
10
  * @param color - The color of the cells to count.
15
11
  */
16
12
  constructor(color) {
@@ -21,38 +17,9 @@ class CellCountPerZoneRule extends Rule {
21
17
  writable: true,
22
18
  value: color
23
19
  });
24
- Object.defineProperty(this, "title", {
25
- enumerable: true,
26
- configurable: true,
27
- writable: true,
28
- value: 'Equal Count Per Zone'
29
- });
30
20
  this.color = color;
31
21
  }
32
- get id() {
33
- return `zone_cell_count`;
34
- }
35
- get explanation() {
36
- return `Zones of the same size have the same number of ${this.color} cells`;
37
- }
38
- get configs() {
39
- return CellCountPerZoneRule.CONFIGS;
40
- }
41
- createExampleGrid() {
42
- if (this.color === Color.Light) {
43
- return CellCountPerZoneRule.EXAMPLE_GRID_LIGHT;
44
- }
45
- else if (this.color === Color.Dark) {
46
- return CellCountPerZoneRule.EXAMPLE_GRID_DARK;
47
- }
48
- else {
49
- return CellCountPerZoneRule.EXAMPLE_GRID_GRAY;
50
- }
51
- }
52
- get searchVariants() {
53
- return CellCountPerZoneRule.SEARCH_VARIANTS;
54
- }
55
- validateGrid(grid) {
22
+ getZoneCounts(grid) {
56
23
  let complete = true;
57
24
  const visited = array(grid.width, grid.height, (i, j) => !grid.getTile(i, j).exists);
58
25
  const zones = [];
@@ -97,85 +64,10 @@ class CellCountPerZoneRule extends Rule {
97
64
  }
98
65
  zones.push(zone);
99
66
  }
100
- if (zones.length <= 1) {
101
- return { state: complete ? State.Satisfied : State.Incomplete };
102
- }
103
- else {
104
- const errorZone = zones.find(z => zones.some(zz => zz !== z &&
105
- zz.positions.length === z.positions.length &&
106
- (zz.completed > z.completed + z.possible ||
107
- zz.completed + zz.possible < z.completed)));
108
- if (errorZone) {
109
- return {
110
- state: State.Error,
111
- positions: errorZone.positions,
112
- };
113
- }
114
- else {
115
- return { state: complete ? State.Satisfied : State.Incomplete };
116
- }
117
- }
118
- }
119
- copyWith({ color }) {
120
- return new CellCountPerZoneRule(color ?? this.color);
67
+ return { zones, complete };
121
68
  }
122
69
  withColor(color) {
123
70
  return this.copyWith({ color });
124
71
  }
125
72
  }
126
- Object.defineProperty(CellCountPerZoneRule, "CONFIGS", {
127
- enumerable: true,
128
- configurable: true,
129
- writable: true,
130
- value: Object.freeze([
131
- {
132
- type: ConfigType.Color,
133
- default: Color.Light,
134
- allowGray: true,
135
- field: 'color',
136
- description: 'Color',
137
- configurable: true,
138
- },
139
- ])
140
- });
141
- Object.defineProperty(CellCountPerZoneRule, "EXAMPLE_GRID_LIGHT", {
142
- enumerable: true,
143
- configurable: true,
144
- writable: true,
145
- value: Object.freeze(GridData.create(['bwbbb', 'wbbwb', 'bbbwb', 'bwbwb'])
146
- .withZones(new GridZones([
147
- { x1: 0, y1: 1, x2: 0, y2: 2 },
148
- { x1: 1, y1: 1, x2: 1, y2: 2 },
149
- { x1: 2, y1: 1, x2: 2, y2: 2 },
150
- { x1: 3, y1: 1, x2: 3, y2: 2 },
151
- { x1: 4, y1: 1, x2: 4, y2: 2 },
152
- { x1: 1, y1: 0, x2: 2, y2: 0 },
153
- { x1: 1, y1: 1, x2: 2, y2: 1 },
154
- { x1: 2, y1: 2, x2: 3, y2: 2 },
155
- { x1: 2, y1: 3, x2: 3, y2: 3 },
156
- ]))
157
- .addRule(new CellCountPerZoneRule(Color.Light)))
158
- });
159
- Object.defineProperty(CellCountPerZoneRule, "EXAMPLE_GRID_DARK", {
160
- enumerable: true,
161
- configurable: true,
162
- writable: true,
163
- value: Object.freeze(CellCountPerZoneRule.EXAMPLE_GRID_LIGHT.withTiles(tiles => tiles.map(row => row.map(tile => tile.withColor(tile.color === Color.Dark ? Color.Light : Color.Dark)))))
164
- });
165
- Object.defineProperty(CellCountPerZoneRule, "EXAMPLE_GRID_GRAY", {
166
- enumerable: true,
167
- configurable: true,
168
- writable: true,
169
- value: Object.freeze(CellCountPerZoneRule.EXAMPLE_GRID_LIGHT.withTiles(tiles => tiles.map(row => row.map(tile => tile.withColor(tile.color === Color.Light ? Color.Gray : tile.color)))))
170
- });
171
- Object.defineProperty(CellCountPerZoneRule, "SEARCH_VARIANTS", {
172
- enumerable: true,
173
- configurable: true,
174
- writable: true,
175
- value: [
176
- new CellCountPerZoneRule(Color.Light).searchVariant(),
177
- new CellCountPerZoneRule(Color.Dark).searchVariant(),
178
- ]
179
- });
180
- export default CellCountPerZoneRule;
181
- export const instance = new CellCountPerZoneRule(Color.Light);
73
+ export const instance = undefined;
@@ -0,0 +1,30 @@
1
+ import { AnyConfig } from '../config.js';
2
+ import GridData from '../grid.js';
3
+ import { Color, RuleState } from '../primitives.js';
4
+ import CellCountPerZoneRule from './cellCountPerZoneRule.js';
5
+ import { SearchVariant } from './rule.js';
6
+ export default class DifferentCountPerZoneRule extends CellCountPerZoneRule {
7
+ readonly color: Color;
8
+ readonly title = "Different Count Per Zone";
9
+ private static readonly CONFIGS;
10
+ private static readonly EXAMPLE_GRID_LIGHT;
11
+ private static readonly EXAMPLE_GRID_DARK;
12
+ private static readonly EXAMPLE_GRID_GRAY;
13
+ private static readonly SEARCH_VARIANTS;
14
+ /**
15
+ * **Zones of the same size have different numbers of &lt;color&gt; cells.**
16
+ *
17
+ * @param color - The color of the cells to count.
18
+ */
19
+ constructor(color: Color);
20
+ get id(): string;
21
+ get explanation(): string;
22
+ get configs(): readonly AnyConfig[] | null;
23
+ createExampleGrid(): GridData;
24
+ get searchVariants(): SearchVariant[];
25
+ validateGrid(grid: GridData): RuleState;
26
+ copyWith({ color }: {
27
+ color?: Color;
28
+ }): this;
29
+ }
30
+ export declare const instance: DifferentCountPerZoneRule;
@@ -0,0 +1,131 @@
1
+ import { ConfigType } from '../config.js';
2
+ import GridData from '../grid.js';
3
+ import GridZones from '../gridZones.js';
4
+ import { Color, State } from '../primitives.js';
5
+ import CellCountPerZoneRule from './cellCountPerZoneRule.js';
6
+ class DifferentCountPerZoneRule extends CellCountPerZoneRule {
7
+ /**
8
+ * **Zones of the same size have different numbers of &lt;color&gt; cells.**
9
+ *
10
+ * @param color - The color of the cells to count.
11
+ */
12
+ constructor(color) {
13
+ super(color);
14
+ Object.defineProperty(this, "color", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: color
19
+ });
20
+ Object.defineProperty(this, "title", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: 'Different Count Per Zone'
25
+ });
26
+ }
27
+ get id() {
28
+ return `zone_diff_count`;
29
+ }
30
+ get explanation() {
31
+ return `Zones of the same size have different numbers of ${this.color} cells`;
32
+ }
33
+ get configs() {
34
+ return DifferentCountPerZoneRule.CONFIGS;
35
+ }
36
+ createExampleGrid() {
37
+ if (this.color === Color.Light) {
38
+ return DifferentCountPerZoneRule.EXAMPLE_GRID_LIGHT;
39
+ }
40
+ else if (this.color === Color.Dark) {
41
+ return DifferentCountPerZoneRule.EXAMPLE_GRID_DARK;
42
+ }
43
+ else {
44
+ return DifferentCountPerZoneRule.EXAMPLE_GRID_GRAY;
45
+ }
46
+ }
47
+ get searchVariants() {
48
+ return DifferentCountPerZoneRule.SEARCH_VARIANTS;
49
+ }
50
+ validateGrid(grid) {
51
+ const { zones, complete } = this.getZoneCounts(grid);
52
+ if (zones.length <= 1) {
53
+ return { state: complete ? State.Satisfied : State.Incomplete };
54
+ }
55
+ else {
56
+ const errorZone = zones.find(z => zones.some(zz => zz !== z &&
57
+ zz.positions.length === z.positions.length &&
58
+ zz.possible === 0 &&
59
+ z.possible === 0 &&
60
+ zz.completed === z.completed));
61
+ if (errorZone) {
62
+ return {
63
+ state: State.Error,
64
+ positions: errorZone.positions,
65
+ };
66
+ }
67
+ else {
68
+ return { state: complete ? State.Satisfied : State.Incomplete };
69
+ }
70
+ }
71
+ }
72
+ copyWith({ color }) {
73
+ return new DifferentCountPerZoneRule(color ?? this.color);
74
+ }
75
+ }
76
+ Object.defineProperty(DifferentCountPerZoneRule, "CONFIGS", {
77
+ enumerable: true,
78
+ configurable: true,
79
+ writable: true,
80
+ value: Object.freeze([
81
+ {
82
+ type: ConfigType.Color,
83
+ default: Color.Light,
84
+ allowGray: true,
85
+ field: 'color',
86
+ description: 'Color',
87
+ configurable: true,
88
+ },
89
+ ])
90
+ });
91
+ Object.defineProperty(DifferentCountPerZoneRule, "EXAMPLE_GRID_LIGHT", {
92
+ enumerable: true,
93
+ configurable: true,
94
+ writable: true,
95
+ value: Object.freeze(GridData.create(['wwbbw', 'wbbwb', 'bbbwb', 'bwbwb'])
96
+ .withZones(new GridZones([
97
+ { x1: 0, y1: 1, x2: 0, y2: 2 },
98
+ { x1: 1, y1: 1, x2: 1, y2: 2 },
99
+ { x1: 2, y1: 1, x2: 2, y2: 2 },
100
+ { x1: 3, y1: 1, x2: 3, y2: 2 },
101
+ { x1: 4, y1: 1, x2: 4, y2: 2 },
102
+ { x1: 1, y1: 0, x2: 2, y2: 0 },
103
+ { x1: 1, y1: 1, x2: 2, y2: 1 },
104
+ { x1: 2, y1: 2, x2: 3, y2: 2 },
105
+ { x1: 2, y1: 3, x2: 3, y2: 3 },
106
+ ]))
107
+ .addRule(new DifferentCountPerZoneRule(Color.Light)))
108
+ });
109
+ Object.defineProperty(DifferentCountPerZoneRule, "EXAMPLE_GRID_DARK", {
110
+ enumerable: true,
111
+ configurable: true,
112
+ writable: true,
113
+ value: Object.freeze(DifferentCountPerZoneRule.EXAMPLE_GRID_LIGHT.withTiles(tiles => tiles.map(row => row.map(tile => tile.withColor(tile.color === Color.Dark ? Color.Light : Color.Dark)))))
114
+ });
115
+ Object.defineProperty(DifferentCountPerZoneRule, "EXAMPLE_GRID_GRAY", {
116
+ enumerable: true,
117
+ configurable: true,
118
+ writable: true,
119
+ value: Object.freeze(DifferentCountPerZoneRule.EXAMPLE_GRID_LIGHT.withTiles(tiles => tiles.map(row => row.map(tile => tile.withColor(tile.color === Color.Light ? Color.Gray : tile.color)))))
120
+ });
121
+ Object.defineProperty(DifferentCountPerZoneRule, "SEARCH_VARIANTS", {
122
+ enumerable: true,
123
+ configurable: true,
124
+ writable: true,
125
+ value: [
126
+ new DifferentCountPerZoneRule(Color.Light).searchVariant(),
127
+ new DifferentCountPerZoneRule(Color.Dark).searchVariant(),
128
+ ]
129
+ });
130
+ export default DifferentCountPerZoneRule;
131
+ export const instance = new DifferentCountPerZoneRule(Color.Light);
@@ -1,10 +1,10 @@
1
1
  export { instance as BanPatternRule } from './banPatternRule.js';
2
- export { instance as CellCountPerZoneRule } from './cellCountPerZoneRule.js';
3
2
  export { instance as CellCountRule } from './cellCountRule.js';
4
3
  export { instance as CompletePatternRule } from './completePatternRule.js';
5
4
  export { instance as ConnectAllRule } from './connectAllRule.js';
6
5
  export { instance as ContainsShapeRule } from './containsShapeRule.js';
7
6
  export { instance as CustomRule } from './customRule.js';
7
+ export { instance as DifferentCountPerZoneRule } from './differentCountPerZoneRule.js';
8
8
  export { instance as ForesightRule } from './foresightRule.js';
9
9
  export { instance as LyingSymbolRule } from './lyingSymbolRule.js';
10
10
  export { instance as MusicGridRule } from './musicGridRule.js';
@@ -12,6 +12,7 @@ export { instance as MysteryRule } from './mysteryRule.js';
12
12
  export { instance as OffByXRule } from './offByXRule.js';
13
13
  export { instance as PerfectionRule } from './perfectionRule.js';
14
14
  export { instance as RegionAreaRule } from './regionAreaRule.js';
15
+ export { instance as SameCountPerZoneRule } from './sameCountPerZoneRule.js';
15
16
  export { instance as SameShapeRule } from './sameShapeRule.js';
16
17
  export { instance as SymbolsPerRegionRule } from './symbolsPerRegionRule.js';
17
18
  export { instance as UndercluedRule } from './undercluedRule.js';
@@ -3,12 +3,12 @@
3
3
  // @ts-nocheck
4
4
  // noinspection JSUnusedGlobalSymbols
5
5
  export { instance as BanPatternRule } from './banPatternRule.js';
6
- export { instance as CellCountPerZoneRule } from './cellCountPerZoneRule.js';
7
6
  export { instance as CellCountRule } from './cellCountRule.js';
8
7
  export { instance as CompletePatternRule } from './completePatternRule.js';
9
8
  export { instance as ConnectAllRule } from './connectAllRule.js';
10
9
  export { instance as ContainsShapeRule } from './containsShapeRule.js';
11
10
  export { instance as CustomRule } from './customRule.js';
11
+ export { instance as DifferentCountPerZoneRule } from './differentCountPerZoneRule.js';
12
12
  export { instance as ForesightRule } from './foresightRule.js';
13
13
  export { instance as LyingSymbolRule } from './lyingSymbolRule.js';
14
14
  export { instance as MusicGridRule } from './musicGridRule.js';
@@ -16,6 +16,7 @@ export { instance as MysteryRule } from './mysteryRule.js';
16
16
  export { instance as OffByXRule } from './offByXRule.js';
17
17
  export { instance as PerfectionRule } from './perfectionRule.js';
18
18
  export { instance as RegionAreaRule } from './regionAreaRule.js';
19
+ export { instance as SameCountPerZoneRule } from './sameCountPerZoneRule.js';
19
20
  export { instance as SameShapeRule } from './sameShapeRule.js';
20
21
  export { instance as SymbolsPerRegionRule } from './symbolsPerRegionRule.js';
21
22
  export { instance as UndercluedRule } from './undercluedRule.js';
@@ -0,0 +1,30 @@
1
+ import { AnyConfig } from '../config.js';
2
+ import GridData from '../grid.js';
3
+ import { Color, RuleState } from '../primitives.js';
4
+ import CellCountPerZoneRule from './cellCountPerZoneRule.js';
5
+ import { SearchVariant } from './rule.js';
6
+ export default class SameCountPerZoneRule extends CellCountPerZoneRule {
7
+ readonly color: Color;
8
+ readonly title = "Equal Count Per Zone";
9
+ private static readonly CONFIGS;
10
+ private static readonly EXAMPLE_GRID_LIGHT;
11
+ private static readonly EXAMPLE_GRID_DARK;
12
+ private static readonly EXAMPLE_GRID_GRAY;
13
+ private static readonly SEARCH_VARIANTS;
14
+ /**
15
+ * **Zones of the same size have the same number of &lt;color&gt; cells.**
16
+ *
17
+ * @param color - The color of the cells to count.
18
+ */
19
+ constructor(color: Color);
20
+ get id(): string;
21
+ get explanation(): string;
22
+ get configs(): readonly AnyConfig[] | null;
23
+ createExampleGrid(): GridData;
24
+ get searchVariants(): SearchVariant[];
25
+ validateGrid(grid: GridData): RuleState;
26
+ copyWith({ color }: {
27
+ color?: Color;
28
+ }): this;
29
+ }
30
+ export declare const instance: SameCountPerZoneRule;
@@ -0,0 +1,130 @@
1
+ import { ConfigType } from '../config.js';
2
+ import GridData from '../grid.js';
3
+ import GridZones from '../gridZones.js';
4
+ import { Color, State } from '../primitives.js';
5
+ import CellCountPerZoneRule from './cellCountPerZoneRule.js';
6
+ class SameCountPerZoneRule extends CellCountPerZoneRule {
7
+ /**
8
+ * **Zones of the same size have the same number of &lt;color&gt; cells.**
9
+ *
10
+ * @param color - The color of the cells to count.
11
+ */
12
+ constructor(color) {
13
+ super(color);
14
+ Object.defineProperty(this, "color", {
15
+ enumerable: true,
16
+ configurable: true,
17
+ writable: true,
18
+ value: color
19
+ });
20
+ Object.defineProperty(this, "title", {
21
+ enumerable: true,
22
+ configurable: true,
23
+ writable: true,
24
+ value: 'Equal Count Per Zone'
25
+ });
26
+ }
27
+ get id() {
28
+ return `zone_cell_count`;
29
+ }
30
+ get explanation() {
31
+ return `Zones of the same size have the same number of ${this.color} cells`;
32
+ }
33
+ get configs() {
34
+ return SameCountPerZoneRule.CONFIGS;
35
+ }
36
+ createExampleGrid() {
37
+ if (this.color === Color.Light) {
38
+ return SameCountPerZoneRule.EXAMPLE_GRID_LIGHT;
39
+ }
40
+ else if (this.color === Color.Dark) {
41
+ return SameCountPerZoneRule.EXAMPLE_GRID_DARK;
42
+ }
43
+ else {
44
+ return SameCountPerZoneRule.EXAMPLE_GRID_GRAY;
45
+ }
46
+ }
47
+ get searchVariants() {
48
+ return SameCountPerZoneRule.SEARCH_VARIANTS;
49
+ }
50
+ validateGrid(grid) {
51
+ const { zones, complete } = this.getZoneCounts(grid);
52
+ if (zones.length <= 1) {
53
+ return { state: complete ? State.Satisfied : State.Incomplete };
54
+ }
55
+ else {
56
+ const errorZone = zones.find(z => zones.some(zz => zz !== z &&
57
+ zz.positions.length === z.positions.length &&
58
+ (zz.completed > z.completed + z.possible ||
59
+ zz.completed + zz.possible < z.completed)));
60
+ if (errorZone) {
61
+ return {
62
+ state: State.Error,
63
+ positions: errorZone.positions,
64
+ };
65
+ }
66
+ else {
67
+ return { state: complete ? State.Satisfied : State.Incomplete };
68
+ }
69
+ }
70
+ }
71
+ copyWith({ color }) {
72
+ return new SameCountPerZoneRule(color ?? this.color);
73
+ }
74
+ }
75
+ Object.defineProperty(SameCountPerZoneRule, "CONFIGS", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: Object.freeze([
80
+ {
81
+ type: ConfigType.Color,
82
+ default: Color.Light,
83
+ allowGray: true,
84
+ field: 'color',
85
+ description: 'Color',
86
+ configurable: true,
87
+ },
88
+ ])
89
+ });
90
+ Object.defineProperty(SameCountPerZoneRule, "EXAMPLE_GRID_LIGHT", {
91
+ enumerable: true,
92
+ configurable: true,
93
+ writable: true,
94
+ value: Object.freeze(GridData.create(['bwbbb', 'wbbwb', 'bbbwb', 'bwbwb'])
95
+ .withZones(new GridZones([
96
+ { x1: 0, y1: 1, x2: 0, y2: 2 },
97
+ { x1: 1, y1: 1, x2: 1, y2: 2 },
98
+ { x1: 2, y1: 1, x2: 2, y2: 2 },
99
+ { x1: 3, y1: 1, x2: 3, y2: 2 },
100
+ { x1: 4, y1: 1, x2: 4, y2: 2 },
101
+ { x1: 1, y1: 0, x2: 2, y2: 0 },
102
+ { x1: 1, y1: 1, x2: 2, y2: 1 },
103
+ { x1: 2, y1: 2, x2: 3, y2: 2 },
104
+ { x1: 2, y1: 3, x2: 3, y2: 3 },
105
+ ]))
106
+ .addRule(new SameCountPerZoneRule(Color.Light)))
107
+ });
108
+ Object.defineProperty(SameCountPerZoneRule, "EXAMPLE_GRID_DARK", {
109
+ enumerable: true,
110
+ configurable: true,
111
+ writable: true,
112
+ value: Object.freeze(SameCountPerZoneRule.EXAMPLE_GRID_LIGHT.withTiles(tiles => tiles.map(row => row.map(tile => tile.withColor(tile.color === Color.Dark ? Color.Light : Color.Dark)))))
113
+ });
114
+ Object.defineProperty(SameCountPerZoneRule, "EXAMPLE_GRID_GRAY", {
115
+ enumerable: true,
116
+ configurable: true,
117
+ writable: true,
118
+ value: Object.freeze(SameCountPerZoneRule.EXAMPLE_GRID_LIGHT.withTiles(tiles => tiles.map(row => row.map(tile => tile.withColor(tile.color === Color.Light ? Color.Gray : tile.color)))))
119
+ });
120
+ Object.defineProperty(SameCountPerZoneRule, "SEARCH_VARIANTS", {
121
+ enumerable: true,
122
+ configurable: true,
123
+ writable: true,
124
+ value: [
125
+ new SameCountPerZoneRule(Color.Light).searchVariant(),
126
+ new SameCountPerZoneRule(Color.Dark).searchVariant(),
127
+ ]
128
+ });
129
+ export default SameCountPerZoneRule;
130
+ export const instance = new SameCountPerZoneRule(Color.Light);
package/dist/index.d.ts CHANGED
@@ -22,6 +22,7 @@ import CompletePatternRule from './data/rules/completePatternRule.js';
22
22
  import ConnectAllRule from './data/rules/connectAllRule.js';
23
23
  import ContainsShapeRule from './data/rules/containsShapeRule.js';
24
24
  import CustomRule from './data/rules/customRule.js';
25
+ import DifferentCountPerZoneRule from './data/rules/differentCountPerZoneRule.js';
25
26
  import ForesightRule from './data/rules/foresightRule.js';
26
27
  import { allRules } from './data/rules/index.js';
27
28
  import LyingSymbolRule from './data/rules/lyingSymbolRule.js';
@@ -33,6 +34,7 @@ import PerfectionRule from './data/rules/perfectionRule.js';
33
34
  import RegionAreaRule from './data/rules/regionAreaRule.js';
34
35
  import RegionShapeRule from './data/rules/regionShapeRule.js';
35
36
  import Rule from './data/rules/rule.js';
37
+ import SameCountPerZoneRule from './data/rules/sameCountPerZoneRule.js';
36
38
  import SameShapeRule from './data/rules/sameShapeRule.js';
37
39
  import SymbolsPerRegionRule from './data/rules/symbolsPerRegionRule.js';
38
40
  import UndercluedRule from './data/rules/undercluedRule.js';
@@ -110,4 +112,4 @@ import ViewpointSymbol from './data/symbols/viewpointSymbol.js';
110
112
  import TileData from './data/tile.js';
111
113
  import TileConnections from './data/tileConnections.js';
112
114
  import validateGrid, { aggregateState, applyFinalOverrides } from './data/validate.js';
113
- export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, getPuzzleTypes, puzzleEquals, validatePuzzleChecklist, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, ContainsShapeRule, CustomRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, ChecksumCompressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerChecksum, SerializerV0, OFFSETS, orientationChars, getShapeVariants, normalizeShape, positionsToShape, sanitizePatternGrid, shapeEquals, tilesToShape, allSolvers, AutoSolver, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, CspuzSolver, gridToJson, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
115
+ export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, getPuzzleTypes, puzzleEquals, validatePuzzleChecklist, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, ContainsShapeRule, CustomRule, DifferentCountPerZoneRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameCountPerZoneRule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, ChecksumCompressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerChecksum, SerializerV0, OFFSETS, orientationChars, getShapeVariants, normalizeShape, positionsToShape, sanitizePatternGrid, shapeEquals, tilesToShape, allSolvers, AutoSolver, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, CspuzSolver, gridToJson, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
package/dist/index.js CHANGED
@@ -25,6 +25,7 @@ import CompletePatternRule from './data/rules/completePatternRule.js';
25
25
  import ConnectAllRule from './data/rules/connectAllRule.js';
26
26
  import ContainsShapeRule from './data/rules/containsShapeRule.js';
27
27
  import CustomRule from './data/rules/customRule.js';
28
+ import DifferentCountPerZoneRule from './data/rules/differentCountPerZoneRule.js';
28
29
  import ForesightRule from './data/rules/foresightRule.js';
29
30
  import { allRules } from './data/rules/index.js';
30
31
  import LyingSymbolRule from './data/rules/lyingSymbolRule.js';
@@ -36,6 +37,7 @@ import PerfectionRule from './data/rules/perfectionRule.js';
36
37
  import RegionAreaRule from './data/rules/regionAreaRule.js';
37
38
  import RegionShapeRule from './data/rules/regionShapeRule.js';
38
39
  import Rule from './data/rules/rule.js';
40
+ import SameCountPerZoneRule from './data/rules/sameCountPerZoneRule.js';
39
41
  import SameShapeRule from './data/rules/sameShapeRule.js';
40
42
  import SymbolsPerRegionRule from './data/rules/symbolsPerRegionRule.js';
41
43
  import UndercluedRule from './data/rules/undercluedRule.js';
@@ -113,4 +115,4 @@ import ViewpointSymbol from './data/symbols/viewpointSymbol.js';
113
115
  import TileData from './data/tile.js';
114
116
  import TileConnections from './data/tileConnections.js';
115
117
  import validateGrid, { aggregateState, applyFinalOverrides } from './data/validate.js';
116
- export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, getPuzzleTypes, puzzleEquals, validatePuzzleChecklist, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, ContainsShapeRule, CustomRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, ChecksumCompressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerChecksum, SerializerV0, OFFSETS, orientationChars, getShapeVariants, normalizeShape, positionsToShape, sanitizePatternGrid, shapeEquals, tilesToShape, allSolvers, AutoSolver, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, CspuzSolver, gridToJson, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
118
+ export { ConfigType, configEquals, Configurable, CachedAccess, allEqual, array, directionToRotation, escape, isSameEdge, maxBy, minBy, move, orientationToRotation, resize, unescape, isEventHandler, handlesFinalValidation, handlesGetTile, handlesGridChange, handlesGridResize, handlesSetGrid, invokeSetGrid, handlesSymbolDisplay, handlesSymbolValidation, GridData, NEIGHBOR_OFFSETS, GridConnections, GridZones, Instruction, COMPARISONS, Color, Comparison, DIRECTIONS, Direction, MajorRule, Mode, ORIENTATIONS, Orientation, PuzzleType, State, WRAPPINGS, Wrapping, directionToggle, orientationToggle, MetadataSchema, PuzzleSchema, getPuzzleTypes, puzzleEquals, validatePuzzleChecklist, BanPatternRule, CellCountPerZoneRule, CellCountRule, CompletePatternRule, ConnectAllRule, ContainsShapeRule, CustomRule, DifferentCountPerZoneRule, ForesightRule, allRules, LyingSymbolRule, ControlLine, Row, MusicGridRule, MysteryRule, OffByXRule, PerfectionRule, RegionAreaRule, RegionShapeRule, Rule, SameCountPerZoneRule, SameShapeRule, SymbolsPerRegionRule, UndercluedRule, UniqueShapeRule, WrapAroundRule, Serializer, Compressor, ChecksumCompressor, CompressorBase, DeflateCompressor, GzipCompressor, StreamCompressor, SerializerBase, SerializerChecksum, SerializerV0, OFFSETS, orientationChars, getShapeVariants, normalizeShape, positionsToShape, sanitizePatternGrid, shapeEquals, tilesToShape, allSolvers, AutoSolver, BacktrackSolver, BTModule, BTGridData, BTTile, IntArray2D, colorToBTTile, createOneTileResult, getOppositeColor, BanPatternBTModule, CellCountBTModule, ConnectAllBTModule, RegionAreaBTModule, RegionShapeBTModule, SameShapeBTModule, SymbolsPerRegionBTModule, UniqueShapeBTModule, AreaNumberBTModule, DartBTModule, DirectionLinkerBTModule, FocusBTModule, GalaxyBTModule, LetterBTModule, LotusBTModule, MinesweeperBTModule, MyopiaBTModule, ViewpointBTModule, CspuzSolver, gridToJson, EventIteratingSolver, Solver, UniversalSolver, AreaNumberModule, CellCountModule, ConnectAllModule, DartModule, allZ3Modules, LetterModule, MyopiaModule, RegionAreaModule, ViewpointModule, Z3Module, convertDirection, Z3Solver, Z3SolverContext, AreaNumberSymbol, CustomIconSymbol, CustomSymbol, CustomTextSymbol, DartSymbol, DirectionLinkerSymbol, FocusSymbol, GalaxySymbol, HiddenSymbol, allSymbols, LetterSymbol, LotusSymbol, MinesweeperSymbol, MultiEntrySymbol, MyopiaSymbol, NumberSymbol, Symbol, ViewpointSymbol, TileData, TileConnections, validateGrid, aggregateState, applyFinalOverrides, };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logic-pad/core",
3
- "version": "0.15.3",
3
+ "version": "0.16.0",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",