UNPKG

scrabble-solver

Version:

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

22 lines (18 loc) 847 B
import { NO_BONUS } from '@scrabble-solver/constants'; import { type Cell, type Config } from '@scrabble-solver/types'; export const getCellsScore = (config: Config, cells: Cell[]): number => { const total = cells.reduce( ({ multiplier, score }, cell: Cell): { multiplier: number; score: number } => { const bonus = config.getCellBonus(cell); const { characterMultiplier, wordMultiplier } = bonus && bonus.canApply(config, cell) ? bonus.value : NO_BONUS; const characterScore = config.pointsMap[cell.tile.character] || 0; const tileScore = cell.tile.isBlank ? config.blankScore : characterScore; return { multiplier: multiplier * wordMultiplier, score: score + tileScore * characterMultiplier, }; }, { multiplier: 1, score: 0 }, ); return total.score * total.multiplier; };