@scrabble-solver/solver 2.12.2 → 2.12.3
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.
- package/build/getPatternHash.js +2 -2
- package/build/solve.js +3 -1
- package/package.json +6 -6
- package/src/fillPattern.test.ts +3 -3
- package/src/generatePatterns.test.ts +13 -0
- package/src/getPatternHash.ts +2 -2
- package/src/getPatternScore.test.ts +4 -3
- package/src/solve.test.ts +68 -6
- package/src/solve.ts +4 -1
package/build/getPatternHash.js
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const getPatternHash = (pattern) => {
|
|
4
4
|
return pattern.cells
|
|
5
|
+
.filter((cell) => cell.isEmpty)
|
|
5
6
|
.map((cell) => {
|
|
6
7
|
const blank = cell.tile.isBlank ? '!' : '';
|
|
7
8
|
const tile = cell.tile.character + blank;
|
|
8
|
-
|
|
9
|
-
return cell.x + ',' + cell.y + ',' + tile;
|
|
9
|
+
return [cell.x, cell.y, tile].join(',');
|
|
10
10
|
})
|
|
11
11
|
.join('-');
|
|
12
12
|
};
|
package/build/solve.js
CHANGED
|
@@ -11,7 +11,9 @@ const getUniquePatterns_1 = __importDefault(require("./getUniquePatterns"));
|
|
|
11
11
|
const solve = (trie, config, board, tiles) => {
|
|
12
12
|
const patterns = (0, generatePatterns_1.default)(config, board);
|
|
13
13
|
const filledPatterns = patterns.flatMap((pattern) => (0, fillPattern_1.default)(trie, config, pattern, tiles));
|
|
14
|
-
const validPatterns =
|
|
14
|
+
const validPatterns = config.twoCharacterTiles.length > 0
|
|
15
|
+
? filledPatterns.filter((pattern) => (0, areDigraphsValid_1.default)(config, pattern))
|
|
16
|
+
: filledPatterns;
|
|
15
17
|
const uniquePatterns = (0, getUniquePatterns_1.default)(validPatterns);
|
|
16
18
|
const results = uniquePatterns.map((pattern, index) => ({
|
|
17
19
|
cells: pattern.cells.map((cell) => cell.toJson()),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scrabble-solver/solver",
|
|
3
|
-
"version": "2.12.
|
|
3
|
+
"version": "2.12.3",
|
|
4
4
|
"description": "Scrabble Solver 2 - Solver",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -25,12 +25,12 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@kamilmielnik/trie": "^2.0.1",
|
|
28
|
-
"@scrabble-solver/types": "^2.12.
|
|
28
|
+
"@scrabble-solver/types": "^2.12.3"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"@scrabble-solver/configs": "^2.12.
|
|
32
|
-
"@scrabble-solver/constants": "^2.12.
|
|
33
|
-
"@scrabble-solver/dictionaries": "^2.12.
|
|
31
|
+
"@scrabble-solver/configs": "^2.12.3",
|
|
32
|
+
"@scrabble-solver/constants": "^2.12.3",
|
|
33
|
+
"@scrabble-solver/dictionaries": "^2.12.3"
|
|
34
34
|
},
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "5400e276feee01557044e4e758b11e86b83fb085"
|
|
36
36
|
}
|
package/src/fillPattern.test.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Trie } from '@kamilmielnik/trie';
|
|
2
|
-
import {
|
|
2
|
+
import { getConfig } from '@scrabble-solver/configs';
|
|
3
3
|
import { dictionaries } from '@scrabble-solver/dictionaries';
|
|
4
|
-
import { Board, Cell, FinalPattern, Locale, Pattern, Tile, VerticalPattern } from '@scrabble-solver/types';
|
|
4
|
+
import { Board, Cell, FinalPattern, Game, Locale, Pattern, Tile, VerticalPattern } from '@scrabble-solver/types';
|
|
5
5
|
|
|
6
6
|
import fillPattern, { fillPatternRecursive } from './fillPattern';
|
|
7
7
|
|
|
8
8
|
const board = Board.fromStringArray([' t ', 'do ', ' ']);
|
|
9
9
|
const locale = Locale.PL_PL;
|
|
10
|
-
const config =
|
|
10
|
+
const config = getConfig(Game.Literaki, locale);
|
|
11
11
|
|
|
12
12
|
describe('fillPattern', () => {
|
|
13
13
|
let trie: Trie | undefined;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { getConfig } from '@scrabble-solver/configs';
|
|
2
|
+
import { Board, Game, Locale } from '@scrabble-solver/types';
|
|
3
|
+
|
|
4
|
+
import generatePatterns from './generatePatterns';
|
|
5
|
+
|
|
6
|
+
describe('generatePatterns', () => {
|
|
7
|
+
it('Generates all patterns for an empty board', () => {
|
|
8
|
+
const config = getConfig(Game.Scrabble, Locale.EN_US);
|
|
9
|
+
const board = Board.create(config.boardWidth, config.boardHeight);
|
|
10
|
+
|
|
11
|
+
expect(generatePatterns(config, board).length).toEqual(54);
|
|
12
|
+
});
|
|
13
|
+
});
|
package/src/getPatternHash.ts
CHANGED
|
@@ -2,11 +2,11 @@ import { Pattern } from '@scrabble-solver/types';
|
|
|
2
2
|
|
|
3
3
|
const getPatternHash = (pattern: Pattern): string => {
|
|
4
4
|
return pattern.cells
|
|
5
|
+
.filter((cell) => cell.isEmpty)
|
|
5
6
|
.map((cell) => {
|
|
6
7
|
const blank = cell.tile.isBlank ? '!' : '';
|
|
7
8
|
const tile = cell.tile.character + blank;
|
|
8
|
-
|
|
9
|
-
return cell.x + ',' + cell.y + ',' + tile;
|
|
9
|
+
return [cell.x, cell.y, tile].join(',');
|
|
10
10
|
})
|
|
11
11
|
.join('-');
|
|
12
12
|
};
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { Board, Cell, HorizontalPattern, Locale, Pattern, Tile, VerticalPattern } from '@scrabble-solver/types';
|
|
1
|
+
import { getConfig } from '@scrabble-solver/configs';
|
|
2
|
+
import { Board, Cell, Game, HorizontalPattern, Locale, Pattern, Tile, VerticalPattern } from '@scrabble-solver/types';
|
|
3
3
|
|
|
4
4
|
import getPatternScore from './getPatternScore';
|
|
5
5
|
|
|
6
|
-
const
|
|
6
|
+
const locale = Locale.PL_PL;
|
|
7
|
+
const config = getConfig(Game.Literaki, locale);
|
|
7
8
|
const board = Board.fromStringArray([
|
|
8
9
|
' kasom ',
|
|
9
10
|
' i ',
|
package/src/solve.test.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
/* eslint-disable max-lines */
|
|
2
|
+
|
|
1
3
|
import { Trie } from '@kamilmielnik/trie';
|
|
2
|
-
import {
|
|
4
|
+
import { getConfig } from '@scrabble-solver/configs';
|
|
3
5
|
import { dictionaries } from '@scrabble-solver/dictionaries';
|
|
4
|
-
import { Board, Locale, Result, Tile } from '@scrabble-solver/types';
|
|
6
|
+
import { Board, Game, Locale, Result, Tile } from '@scrabble-solver/types';
|
|
5
7
|
|
|
6
8
|
import solve from './solve';
|
|
7
9
|
|
|
@@ -16,9 +18,9 @@ const getBestResult = ([firstResult, ...results]: Result[]): Result => {
|
|
|
16
18
|
);
|
|
17
19
|
};
|
|
18
20
|
|
|
19
|
-
describe('solve - PL', () => {
|
|
21
|
+
describe('solve - pl-PL', () => {
|
|
20
22
|
const locale = Locale.PL_PL;
|
|
21
|
-
const config =
|
|
23
|
+
const config = getConfig(Game.Literaki, locale);
|
|
22
24
|
let trie: Trie | undefined;
|
|
23
25
|
|
|
24
26
|
beforeAll(() => {
|
|
@@ -99,11 +101,34 @@ describe('solve - PL', () => {
|
|
|
99
101
|
expect(bestResult.word).toBe('zmartwychwstałą');
|
|
100
102
|
expect(bestResult.points).toBe(1157);
|
|
101
103
|
});
|
|
104
|
+
|
|
105
|
+
it('does not duplicate results', () => {
|
|
106
|
+
const board = Board.fromStringArray([
|
|
107
|
+
' a ',
|
|
108
|
+
' a',
|
|
109
|
+
' ',
|
|
110
|
+
' ',
|
|
111
|
+
' ',
|
|
112
|
+
' ',
|
|
113
|
+
' ',
|
|
114
|
+
' ',
|
|
115
|
+
' ',
|
|
116
|
+
' ',
|
|
117
|
+
' ',
|
|
118
|
+
' ',
|
|
119
|
+
' ',
|
|
120
|
+
' ',
|
|
121
|
+
' ',
|
|
122
|
+
]);
|
|
123
|
+
const tiles = generateTiles(['d']);
|
|
124
|
+
const results = solve(trie!, config, board, tiles);
|
|
125
|
+
expect(results.length).toBe(4);
|
|
126
|
+
});
|
|
102
127
|
});
|
|
103
128
|
|
|
104
|
-
describe('solve - ES', () => {
|
|
129
|
+
describe('solve - es-ES', () => {
|
|
105
130
|
const locale = Locale.ES_ES;
|
|
106
|
-
const config =
|
|
131
|
+
const config = getConfig(Game.Scrabble, locale);
|
|
107
132
|
let trie: Trie | undefined;
|
|
108
133
|
|
|
109
134
|
beforeAll(() => {
|
|
@@ -161,3 +186,40 @@ describe('solve - ES', () => {
|
|
|
161
186
|
expect(words).not.toContain('chocho');
|
|
162
187
|
});
|
|
163
188
|
});
|
|
189
|
+
|
|
190
|
+
describe('solve - en-GB', () => {
|
|
191
|
+
const locale = Locale.EN_GB;
|
|
192
|
+
const config = getConfig(Game.Scrabble, locale);
|
|
193
|
+
let trie: Trie | undefined;
|
|
194
|
+
|
|
195
|
+
beforeAll(() => {
|
|
196
|
+
return dictionaries.get(locale).then((loadedTrie) => {
|
|
197
|
+
trie = loadedTrie;
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
it('no', () => {
|
|
202
|
+
const board = Board.fromStringArray([
|
|
203
|
+
' ',
|
|
204
|
+
' ko',
|
|
205
|
+
' ',
|
|
206
|
+
' ',
|
|
207
|
+
' ',
|
|
208
|
+
' ',
|
|
209
|
+
' ',
|
|
210
|
+
' ',
|
|
211
|
+
' ',
|
|
212
|
+
' ',
|
|
213
|
+
' ',
|
|
214
|
+
' ',
|
|
215
|
+
' ',
|
|
216
|
+
' ',
|
|
217
|
+
' ',
|
|
218
|
+
]);
|
|
219
|
+
const tiles = generateTiles(['n']);
|
|
220
|
+
const results = solve(trie!, config, board, tiles).map(Result.fromJson);
|
|
221
|
+
expect(results.some((result) => result.word === 'no')).toBe(true);
|
|
222
|
+
expect(results.some((result) => result.word === 'on')).toBe(true);
|
|
223
|
+
expect(results.length).toBe(2);
|
|
224
|
+
});
|
|
225
|
+
});
|
package/src/solve.ts
CHANGED
|
@@ -10,7 +10,10 @@ import getUniquePatterns from './getUniquePatterns';
|
|
|
10
10
|
const solve = (trie: Trie, config: Config, board: Board, tiles: Tile[]): ResultJson[] => {
|
|
11
11
|
const patterns = generatePatterns(config, board);
|
|
12
12
|
const filledPatterns = patterns.flatMap((pattern) => fillPattern(trie, config, pattern, tiles));
|
|
13
|
-
const validPatterns =
|
|
13
|
+
const validPatterns =
|
|
14
|
+
config.twoCharacterTiles.length > 0
|
|
15
|
+
? filledPatterns.filter((pattern) => areDigraphsValid(config, pattern))
|
|
16
|
+
: filledPatterns;
|
|
14
17
|
const uniquePatterns = getUniquePatterns(validPatterns);
|
|
15
18
|
const results = uniquePatterns.map((pattern, index) => ({
|
|
16
19
|
cells: pattern.cells.map((cell) => cell.toJson()),
|