A collection of scripts for evaluating game states in different word games
This Python script analyzes all possible opening hands in a tile based word game (e.g. Scrabble) to determine how many can form valid words using a given word list. It performs a full combinatorial sweep of hands based on official tile distributions and reports both raw and weighted statistics.
Exhaustive analysis of possible opening hands. Determines which hands can form at least one valid word. Supports wildcard tiles (?) and weighted probability calculations.
- Prepare a word list Create a plain text file with each word on a new line
Example:
apple - a fruit
zebra
quiz
house - a building
sea
pant
pants - plural of pant
- Minimise the word list
note: capitalisation, and characters after a space will be removed
python wordprocessor.py <base-wordlist.txt> <minimal-wordlist.txt>
- Run the evaluator
python evaluate-hands.py <wordlist.txt>
The script prints:
- Total number of hands analyzed
- Number and percentage of hands that can form valid words
- Weighted statistics based on tile probabilities
When a new dictionary is added, or existing one is updated a github action has been setup to process it and commit the output into the output dir.
Loaded 173 valid words
3,190,000 hands checked | 251,021 dead | 623.4s taken
------- Results --------
Total hands : 3,199,724
With valid : 2,948,703 92.1549%
No options : 251,021 7.8451%
------- Weighted -------
Total hands : 16,007,560,800
With valid : 15,915,965,384 99.4278%
No options : 91,595,416 0.5722%
------------------------
Finds the minimum set of characters that will provide a staring hand with plays. Uses backtracking to generate all combinations of 7 tiles. Checks each hand against a preloaded list of valid words. Wildcards (?) are treated as flexible tiles (so far in all dictionaries a wild card always produces a valid hand). Computes both raw counts and weighted probabilities using combinatorics to cover all possible starting hands.
Finds grids that provide a maximum score for a given word list
Contributions are welcome; here's how you can help:
To add a new dictionary file:
- Click the "Fork" button at the top of this repository
- Navigate to the
dictionariesfolder in your fork - Click "Add file" -> "Create new file"
- Name your file (for consistency please use the format [Dictionary][Year].txt)
- Add your dictionary content (one word, or word + definition per line)
- Scroll down and click "Commit new file"
- Go back to the main page of your fork and click "Contribute" -> "Open pull request"
If there are additional forms of hand analysis you'd like to see , or ways to improve existing scripts, feel free update this repo:
- Fork the repository
- Create a branch
- Make your changes
- Submit a pull request with an explanation of what the changes do (and why that's a good thing).
Found a bug? Open an issue with:
- What you expected
- What actually happened
- Steps to reproduce
See LICENSE