Swizzle

27 January 2013 (Last update: 4 November 2021)

Intro

In 2013, all my friends were playing Ruzzle on their smartphones. It was the viral game of the year but I was the only one not playing it. I only had a dumbphone so I could not join in the fun.

I was fascinated by how addicting the game was, given its simplicity, and I started thinkering how I could replicate it.

Analysis

The game is written in D because at the time I was looking to replace C++ for making games. The more I used C++ the more I found myself spending time avoiding bad patterns and the growing complexity of the language with each major release.

For this project I did not want to use any off the shelf multimedia framework because I wanted to challenge myself and use as less dependencies as possible. So I ended up having to deal with a lot of interfaces in order to use C libraries such as OpenGL, FreeType, and libpng. It turned out to be a huge amount of work so I reduced the scope and only made it work for Windows and not Linux as initially planned. After spending much of my time making interfaces for the C libraries, the game logic to re-implement Ruzzle turned out to be minuscule in comparison.

The game logic is all contained in one class: WordTable. And the most interesting functions are two.

WordTable.reset(). This function prepares the game board by placing the letters. It starts by taking a random word and placing its letters close to each other in the board. Then this process is repeated until there is no more space left. This algorithm ensures that any game has valid words to be discovered. A simpler approach, where letters are placed randomly in the board could lead to corner cases where no words are available in a game.

Example of placing the words: HELLO, WORLD, MUSIC
Example of placing the words: HELLO, WORLD, MUSIC

WordTable.findPossibleWords(). This function finds all available words in the game board. It uses a recursive algorithm that tries to match each word in the word list by trying each neighbor letter at the current position.

Downloads

The source code is available on GitHub and it can be readily compiled on Windows using Visual D. Pre-compiled binaries are also available.