@scrabble-solver/types 2.8.2 → 2.8.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/Board.js +68 -85
- package/build/Bonus.js +15 -21
- package/build/Cell.js +30 -32
- package/build/CharacterBonus.js +18 -40
- package/build/Config.js +62 -117
- package/build/HorizontalPattern.js +17 -63
- package/build/Pattern.js +36 -40
- package/build/Result.js +23 -46
- package/build/Tile.js +22 -24
- package/build/VerticalPattern.js +17 -63
- package/build/WordBonus.js +13 -35
- package/build/WordDefinition.js +13 -15
- package/package.json +3 -3
package/build/Board.js
CHANGED
|
@@ -3,113 +3,96 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var rows = _a.rows;
|
|
6
|
+
const constants_1 = require("@scrabble-solver/constants");
|
|
7
|
+
const Cell_1 = __importDefault(require("./Cell"));
|
|
8
|
+
const Tile_1 = __importDefault(require("./Tile"));
|
|
9
|
+
class Board {
|
|
10
|
+
constructor({ rows }) {
|
|
12
11
|
this.rows = rows;
|
|
13
12
|
this.numberOfColumns = rows[0].length;
|
|
14
13
|
this.numberOfRows = rows.length;
|
|
15
14
|
}
|
|
16
|
-
|
|
15
|
+
static create(width, height) {
|
|
17
16
|
return Board.fromStringArray(Array(height).fill(Array(width).fill(' ').join('')));
|
|
18
|
-
}
|
|
19
|
-
|
|
17
|
+
}
|
|
18
|
+
static fromJson(json) {
|
|
20
19
|
return new Board({
|
|
21
|
-
rows: json.map(
|
|
20
|
+
rows: json.map((row) => row.map(Cell_1.default.fromJson)),
|
|
22
21
|
});
|
|
23
|
-
}
|
|
24
|
-
|
|
22
|
+
}
|
|
23
|
+
static fromStringArray(stringArray) {
|
|
25
24
|
return new Board({
|
|
26
|
-
rows: stringArray.map(
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
y: y,
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
}),
|
|
25
|
+
rows: stringArray.map((row, y) => row.split('').map((character, x) => new Cell_1.default({
|
|
26
|
+
isEmpty: !character || character === constants_1.EMPTY_CELL,
|
|
27
|
+
tile: character === constants_1.EMPTY_CELL ? Tile_1.default.Null : new Tile_1.default({ character }),
|
|
28
|
+
x,
|
|
29
|
+
y,
|
|
30
|
+
}))),
|
|
36
31
|
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
var rows = this.rows.map(function (row) { return row.map(function (cell) { return cell.clone(); }); });
|
|
49
|
-
return new Board({ rows: rows });
|
|
50
|
-
};
|
|
51
|
-
Board.prototype.collides = function (cell) {
|
|
32
|
+
}
|
|
33
|
+
get center() {
|
|
34
|
+
const x = Math.floor(this.numberOfColumns / 2);
|
|
35
|
+
const y = Math.floor(this.numberOfRows / 2);
|
|
36
|
+
return this.rows[y][x];
|
|
37
|
+
}
|
|
38
|
+
clone() {
|
|
39
|
+
const rows = this.rows.map((row) => row.map((cell) => cell.clone()));
|
|
40
|
+
return new Board({ rows });
|
|
41
|
+
}
|
|
42
|
+
collides(cell) {
|
|
52
43
|
return this.collidesUp(cell) || this.collidesDown(cell) || this.collidesLeft(cell) || this.collidesRight(cell);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
var x = _a.x, y = _a.y;
|
|
44
|
+
}
|
|
45
|
+
collidesDown({ x, y }) {
|
|
56
46
|
return y < this.numberOfRows - 1 && !this.rows[y + 1][x].isEmpty;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
var x = _a.x, y = _a.y;
|
|
47
|
+
}
|
|
48
|
+
collidesLeft({ x, y }) {
|
|
60
49
|
return x > 0 && !this.rows[y][x - 1].isEmpty;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
var x = _a.x, y = _a.y;
|
|
50
|
+
}
|
|
51
|
+
collidesRight({ x, y }) {
|
|
64
52
|
return x < this.numberOfColumns - 1 && !this.rows[y][x + 1].isEmpty;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
var x = _a.x, y = _a.y;
|
|
53
|
+
}
|
|
54
|
+
collidesUp({ x, y }) {
|
|
68
55
|
return y > 0 && !this.rows[y - 1][x].isEmpty;
|
|
69
|
-
}
|
|
70
|
-
|
|
56
|
+
}
|
|
57
|
+
equals(other) {
|
|
71
58
|
return (this.numberOfColumns === other.numberOfColumns &&
|
|
72
59
|
this.numberOfRows === other.numberOfRows &&
|
|
73
|
-
this.rows.every(
|
|
74
|
-
return row.every(
|
|
60
|
+
this.rows.every((row, rowIndex) => {
|
|
61
|
+
return row.every((cell, cellIndex) => {
|
|
75
62
|
return cell.equals(other.rows[rowIndex][cellIndex]);
|
|
76
63
|
});
|
|
77
64
|
}));
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
return this.rows.reduce(
|
|
81
|
-
return count + row.reduce(
|
|
65
|
+
}
|
|
66
|
+
getBlanksCount() {
|
|
67
|
+
return this.rows.reduce((count, row) => {
|
|
68
|
+
return count + row.reduce((rowCount, cell) => (cell.tile.isBlank ? rowCount + 1 : rowCount), 0);
|
|
82
69
|
}, 0);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return this.rows.map(
|
|
86
|
-
}
|
|
87
|
-
|
|
70
|
+
}
|
|
71
|
+
getColumn(index) {
|
|
72
|
+
return this.rows.map((row) => row[index]);
|
|
73
|
+
}
|
|
74
|
+
getRow(index) {
|
|
88
75
|
return this.rows[index];
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
return this.rows.reduce(
|
|
92
|
-
return count + row.reduce(
|
|
76
|
+
}
|
|
77
|
+
getTilesCount() {
|
|
78
|
+
return this.rows.reduce((count, row) => {
|
|
79
|
+
return count + row.reduce((rowCount, cell) => (cell.hasTile() ? rowCount + 1 : rowCount), 0);
|
|
93
80
|
}, 0);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
return this.rows.every(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return this.rows.map(
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
return this.rows.map(function (row) { return row.map(String); }).join('\n');
|
|
106
|
-
};
|
|
107
|
-
Board.prototype.updateCell = function (x, y, updateCell) {
|
|
81
|
+
}
|
|
82
|
+
isEmpty() {
|
|
83
|
+
return this.rows.every((row) => row.every(({ isEmpty }) => isEmpty));
|
|
84
|
+
}
|
|
85
|
+
toJson() {
|
|
86
|
+
return this.rows.map((row) => row.map((cell) => cell.toJson()));
|
|
87
|
+
}
|
|
88
|
+
toString() {
|
|
89
|
+
return this.rows.map((row) => row.map(String)).join('\n');
|
|
90
|
+
}
|
|
91
|
+
updateCell(x, y, updateCell) {
|
|
108
92
|
this.rows[y][x] = updateCell(this.rows[y][x]);
|
|
109
|
-
}
|
|
110
|
-
|
|
93
|
+
}
|
|
94
|
+
updateRow(y, updateRow) {
|
|
111
95
|
this.rows[y] = updateRow(this.rows[y]);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
}());
|
|
96
|
+
}
|
|
97
|
+
}
|
|
115
98
|
exports.default = Board;
|
package/build/Bonus.js
CHANGED
|
@@ -1,20 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var multiplier = _a.multiplier, score = _a.score, x = _a.x, y = _a.y;
|
|
3
|
+
class Bonus {
|
|
4
|
+
constructor({ multiplier, score, x, y }) {
|
|
6
5
|
this.multiplier = multiplier;
|
|
7
6
|
this.score = score;
|
|
8
7
|
this.x = x;
|
|
9
8
|
this.y = y;
|
|
10
9
|
}
|
|
11
|
-
|
|
10
|
+
canApply(_config, cell) {
|
|
12
11
|
return cell.isEmpty && this.matchesCellCoordinates(cell);
|
|
13
|
-
}
|
|
14
|
-
|
|
12
|
+
}
|
|
13
|
+
matchesCellCoordinates(cell) {
|
|
15
14
|
return this.x === cell.x && this.y === cell.y;
|
|
16
|
-
}
|
|
17
|
-
|
|
15
|
+
}
|
|
16
|
+
toJson() {
|
|
18
17
|
return {
|
|
19
18
|
multiplier: this.multiplier,
|
|
20
19
|
score: this.score,
|
|
@@ -22,17 +21,12 @@ var Bonus = /** @class */ (function () {
|
|
|
22
21
|
x: this.x,
|
|
23
22
|
y: this.y,
|
|
24
23
|
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
enumerable: false,
|
|
34
|
-
configurable: true
|
|
35
|
-
});
|
|
36
|
-
return Bonus;
|
|
37
|
-
}());
|
|
24
|
+
}
|
|
25
|
+
get value() {
|
|
26
|
+
return {
|
|
27
|
+
characterMultiplier: 1,
|
|
28
|
+
wordMultiplier: 1,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
38
32
|
exports.default = Bonus;
|
package/build/Cell.js
CHANGED
|
@@ -3,17 +3,16 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const Tile_1 = __importDefault(require("./Tile"));
|
|
7
|
+
class Cell {
|
|
8
8
|
// eslint-disable-next-line no-undef
|
|
9
|
-
|
|
10
|
-
var _b = _a.isEmpty, isEmpty = _b === void 0 ? true : _b, _c = _a.tile, tile = _c === void 0 ? Tile_1.default.Null : _c, x = _a.x, y = _a.y;
|
|
9
|
+
constructor({ isEmpty = true, tile = Tile_1.default.Null, x, y }) {
|
|
11
10
|
this.isEmpty = isEmpty;
|
|
12
11
|
this.tile = tile;
|
|
13
12
|
this.x = x;
|
|
14
13
|
this.y = y;
|
|
15
14
|
}
|
|
16
|
-
|
|
15
|
+
static fromJson(json) {
|
|
17
16
|
if (!json) {
|
|
18
17
|
return Cell.Null;
|
|
19
18
|
}
|
|
@@ -23,47 +22,46 @@ var Cell = /** @class */ (function () {
|
|
|
23
22
|
x: json.x,
|
|
24
23
|
y: json.y,
|
|
25
24
|
});
|
|
26
|
-
}
|
|
27
|
-
|
|
25
|
+
}
|
|
26
|
+
clone() {
|
|
28
27
|
return new Cell({
|
|
29
28
|
isEmpty: this.isEmpty,
|
|
30
29
|
tile: this.tile.clone(),
|
|
31
30
|
x: this.x,
|
|
32
31
|
y: this.y,
|
|
33
32
|
});
|
|
34
|
-
}
|
|
35
|
-
|
|
33
|
+
}
|
|
34
|
+
equals(other) {
|
|
36
35
|
return this.x === other.x && this.y === other.y && this.isEmpty === other.isEmpty && this.tile.equals(other.tile);
|
|
37
|
-
}
|
|
38
|
-
|
|
36
|
+
}
|
|
37
|
+
hasTile() {
|
|
39
38
|
return this.tile !== Tile_1.default.Null;
|
|
40
|
-
}
|
|
41
|
-
|
|
39
|
+
}
|
|
40
|
+
isCandidate() {
|
|
42
41
|
return this.isEmpty && this.hasTile();
|
|
43
|
-
}
|
|
44
|
-
|
|
42
|
+
}
|
|
43
|
+
toJson() {
|
|
45
44
|
return {
|
|
46
45
|
isEmpty: this.isEmpty,
|
|
47
46
|
tile: this.tile.toJson(),
|
|
48
47
|
x: this.x,
|
|
49
48
|
y: this.y,
|
|
50
49
|
};
|
|
51
|
-
}
|
|
52
|
-
|
|
50
|
+
}
|
|
51
|
+
toString() {
|
|
53
52
|
return String(this.tile);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}());
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
Cell.Null = Object.freeze({
|
|
56
|
+
isEmpty: true,
|
|
57
|
+
tile: Tile_1.default.Null,
|
|
58
|
+
x: 0,
|
|
59
|
+
y: 0,
|
|
60
|
+
clone: () => Cell.Null,
|
|
61
|
+
equals: (other) => other === Cell.Null,
|
|
62
|
+
hasTile: () => false,
|
|
63
|
+
isCandidate: () => false,
|
|
64
|
+
toString: () => '',
|
|
65
|
+
toJson: () => null,
|
|
66
|
+
});
|
|
69
67
|
exports.default = Cell;
|
package/build/CharacterBonus.js
CHANGED
|
@@ -1,51 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
4
|
};
|
|
20
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
_this.type = constants_1.BONUS_CHARACTER;
|
|
28
|
-
return _this;
|
|
6
|
+
const constants_1 = require("@scrabble-solver/constants");
|
|
7
|
+
const Bonus_1 = __importDefault(require("./Bonus"));
|
|
8
|
+
class CharacterBonus extends Bonus_1.default {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.type = constants_1.BONUS_CHARACTER;
|
|
29
12
|
}
|
|
30
|
-
|
|
31
|
-
return
|
|
32
|
-
}
|
|
33
|
-
|
|
13
|
+
canApply(config, cell) {
|
|
14
|
+
return super.canApply(config, cell) && this.matchesCellTileScore(config, cell);
|
|
15
|
+
}
|
|
16
|
+
matchesCellTileScore(config, cell) {
|
|
34
17
|
if (typeof this.score === 'undefined') {
|
|
35
18
|
return true;
|
|
36
19
|
}
|
|
37
20
|
return this.score === config.pointsMap[cell.tile.character];
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
enumerable: false,
|
|
47
|
-
configurable: true
|
|
48
|
-
});
|
|
49
|
-
return CharacterBonus;
|
|
50
|
-
}(Bonus_1.default));
|
|
21
|
+
}
|
|
22
|
+
get value() {
|
|
23
|
+
return {
|
|
24
|
+
characterMultiplier: this.multiplier,
|
|
25
|
+
wordMultiplier: 1,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
}
|
|
51
29
|
exports.default = CharacterBonus;
|
package/build/Config.js
CHANGED
|
@@ -1,81 +1,45 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
4
|
};
|
|
16
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
const constants_1 = require("@scrabble-solver/constants");
|
|
7
|
+
const CharacterBonus_1 = __importDefault(require("./CharacterBonus"));
|
|
8
|
+
const WordBonus_1 = __importDefault(require("./WordBonus"));
|
|
9
|
+
class Config {
|
|
10
|
+
constructor(config) {
|
|
22
11
|
this.bonuses = getBonuses(config);
|
|
23
12
|
this.config = config;
|
|
24
13
|
this.pointsMap = getPointsMap(this.config);
|
|
25
14
|
}
|
|
26
|
-
|
|
15
|
+
static fromJson(json) {
|
|
27
16
|
return new Config(json);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
enumerable: false,
|
|
55
|
-
configurable: true
|
|
56
|
-
});
|
|
57
|
-
Object.defineProperty(Config.prototype, "boardWidth", {
|
|
58
|
-
get: function () {
|
|
59
|
-
return this.config.boardWidth;
|
|
60
|
-
},
|
|
61
|
-
enumerable: false,
|
|
62
|
-
configurable: true
|
|
63
|
-
});
|
|
64
|
-
Object.defineProperty(Config.prototype, "twoCharacterTiles", {
|
|
65
|
-
get: function () {
|
|
66
|
-
return this.config.tiles.filter(function (tile) { return tile.character.length === 2; }).map(function (tile) { return tile.character; });
|
|
67
|
-
},
|
|
68
|
-
enumerable: false,
|
|
69
|
-
configurable: true
|
|
70
|
-
});
|
|
71
|
-
Config.prototype.getCellBonus = function (cell) {
|
|
72
|
-
return this.bonuses.find(function (bonus) { return bonus.matchesCellCoordinates(cell); });
|
|
73
|
-
};
|
|
74
|
-
Config.prototype.getCellBonusValue = function (cell) {
|
|
75
|
-
var _a;
|
|
76
|
-
return ((_a = this.getCellBonus(cell)) === null || _a === void 0 ? void 0 : _a.value) || constants_1.NO_BONUS;
|
|
77
|
-
};
|
|
78
|
-
Config.prototype.getCharacterPoints = function (character) {
|
|
17
|
+
}
|
|
18
|
+
get allTilesBonusScore() {
|
|
19
|
+
return this.config.allTilesBonusScore;
|
|
20
|
+
}
|
|
21
|
+
get alphabet() {
|
|
22
|
+
return getAlphabet(this.config);
|
|
23
|
+
}
|
|
24
|
+
get blankScore() {
|
|
25
|
+
return this.config.blankScore;
|
|
26
|
+
}
|
|
27
|
+
get boardHeight() {
|
|
28
|
+
return this.config.boardHeight;
|
|
29
|
+
}
|
|
30
|
+
get boardWidth() {
|
|
31
|
+
return this.config.boardWidth;
|
|
32
|
+
}
|
|
33
|
+
get twoCharacterTiles() {
|
|
34
|
+
return this.config.tiles.filter((tile) => tile.character.length === 2).map((tile) => tile.character);
|
|
35
|
+
}
|
|
36
|
+
getCellBonus(cell) {
|
|
37
|
+
return this.bonuses.find((bonus) => bonus.matchesCellCoordinates(cell));
|
|
38
|
+
}
|
|
39
|
+
getCellBonusValue(cell) {
|
|
40
|
+
return this.getCellBonus(cell)?.value || constants_1.NO_BONUS;
|
|
41
|
+
}
|
|
42
|
+
getCharacterPoints(character) {
|
|
79
43
|
if (character === null) {
|
|
80
44
|
return undefined;
|
|
81
45
|
}
|
|
@@ -83,71 +47,52 @@ var Config = /** @class */ (function () {
|
|
|
83
47
|
return this.blankScore;
|
|
84
48
|
}
|
|
85
49
|
return this.pointsMap[character];
|
|
86
|
-
}
|
|
87
|
-
|
|
50
|
+
}
|
|
51
|
+
getTwoCharacterTileByPrefix(character) {
|
|
88
52
|
if (character.length !== 1) {
|
|
89
53
|
return undefined;
|
|
90
54
|
}
|
|
91
|
-
return this.twoCharacterTiles.find(
|
|
92
|
-
}
|
|
93
|
-
|
|
55
|
+
return this.twoCharacterTiles.find((characters) => characters.startsWith(character));
|
|
56
|
+
}
|
|
57
|
+
getTilePoints(tile) {
|
|
94
58
|
if (tile === null) {
|
|
95
59
|
return undefined;
|
|
96
60
|
}
|
|
97
61
|
return tile.isBlank ? this.blankScore : this.getCharacterPoints(tile.character);
|
|
98
|
-
}
|
|
99
|
-
|
|
62
|
+
}
|
|
63
|
+
hasCharacter(character) {
|
|
100
64
|
return this.alphabet.includes(character);
|
|
101
|
-
}
|
|
102
|
-
|
|
65
|
+
}
|
|
66
|
+
isTwoCharacterTilePrefix(character) {
|
|
103
67
|
return typeof this.getTwoCharacterTileByPrefix(character) !== 'undefined';
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
},
|
|
116
|
-
enumerable: false,
|
|
117
|
-
configurable: true
|
|
118
|
-
});
|
|
119
|
-
Object.defineProperty(Config.prototype, "tiles", {
|
|
120
|
-
get: function () {
|
|
121
|
-
return this.config.tiles;
|
|
122
|
-
},
|
|
123
|
-
enumerable: false,
|
|
124
|
-
configurable: true
|
|
125
|
-
});
|
|
126
|
-
Config.prototype.toJson = function () {
|
|
68
|
+
}
|
|
69
|
+
get maximumNumberOfCharacters() {
|
|
70
|
+
return this.config.maximumNumberOfCharacters;
|
|
71
|
+
}
|
|
72
|
+
get numberOfBlanks() {
|
|
73
|
+
return this.config.numberOfBlanks;
|
|
74
|
+
}
|
|
75
|
+
get tiles() {
|
|
76
|
+
return this.config.tiles;
|
|
77
|
+
}
|
|
78
|
+
toJson() {
|
|
127
79
|
return this.config;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return config.bonuses.map(function (bonus) {
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
const getBonuses = (config) => {
|
|
83
|
+
return config.bonuses.map((bonus) => {
|
|
133
84
|
if (bonus.type === constants_1.BONUS_CHARACTER) {
|
|
134
85
|
return new CharacterBonus_1.default(bonus);
|
|
135
86
|
}
|
|
136
87
|
if (bonus.type === constants_1.BONUS_WORD) {
|
|
137
88
|
return new WordBonus_1.default(bonus);
|
|
138
89
|
}
|
|
139
|
-
throw new Error(
|
|
90
|
+
throw new Error(`Unsupported Bonus type: "${bonus.type}"`);
|
|
140
91
|
});
|
|
141
92
|
};
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return config.tiles.reduce(function (pointsMap, _a) {
|
|
148
|
-
var _b;
|
|
149
|
-
var character = _a.character, score = _a.score;
|
|
150
|
-
return (__assign(__assign({}, pointsMap), (_b = {}, _b[character] = score, _b)));
|
|
151
|
-
}, {});
|
|
152
|
-
};
|
|
93
|
+
const getAlphabet = (config) => config.tiles.map(({ character }) => character);
|
|
94
|
+
const getPointsMap = (config) => config.tiles.reduce((pointsMap, { character, score }) => ({
|
|
95
|
+
...pointsMap,
|
|
96
|
+
[character]: score,
|
|
97
|
+
}), {});
|
|
153
98
|
exports.default = Config;
|
|
@@ -1,85 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
4
|
};
|
|
45
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function HorizontalPattern() {
|
|
50
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
51
|
-
}
|
|
52
|
-
HorizontalPattern.prototype.clone = function () {
|
|
6
|
+
const Pattern_1 = __importDefault(require("./Pattern"));
|
|
7
|
+
class HorizontalPattern extends Pattern_1.default {
|
|
8
|
+
clone() {
|
|
53
9
|
return new HorizontalPattern({
|
|
54
10
|
board: this.board,
|
|
55
|
-
cells: this.cells.map(
|
|
11
|
+
cells: this.cells.map((cell) => cell.clone()),
|
|
56
12
|
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var collisions = [];
|
|
13
|
+
}
|
|
14
|
+
getCollisions() {
|
|
15
|
+
const collisions = [];
|
|
61
16
|
this.cells
|
|
62
|
-
.filter(
|
|
63
|
-
.forEach(
|
|
64
|
-
|
|
65
|
-
|
|
17
|
+
.filter((cell) => cell.isEmpty && (this.board.collidesUp(cell) || this.board.collidesDown(cell)))
|
|
18
|
+
.forEach((cell) => {
|
|
19
|
+
const column = this.board.getColumn(cell.x);
|
|
20
|
+
let y = cell.y - 1;
|
|
66
21
|
while (y >= 0 && column[y].hasTile()) {
|
|
67
22
|
--y;
|
|
68
23
|
}
|
|
69
|
-
|
|
24
|
+
const previousCells = column.slice(y + 1, cell.y);
|
|
70
25
|
y = cell.y + 1;
|
|
71
26
|
while (y < column.length && column[y].hasTile()) {
|
|
72
27
|
++y;
|
|
73
28
|
}
|
|
74
|
-
|
|
75
|
-
|
|
29
|
+
const nextCells = column.slice(cell.y + 1, y);
|
|
30
|
+
const cells = [...previousCells, cell, ...nextCells];
|
|
76
31
|
if (cells.length > 1) {
|
|
77
|
-
|
|
32
|
+
const pattern = new Pattern_1.default({ board: this.board, cells });
|
|
78
33
|
collisions.push(pattern);
|
|
79
34
|
}
|
|
80
35
|
});
|
|
81
36
|
return collisions;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}(Pattern_1.default));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
85
39
|
exports.default = HorizontalPattern;
|
package/build/Pattern.js
CHANGED
|
@@ -1,56 +1,52 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var board = _a.board, cells = _a.cells;
|
|
3
|
+
class Pattern {
|
|
4
|
+
constructor({ board, cells }) {
|
|
6
5
|
this.board = board;
|
|
7
6
|
this.cells = cells;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
canBePlaced(config) {
|
|
9
|
+
const numberOfEmptyCells = this.getNumberOfEmptyCells();
|
|
10
|
+
const isNumberOfUsedCellsInRange = numberOfEmptyCells >= 1 && numberOfEmptyCells <= config.maximumNumberOfCharacters;
|
|
12
11
|
return (isNumberOfUsedCellsInRange &&
|
|
13
12
|
(this.hasAtLeast1NonEmptyCell() || this.collides() || (this.goesThroughBoardCenter() && this.board.isEmpty())));
|
|
14
|
-
}
|
|
15
|
-
|
|
13
|
+
}
|
|
14
|
+
clone() {
|
|
16
15
|
return new Pattern({
|
|
17
16
|
board: this.board,
|
|
18
|
-
cells: this.cells.map(
|
|
17
|
+
cells: this.cells.map((cell) => cell.clone()),
|
|
19
18
|
});
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
Pattern.prototype.getCollisions = function () {
|
|
19
|
+
}
|
|
20
|
+
collides() {
|
|
21
|
+
return this.cells.some((cell) => cell.isEmpty && this.board.collides(cell));
|
|
22
|
+
}
|
|
23
|
+
getIndexOfFirstCellWithoutTile() {
|
|
24
|
+
return this.cells.findIndex((cell) => !cell.hasTile());
|
|
25
|
+
}
|
|
26
|
+
getNumberOfEmptyCells() {
|
|
27
|
+
return this.cells.filter((cell) => cell.isEmpty).length;
|
|
28
|
+
}
|
|
29
|
+
goesThroughBoardCenter() {
|
|
30
|
+
return this.cells.some((cell) => cell.x === this.board.center.x && cell.y === this.board.center.y && cell.isEmpty);
|
|
31
|
+
}
|
|
32
|
+
hasAtLeast1EmptyCell() {
|
|
33
|
+
return this.cells.some((cell) => cell.isEmpty);
|
|
34
|
+
}
|
|
35
|
+
hasAtLeast1NonEmptyCell() {
|
|
36
|
+
return this.cells.some((cell) => !cell.isEmpty);
|
|
37
|
+
}
|
|
38
|
+
getCollisions() {
|
|
42
39
|
return [];
|
|
43
|
-
}
|
|
44
|
-
|
|
40
|
+
}
|
|
41
|
+
toJson() {
|
|
45
42
|
return {
|
|
46
|
-
cells: this.cells.map(
|
|
47
|
-
collisions: this.getCollisions().map(
|
|
43
|
+
cells: this.cells.map((cell) => cell.toJson()),
|
|
44
|
+
collisions: this.getCollisions().map((collision) => collision.toJson()),
|
|
48
45
|
word: this.toString(),
|
|
49
46
|
};
|
|
50
|
-
}
|
|
51
|
-
|
|
47
|
+
}
|
|
48
|
+
toString() {
|
|
52
49
|
return this.cells.map(String).join('');
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
}());
|
|
50
|
+
}
|
|
51
|
+
}
|
|
56
52
|
exports.default = Pattern;
|
package/build/Result.js
CHANGED
|
@@ -3,12 +3,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
var tiles = getTiles(cells);
|
|
6
|
+
const constants_1 = require("@scrabble-solver/constants");
|
|
7
|
+
const Cell_1 = __importDefault(require("./Cell"));
|
|
8
|
+
class Result {
|
|
9
|
+
constructor({ cells, id, numberOfCollisions, points, }) {
|
|
10
|
+
const tiles = getTiles(cells);
|
|
12
11
|
this.cells = cells;
|
|
13
12
|
this.id = id;
|
|
14
13
|
this.length = cells.length;
|
|
@@ -24,55 +23,33 @@ var Result = /** @class */ (function () {
|
|
|
24
23
|
this.tilesCharacters = getTilesCharacters(tiles);
|
|
25
24
|
this.word = getWord(cells);
|
|
26
25
|
}
|
|
27
|
-
|
|
26
|
+
static fromJson(json) {
|
|
28
27
|
return new Result({
|
|
29
28
|
cells: json.cells.map(Cell_1.default.fromJson),
|
|
30
29
|
id: json.id,
|
|
31
30
|
numberOfCollisions: json.numberOfCollisions,
|
|
32
31
|
points: json.points,
|
|
33
32
|
});
|
|
34
|
-
}
|
|
35
|
-
|
|
33
|
+
}
|
|
34
|
+
toJson() {
|
|
36
35
|
return {
|
|
37
|
-
cells: this.cells.map(
|
|
36
|
+
cells: this.cells.map((cell) => cell.toJson()),
|
|
38
37
|
id: this.id,
|
|
39
38
|
numberOfCollisions: this.numberOfCollisions,
|
|
40
39
|
points: this.points,
|
|
41
40
|
};
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
})
|
|
56
|
-
var getNonBlanks = function (tiles) { return tiles.filter(function (_a) {
|
|
57
|
-
var isBlank = _a.isBlank;
|
|
58
|
-
return !isBlank;
|
|
59
|
-
}); };
|
|
60
|
-
var getPointsRatio = function (tiles, points) { return points / tiles.length; };
|
|
61
|
-
var getTiles = function (cells) { return cells.filter(function (_a) {
|
|
62
|
-
var isEmpty = _a.isEmpty;
|
|
63
|
-
return isEmpty;
|
|
64
|
-
}).map(function (_a) {
|
|
65
|
-
var tile = _a.tile;
|
|
66
|
-
return tile;
|
|
67
|
-
}); };
|
|
68
|
-
var getTilesCharacters = function (tiles) { return getNonBlankCharacters(tiles).sort(charactersComparator).join(''); };
|
|
69
|
-
var getWord = function (cells) { return cells.map(String).join(''); };
|
|
70
|
-
var isConsonant = function (_a) {
|
|
71
|
-
var character = _a.character, isBlank = _a.isBlank;
|
|
72
|
-
return constants_1.CONSONANTS.includes(character) && !isBlank;
|
|
73
|
-
};
|
|
74
|
-
var isVowel = function (_a) {
|
|
75
|
-
var character = _a.character, isBlank = _a.isBlank;
|
|
76
|
-
return constants_1.VOWELS.includes(character) && !isBlank;
|
|
77
|
-
};
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const charactersComparator = (a, b) => a.localeCompare(b);
|
|
44
|
+
const getBlanks = (tiles) => tiles.filter(({ isBlank }) => isBlank);
|
|
45
|
+
const getConsonants = (tiles) => tiles.filter(isConsonant);
|
|
46
|
+
const getVowels = (tiles) => tiles.filter(isVowel);
|
|
47
|
+
const getNonBlankCharacters = (tiles) => getNonBlanks(tiles).map(({ character }) => character);
|
|
48
|
+
const getNonBlanks = (tiles) => tiles.filter(({ isBlank }) => !isBlank);
|
|
49
|
+
const getPointsRatio = (tiles, points) => points / tiles.length;
|
|
50
|
+
const getTiles = (cells) => cells.filter(({ isEmpty }) => isEmpty).map(({ tile }) => tile);
|
|
51
|
+
const getTilesCharacters = (tiles) => getNonBlankCharacters(tiles).sort(charactersComparator).join('');
|
|
52
|
+
const getWord = (cells) => cells.map(String).join('');
|
|
53
|
+
const isConsonant = ({ character, isBlank }) => constants_1.CONSONANTS.includes(character) && !isBlank;
|
|
54
|
+
const isVowel = ({ character, isBlank }) => constants_1.VOWELS.includes(character) && !isBlank;
|
|
78
55
|
exports.default = Result;
|
package/build/Tile.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var character = _a.character, _b = _a.isBlank, isBlank = _b === void 0 ? false : _b;
|
|
3
|
+
const constants_1 = require("@scrabble-solver/constants");
|
|
4
|
+
class Tile {
|
|
5
|
+
constructor({ character, isBlank = false }) {
|
|
7
6
|
this.character = character;
|
|
8
7
|
this.isBlank = isBlank;
|
|
9
8
|
}
|
|
10
|
-
|
|
9
|
+
static fromJson(json) {
|
|
11
10
|
if (!json) {
|
|
12
11
|
return Tile.Null;
|
|
13
12
|
}
|
|
@@ -15,33 +14,32 @@ var Tile = /** @class */ (function () {
|
|
|
15
14
|
character: json.character,
|
|
16
15
|
isBlank: json.isBlank,
|
|
17
16
|
});
|
|
18
|
-
}
|
|
19
|
-
|
|
17
|
+
}
|
|
18
|
+
clone() {
|
|
20
19
|
return new Tile({
|
|
21
20
|
character: this.character,
|
|
22
21
|
isBlank: this.isBlank,
|
|
23
22
|
});
|
|
24
|
-
}
|
|
25
|
-
|
|
23
|
+
}
|
|
24
|
+
equals(other) {
|
|
26
25
|
return this.character === other.character && this.isBlank === other.isBlank;
|
|
27
|
-
}
|
|
28
|
-
|
|
26
|
+
}
|
|
27
|
+
toJson() {
|
|
29
28
|
return {
|
|
30
29
|
character: this.character,
|
|
31
30
|
isBlank: this.isBlank,
|
|
32
31
|
};
|
|
33
|
-
}
|
|
34
|
-
|
|
32
|
+
}
|
|
33
|
+
toString() {
|
|
35
34
|
return this.character;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}());
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
Tile.Null = Object.freeze({
|
|
38
|
+
character: constants_1.EMPTY_CELL,
|
|
39
|
+
isBlank: false,
|
|
40
|
+
clone: () => Tile.Null,
|
|
41
|
+
equals: (other) => other === Tile.Null,
|
|
42
|
+
toJson: () => null,
|
|
43
|
+
toString: () => constants_1.EMPTY_CELL,
|
|
44
|
+
});
|
|
47
45
|
exports.default = Tile;
|
package/build/VerticalPattern.js
CHANGED
|
@@ -1,85 +1,39 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
18
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
19
|
-
if (!m) return o;
|
|
20
|
-
var i = m.call(o), r, ar = [], e;
|
|
21
|
-
try {
|
|
22
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
23
|
-
}
|
|
24
|
-
catch (error) { e = { error: error }; }
|
|
25
|
-
finally {
|
|
26
|
-
try {
|
|
27
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
28
|
-
}
|
|
29
|
-
finally { if (e) throw e.error; }
|
|
30
|
-
}
|
|
31
|
-
return ar;
|
|
32
|
-
};
|
|
33
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
34
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
35
|
-
if (ar || !(i in from)) {
|
|
36
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
37
|
-
ar[i] = from[i];
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
41
|
-
};
|
|
42
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
43
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
44
4
|
};
|
|
45
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
function VerticalPattern() {
|
|
50
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
51
|
-
}
|
|
52
|
-
VerticalPattern.prototype.clone = function () {
|
|
6
|
+
const Pattern_1 = __importDefault(require("./Pattern"));
|
|
7
|
+
class VerticalPattern extends Pattern_1.default {
|
|
8
|
+
clone() {
|
|
53
9
|
return new VerticalPattern({
|
|
54
10
|
board: this.board,
|
|
55
|
-
cells: this.cells.map(
|
|
11
|
+
cells: this.cells.map((cell) => cell.clone()),
|
|
56
12
|
});
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var collisions = [];
|
|
13
|
+
}
|
|
14
|
+
getCollisions() {
|
|
15
|
+
const collisions = [];
|
|
61
16
|
this.cells
|
|
62
|
-
.filter(
|
|
63
|
-
.forEach(
|
|
64
|
-
|
|
65
|
-
|
|
17
|
+
.filter((cell) => cell.isEmpty && (this.board.collidesLeft(cell) || this.board.collidesRight(cell)))
|
|
18
|
+
.forEach((cell) => {
|
|
19
|
+
const row = this.board.getRow(cell.y);
|
|
20
|
+
let x = cell.x - 1;
|
|
66
21
|
while (x >= 0 && row[x].hasTile()) {
|
|
67
22
|
--x;
|
|
68
23
|
}
|
|
69
|
-
|
|
24
|
+
const previousCells = row.slice(x + 1, cell.x);
|
|
70
25
|
x = cell.x + 1;
|
|
71
26
|
while (x < row.length && row[x].hasTile()) {
|
|
72
27
|
++x;
|
|
73
28
|
}
|
|
74
|
-
|
|
75
|
-
|
|
29
|
+
const nextCells = row.slice(cell.x + 1, x);
|
|
30
|
+
const cells = [...previousCells, cell, ...nextCells];
|
|
76
31
|
if (cells.length > 1) {
|
|
77
|
-
|
|
32
|
+
const pattern = new Pattern_1.default({ board: this.board, cells });
|
|
78
33
|
collisions.push(pattern);
|
|
79
34
|
}
|
|
80
35
|
});
|
|
81
36
|
return collisions;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}(Pattern_1.default));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
85
39
|
exports.default = VerticalPattern;
|
package/build/WordBonus.js
CHANGED
|
@@ -1,42 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
18
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
19
4
|
};
|
|
20
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
_this.type = constants_1.BONUS_WORD;
|
|
28
|
-
return _this;
|
|
6
|
+
const constants_1 = require("@scrabble-solver/constants");
|
|
7
|
+
const Bonus_1 = __importDefault(require("./Bonus"));
|
|
8
|
+
class WordBonus extends Bonus_1.default {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.type = constants_1.BONUS_WORD;
|
|
29
12
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
enumerable: false,
|
|
38
|
-
configurable: true
|
|
39
|
-
});
|
|
40
|
-
return WordBonus;
|
|
41
|
-
}(Bonus_1.default));
|
|
13
|
+
get value() {
|
|
14
|
+
return {
|
|
15
|
+
characterMultiplier: 1,
|
|
16
|
+
wordMultiplier: this.multiplier,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
}
|
|
42
20
|
exports.default = WordBonus;
|
package/build/WordDefinition.js
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var definitions = _a.definitions, isAllowed = _a.isAllowed, word = _a.word;
|
|
3
|
+
class WordDefinition {
|
|
4
|
+
constructor({ definitions, isAllowed, word }) {
|
|
6
5
|
this.definitions = definitions;
|
|
7
6
|
this.isAllowed = isAllowed;
|
|
8
7
|
this.word = word;
|
|
9
8
|
}
|
|
10
|
-
|
|
9
|
+
static fromJson(json) {
|
|
11
10
|
if (!json) {
|
|
12
11
|
return WordDefinition.Null;
|
|
13
12
|
}
|
|
@@ -16,20 +15,19 @@ var WordDefinition = /** @class */ (function () {
|
|
|
16
15
|
isAllowed: json.isAllowed,
|
|
17
16
|
word: json.word,
|
|
18
17
|
});
|
|
19
|
-
}
|
|
20
|
-
|
|
18
|
+
}
|
|
19
|
+
toJson() {
|
|
21
20
|
return {
|
|
22
21
|
definitions: this.definitions,
|
|
23
22
|
isAllowed: this.isAllowed,
|
|
24
23
|
word: this.word,
|
|
25
24
|
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
}());
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
WordDefinition.Null = Object.freeze({
|
|
28
|
+
definitions: [],
|
|
29
|
+
isAllowed: false,
|
|
30
|
+
word: '',
|
|
31
|
+
toJson: () => null,
|
|
32
|
+
});
|
|
35
33
|
exports.default = WordDefinition;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@scrabble-solver/types",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.3",
|
|
4
4
|
"description": "Scrabble Solver 2 - Types",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"clean:force": "npm run clean && rimraf package-lock.json"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@scrabble-solver/constants": "^2.8.
|
|
27
|
+
"@scrabble-solver/constants": "^2.8.3"
|
|
28
28
|
},
|
|
29
|
-
"gitHead": "
|
|
29
|
+
"gitHead": "116f214733e7ad071044f556bcf67e867da3d9ca"
|
|
30
30
|
}
|