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.

51 lines (39 loc) 1.24 kB
import { type BONUS_CHARACTER, type BONUS_WORD } from '@scrabble-solver/constants'; import { type BonusJson } from './BonusJson'; import { type BonusValue } from './BonusValue'; import { type Cell } from './Cell'; import { type Config } from './Config'; export abstract class Bonus { public readonly multiplier: number; public readonly score: number | undefined; public abstract readonly type: typeof BONUS_CHARACTER | typeof BONUS_WORD; public readonly x: number; public readonly y: number; constructor({ multiplier, score, x, y }: { multiplier: number; score?: number; x: number; y: number }) { this.multiplier = multiplier; this.score = score; this.x = x; this.y = y; } public canApply(_config: Config, cell: Cell): boolean { return cell.isEmpty && this.matchesCellCoordinates(cell); } public matchesCellCoordinates(cell: Cell): boolean { return this.x === cell.x && this.y === cell.y; } public toJson(): BonusJson { return { multiplier: this.multiplier, score: this.score, type: this.type, x: this.x, y: this.y, }; } public get value(): BonusValue { return { characterMultiplier: 1, wordMultiplier: 1, }; } }