Table of Contents
I wanted to explore if it was possible to create educational puzzle games, even for very young players or somewhat odd topics.
Years ago I made several puzzle games and learned some crucial lessons.
- How to randomly generate puzzles (instead of handcrafting them), and how to do it fast and well.
- The importance of a “command” system to get do/undo, solution checking, and more for free.
- And … that you need a very fast programming language to be able to do this at all.
I had to stop developing such games because my old laptop just could not run it anymore. I had to use Rust for generating the puzzles, but used different software (e.g. Godot Game Engine) to make games, which meant I had to code all the logic twice. That was, obviously, frustrating and a big time sink. My laptop was closer and closer to crashing randomly too. So I stopped.
Now that I’ve launched my educational store, however, I realized education was the perfect place for my puzzle ideas. A puzzle is basically the most efficient way to teach people to problem solve (following specific rules)! I could hyperfocus a puzzle on colors, or shapes, or counting, and get something good.
Then I discovered that, in the mean time, someone created a plugin that allowed writing Rust right inside Godot. I could write my puzzle logic only once and get randomly generated puzzles for free!
And so I returned to puzzle game development with my simplest idea (at the time): a puzzle to teach colors. The end result is my first digital puzzle game on the online store called Rainbow Market
What’s the idea?
Random animals appear. Each “turn”, you tap an animal to give the current color to them.
Each animal
- Wants some colors
- Is a color itself too
Once all their desires are fulfilled, the animal leaves happily … and gives you its color.
That’s how it becomes a puzzle, instead of just a homework exercise. You need to be smart about the order of giving colors, because you need the “reward” from happy animals at the right time.
Example: Two animals both want PINK. One animal will give you “BLUE” upon completion, another gives you nothing. You need that BLUE to make another animal happy, so you give the PINK tot he first animal.
That’s all. It needs to stay extremely simple to be playable by kids still learning about colors, of course.
Generating Puzzles
For such a simple puzzle, we don’t need the power of Rust. I feel very silly for dropping my puzzle games entirely all those years ago, because there are obviously loads of ideas that are “simple enough” to generate with a “slower language” (like the GDScript built into Godot). I could’ve made all of those!
But, well, you live and you learn.
How do we generate these puzzles?
- Start with X random colors and Y blank animals (who aren’t assigned anything yet).
- Repeat the following loop.
- Pick a random animal that isn’t done yet.
- If none exists, or with a slight random chance (say 5%), add a new blank animal.
- Give our current color to that animal. (We pretend it “wanted” that color all along!)
- Decide if the animal is “done”. (It’s full, random chance, or we’re out of colors and need its reward.)
- Add its reward color to the end of our color list.
- Mark it as “done”.
- (If we’re out of colors, guarantee at least 1 reward, so we)
- Pick a random animal that isn’t done yet.
- Repeat until all animals are done.
We simply save the “animal” picked in every iteration of that loop. That list is our exact solution in the end.
This is quite quick and simple. It’s also not entirely correct yet.
It took me a bit—after implementing the visuals to show what happens—to realize the logic mistakes here.
- Mistake #1: The final animal’s “reward” is pointless. It just adds colors you won’t use anymore, ruining our “perfect finish”.
- So … just remove the reward from that final animal once done.
- Mistake #2: To control difficulty, I need to control the min/max number of animals and colors.
- So, check if the end result is valid. If not, just throw away and try again.
The issue is that the puzzle will often fail these bound checks. It might need hundreds of retries—thousands if you’re unlucky—because it keeps adding too many or too few animals, for example. That’s why you generally want to be a bit smarter in the generation itself.
The extra checks below changed it so that the generation always found perfect puzzles within 1–5 attempts.
- We don’t add a blank animal if we’re already at max.
- If we NEED to add an animal (because we have colors left), but we’re already at max, just fail the puzzle and retry.
- Check if the simulation “needs to continue” (too few animals, animals that are not done, or unused colors left).
- If we do NOT need to continue, always finish our current animal, which finishes the simulation.
- If we do NOT need to continue, strip the reward from this final animal. (Set the reward to nothing + remove those added colors from the final list.)
- If we DO need to continue, ensure our animal has a reward (so >0 reward colors). Otherwise continuing won’t actually help us, because nothing changes.
Now we get nice puzzles about clicking a few animals and giving them colors ;) And we can control their difficulty by changing those boundaries (how many animals, how many colors, etcetera).
That’s it, really
I added a simple button to automatically play this solution, which was a godsend for checking and debugging this. I made the generation seeded, so I could actually create a little campaign with saved seeds, and allow you to replay exact levels you struggled with.
Then I added the basic menus, sound effects, and some tweens/animations, and we had a color-focused puzzle game! One that’s absolutely playable by 4-year-olds, as all you do is tap an animal (which matches color with the background). I can even remove the “reward” entirely for the first few levels, removing the puzzle aspect but making it easier to get started.
Because it was such a tiny test game (to check the viability of puzzle games at my online educational store), I used free asset packs for the few images needed and did not add any other bells and whistles. I didn’t even see the point adding “settings” because there are … no settings to tweak.
I did decide to add a tutorial. (With such educational games, explaining it in two sentences to the teacher/parent, and them guiding their kid is usually the best way. But I still want to support the kid playing all on their own, or the game being playable without any reading.)
It took me a while to figure this one out actually. How do you explain the idea of “tap an animal that wants the same color as the one shown” without text? In as simple a way as possible?
- Any image I make is just going to be another image in a sea of images that mean nothing to the player yet. Not great.
- So I need to actually highlight/animate the specific sprites in the puzzle. I need to actually read the puzzle solution and indicate (on the “easiest” difficulty) what the player should tap.
- But if I add a pointing finger to both the “color shown” and the “animal to tap” … then it’s not clear which of the two you should tap!
- Then I realized I could do a sequence.
- Highlight color shown.
- Highlight animal that wants it.
- Show a single pointing finger above the animal, indicating to tap that.
Until the next game,
Pandaqi