Skip to main content

Play a word-guessing game

Project description

lettergame

Play a word-guessing game!

Rules

  • The computer chooses an N-letter word from a dictionary file.
    • The word has no repeated letters.
  • Each round, you guess a word following those same rules.
    • The computer tells you how many letters of your guess are also in the correct word.
    • It ignores the position of the letters, i.e. NOTES and STONE will have the same result.
  • When you guess the correct word, you win!
  • You should only be guessing real words, so it isn't too easy.

An example:

The computer secretly chooses the word 'EARTH'.
You guess 'GIRTH' -- 3 letters are correct (R, T, H).
You guess 'BIRTH' -- 3 letters are correct (R, T, H).
It is now probable that GI and BI are both incorrect (but not definite!).
To be sure, you guess 'BINGO' -- 0 letters are correct, so you know it must be R, T, and H.
You guess 'HEART' -- 5 letters are correct, but the order is not.
You guess 'EARTH' -- you win.

Installation

Using a virtual environment

# Create and activate virtual environment
python -m venv venv
source venv/bin/activate
# Install pip package
pip install lettergame

Note that the virtual environment must be active when using the command.

Using pipx

# Install pipx
pip install pipx
# Install pip package globally using pipx
pipx install lettergame

Using a manual link

# Clone this repository
git clone https://github.com/xorwow/lettergame
# Link to the game file from your BIN
ln -s lettergame/game.py ~/.local/bin/lettergame

Usage

First, install a dictionary file (see below). Then, start a game by running lettergame in your terminal (must have color support).

Dictionary file

To play the game, a dictionary file is required. It contains the words the computer can choose from. It is recommended to use non-plural nouns. You can find lists of common nouns online.

The game expects one word per line. The words can be any length. On start, the game loads all words that:

  • Don't have any repeating characters.
  • Fit the target word length.
  • Only contain A-Z/a-z.

By default, the game look for this file in ~/.config/lettergame/words.txt.

Options

The following flags are available:

  • --word-length|-n <number> specifies the target word size.
  • --dict-file|-f <path> specifies a custom path to the dictionary file.
  • --load-hash|-l <hash> forces the game to choose the target word of a previous game.
    • The shortened hash of the chosen word is shown at the beginning of the game.
    • This can be used to continue an interrupted game (although previous guesses are not loaded).
  • --difficult|-d disables automatic marking of letters based on obvious clues (see below).

Marking letters

The game shows you the alphabet and a list of previous guesses at the beginning of each round, with letters colored green, yellow, or red to keep track of which letters you have already ruled out or assume to be correct. Green means correct, red means incorrect, and yellow means unknown. This is meant as a memory aid, and will not influence the game's logic.

You can mark letters as correct/incorrect/unknown by entering +<letters>, -<letters>, or ~<letters> in the guess prompt. For example, enter +abc to mark a, b, and c as correct. They will be shown in green in the alphabet and the list of previous guesses.

If --difficult mode is not enabled, the game will also automatically mark letters in some obvious cases for convenience:

  • If a guess has no matches, all of its letters are marked as incorrect.
  • If the number of matches is equal to the amount of letters in the guess which aren't already marked as incorrect, all other letters are marked as correct (ex.: CASE matches 3 letters and C is marked as incorrect -> A, S, and E must be correct).
  • If the number of matches is equal to the amount of letters in the guess which are already marked as correct, all other letters are marked as incorrect.
  • If all correct letters have been guessed, all other letters are marked as incorrect.

Note that falsely marking a letter as (in)correct may create additional false marks based on that assumption.

Cheating

If you give up but still want to know the correct word, enter _reveal in the guess prompt.

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

lettergame-1.0.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

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

lettergame-1.0.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file lettergame-1.0.0.tar.gz.

File metadata

  • Download URL: lettergame-1.0.0.tar.gz
  • Upload date:
  • Size: 6.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for lettergame-1.0.0.tar.gz
Algorithm Hash digest
SHA256 03bec1eb2d4a90723d12ce4312e22ad0cbdcdf875ae4ac76ef245deb3e6b13b0
MD5 b64513e4c3ec5016e69da0adaa84bcaf
BLAKE2b-256 f0d93fa13bceeefc9c5900e7e96d8896914bed26cd47ab695ba56a7e622681a3

See more details on using hashes here.

File details

Details for the file lettergame-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: lettergame-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.1

File hashes

Hashes for lettergame-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8f2e76be2311113ee0c47b17cde184353d5a98e535ec0708459453dc25f84358
MD5 63b5a436205a4e53437da1a17b04da49
BLAKE2b-256 57716780b917dcf7cb0afe912840d506636efef600f8a476eb3f05445d496acc

See more details on using hashes here.

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