06/19/24: Random Generation- Algorithm Design


This week I'm going to talk more about the design of random generation algorithm.

Roguelites use randomly generated rooms to provide variety in gameplay: different terrain impacts the way the player moves around and fights enemies, and it keeps visual variety up as well, allowing a game to be endless while still being fun. Up until now, I've been playtesting this game with pre-made rooms because it makes testing specific features and mechanics easier (simple rooms and little-to-no randomness means that I can parse more useful and specific information).

The random generation involves the following components:

  1. Entrance and Exit: These are the first elements placed in a room. There's not too much to say about them, but they do affect where walls can be placed and just provide some more visual variety by changing where you enter a room from.
  2. Fences: A "fence" is a sequence of wall units that begin at one of the borders and goes a little under halfway to the screen. These can provide cover, partition rooms into pathways, and can even be used to make "subrooms."
  3. Quads: A "quad" is a group of four wall units placed in a square formation. They can give you something to circle around if you need to evade an enemy.
  4. Pairs: A "pair" is a group of two walls. They can also serve as cover, but are more reliable on the wide side. These can be combined with other types of walls to make new formations. The number of pairs created depends on the number of fences and quads created.
  5. Singles: Like with pairs, single wall units can be attached to existing components, or help define clear pathways for characters to move around in. Also like pairs, the number of singles created depends on the number of fences and quads created (they pull from the same "pool" of singles).


Perhaps the most interesting thing I've learned about random generation is that it's often defined just as much by what CAN'T be spawned as by what can be spawned. For example:

  • The dimensions of where a wall can spawn had to be restricted. Right now, I don't want any walls to be in corners, and non-fence components must be at least two spaces away from any border, as due to the camera angle, it can appear as you're boxed in when you're actually not.
  • Like I mentioned last week, I needed to prevent the walls from creating "boxes" that are inaccessible from the entrance, which is where the modified Breadth-First Search algorithm came from.
  • I also needed to calculate the amount of walls around a specific grid space, and modify the way quads are spawned to prevent certain shapes from appearing.

In a way, when you're designing a random generation algorithm, you're really doing metadesign, or designing design, which is super fascinating to me!

The resulting open spaces in a room is the list from which the Enemy Spawn Manager chooses positions for enemies. This is why it's important that all spaces are reachable: I don't want to softlock the player by having an enemy spawn in a box.

Note that no walls are spawned for a Boss fight; they complicate Boss fights, and I think they can actually kind of distract from the main challenge.

Now that random generation is done, I've began work on the Rank Up Systems, where defeating Bosses allows you to upgrade your Health, Inventory Space, or Signature Gain. This will be the final major feature for Castle Fractal, so it's really exciting to near the finish line after almost three years of development!

Get Castle Fractal: Combat Prototype 02

Leave a comment

Log in with itch.io to leave a comment.