@logic-pad/core 0.17.0 → 0.18.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.
|
@@ -3083,9 +3083,10 @@ declare global {
|
|
|
3083
3083
|
}): this;
|
|
3084
3084
|
withRevealLocation(revealLocation: boolean): this;
|
|
3085
3085
|
}
|
|
3086
|
-
export declare class HouseSymbol extends
|
|
3086
|
+
export declare class HouseSymbol extends NumberSymbol {
|
|
3087
3087
|
readonly x: number;
|
|
3088
3088
|
readonly y: number;
|
|
3089
|
+
readonly number: number;
|
|
3089
3090
|
readonly title = 'House';
|
|
3090
3091
|
private static readonly CONFIGS;
|
|
3091
3092
|
private static readonly EXAMPLE_GRID;
|
|
@@ -3094,14 +3095,26 @@ declare global {
|
|
|
3094
3095
|
*
|
|
3095
3096
|
* @param x - The x-coordinate of the symbol.
|
|
3096
3097
|
* @param y - The y-coordinate of the symbol.
|
|
3098
|
+
* @param number - The number of houses in this region.
|
|
3097
3099
|
*/
|
|
3098
|
-
constructor(x: number, y: number);
|
|
3100
|
+
constructor(x: number, y: number, number: number);
|
|
3099
3101
|
get id(): string;
|
|
3100
3102
|
get explanation(): string;
|
|
3101
3103
|
get configs(): readonly AnyConfig[] | null;
|
|
3102
3104
|
createExampleGrid(): GridData;
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
+
countTiles(grid: GridData): {
|
|
3106
|
+
completed: number;
|
|
3107
|
+
possible: number;
|
|
3108
|
+
};
|
|
3109
|
+
copyWith({
|
|
3110
|
+
x,
|
|
3111
|
+
y,
|
|
3112
|
+
number,
|
|
3113
|
+
}: {
|
|
3114
|
+
x?: number;
|
|
3115
|
+
y?: number;
|
|
3116
|
+
number?: number;
|
|
3117
|
+
}): this;
|
|
3105
3118
|
}
|
|
3106
3119
|
export declare const allSymbols: Map<string, Symbol$1>;
|
|
3107
3120
|
export declare function aggregateState(
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { AnyConfig } from '../config.js';
|
|
2
2
|
import GridData from '../grid.js';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
export default class HouseSymbol extends Symbol {
|
|
3
|
+
import NumberSymbol from './numberSymbol.js';
|
|
4
|
+
export default class HouseSymbol extends NumberSymbol {
|
|
6
5
|
readonly x: number;
|
|
7
6
|
readonly y: number;
|
|
7
|
+
readonly number: number;
|
|
8
8
|
readonly title = "House";
|
|
9
9
|
private static readonly CONFIGS;
|
|
10
10
|
private static readonly EXAMPLE_GRID;
|
|
@@ -13,16 +13,21 @@ export default class HouseSymbol extends Symbol {
|
|
|
13
13
|
*
|
|
14
14
|
* @param x - The x-coordinate of the symbol.
|
|
15
15
|
* @param y - The y-coordinate of the symbol.
|
|
16
|
+
* @param number - The number of houses in this region.
|
|
16
17
|
*/
|
|
17
|
-
constructor(x: number, y: number);
|
|
18
|
+
constructor(x: number, y: number, number: number);
|
|
18
19
|
get id(): string;
|
|
19
20
|
get explanation(): string;
|
|
20
21
|
get configs(): readonly AnyConfig[] | null;
|
|
21
22
|
createExampleGrid(): GridData;
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
countTiles(grid: GridData): {
|
|
24
|
+
completed: number;
|
|
25
|
+
possible: number;
|
|
26
|
+
};
|
|
27
|
+
copyWith({ x, y, number, }: {
|
|
24
28
|
x?: number;
|
|
25
29
|
y?: number;
|
|
30
|
+
number?: number;
|
|
26
31
|
}): this;
|
|
27
32
|
}
|
|
28
33
|
export declare const instance: HouseSymbol;
|
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { ConfigType } from '../config.js';
|
|
2
2
|
import GridData from '../grid.js';
|
|
3
3
|
import { array } from '../dataHelper.js';
|
|
4
|
-
import { Color
|
|
5
|
-
import
|
|
6
|
-
class HouseSymbol extends
|
|
4
|
+
import { Color } from '../primitives.js';
|
|
5
|
+
import NumberSymbol from './numberSymbol.js';
|
|
6
|
+
class HouseSymbol extends NumberSymbol {
|
|
7
7
|
/**
|
|
8
8
|
* **Houses must connect to exactly one other house**
|
|
9
9
|
*
|
|
10
10
|
* @param x - The x-coordinate of the symbol.
|
|
11
11
|
* @param y - The y-coordinate of the symbol.
|
|
12
|
+
* @param number - The number of houses in this region.
|
|
12
13
|
*/
|
|
13
|
-
constructor(x, y) {
|
|
14
|
-
super(x, y);
|
|
14
|
+
constructor(x, y, number) {
|
|
15
|
+
super(x, y, number);
|
|
15
16
|
Object.defineProperty(this, "x", {
|
|
16
17
|
enumerable: true,
|
|
17
18
|
configurable: true,
|
|
@@ -24,6 +25,12 @@ class HouseSymbol extends Symbol {
|
|
|
24
25
|
writable: true,
|
|
25
26
|
value: y
|
|
26
27
|
});
|
|
28
|
+
Object.defineProperty(this, "number", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: number
|
|
33
|
+
});
|
|
27
34
|
Object.defineProperty(this, "title", {
|
|
28
35
|
enumerable: true,
|
|
29
36
|
configurable: true,
|
|
@@ -35,7 +42,7 @@ class HouseSymbol extends Symbol {
|
|
|
35
42
|
return `house`;
|
|
36
43
|
}
|
|
37
44
|
get explanation() {
|
|
38
|
-
return '*
|
|
45
|
+
return '*House numbers* count the number of houses in the region';
|
|
39
46
|
}
|
|
40
47
|
get configs() {
|
|
41
48
|
return HouseSymbol.CONFIGS;
|
|
@@ -43,45 +50,39 @@ class HouseSymbol extends Symbol {
|
|
|
43
50
|
createExampleGrid() {
|
|
44
51
|
return HouseSymbol.EXAMPLE_GRID;
|
|
45
52
|
}
|
|
46
|
-
|
|
53
|
+
countTiles(grid) {
|
|
47
54
|
const thisX = Math.floor(this.x);
|
|
48
55
|
const thisY = Math.floor(this.y);
|
|
49
|
-
let complete = true;
|
|
50
56
|
const visited = array(grid.width, grid.height, () => false);
|
|
51
57
|
const connected = array(grid.width, grid.height, () => false);
|
|
52
58
|
const color = grid.getTile(thisX, thisY).color;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
if (color === Color.Gray)
|
|
60
|
+
return { completed: 0, possible: Number.MAX_SAFE_INTEGER };
|
|
61
|
+
grid.iterateArea({ x: thisX, y: thisY }, tile => tile.color === Color.Gray || tile.color === color, (_, x, y) => {
|
|
56
62
|
visited[y][x] = true;
|
|
57
|
-
if (tile.color === Color.Gray)
|
|
58
|
-
complete = false;
|
|
59
63
|
});
|
|
60
64
|
grid.iterateArea({ x: thisX, y: thisY }, tile => tile.color === color, (_, x, y) => {
|
|
61
65
|
connected[y][x] = true;
|
|
62
66
|
});
|
|
63
|
-
let
|
|
67
|
+
let completedHouses = 0;
|
|
64
68
|
let possibleHouses = 0;
|
|
65
69
|
for (const symbol of grid.symbols.get(this.id) ?? []) {
|
|
66
|
-
if (symbol
|
|
70
|
+
if (symbol instanceof HouseSymbol) {
|
|
67
71
|
const symbolX = Math.floor(symbol.x);
|
|
68
72
|
const symbolY = Math.floor(symbol.y);
|
|
69
73
|
if (connected[symbolY][symbolX])
|
|
70
|
-
|
|
74
|
+
completedHouses++;
|
|
71
75
|
else if (visited[symbolY][symbolX])
|
|
72
76
|
possibleHouses++;
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
79
|
-
return complete || (connectedHouses === 1 && possibleHouses === 0)
|
|
80
|
-
? State.Satisfied
|
|
81
|
-
: State.Incomplete;
|
|
79
|
+
return {
|
|
80
|
+
completed: completedHouses,
|
|
81
|
+
possible: completedHouses + possibleHouses,
|
|
82
|
+
};
|
|
82
83
|
}
|
|
83
|
-
copyWith({ x, y }) {
|
|
84
|
-
return new HouseSymbol(x ?? this.x, y ?? this.y);
|
|
84
|
+
copyWith({ x, y, number, }) {
|
|
85
|
+
return new HouseSymbol(x ?? this.x, y ?? this.y, number ?? this.number);
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
Object.defineProperty(HouseSymbol, "CONFIGS", {
|
|
@@ -103,6 +104,14 @@ Object.defineProperty(HouseSymbol, "CONFIGS", {
|
|
|
103
104
|
description: 'Y',
|
|
104
105
|
configurable: false,
|
|
105
106
|
},
|
|
107
|
+
{
|
|
108
|
+
type: ConfigType.Number,
|
|
109
|
+
default: 2,
|
|
110
|
+
field: 'number',
|
|
111
|
+
description: 'Number',
|
|
112
|
+
explanation: 'Number of houses in this region',
|
|
113
|
+
configurable: true,
|
|
114
|
+
},
|
|
106
115
|
])
|
|
107
116
|
});
|
|
108
117
|
Object.defineProperty(HouseSymbol, "EXAMPLE_GRID", {
|
|
@@ -110,12 +119,12 @@ Object.defineProperty(HouseSymbol, "EXAMPLE_GRID", {
|
|
|
110
119
|
configurable: true,
|
|
111
120
|
writable: true,
|
|
112
121
|
value: Object.freeze(GridData.create(['bbbww', 'wwwbw', 'wbbbw', 'wwwww'])
|
|
113
|
-
.addSymbol(new HouseSymbol(0, 0))
|
|
114
|
-
.addSymbol(new HouseSymbol(2, 0))
|
|
115
|
-
.addSymbol(new HouseSymbol(3, 0))
|
|
116
|
-
.addSymbol(new HouseSymbol(2, 1))
|
|
117
|
-
.addSymbol(new HouseSymbol(3, 1))
|
|
118
|
-
.addSymbol(new HouseSymbol(1, 2)))
|
|
122
|
+
.addSymbol(new HouseSymbol(0, 0, 2))
|
|
123
|
+
.addSymbol(new HouseSymbol(2, 0, 2))
|
|
124
|
+
.addSymbol(new HouseSymbol(3, 0, 2))
|
|
125
|
+
.addSymbol(new HouseSymbol(2, 1, 2))
|
|
126
|
+
.addSymbol(new HouseSymbol(3, 1, 2))
|
|
127
|
+
.addSymbol(new HouseSymbol(1, 2, 2)))
|
|
119
128
|
});
|
|
120
129
|
export default HouseSymbol;
|
|
121
|
-
export const instance = new HouseSymbol(0, 0);
|
|
130
|
+
export const instance = new HouseSymbol(0, 0, 2);
|