scrabble-solver 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.
Files changed (184) hide show
  1. package/.eslintrc.js +1 -1
  2. package/lerna.json +1 -1
  3. package/package.json +1 -1
  4. package/packages/configs/build/getConfig.js +6 -12
  5. package/packages/configs/build/getLocaleConfig.js +2 -2
  6. package/packages/configs/build/isConfigId.js +5 -8
  7. package/packages/configs/build/literaki/bonuses.js +2 -2
  8. package/packages/configs/build/literaki/literaki.js +14 -27
  9. package/packages/configs/build/literaki/tiles/tilesDe.js +1 -1
  10. package/packages/configs/build/literaki/tiles/tilesEn.js +1 -1
  11. package/packages/configs/build/literaki/tiles/tilesEs.js +1 -1
  12. package/packages/configs/build/literaki/tiles/tilesFr.js +1 -1
  13. package/packages/configs/build/literaki/tiles/tilesPl.js +1 -1
  14. package/packages/configs/build/scrabble/bonuses.js +2 -2
  15. package/packages/configs/build/scrabble/scrabble.js +14 -27
  16. package/packages/configs/build/scrabble/tiles/tilesDe.js +1 -1
  17. package/packages/configs/build/scrabble/tiles/tilesEn.js +1 -1
  18. package/packages/configs/build/scrabble/tiles/tilesEs.js +1 -1
  19. package/packages/configs/build/scrabble/tiles/tilesFr.js +1 -1
  20. package/packages/configs/build/scrabble/tiles/tilesPl.js +1 -1
  21. package/packages/configs/package.json +3 -3
  22. package/packages/constants/package.json +1 -1
  23. package/packages/dictionaries/build/Dictionaries.js +37 -110
  24. package/packages/dictionaries/build/constants/index.js +2 -2
  25. package/packages/dictionaries/build/index.js +1 -1
  26. package/packages/dictionaries/build/lib/DiskCache.js +31 -91
  27. package/packages/dictionaries/build/lib/LayeredCache.js +37 -101
  28. package/packages/dictionaries/build/lib/MemoryCache.js +16 -17
  29. package/packages/dictionaries/build/lib/createAsyncProxy.js +14 -58
  30. package/packages/dictionaries/build/lib/createCacheTimestampComparator.js +4 -4
  31. package/packages/dictionaries/build/lib/downloadDictionary.js +10 -54
  32. package/packages/dictionaries/build/lib/getDictionaryFilepath.js +4 -4
  33. package/packages/dictionaries/build/lib/readFile.js +12 -50
  34. package/packages/dictionaries/build/lib/writeFile.js +12 -50
  35. package/packages/dictionaries/package-lock.json +2 -2
  36. package/packages/dictionaries/package.json +4 -4
  37. package/packages/dictionaries/src/lib/LayeredCache.ts +17 -8
  38. package/packages/logger/build/constants.js +2 -2
  39. package/packages/logger/build/logger.js +4 -4
  40. package/packages/logger/package-lock.json +2 -2
  41. package/packages/logger/package.json +1 -1
  42. package/packages/scrabble-solver/.next/BUILD_ID +1 -1
  43. package/packages/scrabble-solver/.next/build-manifest.json +5 -5
  44. package/packages/scrabble-solver/.next/cache/.tsbuildinfo +1 -1
  45. package/packages/scrabble-solver/.next/cache/eslint/.cache_8dgz12 +1 -1
  46. package/packages/scrabble-solver/.next/cache/next-server.js.nft.json +1 -1
  47. package/packages/scrabble-solver/.next/cache/webpack/client-production/0.pack +0 -0
  48. package/packages/scrabble-solver/.next/cache/webpack/client-production/index.pack +0 -0
  49. package/packages/scrabble-solver/.next/cache/webpack/server-production/0.pack +0 -0
  50. package/packages/scrabble-solver/.next/cache/webpack/server-production/index.pack +0 -0
  51. package/packages/scrabble-solver/.next/next-server.js.nft.json +1 -1
  52. package/packages/scrabble-solver/.next/prerender-manifest.json +1 -1
  53. package/packages/scrabble-solver/.next/routes-manifest.json +1 -1
  54. package/packages/scrabble-solver/.next/server/chunks/413.js +391 -673
  55. package/packages/scrabble-solver/.next/server/chunks/515.js +414 -500
  56. package/packages/scrabble-solver/.next/server/chunks/907.js +397 -679
  57. package/packages/scrabble-solver/.next/server/middleware-build-manifest.js +1 -1
  58. package/packages/scrabble-solver/.next/server/pages/404.html +1 -1
  59. package/packages/scrabble-solver/.next/server/pages/404.js.nft.json +1 -1
  60. package/packages/scrabble-solver/.next/server/pages/500.html +2 -2
  61. package/packages/scrabble-solver/.next/server/pages/_app.js +7 -10
  62. package/packages/scrabble-solver/.next/server/pages/_app.js.nft.json +1 -1
  63. package/packages/scrabble-solver/.next/server/pages/_document.js +0 -3
  64. package/packages/scrabble-solver/.next/server/pages/_error.js.nft.json +1 -1
  65. package/packages/scrabble-solver/.next/server/pages/api/dictionary/[locale]/[word].js +114 -171
  66. package/packages/scrabble-solver/.next/server/pages/api/solve.js +428 -1164
  67. package/packages/scrabble-solver/.next/server/pages/index.html +1 -1
  68. package/packages/scrabble-solver/.next/server/pages/index.js +2 -2
  69. package/packages/scrabble-solver/.next/server/pages/index.js.nft.json +1 -1
  70. package/packages/scrabble-solver/.next/server/pages/index.json +1 -1
  71. package/packages/scrabble-solver/.next/static/OhUvTNKwyrrzmNwKBnpUU/_buildManifest.js +1 -0
  72. package/packages/scrabble-solver/.next/static/{nXSSCVI5pGlS_NxEidxkS → OhUvTNKwyrrzmNwKBnpUU}/_ssgManifest.js +0 -0
  73. package/packages/scrabble-solver/.next/static/chunks/{195-fcadef5c6eed8338.js → 195-4b75c9c697b7b455.js} +1 -1
  74. package/packages/scrabble-solver/.next/static/chunks/pages/_app-72522bfb306a8aef.js +1 -0
  75. package/packages/scrabble-solver/.next/trace +42 -42
  76. package/packages/scrabble-solver/package-lock.json +2 -2
  77. package/packages/scrabble-solver/package.json +8 -8
  78. package/packages/scrabble-solver/src/components/Board/Board.tsx +1 -1
  79. package/packages/scrabble-solver/src/components/Board/BoardPure.tsx +1 -1
  80. package/packages/scrabble-solver/src/components/Board/components/Cell/Button.tsx +1 -1
  81. package/packages/scrabble-solver/src/components/Board/components/Cell/Cell.tsx +1 -1
  82. package/packages/scrabble-solver/src/components/Board/components/Cell/CellPure.tsx +1 -1
  83. package/packages/scrabble-solver/src/components/Button/Button.tsx +1 -1
  84. package/packages/scrabble-solver/src/components/Checkbox/Checkbox.tsx +1 -1
  85. package/packages/scrabble-solver/src/components/Dictionary/Dictionary.tsx +1 -1
  86. package/packages/scrabble-solver/src/components/DictionaryInput/DictionaryInput.tsx +1 -1
  87. package/packages/scrabble-solver/src/components/EmptyState/EmptyState.tsx +1 -1
  88. package/packages/scrabble-solver/src/components/Key/Key.tsx +1 -1
  89. package/packages/scrabble-solver/src/components/KeyMap/KeyMap.tsx +1 -1
  90. package/packages/scrabble-solver/src/components/KeyMap/components/Mapping/Mapping.tsx +1 -1
  91. package/packages/scrabble-solver/src/components/Loading/Loading.tsx +1 -1
  92. package/packages/scrabble-solver/src/components/Logo/Logo.tsx +1 -1
  93. package/packages/scrabble-solver/src/components/NavButtons/NavButtons.tsx +1 -1
  94. package/packages/scrabble-solver/src/components/NotFound/NotFound.tsx +1 -1
  95. package/packages/scrabble-solver/src/components/PlainTiles/PlainTiles.tsx +1 -1
  96. package/packages/scrabble-solver/src/components/PlainTiles/Tile.tsx +1 -1
  97. package/packages/scrabble-solver/src/components/Rack/Rack.tsx +1 -1
  98. package/packages/scrabble-solver/src/components/Rack/RackTile.tsx +1 -1
  99. package/packages/scrabble-solver/src/components/Radio/Radio.tsx +1 -1
  100. package/packages/scrabble-solver/src/components/RemainingTiles/Character.tsx +1 -1
  101. package/packages/scrabble-solver/src/components/RemainingTiles/RemainingTiles.tsx +1 -1
  102. package/packages/scrabble-solver/src/components/Results/Cell.tsx +1 -1
  103. package/packages/scrabble-solver/src/components/Results/HeaderButton.tsx +1 -1
  104. package/packages/scrabble-solver/src/components/Results/Result.tsx +1 -1
  105. package/packages/scrabble-solver/src/components/Results/Results.tsx +1 -1
  106. package/packages/scrabble-solver/src/components/Results/SolveButton.tsx +1 -1
  107. package/packages/scrabble-solver/src/components/ResultsInput/ResultsInput.tsx +1 -1
  108. package/packages/scrabble-solver/src/components/Screen/Screen.tsx +1 -1
  109. package/packages/scrabble-solver/src/components/Settings/Settings.tsx +1 -1
  110. package/packages/scrabble-solver/src/components/Settings/components/AutoGroupTilesSetting/AutoGroupTilesSetting.tsx +1 -1
  111. package/packages/scrabble-solver/src/components/Settings/components/ConfigSetting/ConfigSetting.tsx +1 -1
  112. package/packages/scrabble-solver/src/components/Settings/components/LocaleSetting/LocaleSetting.tsx +1 -1
  113. package/packages/scrabble-solver/src/components/Sidebar/Sidebar.tsx +1 -1
  114. package/packages/scrabble-solver/src/components/Sidebar/components/Section/Section.tsx +1 -1
  115. package/packages/scrabble-solver/src/components/Splash/Splash.tsx +1 -1
  116. package/packages/scrabble-solver/src/components/SquareButton/Link.tsx +1 -1
  117. package/packages/scrabble-solver/src/components/SquareButton/SquareButton.tsx +1 -1
  118. package/packages/scrabble-solver/src/components/Tile/Tile.tsx +1 -1
  119. package/packages/scrabble-solver/src/components/Tile/TilePure.tsx +1 -1
  120. package/packages/scrabble-solver/src/components/Tooltip/useTooltip.tsx +1 -1
  121. package/packages/scrabble-solver/src/components/Well/Well.tsx +1 -1
  122. package/packages/scrabble-solver/src/hooks/usePortal.tsx +19 -9
  123. package/packages/scrabble-solver/src/lib/memoize.ts +1 -1
  124. package/packages/scrabble-solver/src/pages/_app.tsx +1 -1
  125. package/packages/scrabble-solver/src/pages/_document.tsx +1 -1
  126. package/packages/scrabble-solver/src/pages/index.tsx +1 -1
  127. package/packages/solver/build/PatternsFiller.js +37 -67
  128. package/packages/solver/build/PatternsGenerator.js +42 -75
  129. package/packages/solver/build/ScoresCalculator.js +20 -24
  130. package/packages/solver/build/Solver.js +19 -23
  131. package/packages/solver/package-lock.json +2 -2
  132. package/packages/solver/package.json +5 -5
  133. package/packages/solver/src/PatternsFiller.ts +3 -2
  134. package/packages/types/build/Board.js +68 -85
  135. package/packages/types/build/Bonus.js +15 -21
  136. package/packages/types/build/Cell.js +30 -32
  137. package/packages/types/build/CharacterBonus.js +18 -40
  138. package/packages/types/build/Config.js +62 -117
  139. package/packages/types/build/HorizontalPattern.js +17 -63
  140. package/packages/types/build/Pattern.js +36 -40
  141. package/packages/types/build/Result.js +23 -46
  142. package/packages/types/build/Tile.js +22 -24
  143. package/packages/types/build/VerticalPattern.js +17 -63
  144. package/packages/types/build/WordBonus.js +13 -35
  145. package/packages/types/build/WordDefinition.js +13 -15
  146. package/packages/types/package.json +2 -2
  147. package/packages/word-definitions/build/crawl/crawl.js +15 -16
  148. package/packages/word-definitions/build/crawl/crawlEnglish.js +3 -3
  149. package/packages/word-definitions/build/crawl/crawlFrench.js +3 -3
  150. package/packages/word-definitions/build/crawl/crawlGerman.js +3 -3
  151. package/packages/word-definitions/build/crawl/crawlPolish.js +3 -3
  152. package/packages/word-definitions/build/crawl/crawlSpanish.js +3 -3
  153. package/packages/word-definitions/build/getWordDefinition.js +9 -52
  154. package/packages/word-definitions/build/lib/normalizeDefinition.js +15 -15
  155. package/packages/word-definitions/build/lib/request.js +8 -20
  156. package/packages/word-definitions/build/lib/unique.js +1 -1
  157. package/packages/word-definitions/build/parse/parse.js +18 -19
  158. package/packages/word-definitions/build/parse/parseEnglish.js +5 -5
  159. package/packages/word-definitions/build/parse/parseFrench.js +5 -5
  160. package/packages/word-definitions/build/parse/parseGerman.js +6 -6
  161. package/packages/word-definitions/build/parse/parsePolish.js +6 -6
  162. package/packages/word-definitions/build/parse/parseSpanish.js +9 -9
  163. package/packages/word-definitions/package-lock.json +8 -8
  164. package/packages/word-definitions/package.json +2 -2
  165. package/packages/word-lists/build/getDeDeWordList.js +5 -43
  166. package/packages/word-lists/build/getEnGbWordList.js +5 -43
  167. package/packages/word-lists/build/getEnUsWordList.js +5 -43
  168. package/packages/word-lists/build/getEsEsWordList.js +7 -50
  169. package/packages/word-lists/build/getFrFrWordList.js +9 -50
  170. package/packages/word-lists/build/getPlPlWordList.js +34 -91
  171. package/packages/word-lists/build/getWordList.js +16 -17
  172. package/packages/word-lists/build/lib/downloadFile.js +5 -5
  173. package/packages/word-lists/build/lib/downloadHtml.js +8 -8
  174. package/packages/word-lists/build/lib/extractWords.js +5 -5
  175. package/packages/word-lists/build/lib/findFirstWordIndex.js +6 -6
  176. package/packages/word-lists/build/lib/getHash.js +2 -5
  177. package/packages/word-lists/build/lib/getTempFilename.js +3 -3
  178. package/packages/word-lists/build/lib/getTxtWordList.js +12 -56
  179. package/packages/word-lists/package-lock.json +2 -2
  180. package/packages/word-lists/package.json +2 -2
  181. package/packages/word-lists/src/getFrFrWordList.ts +1 -0
  182. package/tsconfig.json +1 -1
  183. package/packages/scrabble-solver/.next/static/chunks/pages/_app-f4030148d742bcd2.js +0 -1
  184. package/packages/scrabble-solver/.next/static/nXSSCVI5pGlS_NxEidxkS/_buildManifest.js +0 -1
@@ -1,104 +1,74 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
2
  Object.defineProperty(exports, "__esModule", { value: true });
28
- var constants_1 = require("@scrabble-solver/constants");
29
- var types_1 = require("@scrabble-solver/types");
30
- var PatternsFiller = /** @class */ (function () {
31
- function PatternsFiller(config, trie) {
3
+ const constants_1 = require("@scrabble-solver/constants");
4
+ const types_1 = require("@scrabble-solver/types");
5
+ class PatternsFiller {
6
+ constructor(config, trie) {
32
7
  this.config = config;
33
8
  this.trie = trie;
34
9
  }
35
- PatternsFiller.prototype.fill = function (pattern, tiles) {
36
- var patterns = [];
10
+ fill(pattern, tiles) {
11
+ const patterns = [];
37
12
  if (pattern.getNumberOfEmptyCells() > tiles.length) {
38
13
  return [];
39
14
  }
40
- var onPatternFound = function (newPattern) { return patterns.push(newPattern); };
41
- var tilesPermutations = this.generateBlankTilesPermutations(tiles);
42
- for (var index = 0; index < tilesPermutations.length; ++index) {
43
- var tilesPermutation = tilesPermutations[index];
15
+ const onPatternFound = (newPattern) => patterns.push(newPattern);
16
+ const tilesPermutations = this.generateBlankTilesPermutations(tiles);
17
+ for (let index = 0; index < tilesPermutations.length; ++index) {
18
+ const tilesPermutation = tilesPermutations[index];
44
19
  this.fillPattern(pattern, String(pattern), tilesPermutation, onPatternFound);
45
20
  }
46
21
  return patterns;
47
- };
48
- PatternsFiller.prototype.fillPattern = function (pattern, word, tiles, onPatternFound) {
49
- var indexOfFirstCellWithoutTile = pattern.getIndexOfFirstCellWithoutTile();
22
+ }
23
+ fillPattern(pattern, word, tiles, onPatternFound) {
24
+ const indexOfFirstCellWithoutTile = pattern.getIndexOfFirstCellWithoutTile();
50
25
  if (indexOfFirstCellWithoutTile === -1) {
51
26
  if (this.canAddPattern(pattern, word)) {
52
27
  onPatternFound(pattern.clone());
53
28
  }
54
29
  }
55
30
  else {
56
- for (var index = 0; index < tiles.length; ++index) {
57
- var tile = tiles[index];
58
- var remainingTiles = tiles.slice(0, index).concat(tiles.slice(index + 1));
59
- var previousTile = pattern.cells[indexOfFirstCellWithoutTile].tile;
31
+ for (let index = 0; index < tiles.length; ++index) {
32
+ const tile = tiles[index];
33
+ const previousTile = pattern.cells[indexOfFirstCellWithoutTile].tile;
60
34
  pattern.cells[indexOfFirstCellWithoutTile].tile = tile;
61
- var indexOfNextCellWithoutTile = pattern.getIndexOfFirstCellWithoutTile();
62
- var indexOfFirstEmptyLetter = word.indexOf(constants_1.EMPTY_CELL);
63
- var newWordPrefix = word.substring(0, indexOfFirstEmptyLetter) + tile.character;
64
- var newWord = newWordPrefix + word.substring(indexOfFirstEmptyLetter + 1);
35
+ const indexOfNextCellWithoutTile = pattern.getIndexOfFirstCellWithoutTile();
36
+ const indexOfFirstEmptyLetter = word.indexOf(constants_1.EMPTY_CELL);
37
+ const newWordPrefix = word.substring(0, indexOfFirstEmptyLetter) + tile.character;
38
+ const newWord = newWordPrefix + word.substring(indexOfFirstEmptyLetter + 1);
65
39
  if (indexOfNextCellWithoutTile === -1) {
66
40
  if (this.canAddPattern(pattern, newWord)) {
67
41
  onPatternFound(pattern.clone());
68
42
  }
69
43
  }
70
44
  else if (this.trie.hasPrefix(newWordPrefix)) {
71
- this.fillPattern(pattern, newWord, remainingTiles, onPatternFound);
45
+ tiles.splice(index, 1);
46
+ this.fillPattern(pattern, newWord, tiles, onPatternFound);
47
+ tiles.splice(index, 0, tile);
72
48
  }
73
49
  pattern.cells[indexOfFirstCellWithoutTile].tile = previousTile;
74
50
  }
75
51
  }
76
- };
77
- PatternsFiller.prototype.canAddPattern = function (pattern, word) {
78
- var _this = this;
52
+ }
53
+ canAddPattern(pattern, word) {
79
54
  return (this.trie.has(word) &&
80
55
  pattern
81
56
  .getCollisions()
82
57
  .map(String)
83
- .every(function (collision) { return _this.trie.has(collision); }));
84
- };
85
- PatternsFiller.prototype.generateBlankTilesPermutations = function (tiles) {
86
- var _this = this;
87
- var alphabet = this.config.alphabet;
88
- var firstBlankIndex = tiles.findIndex(function (_a) {
89
- var character = _a.character, isBlank = _a.isBlank;
90
- return isBlank && !alphabet.includes(character);
91
- });
58
+ .every((collision) => this.trie.has(collision)));
59
+ }
60
+ generateBlankTilesPermutations(tiles) {
61
+ const { alphabet } = this.config;
62
+ const firstBlankIndex = tiles.findIndex(({ character, isBlank }) => isBlank && !alphabet.includes(character));
92
63
  if (firstBlankIndex === -1) {
93
64
  return [tiles];
94
65
  }
95
- var remainingTiles = tiles.slice(0, firstBlankIndex).concat(tiles.slice(firstBlankIndex + 1));
96
- return this.config.alphabet.reduce(function (permutations, character) {
97
- var newTile = new types_1.Tile({ character: character, isBlank: true });
98
- var newTiles = __spreadArray(__spreadArray([], __read(remainingTiles), false), [newTile], false);
99
- return permutations.concat(_this.generateBlankTilesPermutations(newTiles));
66
+ const remainingTiles = tiles.slice(0, firstBlankIndex).concat(tiles.slice(firstBlankIndex + 1));
67
+ return this.config.alphabet.reduce((permutations, character) => {
68
+ const newTile = new types_1.Tile({ character, isBlank: true });
69
+ const newTiles = [...remainingTiles, newTile];
70
+ return permutations.concat(this.generateBlankTilesPermutations(newTiles));
100
71
  }, []);
101
- };
102
- return PatternsFiller;
103
- }());
72
+ }
73
+ }
104
74
  exports.default = PatternsFiller;
@@ -1,95 +1,62 @@
1
1
  "use strict";
2
- var __read = (this && this.__read) || function (o, n) {
3
- var m = typeof Symbol === "function" && o[Symbol.iterator];
4
- if (!m) return o;
5
- var i = m.call(o), r, ar = [], e;
6
- try {
7
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
8
- }
9
- catch (error) { e = { error: error }; }
10
- finally {
11
- try {
12
- if (r && !r.done && (m = i["return"])) m.call(i);
13
- }
14
- finally { if (e) throw e.error; }
15
- }
16
- return ar;
17
- };
18
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
19
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
20
- if (ar || !(i in from)) {
21
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
- ar[i] = from[i];
23
- }
24
- }
25
- return to.concat(ar || Array.prototype.slice.call(from));
26
- };
27
2
  Object.defineProperty(exports, "__esModule", { value: true });
28
- var types_1 = require("@scrabble-solver/types");
29
- var PatternsGenerator = /** @class */ (function () {
30
- function PatternsGenerator(config) {
3
+ const types_1 = require("@scrabble-solver/types");
4
+ class PatternsGenerator {
5
+ constructor(config) {
31
6
  this.config = config;
32
7
  }
33
- PatternsGenerator.prototype.generate = function (board) {
34
- return __spreadArray(__spreadArray([], __read(this.generateHorizontal(board)), false), __read(this.generateVertical(board)), false);
35
- };
36
- PatternsGenerator.prototype.generateHorizontal = function (board) {
8
+ generate(board) {
9
+ return [...this.generateHorizontal(board), ...this.generateVertical(board)];
10
+ }
11
+ generateHorizontal(board) {
37
12
  return this.generatePatterns({
38
- board: board,
39
- getNthVector: function (index) { return board.getRow(index); },
13
+ board,
14
+ getNthVector: (index) => board.getRow(index),
40
15
  numberOfVectors: this.config.boardHeight,
41
16
  PatternModel: types_1.HorizontalPattern,
42
17
  });
43
- };
44
- PatternsGenerator.prototype.generateVertical = function (board) {
18
+ }
19
+ generateVertical(board) {
45
20
  return this.generatePatterns({
46
- board: board,
47
- getNthVector: function (index) { return board.getColumn(index); },
21
+ board,
22
+ getNthVector: (index) => board.getColumn(index),
48
23
  numberOfVectors: this.config.boardWidth,
49
24
  PatternModel: types_1.VerticalPattern,
50
25
  });
51
- };
52
- PatternsGenerator.prototype.generatePatterns = function (_a) {
53
- var _this = this;
54
- var board = _a.board, getNthVector = _a.getNthVector, numberOfVectors = _a.numberOfVectors, PatternModel = _a.PatternModel;
55
- return this.generateVectors({ getNthVector: getNthVector, numberOfVectors: numberOfVectors }).reduce(function (patterns, cells) {
56
- return patterns.concat(_this.generateCellsPatterns({ board: board, PatternModel: PatternModel, cells: cells }));
26
+ }
27
+ generatePatterns({ board, getNthVector, numberOfVectors, PatternModel, }) {
28
+ return this.generateVectors({ getNthVector, numberOfVectors }).reduce((patterns, cells) => {
29
+ return patterns.concat(this.generateCellsPatterns({ board, PatternModel, cells }));
57
30
  }, []);
58
- };
59
- PatternsGenerator.prototype.generateVectors = function (_a) {
60
- var getNthVector = _a.getNthVector, numberOfVectors = _a.numberOfVectors;
31
+ }
32
+ generateVectors({ getNthVector, numberOfVectors, }) {
61
33
  return Array(numberOfVectors)
62
34
  .fill(0)
63
- .map(function (_, index) { return getNthVector(index); });
64
- };
65
- PatternsGenerator.prototype.generateCellsPatterns = function (_a) {
66
- var _this = this;
67
- var board = _a.board, cells = _a.cells, PatternModel = _a.PatternModel;
68
- return this.generateStartIndices(cells).reduce(function (patterns, startIndex) {
69
- return patterns.concat(_this.generateEndIndices(cells, startIndex).reduce(function (placeablePatterns, endIndex) {
70
- var pattern = new PatternModel({
71
- board: board,
72
- cells: cells.slice(startIndex, endIndex + 1),
73
- });
74
- if (pattern.canBePlaced(_this.config)) {
75
- placeablePatterns.push(pattern);
76
- }
77
- return placeablePatterns;
78
- }, []));
79
- }, []);
80
- };
81
- PatternsGenerator.prototype.generateStartIndices = function (cells) {
35
+ .map((_, index) => getNthVector(index));
36
+ }
37
+ generateCellsPatterns({ board, cells, PatternModel, }) {
38
+ return this.generateStartIndices(cells).reduce((patterns, startIndex) => patterns.concat(this.generateEndIndices(cells, startIndex).reduce((placeablePatterns, endIndex) => {
39
+ const pattern = new PatternModel({
40
+ board,
41
+ cells: cells.slice(startIndex, endIndex + 1),
42
+ });
43
+ if (pattern.canBePlaced(this.config)) {
44
+ placeablePatterns.push(pattern);
45
+ }
46
+ return placeablePatterns;
47
+ }, [])), []);
48
+ }
49
+ generateStartIndices(cells) {
82
50
  return Array(cells.length - 1)
83
51
  .fill(0)
84
- .map(function (_, startIndex) { return startIndex; })
85
- .filter(function (startIndex) { return startIndex === 0 || !cells[startIndex - 1].hasTile(); });
86
- };
87
- PatternsGenerator.prototype.generateEndIndices = function (cells, startIndex) {
52
+ .map((_, startIndex) => startIndex)
53
+ .filter((startIndex) => startIndex === 0 || !cells[startIndex - 1].hasTile());
54
+ }
55
+ generateEndIndices(cells, startIndex) {
88
56
  return Array(cells.length - startIndex - 1)
89
57
  .fill(0)
90
- .map(function (_, endIndex) { return endIndex + startIndex + 1; })
91
- .filter(function (endIndex) { return endIndex >= cells.length - 1 || !cells[endIndex + 1].hasTile(); });
92
- };
93
- return PatternsGenerator;
94
- }());
58
+ .map((_, endIndex) => endIndex + startIndex + 1)
59
+ .filter((endIndex) => endIndex >= cells.length - 1 || !cells[endIndex + 1].hasTile());
60
+ }
61
+ }
95
62
  exports.default = PatternsGenerator;
@@ -1,14 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- var constants_1 = require("@scrabble-solver/constants");
4
- var ScoresCalculator = /** @class */ (function () {
5
- function ScoresCalculator(config) {
6
- var _this = this;
7
- this.reduceCellScore = function (_a, cell) {
8
- var multiplier = _a.multiplier, score = _a.score;
9
- var bonus = _this.config.getCellBonus(cell);
10
- var _b = bonus && bonus.canApply(_this.config, cell) ? bonus.value : constants_1.NO_BONUS, characterMultiplier = _b.characterMultiplier, wordMultiplier = _b.wordMultiplier;
11
- var characterScore = cell.tile.isBlank ? _this.config.blankScore : _this.config.pointsMap[cell.tile.character];
3
+ const constants_1 = require("@scrabble-solver/constants");
4
+ class ScoresCalculator {
5
+ constructor(config) {
6
+ this.reduceCellScore = ({ multiplier, score }, cell) => {
7
+ const bonus = this.config.getCellBonus(cell);
8
+ const { characterMultiplier, wordMultiplier } = bonus && bonus.canApply(this.config, cell) ? bonus.value : constants_1.NO_BONUS;
9
+ const characterScore = cell.tile.isBlank ? this.config.blankScore : this.config.pointsMap[cell.tile.character];
12
10
  return {
13
11
  multiplier: multiplier * wordMultiplier,
14
12
  score: score + characterScore * characterMultiplier,
@@ -16,26 +14,24 @@ var ScoresCalculator = /** @class */ (function () {
16
14
  };
17
15
  this.config = config;
18
16
  }
19
- ScoresCalculator.prototype.calculate = function (pattern) {
17
+ calculate(pattern) {
20
18
  return this.calculatePatternScoreWithCollisions(pattern) + this.calculateBonusScore(pattern);
21
- };
22
- ScoresCalculator.prototype.calculateBonusScore = function (pattern) {
23
- var areAllTilesUsed = pattern.getNumberOfEmptyCells() === this.config.maximumNumberOfCharacters;
19
+ }
20
+ calculateBonusScore(pattern) {
21
+ const areAllTilesUsed = pattern.getNumberOfEmptyCells() === this.config.maximumNumberOfCharacters;
24
22
  return areAllTilesUsed ? this.config.allTilesBonusScore : 0;
25
- };
26
- ScoresCalculator.prototype.calculatePatternScoreWithCollisions = function (pattern) {
27
- var _this = this;
23
+ }
24
+ calculatePatternScoreWithCollisions(pattern) {
28
25
  return pattern
29
26
  .getCollisions()
30
- .reduce(function (patternsScore, collisionPattern) { return patternsScore + _this.calculatePatternScore(collisionPattern); }, this.calculatePatternScore(pattern));
31
- };
32
- ScoresCalculator.prototype.calculatePatternScore = function (pattern) {
33
- var _a = pattern.cells.reduce(this.reduceCellScore, {
27
+ .reduce((patternsScore, collisionPattern) => patternsScore + this.calculatePatternScore(collisionPattern), this.calculatePatternScore(pattern));
28
+ }
29
+ calculatePatternScore(pattern) {
30
+ const { multiplier, score } = pattern.cells.reduce(this.reduceCellScore, {
34
31
  multiplier: 1,
35
32
  score: 0,
36
- }), multiplier = _a.multiplier, score = _a.score;
33
+ });
37
34
  return score * multiplier;
38
- };
39
- return ScoresCalculator;
40
- }());
35
+ }
36
+ }
41
37
  exports.default = ScoresCalculator;
@@ -3,33 +3,29 @@ 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
- var types_1 = require("@scrabble-solver/types");
7
- var uniqBy_1 = __importDefault(require("lodash/uniqBy"));
8
- var PatternsFiller_1 = __importDefault(require("./PatternsFiller"));
9
- var PatternsGenerator_1 = __importDefault(require("./PatternsGenerator"));
10
- var ScoresCalculator_1 = __importDefault(require("./ScoresCalculator"));
11
- var Solver = /** @class */ (function () {
12
- function Solver(config, trie) {
6
+ const types_1 = require("@scrabble-solver/types");
7
+ const uniqBy_1 = __importDefault(require("lodash/uniqBy"));
8
+ const PatternsFiller_1 = __importDefault(require("./PatternsFiller"));
9
+ const PatternsGenerator_1 = __importDefault(require("./PatternsGenerator"));
10
+ const ScoresCalculator_1 = __importDefault(require("./ScoresCalculator"));
11
+ class Solver {
12
+ constructor(config, trie) {
13
13
  this.patternsFiller = new PatternsFiller_1.default(config, trie);
14
14
  this.patternsGenerator = new PatternsGenerator_1.default(config);
15
15
  this.scoresCalculator = new ScoresCalculator_1.default(config);
16
16
  }
17
- Solver.prototype.solve = function (board, tiles) {
18
- var _this = this;
19
- var patterns = this.patternsGenerator
17
+ solve(board, tiles) {
18
+ const patterns = this.patternsGenerator
20
19
  .generate(board)
21
- .reduce(function (filledPatterns, pattern) { return filledPatterns.concat(_this.patternsFiller.fill(pattern, tiles)); }, []);
22
- var uniquePatterns = (0, uniqBy_1.default)(patterns, function (pattern) { return JSON.stringify(pattern.toJson()); });
23
- var results = uniquePatterns.map(function (pattern, index) {
24
- return new types_1.Result({
25
- cells: pattern.cells,
26
- id: index,
27
- numberOfCollisions: pattern.getCollisions().length,
28
- points: _this.scoresCalculator.calculate(pattern),
29
- });
30
- });
20
+ .reduce((filledPatterns, pattern) => filledPatterns.concat(this.patternsFiller.fill(pattern, tiles)), []);
21
+ const uniquePatterns = (0, uniqBy_1.default)(patterns, (pattern) => JSON.stringify(pattern.toJson()));
22
+ const results = uniquePatterns.map((pattern, index) => new types_1.Result({
23
+ cells: pattern.cells,
24
+ id: index,
25
+ numberOfCollisions: pattern.getCollisions().length,
26
+ points: this.scoresCalculator.calculate(pattern),
27
+ }));
31
28
  return results;
32
- };
33
- return Solver;
34
- }());
29
+ }
30
+ }
35
31
  exports.default = Solver;
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@scrabble-solver/solver",
3
- "version": "2.8.2",
3
+ "version": "2.8.3",
4
4
  "lockfileVersion": 2,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "@scrabble-solver/solver",
9
- "version": "2.8.2",
9
+ "version": "2.8.3",
10
10
  "license": "CC-BY-NC-ND-4.0",
11
11
  "dependencies": {
12
12
  "@kamilmielnik/trie": "^1.0.3",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scrabble-solver/solver",
3
- "version": "2.8.2",
3
+ "version": "2.8.3",
4
4
  "description": "Scrabble Solver 2 - Solver",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -25,13 +25,13 @@
25
25
  },
26
26
  "dependencies": {
27
27
  "@kamilmielnik/trie": "^1.0.3",
28
- "@scrabble-solver/types": "^2.8.2",
28
+ "@scrabble-solver/types": "^2.8.3",
29
29
  "lodash": "^4.17.21"
30
30
  },
31
31
  "devDependencies": {
32
- "@scrabble-solver/configs": "^2.8.2",
33
- "@scrabble-solver/constants": "^2.8.2",
34
- "@scrabble-solver/dictionaries": "^2.8.2",
32
+ "@scrabble-solver/configs": "^2.8.3",
33
+ "@scrabble-solver/constants": "^2.8.3",
34
+ "@scrabble-solver/dictionaries": "^2.8.3",
35
35
  "@types/lodash": "^4.14.185"
36
36
  },
37
37
  "gitHead": "1e2d1ad49a288d4a44196d8e3336740da132c637"
@@ -45,7 +45,6 @@ class PatternsFiller {
45
45
  } else {
46
46
  for (let index = 0; index < tiles.length; ++index) {
47
47
  const tile = tiles[index];
48
- const remainingTiles = tiles.slice(0, index).concat(tiles.slice(index + 1));
49
48
  const previousTile = pattern.cells[indexOfFirstCellWithoutTile].tile;
50
49
  pattern.cells[indexOfFirstCellWithoutTile].tile = tile;
51
50
  const indexOfNextCellWithoutTile = pattern.getIndexOfFirstCellWithoutTile();
@@ -57,7 +56,9 @@ class PatternsFiller {
57
56
  onPatternFound(pattern.clone());
58
57
  }
59
58
  } else if (this.trie.hasPrefix(newWordPrefix)) {
60
- this.fillPattern(pattern, newWord, remainingTiles, onPatternFound);
59
+ tiles.splice(index, 1);
60
+ this.fillPattern(pattern, newWord, tiles, onPatternFound);
61
+ tiles.splice(index, 0, tile);
61
62
  }
62
63
  pattern.cells[indexOfFirstCellWithoutTile].tile = previousTile;
63
64
  }
@@ -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
- var constants_1 = require("@scrabble-solver/constants");
7
- var Cell_1 = __importDefault(require("./Cell"));
8
- var Tile_1 = __importDefault(require("./Tile"));
9
- var Board = /** @class */ (function () {
10
- function Board(_a) {
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
- Board.create = function (width, height) {
15
+ static create(width, height) {
17
16
  return Board.fromStringArray(Array(height).fill(Array(width).fill(' ').join('')));
18
- };
19
- Board.fromJson = function (json) {
17
+ }
18
+ static fromJson(json) {
20
19
  return new Board({
21
- rows: json.map(function (row) { return row.map(Cell_1.default.fromJson); }),
20
+ rows: json.map((row) => row.map(Cell_1.default.fromJson)),
22
21
  });
23
- };
24
- Board.fromStringArray = function (stringArray) {
22
+ }
23
+ static fromStringArray(stringArray) {
25
24
  return new Board({
26
- rows: stringArray.map(function (row, y) {
27
- return row.split('').map(function (character, x) {
28
- return new Cell_1.default({
29
- isEmpty: !character || character === constants_1.EMPTY_CELL,
30
- tile: character === constants_1.EMPTY_CELL ? Tile_1.default.Null : new Tile_1.default({ character: character }),
31
- x: x,
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
- Object.defineProperty(Board.prototype, "center", {
39
- get: function () {
40
- var x = Math.floor(this.numberOfColumns / 2);
41
- var y = Math.floor(this.numberOfRows / 2);
42
- return this.rows[y][x];
43
- },
44
- enumerable: false,
45
- configurable: true
46
- });
47
- Board.prototype.clone = function () {
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
- Board.prototype.collidesDown = function (_a) {
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
- Board.prototype.collidesLeft = function (_a) {
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
- Board.prototype.collidesRight = function (_a) {
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
- Board.prototype.collidesUp = function (_a) {
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
- Board.prototype.equals = function (other) {
56
+ }
57
+ equals(other) {
71
58
  return (this.numberOfColumns === other.numberOfColumns &&
72
59
  this.numberOfRows === other.numberOfRows &&
73
- this.rows.every(function (row, rowIndex) {
74
- return row.every(function (cell, cellIndex) {
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
- Board.prototype.getBlanksCount = function () {
80
- return this.rows.reduce(function (count, row) {
81
- return count + row.reduce(function (rowCount, cell) { return (cell.tile.isBlank ? rowCount + 1 : rowCount); }, 0);
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
- Board.prototype.getColumn = function (index) {
85
- return this.rows.map(function (row) { return row[index]; });
86
- };
87
- Board.prototype.getRow = function (index) {
70
+ }
71
+ getColumn(index) {
72
+ return this.rows.map((row) => row[index]);
73
+ }
74
+ getRow(index) {
88
75
  return this.rows[index];
89
- };
90
- Board.prototype.getTilesCount = function () {
91
- return this.rows.reduce(function (count, row) {
92
- return count + row.reduce(function (rowCount, cell) { return (cell.hasTile() ? rowCount + 1 : rowCount); }, 0);
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
- Board.prototype.isEmpty = function () {
96
- return this.rows.every(function (row) { return row.every(function (_a) {
97
- var isEmpty = _a.isEmpty;
98
- return isEmpty;
99
- }); });
100
- };
101
- Board.prototype.toJson = function () {
102
- return this.rows.map(function (row) { return row.map(function (cell) { return cell.toJson(); }); });
103
- };
104
- Board.prototype.toString = function () {
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
- Board.prototype.updateRow = function (y, updateRow) {
93
+ }
94
+ updateRow(y, updateRow) {
111
95
  this.rows[y] = updateRow(this.rows[y]);
112
- };
113
- return Board;
114
- }());
96
+ }
97
+ }
115
98
  exports.default = Board;