UNPKG

scrabble-solver

Version:

Scrabble Solver 2 - Free, open-source, cross-platform, multi-language analysis tool for Scrabble, Scrabble Duel, Super Scrabble, Letter League, Literaki, and Kelimelik. Quickly find the top-scoring words using the given board and tiles.

35 lines (34 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.VerticalPattern = void 0; const Pattern_1 = require("./Pattern"); class VerticalPattern extends Pattern_1.Pattern { clone() { return new VerticalPattern(this.board, this.cells.map((cell) => cell.clone())); } getCollisions() { const collisions = []; this.cells .filter((cell) => cell.isEmpty && (this.board.collidesLeft(cell) || this.board.collidesRight(cell))) .forEach((cell) => { const row = this.board.getRow(cell.y); let x = cell.x - 1; while (x >= 0 && row[x].hasTile()) { --x; } const previousCells = row.slice(x + 1, cell.x); x = cell.x + 1; while (x < row.length && row[x].hasTile()) { ++x; } const nextCells = row.slice(cell.x + 1, x); const cells = [...previousCells, cell, ...nextCells]; if (cells.length > 1) { const pattern = new Pattern_1.Pattern(this.board, cells); collisions.push(pattern); } }); return collisions; } } exports.VerticalPattern = VerticalPattern;