Skip to main content

A trie-guided solver for the Discord SpellCast word game.

Project description

spellcast-solver

A solver for the Discord SpellCast word game. Give it a board and it finds the highest-scoring words you can spell by linking adjacent tiles.

How it works

SpellCast is a path-finding word game: you spell a word by stepping between tiles that touch (including diagonally), using each tile at most once, and you score letter values modified by bonus tiles.

The solver does a depth-first search over the board, but the key idea is that the search is guided by a trie built from the dictionary. The DFS over the grid and the descent through the trie are the same traversal:

  • Each tile you step onto follows one child edge of the current trie node.
  • If that child does not exist, no word continues down this path, so the whole branch is pruned instantly.
  • Terminal trie nodes carry the full word, so a match never has to rebuild the string it spelled.

This is both cleaner and cheaper than checking a prefix set: extending a path is an O(1) child lookup instead of rebuilding and re-hashing the prefix string at every step, and the trie shares prefixes instead of storing a separate string for each one.

Install

pip install spellcast-solver

The package bundles the public-domain ENABLE word list (~173k words), so it works with no setup. SpellCast does not publish its exact dictionary, but ENABLE is a close match. To use a different list, pass --words PATH on the CLI or load_trie(path) in code.

Usage

spellcast-solve examples/board_redeye.txt --top 10

Output is best score first, with the path and any bonuses applied:

  66  REDEYE           R(2,1) -> E(1,0) -> D(0,0) -> E(0,1) -> Y(0,2) -> E(0,3)  [long]

Board format

One row per line, whitespace-separated cells. Each cell is a letter, optionally followed by /BONUS and/or * for a gem tile. Bonus codes: DL, TL, DW, TW (or 2L, 3L, 2W, 3W). Lines starting with # are comments.

D     E/TL  Y/DW  E     E/DL
E     I/DL  C     A/DL  E
T     R/DW  K     A/TL  A/DL
A     E     G     E     B
B     S     E     W     J

Library

from spellcast_solver import Board, Solver, load_trie

board = Board.parse(open("examples/board_redeye.txt").read())
solver = Solver(board, load_trie())
moves = solver.solve()
print(moves[0].word, moves[0].score)

Scoring

  • Each letter has a fixed point value (see LETTER_VALUES in tiles.py).
  • DL / TL multiply a single tile's value by 2 / 3.
  • DW / TW multiply the whole word by 2 / 3 and stack multiplicatively.
  • Words of six letters or more get a flat +10 long-word bonus, added after the word multiplier (so the multiplier does not apply to the bonus).

Letter values are taken directly from the official SpellCast scoring table (see Sources). Any tile value can still be overridden if your board shows something different.

Development

pip install -e ".[dev]"
pytest

Sources

License

MIT, except the bundled word list (src/spellcast_solver/data/enable.txt), which is the ENABLE word list and is in the public domain.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spellcast_solver-1.0.1.tar.gz (463.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spellcast_solver-1.0.1-py3-none-any.whl (463.7 kB view details)

Uploaded Python 3

File details

Details for the file spellcast_solver-1.0.1.tar.gz.

File metadata

  • Download URL: spellcast_solver-1.0.1.tar.gz
  • Upload date:
  • Size: 463.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for spellcast_solver-1.0.1.tar.gz
Algorithm Hash digest
SHA256 29437c0357ec9b9f1890b015a86af6c4cbb6197955e291a414099a96e9e009c2
MD5 490d28bbd376b1c0da9ead1e373816b7
BLAKE2b-256 29a66662641f1c6d5b381fb92cdc7e5c83487d03ac5e68f0c57399e76aa49bcc

See more details on using hashes here.

Provenance

The following attestation bundles were made for spellcast_solver-1.0.1.tar.gz:

Publisher: publish.yml on chrille0313/spellcast-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file spellcast_solver-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for spellcast_solver-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d8a0b9566ebc2bfd51981dac63f76551bb6a978301f5ce2d3c01a06547713ab7
MD5 db851d50aaf0aff0198669f513133d8d
BLAKE2b-256 a0beca2d5b23f69a6b6696413e7b35ee2a61521e2a1f918346f07dfecee8aeae

See more details on using hashes here.

Provenance

The following attestation bundles were made for spellcast_solver-1.0.1-py3-none-any.whl:

Publisher: publish.yml on chrille0313/spellcast-solver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page