Skip to content

Procedural Content Generation

PCG is the algorithmic creation of data with limited or no human input. In the context of tilemap generation, PCG allows for the automatic creation of varied maps by applying rules and randomness.

Overview

PCG typically employs randomness combined with deterministic algorithms to generate game content such as levels, terrains, or tilemaps. This approach is good for:

  • Increased replayability due to unpredictable map layouts.
  • Reduced manual effort for content creation.
  • Dynamic content tailored to game conditions or player actions.

PCG in Acid

Acid supports PCG through constructs that allow:

  • Iteration over tile coordinates.
  • Random value generation.
  • Conditional logic for tile placement.
  • Custom methods for complex behavior (e.g., cellular automata).

Example: Random Initialization

gen! {
    $i * (0, 29) {
        $j * (0, 19) {
            set_rand_range(0, 100)
            if rand() > 75 do [
                set($i, $j, $ALIVE)
            ] else [
                set($i, $j, $DEAD)
            ]
        }
    }
}

This snippet randomly sets tiles as either ALIVE or DEAD based on a probability threshold.

Cellular Automata for Map Evolution

Acid can implement classic cellular automata (e.g., Conway's Game of Life) to evolve tile states over iterations, producing organic and unique patterns.

Benefits of two-dimensional PCG in Acid

  • Flexibility to define custom tile behaviors.
  • Powerful abstractions like the method feature for macro definition and the builtin gen! function for reusability.
  • Clear syntax blending iteration, conditional logic, and randomness.