Procedural Puzzle Generation in The Witness

Spoilers for The Witness

I finally got around to playing The Witness last month, and enjoyed most of it a lot. The vast majority of the puzzles are hand crafted by Jonathan Blow and his team, but near the end is an infamous section, The Challenge. The Challenge is the only timed section in the game. To stop you simply memorising the puzzle answers, all puzzles in this section are randomly generated.

The change of pace and style, coupled with the intense music, and with a few curveballs thrown in, makes it one of the most memorable sections of the game.

I was naturally intensely curious as to how this generation works, and fortunately Blow shared all the key code for this section on stream last year. So I naturally got stuck in.

The answer is: they are all incredibly simple. They rely on generate-and-test. I.e. a relatively unsophisticated random generator randomly places puzzle elements, then the result is checked to see if it has a solution. If not, then you simply retry until you get a good one. There’s little attempt at making puzzles too easy, or too hard, as long as they are solvable. I certainly found playing this section, there was a good chance of running into a puzzle that was too hard, or very quick, but as the whole sequence is only six and a half minutes, it’s not too punishing to have to retry a couple of times.

Let’s dive into each puzzle, and what it does specifically. Each puzzle is named lotus_ as that is the codename for this section.

Continue reading →

Mesh Welding with Spatial Hashing

Recently I’ve been looking at Mesh Welding algorithms.

Mesh Welding is when you have a a mesh, i.e. a collection of vertices, edges and faces, and you merge any vertices which are close enough together.

This is a common operation in procgen, as it’s often convenient to generate several things completely independently, then join them together afterwards. I’ve had to re-implement it several times.

Continue reading →

Oatmeal Spice

Say you’ve written a little procedural generation program. Say it’s some art, music or level generator. It looks kinda cool, but after a few generations, you are already bored with it. Somehow, for all your careful design, all your generated results look samey, boring. This is Kate Compton’s ten-thousand bowl of oatmeal problem: every bowl of oatmeal is unique, but that does not make them interesting or valuable.

What can you do about it? In this article, I want to talk about how we can improve the interestingness of the results, not by adding more content, but by taking things away.

Continue reading →

Dihedral Subgroups Explained Via Factorio

The dihedral group is the mathematical formalism behind all the rotations and reflections of a regular polygon. For an n sided polygon, there are always n possible rotations, and n reflections, for 2n possible symmetries.

Combining any two symmetries gives another from the same group, that is what makes it a group in the mathematical sense.

The theory of it is useful to know for gamedev. I was reminded of this when seeing this Factorio devlog, where the developer ran into some trouble because he initially forgot to account for all the cases.

Continue reading →

Infinite Random Rectangles – the Poisson Rect process

Previously, we looked at how to sample points randomly at a given density across an infinite plane.

It’s harder than it sounds, as I was looking for an algorithm that was not biased by the size/shape of the chunks used to calculate it.

Today let’s extend that to filling the infinite plane with random non-overlapping rectangles. As before, that means finding a deterministic chunked algorithm that we can prove is unaffected by the choice of chunking.

Continue reading →