@scrabble-solver/types 2.15.10 → 2.15.12
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/Bingo.d.ts +10 -0
- package/build/Bingo.js +16 -0
- package/build/Board.d.ts +1 -1
- package/build/Board.js +40 -14
- package/build/BoardJson.d.ts +1 -1
- package/build/Bonus.d.ts +4 -4
- package/build/Cell.d.ts +1 -1
- package/build/CellJson.d.ts +1 -1
- package/build/CharacterBonus.d.ts +2 -2
- package/build/Collision.d.ts +1 -1
- package/build/CollisionJson.d.ts +1 -1
- package/build/Config.d.ts +11 -9
- package/build/Config.js +5 -2
- package/build/ConfigJson.d.ts +6 -5
- package/build/Dictionary.d.ts +1 -1
- package/build/Game.d.ts +1 -0
- package/build/Game.js +1 -0
- package/build/Pattern.d.ts +4 -4
- package/build/PatternJson.d.ts +1 -1
- package/build/Result.d.ts +4 -2
- package/build/Result.js +6 -0
- package/build/ResultJson.d.ts +2 -2
- package/build/Tile.d.ts +1 -1
- package/build/TileConfig.d.ts +1 -1
- package/build/WordBonus.d.ts +1 -1
- package/build/WordDefinition.d.ts +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.js +5 -1
- package/package.json +3 -3
- package/src/Bingo.ts +19 -0
- package/src/Board.ts +49 -20
- package/src/BoardJson.ts +1 -1
- package/src/Bonus.ts +4 -4
- package/src/Cell.ts +1 -1
- package/src/CellJson.ts +1 -1
- package/src/CharacterBonus.ts +2 -2
- package/src/Collision.ts +1 -1
- package/src/CollisionJson.ts +1 -1
- package/src/Config.ts +15 -10
- package/src/ConfigJson.ts +6 -5
- package/src/Dictionary.ts +1 -1
- package/src/Game.ts +1 -0
- package/src/Pattern.ts +4 -4
- package/src/PatternJson.ts +1 -1
- package/src/Result.ts +10 -2
- package/src/ResultJson.ts +2 -2
- package/src/Tile.ts +1 -1
- package/src/TileConfig.ts +1 -1
- package/src/WordBonus.ts +1 -1
- package/src/WordDefinition.ts +1 -1
- package/src/index.ts +1 -0
package/build/Bingo.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export type MultiplierBingo = {
|
|
2
|
+
multiplier: number;
|
|
3
|
+
};
|
|
4
|
+
export type ScoreBingo = {
|
|
5
|
+
score: number;
|
|
6
|
+
};
|
|
7
|
+
export type Bingo = MultiplierBingo | ScoreBingo;
|
|
8
|
+
export declare const isBingo: (value: unknown) => value is Bingo;
|
|
9
|
+
export declare const isScoreBingo: (value: unknown) => value is ScoreBingo;
|
|
10
|
+
export declare const isMultiplierBingo: (value: unknown) => value is MultiplierBingo;
|
package/build/Bingo.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isMultiplierBingo = exports.isScoreBingo = exports.isBingo = void 0;
|
|
4
|
+
const isObject_1 = require("./isObject");
|
|
5
|
+
const isBingo = (value) => {
|
|
6
|
+
return (0, exports.isScoreBingo)(value) || (0, exports.isMultiplierBingo)(value);
|
|
7
|
+
};
|
|
8
|
+
exports.isBingo = isBingo;
|
|
9
|
+
const isScoreBingo = (value) => {
|
|
10
|
+
return (0, isObject_1.isObject)(value) && 'score' in value && typeof value.score === 'number';
|
|
11
|
+
};
|
|
12
|
+
exports.isScoreBingo = isScoreBingo;
|
|
13
|
+
const isMultiplierBingo = (value) => {
|
|
14
|
+
return (0, isObject_1.isObject)(value) && 'multiplier' in value && typeof value.multiplier === 'number';
|
|
15
|
+
};
|
|
16
|
+
exports.isMultiplierBingo = isMultiplierBingo;
|
package/build/Board.d.ts
CHANGED
package/build/Board.js
CHANGED
|
@@ -70,20 +70,9 @@ class Board {
|
|
|
70
70
|
}, 0);
|
|
71
71
|
}
|
|
72
72
|
getWords() {
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
for (let y = 0; y < this.rowsCount; ++y) {
|
|
77
|
-
column.push(this.rows[y][x]);
|
|
78
|
-
}
|
|
79
|
-
columns.push(column);
|
|
80
|
-
}
|
|
81
|
-
const columnsBoard = new Board({ rows: columns });
|
|
82
|
-
const lines = this.toString().split('\n').concat(columnsBoard.toString().split('\n'));
|
|
83
|
-
const words = lines
|
|
84
|
-
.flatMap((line) => line.replaceAll(/\s+/g, constants_1.EMPTY_CELL).split(' '))
|
|
85
|
-
.filter((word) => word.length > 1);
|
|
86
|
-
return words;
|
|
73
|
+
const horizontalWords = getHorizontalWords(this.rows);
|
|
74
|
+
const verticalWords = getHorizontalWords(transpose(this.rows));
|
|
75
|
+
return [...horizontalWords, ...verticalWords];
|
|
87
76
|
}
|
|
88
77
|
isEmpty() {
|
|
89
78
|
return this.rows.every((row) => row.every(({ isEmpty }) => isEmpty));
|
|
@@ -113,3 +102,40 @@ Board.fromJson = (json) => {
|
|
|
113
102
|
rows: json.map((row) => row.map(Cell_1.Cell.fromJson)),
|
|
114
103
|
});
|
|
115
104
|
};
|
|
105
|
+
const transpose = (array) => {
|
|
106
|
+
const rows = array.length;
|
|
107
|
+
const cols = array[0].length;
|
|
108
|
+
const transposed = Array(cols)
|
|
109
|
+
.fill(null)
|
|
110
|
+
.map(() => Array(rows));
|
|
111
|
+
for (let y = 0; y < rows; ++y) {
|
|
112
|
+
for (let x = 0; x < cols; ++x) {
|
|
113
|
+
transposed[x][y] = array[y][x];
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return transposed;
|
|
117
|
+
};
|
|
118
|
+
const getHorizontalWords = (cells) => {
|
|
119
|
+
const words = [];
|
|
120
|
+
for (const row of cells) {
|
|
121
|
+
let currentWord = [];
|
|
122
|
+
for (const cell of row) {
|
|
123
|
+
if (!cell.isEmpty) {
|
|
124
|
+
currentWord.push(cell);
|
|
125
|
+
}
|
|
126
|
+
else if (currentWord.length > 0) {
|
|
127
|
+
if (currentWord.length > 1) {
|
|
128
|
+
words.push(wordToString(currentWord));
|
|
129
|
+
}
|
|
130
|
+
currentWord = [];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
if (currentWord.length > 1) {
|
|
134
|
+
words.push(wordToString(currentWord));
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return words;
|
|
138
|
+
};
|
|
139
|
+
const wordToString = (currentWord) => {
|
|
140
|
+
return currentWord.map((cell) => cell.tile.character).join('');
|
|
141
|
+
};
|
package/build/BoardJson.d.ts
CHANGED
package/build/Bonus.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { BONUS_CHARACTER, BONUS_WORD } from '@scrabble-solver/constants';
|
|
2
|
-
import { BonusJson } from './BonusJson';
|
|
3
|
-
import { BonusValue } from './BonusValue';
|
|
4
|
-
import { Cell } from './Cell';
|
|
1
|
+
import { type BONUS_CHARACTER, type BONUS_WORD } from '@scrabble-solver/constants';
|
|
2
|
+
import { type BonusJson } from './BonusJson';
|
|
3
|
+
import { type BonusValue } from './BonusValue';
|
|
4
|
+
import { type Cell } from './Cell';
|
|
5
5
|
import { type Config } from './Config';
|
|
6
6
|
export declare abstract class Bonus {
|
|
7
7
|
readonly multiplier: number;
|
package/build/Cell.d.ts
CHANGED
package/build/CellJson.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Bonus } from './Bonus';
|
|
2
|
-
import { BonusValue } from './BonusValue';
|
|
3
|
-
import { Cell } from './Cell';
|
|
2
|
+
import { type BonusValue } from './BonusValue';
|
|
3
|
+
import { type Cell } from './Cell';
|
|
4
4
|
import { type Config } from './Config';
|
|
5
5
|
export declare class CharacterBonus extends Bonus {
|
|
6
6
|
readonly type = "BONUS_CHARACTER";
|
package/build/Collision.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { Cell } from './Cell';
|
|
1
|
+
import { type Cell } from './Cell';
|
|
2
2
|
export type Collision = Cell[];
|
package/build/CollisionJson.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { CellJson } from './CellJson';
|
|
1
|
+
import { type CellJson } from './CellJson';
|
|
2
2
|
export type CollisionJson = CellJson[];
|
package/build/Config.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { type Bingo } from './Bingo';
|
|
2
|
+
import { type Bonus } from './Bonus';
|
|
3
|
+
import { type BonusValue } from './BonusValue';
|
|
4
|
+
import { type Cell } from './Cell';
|
|
5
|
+
import { type ConfigJson } from './ConfigJson';
|
|
6
|
+
import { type Game } from './Game';
|
|
7
|
+
import { type Locale } from './Locale';
|
|
8
|
+
import { type Tile } from './Tile';
|
|
9
|
+
import { type TileConfig } from './TileConfig';
|
|
9
10
|
export declare class Config {
|
|
10
11
|
static fromJson: (json: ConfigJson) => Config;
|
|
11
12
|
readonly bonuses: Bonus[];
|
|
@@ -13,7 +14,7 @@ export declare class Config {
|
|
|
13
14
|
readonly pointsMap: Record<string, number>;
|
|
14
15
|
constructor(config: ConfigJson);
|
|
15
16
|
get alphabet(): string[];
|
|
16
|
-
get
|
|
17
|
+
get bingo(): Bingo;
|
|
17
18
|
get blankScore(): number;
|
|
18
19
|
get blanksCount(): number;
|
|
19
20
|
get boardHeight(): number;
|
|
@@ -29,6 +30,7 @@ export declare class Config {
|
|
|
29
30
|
hasCharacter(character: string): boolean;
|
|
30
31
|
isTwoCharacterTilePrefix(character: string): boolean;
|
|
31
32
|
get rackSize(): number;
|
|
33
|
+
get supportsRemainingTiles(): boolean;
|
|
32
34
|
get tiles(): TileConfig[];
|
|
33
35
|
toJson(): ConfigJson;
|
|
34
36
|
}
|
package/build/Config.js
CHANGED
|
@@ -13,8 +13,8 @@ class Config {
|
|
|
13
13
|
get alphabet() {
|
|
14
14
|
return getAlphabet(this.config);
|
|
15
15
|
}
|
|
16
|
-
get
|
|
17
|
-
return this.config.
|
|
16
|
+
get bingo() {
|
|
17
|
+
return this.config.bingo;
|
|
18
18
|
}
|
|
19
19
|
get blankScore() {
|
|
20
20
|
return this.config.blankScore;
|
|
@@ -73,6 +73,9 @@ class Config {
|
|
|
73
73
|
get rackSize() {
|
|
74
74
|
return this.config.rackSize;
|
|
75
75
|
}
|
|
76
|
+
get supportsRemainingTiles() {
|
|
77
|
+
return this.tiles.every((tile) => typeof tile.count === 'number');
|
|
78
|
+
}
|
|
76
79
|
get tiles() {
|
|
77
80
|
return this.config.tiles;
|
|
78
81
|
}
|
package/build/ConfigJson.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { type Bingo } from './Bingo';
|
|
2
|
+
import { type BonusJson } from './BonusJson';
|
|
3
|
+
import { type Game } from './Game';
|
|
4
|
+
import { type Locale } from './Locale';
|
|
5
|
+
import { type TileConfig } from './TileConfig';
|
|
5
6
|
export interface ConfigJson {
|
|
6
|
-
|
|
7
|
+
bingo: Bingo;
|
|
7
8
|
blankScore: number;
|
|
8
9
|
blanksCount: number;
|
|
9
10
|
boardHeight: number;
|
package/build/Dictionary.d.ts
CHANGED
package/build/Game.d.ts
CHANGED
package/build/Game.js
CHANGED
package/build/Pattern.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Board } from './Board';
|
|
2
|
-
import { Cell } from './Cell';
|
|
3
|
-
import { Config } from './Config';
|
|
4
|
-
import { PatternJson } from './PatternJson';
|
|
1
|
+
import { type Board } from './Board';
|
|
2
|
+
import { type Cell } from './Cell';
|
|
3
|
+
import { type Config } from './Config';
|
|
4
|
+
import { type PatternJson } from './PatternJson';
|
|
5
5
|
export declare class Pattern {
|
|
6
6
|
readonly board: Board;
|
|
7
7
|
readonly cells: Cell[];
|
package/build/PatternJson.d.ts
CHANGED
package/build/Result.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Cell } from './Cell';
|
|
2
|
-
import { ResultJson } from './ResultJson';
|
|
3
|
-
import { Tile } from './Tile';
|
|
2
|
+
import { type ResultJson } from './ResultJson';
|
|
3
|
+
import { type Tile } from './Tile';
|
|
4
4
|
type Collision = Cell[];
|
|
5
5
|
export declare class Result {
|
|
6
6
|
static fromJson: (json: ResultJson) => Result;
|
|
@@ -25,5 +25,7 @@ export declare class Result {
|
|
|
25
25
|
points: number;
|
|
26
26
|
});
|
|
27
27
|
toJson(): ResultJson;
|
|
28
|
+
isHorizontal(): boolean;
|
|
29
|
+
isVertical(): boolean;
|
|
28
30
|
}
|
|
29
31
|
export {};
|
package/build/Result.js
CHANGED
|
@@ -29,6 +29,12 @@ class Result {
|
|
|
29
29
|
points: this.points,
|
|
30
30
|
};
|
|
31
31
|
}
|
|
32
|
+
isHorizontal() {
|
|
33
|
+
return this.cells[0].y === this.cells[1].y;
|
|
34
|
+
}
|
|
35
|
+
isVertical() {
|
|
36
|
+
return this.cells[0].x === this.cells[1].x;
|
|
37
|
+
}
|
|
32
38
|
}
|
|
33
39
|
exports.Result = Result;
|
|
34
40
|
Result.fromJson = (json) => {
|
package/build/ResultJson.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { CellJson } from './CellJson';
|
|
2
|
-
import { CollisionJson } from './CollisionJson';
|
|
1
|
+
import { type CellJson } from './CellJson';
|
|
2
|
+
import { type CollisionJson } from './CollisionJson';
|
|
3
3
|
export interface ResultJson {
|
|
4
4
|
cells: CellJson[];
|
|
5
5
|
collisions: CollisionJson[];
|
package/build/Tile.d.ts
CHANGED
package/build/TileConfig.d.ts
CHANGED
package/build/WordBonus.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { WordDefinitionJson } from './WordDefinitionJson';
|
|
1
|
+
import { type WordDefinitionJson } from './WordDefinitionJson';
|
|
2
2
|
export declare class WordDefinition {
|
|
3
3
|
static fromJson: (json: WordDefinitionJson | null) => WordDefinition;
|
|
4
4
|
static readonly Null: WordDefinition;
|
package/build/index.d.ts
CHANGED
package/build/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WordDefinition = exports.WordBonus = exports.VerticalPattern = exports.isTileJson = exports.Tile = exports.Result = exports.Pattern = exports.Locale = exports.isLocale = exports.isObject = exports.isError = exports.HorizontalPattern = exports.isGame = exports.Game = exports.FinalPattern = exports.Config = exports.CharacterBonus = exports.isCellJson = exports.Cell = exports.Bonus = exports.isBoardJson = exports.Board = void 0;
|
|
3
|
+
exports.WordDefinition = exports.WordBonus = exports.VerticalPattern = exports.isTileJson = exports.Tile = exports.Result = exports.Pattern = exports.Locale = exports.isLocale = exports.isObject = exports.isError = exports.HorizontalPattern = exports.isGame = exports.Game = exports.FinalPattern = exports.Config = exports.CharacterBonus = exports.isCellJson = exports.Cell = exports.Bonus = exports.isBoardJson = exports.Board = exports.isScoreBingo = exports.isMultiplierBingo = exports.isBingo = void 0;
|
|
4
|
+
var Bingo_1 = require("./Bingo");
|
|
5
|
+
Object.defineProperty(exports, "isBingo", { enumerable: true, get: function () { return Bingo_1.isBingo; } });
|
|
6
|
+
Object.defineProperty(exports, "isMultiplierBingo", { enumerable: true, get: function () { return Bingo_1.isMultiplierBingo; } });
|
|
7
|
+
Object.defineProperty(exports, "isScoreBingo", { enumerable: true, get: function () { return Bingo_1.isScoreBingo; } });
|
|
4
8
|
var Board_1 = require("./Board");
|
|
5
9
|
Object.defineProperty(exports, "Board", { enumerable: true, get: function () { return Board_1.Board; } });
|
|
6
10
|
var BoardJson_1 = require("./BoardJson");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scrabble-solver/types",
|
|
3
|
-
"version": "2.15.
|
|
3
|
+
"version": "2.15.12",
|
|
4
4
|
"description": "Scrabble Solver 2 - Types",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"clean": "rimraf build/"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@scrabble-solver/constants": "^2.15.
|
|
26
|
+
"@scrabble-solver/constants": "^2.15.12"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "1eeef2b2975e63b195885dd2636c53624d300c6b"
|
|
29
29
|
}
|
package/src/Bingo.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isObject } from './isObject';
|
|
2
|
+
|
|
3
|
+
export type MultiplierBingo = { multiplier: number };
|
|
4
|
+
|
|
5
|
+
export type ScoreBingo = { score: number };
|
|
6
|
+
|
|
7
|
+
export type Bingo = MultiplierBingo | ScoreBingo;
|
|
8
|
+
|
|
9
|
+
export const isBingo = (value: unknown): value is Bingo => {
|
|
10
|
+
return isScoreBingo(value) || isMultiplierBingo(value);
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export const isScoreBingo = (value: unknown): value is ScoreBingo => {
|
|
14
|
+
return isObject(value) && 'score' in value && typeof value.score === 'number';
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export const isMultiplierBingo = (value: unknown): value is MultiplierBingo => {
|
|
18
|
+
return isObject(value) && 'multiplier' in value && typeof value.multiplier === 'number';
|
|
19
|
+
};
|
package/src/Board.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EMPTY_CELL } from '@scrabble-solver/constants';
|
|
2
2
|
|
|
3
|
-
import { BoardJson } from './BoardJson';
|
|
3
|
+
import { type BoardJson } from './BoardJson';
|
|
4
4
|
import { Cell } from './Cell';
|
|
5
5
|
import { Tile } from './Tile';
|
|
6
6
|
|
|
@@ -110,25 +110,9 @@ export class Board {
|
|
|
110
110
|
}
|
|
111
111
|
|
|
112
112
|
public getWords(): string[] {
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const column: Cell[] = [];
|
|
117
|
-
|
|
118
|
-
for (let y = 0; y < this.rowsCount; ++y) {
|
|
119
|
-
column.push(this.rows[y][x]);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
columns.push(column);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const columnsBoard = new Board({ rows: columns });
|
|
126
|
-
const lines = this.toString().split('\n').concat(columnsBoard.toString().split('\n'));
|
|
127
|
-
const words = lines
|
|
128
|
-
.flatMap((line) => line.replaceAll(/\s+/g, EMPTY_CELL).split(' '))
|
|
129
|
-
.filter((word) => word.length > 1);
|
|
130
|
-
|
|
131
|
-
return words;
|
|
113
|
+
const horizontalWords = getHorizontalWords(this.rows);
|
|
114
|
+
const verticalWords = getHorizontalWords(transpose(this.rows));
|
|
115
|
+
return [...horizontalWords, ...verticalWords];
|
|
132
116
|
}
|
|
133
117
|
|
|
134
118
|
public isEmpty(): boolean {
|
|
@@ -151,3 +135,48 @@ export class Board {
|
|
|
151
135
|
this.rows[y] = updateRow(this.rows[y]);
|
|
152
136
|
}
|
|
153
137
|
}
|
|
138
|
+
|
|
139
|
+
const transpose = <T>(array: T[][]): T[][] => {
|
|
140
|
+
const rows = array.length;
|
|
141
|
+
const cols = array[0].length;
|
|
142
|
+
const transposed: T[][] = Array(cols)
|
|
143
|
+
.fill(null)
|
|
144
|
+
.map(() => Array(rows));
|
|
145
|
+
|
|
146
|
+
for (let y = 0; y < rows; ++y) {
|
|
147
|
+
for (let x = 0; x < cols; ++x) {
|
|
148
|
+
transposed[x][y] = array[y][x];
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return transposed;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const getHorizontalWords = (cells: Cell[][]): string[] => {
|
|
156
|
+
const words: string[] = [];
|
|
157
|
+
|
|
158
|
+
for (const row of cells) {
|
|
159
|
+
let currentWord: Cell[] = [];
|
|
160
|
+
|
|
161
|
+
for (const cell of row) {
|
|
162
|
+
if (!cell.isEmpty) {
|
|
163
|
+
currentWord.push(cell);
|
|
164
|
+
} else if (currentWord.length > 0) {
|
|
165
|
+
if (currentWord.length > 1) {
|
|
166
|
+
words.push(wordToString(currentWord));
|
|
167
|
+
}
|
|
168
|
+
currentWord = [];
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
if (currentWord.length > 1) {
|
|
173
|
+
words.push(wordToString(currentWord));
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
return words;
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
const wordToString = (currentWord: Cell[]): string => {
|
|
181
|
+
return currentWord.map((cell) => cell.tile.character).join('');
|
|
182
|
+
};
|
package/src/BoardJson.ts
CHANGED
package/src/Bonus.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BONUS_CHARACTER, BONUS_WORD } from '@scrabble-solver/constants';
|
|
1
|
+
import { type BONUS_CHARACTER, type BONUS_WORD } from '@scrabble-solver/constants';
|
|
2
2
|
|
|
3
|
-
import { BonusJson } from './BonusJson';
|
|
4
|
-
import { BonusValue } from './BonusValue';
|
|
5
|
-
import { Cell } from './Cell';
|
|
3
|
+
import { type BonusJson } from './BonusJson';
|
|
4
|
+
import { type BonusValue } from './BonusValue';
|
|
5
|
+
import { type Cell } from './Cell';
|
|
6
6
|
import { type Config } from './Config';
|
|
7
7
|
|
|
8
8
|
export abstract class Bonus {
|
package/src/Cell.ts
CHANGED
package/src/CellJson.ts
CHANGED
package/src/CharacterBonus.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BONUS_CHARACTER } from '@scrabble-solver/constants';
|
|
2
2
|
|
|
3
3
|
import { Bonus } from './Bonus';
|
|
4
|
-
import { BonusValue } from './BonusValue';
|
|
5
|
-
import { Cell } from './Cell';
|
|
4
|
+
import { type BonusValue } from './BonusValue';
|
|
5
|
+
import { type Cell } from './Cell';
|
|
6
6
|
import { type Config } from './Config';
|
|
7
7
|
|
|
8
8
|
export class CharacterBonus extends Bonus {
|
package/src/Collision.ts
CHANGED
package/src/CollisionJson.ts
CHANGED
package/src/Config.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
import { BLANK, BONUS_CHARACTER, BONUS_WORD, NO_BONUS } from '@scrabble-solver/constants';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { type Bingo } from './Bingo';
|
|
4
|
+
import { type Bonus } from './Bonus';
|
|
5
|
+
import { type BonusValue } from './BonusValue';
|
|
6
|
+
import { type Cell } from './Cell';
|
|
6
7
|
import { CharacterBonus } from './CharacterBonus';
|
|
7
|
-
import { ConfigJson } from './ConfigJson';
|
|
8
|
-
import { Game } from './Game';
|
|
9
|
-
import { Locale } from './Locale';
|
|
10
|
-
import { Tile } from './Tile';
|
|
11
|
-
import { TileConfig } from './TileConfig';
|
|
8
|
+
import { type ConfigJson } from './ConfigJson';
|
|
9
|
+
import { type Game } from './Game';
|
|
10
|
+
import { type Locale } from './Locale';
|
|
11
|
+
import { type Tile } from './Tile';
|
|
12
|
+
import { type TileConfig } from './TileConfig';
|
|
12
13
|
import { WordBonus } from './WordBonus';
|
|
13
14
|
|
|
14
15
|
export class Config {
|
|
@@ -32,8 +33,8 @@ export class Config {
|
|
|
32
33
|
return getAlphabet(this.config);
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
public get
|
|
36
|
-
return this.config.
|
|
36
|
+
public get bingo(): Bingo {
|
|
37
|
+
return this.config.bingo;
|
|
37
38
|
}
|
|
38
39
|
|
|
39
40
|
public get blankScore(): number {
|
|
@@ -112,6 +113,10 @@ export class Config {
|
|
|
112
113
|
return this.config.rackSize;
|
|
113
114
|
}
|
|
114
115
|
|
|
116
|
+
public get supportsRemainingTiles(): boolean {
|
|
117
|
+
return this.tiles.every((tile) => typeof tile.count === 'number');
|
|
118
|
+
}
|
|
119
|
+
|
|
115
120
|
public get tiles(): TileConfig[] {
|
|
116
121
|
return this.config.tiles;
|
|
117
122
|
}
|
package/src/ConfigJson.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { type Bingo } from './Bingo';
|
|
2
|
+
import { type BonusJson } from './BonusJson';
|
|
3
|
+
import { type Game } from './Game';
|
|
4
|
+
import { type Locale } from './Locale';
|
|
5
|
+
import { type TileConfig } from './TileConfig';
|
|
5
6
|
|
|
6
7
|
export interface ConfigJson {
|
|
7
|
-
|
|
8
|
+
bingo: Bingo;
|
|
8
9
|
blankScore: number;
|
|
9
10
|
blanksCount: number;
|
|
10
11
|
boardHeight: number;
|
package/src/Dictionary.ts
CHANGED
package/src/Game.ts
CHANGED
package/src/Pattern.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { Board } from './Board';
|
|
2
|
-
import { Cell } from './Cell';
|
|
3
|
-
import { Config } from './Config';
|
|
4
|
-
import { PatternJson } from './PatternJson';
|
|
1
|
+
import { type Board } from './Board';
|
|
2
|
+
import { type Cell } from './Cell';
|
|
3
|
+
import { type Config } from './Config';
|
|
4
|
+
import { type PatternJson } from './PatternJson';
|
|
5
5
|
|
|
6
6
|
export class Pattern {
|
|
7
7
|
public readonly board: Board;
|
package/src/PatternJson.ts
CHANGED
package/src/Result.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { CONSONANTS, VOWELS } from '@scrabble-solver/constants';
|
|
2
2
|
|
|
3
3
|
import { Cell } from './Cell';
|
|
4
|
-
import { ResultJson } from './ResultJson';
|
|
5
|
-
import { Tile } from './Tile';
|
|
4
|
+
import { type ResultJson } from './ResultJson';
|
|
5
|
+
import { type Tile } from './Tile';
|
|
6
6
|
|
|
7
7
|
type Collision = Cell[];
|
|
8
8
|
|
|
@@ -80,6 +80,14 @@ export class Result {
|
|
|
80
80
|
points: this.points,
|
|
81
81
|
};
|
|
82
82
|
}
|
|
83
|
+
|
|
84
|
+
public isHorizontal(): boolean {
|
|
85
|
+
return this.cells[0].y === this.cells[1].y;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public isVertical(): boolean {
|
|
89
|
+
return this.cells[0].x === this.cells[1].x;
|
|
90
|
+
}
|
|
83
91
|
}
|
|
84
92
|
|
|
85
93
|
const getBlanks = (tiles: Tile[]): Tile[] => tiles.filter(({ isBlank }) => isBlank);
|
package/src/ResultJson.ts
CHANGED
package/src/Tile.ts
CHANGED
package/src/TileConfig.ts
CHANGED
package/src/WordBonus.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { BONUS_WORD } from '@scrabble-solver/constants';
|
|
2
2
|
|
|
3
3
|
import { Bonus } from './Bonus';
|
|
4
|
-
import { BonusValue } from './BonusValue';
|
|
4
|
+
import { type BonusValue } from './BonusValue';
|
|
5
5
|
|
|
6
6
|
export class WordBonus extends Bonus {
|
|
7
7
|
public readonly type = BONUS_WORD;
|
package/src/WordDefinition.ts
CHANGED
package/src/index.ts
CHANGED