Sanapeli

· Python · numpy · pygame · TypeScript · Source on GitHub

Sanapeli (“word game”) is a Finnish five-letter word-guessing game and my first game project. It is inspired by the New York Times counterpart Wordle. Grant Sanderson at the time made a video about ideal guesses using information theory and I wanted to have a crack at programming the game interface as well as a recommendation algorithm.

The recommendation algorithm does not follow the one proposed by Grant Sanderson. Instead, it uses Numpy library and an optimized algorithm to find the best guess to eliminate the most words left. The ideal guess is decided by the best worst case. So even if some guess reduces the set of possible words most by average, it might have a worse worst case scenario.

At the time of making the project, I had completed two python basics courses and wanted to see what I can create with the limited tool set I had available. Later when my skillset had developed, I improved the algorithm to use numpy efficiently and expand the set of valid guesses.

As this website is meant to showcase my projects, I translated the project to web-application with Claude Opus 5.5, where the new game interface is authored by the LLM, but the recommendation algorithm is a copy of my original work. The original project used pygame library for the interface and the source code can be accessed via the link on top of the page.

Generated content · written by Claude Opus 5.5

How to play

Guess the hidden five-letter Finnish word in five tries. Type on your keyboard or tap the keys, press Enter to guess and Backspace to erase. After each guess the tiles are coloured:

  • green: the letter is in the word, in that slot,
  • yellow: the letter is in the word, but in another slot,
  • grey: the letter is not in the word.

Only words from the game’s list of 2,808 words count as guesses. Hints (or the § key) shows the suggested guesses. Finnish five-letter words never use the letter x, so the original game used the x key as a shortcut to restart with the same hidden word. That shortcut still works here.

How the hints work

After every guess the solver keeps only the words that would have produced the same colours. These are the candidates. Then it picks guesses that make the worst case as good as possible:

  1. If one or two candidates are left, it simply lists them.
  2. Otherwise it scores possible guesses. For a guess, it assumes each candidate in turn is the answer, counts how many candidates would still be left, and keeps the largest count. The ten guesses with the smallest worst case are shown, best first.
  3. Scoring every word against every candidate is slow while many candidates remain. So with ten or more candidates, the solver first looks for up to five letters that have not been guessed yet and split the candidates best: each letter divides them into words that contain it and words that don’t, and the search minimises the largest group. Only words containing all of those letters are scored.

The first suggestions are always the same, so they are stored instead of computed.

Browser port of the game interface made and recommendation algorithm translated with the help from Claude Opus 5.5.