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.
57 lines (45 loc) • 1.22 kB
text/typescript
import { EMPTY_CELL } from '@scrabble-solver/constants';
import { type TileJson } from './TileJson';
export class Tile {
public static fromJson = (json: TileJson | null): Tile => {
if (!json) {
return Tile.Null;
}
return new Tile({
character: json.character,
isBlank: json.isBlank,
});
};
public static readonly Null: Tile = Object.freeze({
character: EMPTY_CELL,
isBlank: false,
clone: () => Tile.Null,
equals: (other: Tile) => other === Tile.Null,
toJson: () => null,
toString: () => EMPTY_CELL,
});
public character: string;
public isBlank: boolean;
constructor({ character, isBlank = false }: { character: string; isBlank?: boolean }) {
this.character = character;
this.isBlank = isBlank;
}
public clone(): Tile {
return new Tile({
character: this.character,
isBlank: this.isBlank,
});
}
public equals(other: Tile): boolean {
return this.character === other.character && this.isBlank === other.isBlank;
}
public toJson(): TileJson | null {
return {
character: this.character,
isBlank: this.isBlank,
};
}
public toString(): string {
return this.character;
}
}