Daily news, dev blogs, and stories from Game Developer straight to your inbox
Featured Blog | This community-written post highlights the best of what the game industry has to offer. Read more like it on the Game Developer Blogs.
A detailing of the logic behind the puzzle generation in the shape-cutting game Perfection.
August 1, 2013
3 Min Read
Perfection. is sort of technically interesting, since it has randomly-generated puzzles. For those who may be unfamiliar, the puzzles take the form of polygons you can cut in straight lines and a shape you're trying to match the polygon to.
I've had lots of people ask me about what goes on under the hood, enough that I decided to just make a brief little post about the interesting parts of it. I'm not actually a good programmer (Perfection. was made in Game Maker, y'know) but I'm hoping some of the techniques here are informative to others or inspire some interesting game designs! Also, I got to have fun making explainer GIFs.
Step One: Generate a Shape
The game picks a number of sides for the shape; when you start out the range is around 4-6, but as you clear shapes this eventually grows to 10-15. Then it just goes in a circle, creating points at a random distance from the center (with some extra rules about staying at about the same distance of te surrounding points). A shape is born! This is saved as the starting shape for the puzzle.
Step Two: Cut It Up
Then the game just plays itself in fast motion, basically, sticking to its own rules and making a goal shape that the player can make. There's a rule that every shape centers itself on the screen, which is what makes the game actually a puzzle and not just a matter of tracing the lines. To pick cut locations, it picks a point at a random angle and in a random range of distance from the center, then makes a line through that point and cuts it there. For puzzles that take more cuts, it just does this more times. For shapes that require rotation and scaling, it rotates and scales the goal. It's that easy! :o
Bonus: Detecting the Similarity
This is another thing people wonder about. Basically, the game breaks each shape into a grid of 0s and 1s--0 means it does not exist there, 1 means it does exist there. Then it puts those grids on top of each other. Anywhere where one shape exists and one does not, that counts as a difference. Anywhere where both shapes exist, that is a similarity. The surface area of difference divided by the combined surface area of the overlapped shapes is the percentage of difference--the game gives you a win when this is at or under around 12%. It's not *completely* binary; edge boxes in the "difference" shape are treated as only "half" a difference, so the game is a bit more forgiving.
I haven't seen another game that works structurally like this, but I feel there's a lot to explore here. When your game works within a system of mechanics the way Perfection. does, techniques like this can be used to generate puzzles forever. In this game I start with the starting point and then create alterations for the player to replicate; for other games, it could go the other way, starting with a goal and then creating alterations the player has to reverse engineer. When the rules are interesting and predictable, the puzzles will be interesting, too.
Read more about:Featured Blogs
You May Also Like
Exploring the 2024 State of the Game Industry report - Game Developer Podcast ep. 39Feb 2, 2024
Phantom inspiration and the ethical auteur with Xalavier Nelson Jr.Dec 8, 2023
Designing Killer Queen: from playground experiment to modern arcade sensationOct 18, 2023
Rod Humble and King Choi illustrate the ambition of Life By YouSep 22, 2023
Get daily news, dev blogs, and stories from Game Developer straight to your inbox
Subscribe to Game Developer Newsletters to stay caught up with the latest news, design insights, marketing tips, and more