I work as a software engineer. Sometimes work is very interesting, getting to brainstorm ways to solve complex problems using code and algorithms. But lately, I'm often stuck waiting. Waiting for code to compile, waiting for a system to deploy, waiting for automated tests to run... it gets pretty boring sometimes.
Now of course I could use this time to do more productive tasks, but I usually use it to check my phone and do my daily NYT puzzles. It started with the Wordle, but now everyday I also do the Mini, Connections, and Strands, as well as other non-NYT daily games like the
[Tradle],
[Spotle],
[Poeltl]... Theres no shortage of these types of games. However, being on my phone while at the office is a pretty bad look. To get around this, I made a little terminal based
[Wordle clone in Go], so it would still look like im being productive. I thought this would make all the idle waiting I have to do a bit more bearable, but it turns out after doing the Wordle daily since 2022 its not that much fun anymore. So I decided to challenge myself to make a Wordle-type game to add to the hundreds of others that exist on the web already.
The first idea that I thought of was simple: a game where you have to get from a starting word to and end one while only changing one letter at a time while still making valid words every move. This seemed very easy and straight forward. However, when I pitched the idea to my girlfriend, she informed me that the game
[already existed]. Of course it did. So I played a couple of rounds of it and honestly I'm glad that someone else already beat me to the punch because it was very boring. By only getting to change one letter at a time, it was almost always incredibly obvious which letter to change to get to the end word. For example:
This had me wonder, could you even get to every other n-letter word by only changing one letter at a time?
I downloaded a set of all acceptable scrabble words and wrote a quick test. I started with 5-letter words to stay true to the wordle-clone theme. The test would check if two words could be connected by only changing one letter at a time. If so, they would be part of the same "group". After running the test, I got this:
914 groups, with 5 groups having over 10 members and 1 group having over 100 members (1856 members).
So one large group, and a lot of very small ones. I tried again for words from 4-letters long to 10-letters. The results were essencially the same.
Maybe this was why I felt the game was too easy. If every word was in the same group, maybe it would allow for more complex and less obvious paths to the answer. The easiest way I could think of to make one large group was to allow more than one letter to be changed at a time. So I tried with 2 changes allowed:
8 groups, with only one group containing more than 10 members (3225 members).
A much more interesting result. The only words that could not be connected into this large group were: hajji, hi-fi, jihad, kudos, kudzu, nohow, uh-uh, and xylem. Apparently I forgot to purge the words that contain special characters, but thats not a big deal honestly. I quickly whipped up a prototype of the game and gave it a shot:
For small words, it still wasn't that difficult, but when I tried with words with 7+ letters I had a lot of trouble solving them. Maybe theres a middle ground I can find between "puzzle for 3rd grader" and "impossible unless you have a dictionary next to you".
To increase the pool of words even more, I figured being able to add or remove letters would work well. Doing this would no longer limit all of the words having to be the same length, making more complex paths possible to take between words. I decided to run the group test again where you're able to make 1 change: either add a letter, remove a letter, or change a letter:
27593 groups, with 17 groups having over 10 members and only one group having over 100 members (8482 members)
The group size was a lot larger now, which I felt would make the game a lot better. I wanted to test it again where you could make two changes, but coming up with a way to check if a word was two (or more) changes different from another proved to be a bit tricky. For example, going from "infer" to "miner" would be a valid move with 2 changes (remove the "f", add a "m" at the start). Maybe I just haven't grinded enough leetcode, but it was not very obvious to me. Try and come up with an implementation for:
bool isValidMove(string start, string end, int maxDifferences)
Here's
[mine] (Don't make fun of me). I feel like its a pretty clever way of doing it. Anyways, after running that test this is what I got:
9306 groups, with 22 groups having over 10 members and again only one having over 100 members (27935 members).
Having a pool of over 27000 words felt pretty acceptable to me, so I just removed all of the words not in that group from the word list. The option of being able to either add or remove letters made me feel less like I was directly ripping off another game.
I was still finding it hard to zero in on a good difficulty for the game. It always felt either just a bit too easy or just a bit to hard. Being lazy, I decided to just split the game into two modes:
Easy mode: Only using 5-letter words
Hard mode: Using words of any length
Other changes I wanted to do to make the game more playable for it to start/end with more common words that weren't too long (No reason in trying to get from abcoulomb to boustrophedonic (Which is actually possible by only making 2 changes at a time!)), and for the game to let you know what the minimum amount of moves you needed to make to reach the end word was. This became a whole excersise in itself as doing a basic BFS to find the shortest path in a huge graph takes a long time. On average, maybe 5 seconds on my work laptop, and sometimes up to 15. Is there a more efficient way to compute this? Maybe pre-compute something and have it cached? I guess this is a non-issue if you're only putting out one puzzle every 24 hours like wordle, but for repeated playing it's a touch annoying. Something to improve on in the future I guess.
The final thing I wanted to do was to give this game some kind of theme. I played easily the worst round of golf of my life last weekend (I shot 114), so golf was on my mind. I decided to give the player the minimum amount of steps it would take to get to the end word as the "par" for the round, and every additional guess would act like an extra stroke. For example, using 5 moves to get to a word where the quickest path was only 3 moves would score you a double bogey (+2). Now what to call it? Golfle? That sounds horrible. Like comically horrible. Plus, I looked it up and theres already some sort of games with that name. Well I can't think of anything else so I guess I'm claiming it.
And voila, I made a kind of fun (debatable) game and managed to kill some time while waiting for some tests to run at work. In the spirit of this being a Wordle clone, I plan on making a web interface for this. That will have to be a weekend project though, because I don't think I can get away with coding a whole front-end while at the office.