Hangperson

I’ve written a new variant on that old game, hangman, but modernized it just a bit. The game can be played online in your browser at http://templaro.com/games/hangperson. The game play is familiar: guess the missing letters of a word or die trying, but I’ve added some features. First you can play in English, French, Russian or Greek. So that’s a bit different. Also, you can pick your difficulty. A scoreboard keeps track of how many games you have won out of however many you have played. Finally, as you would expect, if you guess incorrectly, body parts get added to a picture and when the last part is added, you lose. There is a different, culturally inappropriate picture for each language.

Origin Story

This game came about entirely because I was trying out the Codex plug-in for visual studio and the first thing that came to mind as a good test of its capabilities in python was to tell it to make a command-line version of hangman.

I have programmed since highschool and I can write passable python code. However, I write code slowly because I’m often away from it for months between projects and every time I need to put it back into my head. When I let Codex loose on this project, it immediately came up with an entire roadmap to a minimal CLI version and made a number of good suggestions versus my rough sketch.

It was over before I knew it – a working prototype. It got a couple bits of logic twisted around the wrong way, but easily rectified. Since I had set an afternoon aside for this and I was barely 15 minutes in, I asked it to extend the CLI version to use wxPython and create a graphic version. I played with images while codex did the hardwork, surfacing occasionally for input. It took a while to iterate designs and get the UI right, but infinitely less time than if I was attempting it by hand.

Up to that point, I had just used a short word list for each language for proof-of-concept, but I wanted two things: a larger vocabulary and a way of dialing difficulty up and down. The latter is not trivial: longer is not harder for hangman (in fact, longer is easier). There are a lot of factors that contribute to difficulty and I thought about them for the next week. Some of them are: how common a word is (frequency of word use), how many repeated versus unique letters occur in a word, how many low-frequency letters occur in the word, whether the world contains high-frequency predictable patterns (e.g., words in english ending in -tion), and other factors. Thoses factors boiled into heuristic rules specific to each language. The game’s easy-medium-hard classification weighs those factors as well as the number of guesses permitted.

To produce a long list of fair words for each language and to derive the word-frequency statistics that I needed for the difficulty rules, I made a pipeline for collecting existing large web-scraped corpora for each language, cleaning them up, running them through dictionaries and rules filters, and finally compiling frequency lists. I learned a lot about unicode, collation, case conversion and other necromantic incantations.

For my own sanity, I tried to keep the project as consistent across languages as possible, but some tweaking was unavoidable. For instance, you must supply the correct accents in French. The letters e, é and è are considered different characters. In Greek, you don’t need to enter any accents. For Russian, I tried to standardize on the masculine singular nominative form of nouns and adjectives, whether short or long form. Significant head scratching was involved.

Adding a GUI

At the end of this, I realized that the game would never see the light of day if existed only as a linux-based python program requiring some specific libraries, so I played around with porting to windows and Mac. Once again, I learned a lot about how wxPython can look different on each platform. Finally, I produced executable versions for both PC and Mac.

I can tell you they worked, but you’ll probably never get a chance to find out because of course both ecosystems now require code signing to distribute programs. And I can’t really justify laying money each year for the off chance that I might write something for one platform or the other.

Finally, online

So, my miserliness brought me to the final chapter of this project, implementing as a webpage. Here I was in less familiar territory, and codex did a great job chunking the conversion from python into manageable pieces. The final product was a static React/Vite client. The UI is React, the Typescript game engine lives in the browser, with a smattering of CSS to dress it up. Essentially nothing is going on behind the scenes on server except for providing resources (images, JSON, etc.) as needed.

The code lives at https://github.com/dhakajack/hangperson/.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.