# How does Planet Work

It’s been over a year since I last deconstructed how a game does its procedural generation. Today we’ll be looking at Planet, a 2016 cosy design toy by one of my favourite developers, Oskar StÃ¥lberg.

# Everything you need to know about Quaternions for Game Development

They represent 3d rotations.

That’s it, that’s the article.

# Defining Chess Piece Moves using Regular Expressions

Suppose you wanted to code a simple chess game. One key bit of game logic is to describe what are legal moves for each piece. There’s only 6 types of piece (pawn, knight, bishop, rook, queen, king) so this isn’t exactly a hard task. You can write rules such as:

def canRookMove(from, to):
# Ignores questions about colliding with other pieces
return (from.x == to.x or from.y == to.y) and from is not to

But these days, I’ve been thinking a lot about grids, and the above approach just doesn’t generalize. What if you wanted to play chess on a stranger grid?

What would it mean to play chess on the grid above, or a hexagonal grid, and so on? You’d have to write a whole new set of rules, and they could get very complicated depending on the grid in question. What I want is a language that describes how pieces move, which generalizes to any board. And I think I’ve found it, using regular expressions.

# Learning to Finish Things

For many years I was a hobbyist programmer. I’d try out small projects, experiment, then move on to the next thing. This was a great way to learn a lot, but I’ve got almost nothing tangible to show from that era. Despite the best of intentions, every project reached a point where it started to drag, and I’d get bored and move on.

It was only a problem for the projects I worked on myself. Working for others, I never really found the same problems. It was a problem of motivation and focus.

More recently, it is different. Now when I start hobby projects, there’s a good chance I’ll cross that finish line, and have something I’m ready to share with the world. What changed? Well in part it is increased experience and maturity, things I cannot teach. But also, I have found some strategies and thought processes helpful, and other, very tempting ones, not so much.

In short, I’ve learned to finish, which is a real skill you can learn over time. I thought I’d share with you what has worked for me. Maybe it’ll work for you too. I make software, but I think this advice is generally true for any other spare time activities. There’s three sections – scope, motivation and distractions.

# VoronatorSharp

I’ve relased a new library, VoronatorSharp.

VoronatorSharp is a C# library that computes Voronoi diagrams. The Voronoi diagram for a collection of points is the polygons that enclose the areas nearest each of those sites.

Voronoi diagrams have applications in a number of areas such as computer graphics.

This library features:

• Computes Voronoi diagrams and Delaunay triangulations.
• Voronoi polygons can be clipped to a rectangular area.
• Uses a n log(n) sweephull algorithm.
• The implementation attempts to minimize memory allocations.
• Integrates with Unity or can be be used standalone.
• Uses robust orientation code.
• Handles Voronoi diagrams with only 1 or 2 points, and collinear points.

# Rotation Graphs

Graphs are a data structure we’ve already talked a lot. Today we’re looking at extension of them which is both obvious and common, but I think is rarely actually discussed. Normal graphs are just a collection of nodes and edges, and contain no spatial information. We’re going to introduce rotation graphs (aka rotation maps) that contain just enough information to allow a concept of turning left or right – i.e. rotation.

# Mosaic Paint

As a side-project of a side-project, I’ve made a little painting program. It’s like a normal paint program, only you paint on a tile grid instead of pixels. You can create mosaic and stained-glass style images.

Try it out!

# The Grokalow

One day, the grokalow crawled out of the swamp.

“It looks like a gargantuan alligator”, cried a bystander, as it approached.

“Nay, it is a brobdingnagian crocodile”, countered a second, as the grokalow licked its leathery lips.

“Without a clear definition, we cannot conclude this thing is a threat”, surmised the third, settling the matter.

The grokalow ate them all, with great satisfaction.

# Editable WFC

When I spoke about autotiling, I briefly touched on how it’s possible to use Wave Function Collapse (or other constraint based generators) as a form of autotiling, i.e. user-directed editing of tilemaps.

I’ve usually referred to this technique as “editable WFC“. It’s a combination of autotiling and WFC, and contains the best of both:

• Being an autotiler, it allows users to easily and interactively make changes to an existing level.
• Being constraint based, it automatically ensures that those changes are consistent with the predefined rules of the constraints, potentially making further changes to the level to make it fit

This is different from most other autotilers, which either require manual configuration of patterns used to enforce good behaviour, hidden layers, or come with more stringent requirements on what tiles are available.