Practical PCG Through Large Language Models

Muhammad Umair Nasir, Julian Togelius · DOI

Abstract

This paper presents a practical framework for Procedural Content Generation (PCG) using Large Language Models (LLMs) in scenarios where training data is extremely limited. By employing a two-stage pipeline involving human-in-the-loop bootstrapping and automated data augmentation, the authors demonstrate that GPT-3 can generate high-quality, playable 2D game levels for the indie title Metavoidal using as few as 60 hand-designed examples. The results highlight a cost-effective path for indie developers to integrate advanced machine learning into their content pipelines without the need for massive datasets.

Introduction

Procedural Content Generation (PCG) is a staple of modern game development, traditionally divided between rigid, hand-coded heuristics and data-hungry Machine Learning (ML) models. While LLMs have recently shown promise in generating levels for classic games, they typically require massive datasets to learn the underlying "grammar" of a level.

In the real world of indie game development, studios rarely possess thousands of pre-made levels. This research addresses the "small data" problem: how to leverage the power of LLMs for a game currently under development where only a few dozen hand-designed rooms exist. Furthermore, the study explores how to ensure LLMs respect strict spatial constraints—such as door connectivity and solid wall boundaries—that are vital for functional gameplay.

Methodology

The researchers proposed a two-stage pipeline using OpenAI’s GPT-3 (specifically the text-davinci-003 variant), treating spatial layouts as a sequence of tokens similar to natural language or code.

1. Controllable Prompting

Instead of open-ended generation, the researchers encoded specific constraints into the prompt, including room dimensions, base tile types, and desired decorative patterns. Levels were represented as strings of characters (e.g., "#" for walls, "A" for walkable paths), allowing the LLM to process the layout as a text-based sequence.

2. Stage 1: Human-in-the-Loop Bootstrapping

The model was initially fine-tuned on just 60 hand-designed rooms. Because early outputs often contained architectural errors (broken walls or disconnected paths), a human designer manually repaired the most promising failures. These corrected levels were then added back into the training set to "bootstrap" the model’s understanding of the game's spatial rules.

3. Data Augmentation

To overcome the scarcity of training data, the team employed four augmentation techniques: horizontal and vertical flipping, 90-degree rotations, and tile texture swapping (e.g., changing wood to marble). This expanded the initial pool of 60 levels into a more robust training set of 840 examples.

4. Stage 2: Iterative Automated Refinement

The model underwent a second round of fine-tuning on the augmented data. It then generated batches of 100 rooms. Only the "Playable-Novel" levels—those that passed all seven of the game's strict architectural constraints and were sufficiently different from the training data—were added back into the dataset for subsequent rounds of fine-tuning.

Datasets

The study utilized a bespoke dataset from Metavoidal, a 2D roguelite brawler developed by Yellow Lab Games.

  • Initial Dataset: 60 hand-designed rooms created by a professional 2D game artist.
  • Final Augmented Dataset: 840 levels generated through the transformation and bootstrapping techniques described above.

Key Results and Insights

  • Playability and Novelty: The system successfully generated 37% Playable-Novel levels from the initial scarce data, proving that the model could innovate beyond its training set while maintaining functional integrity.
  • Constraint Adherence: The "Accuracy" metric—measuring how well the LLM followed the specific tile percentages requested in the prompt—improved significantly from Stage 1 to the end of Stage 2.
  • Spatial Syntax: The core finding is that if an LLM can learn the syntax of a programming language, it can learn the "spatial syntax" of a dungeon. By treating levels as language, the model learned to respect complex rules like door spacing and path connectivity.
  • Cost-Effectiveness: The entire experiment cost approximately $300 in API fees, making this a highly viable approach for indie developers who lack the resources for custom ML infrastructure.

Limitations and Future Work

While the results are promising, the authors identified several limitations. The current method is strictly limited to 2D grid-based levels; adapting this to 3D environments remains a significant challenge. Additionally, Stage 1 still requires a degree of manual human intervention to fix broken levels. Future research may focus on automated "repair" scripts to further reduce the human workload and the development of generalized PCG models capable of generating levels for multiple game genres from a single prompt.

Conclusion

This research demonstrates that "Big Data" is not a prerequisite for using LLMs in game design. Through clever bootstrapping and data augmentation, developers can transform a handful of examples into a powerful, controllable generation tool that respects the practical constraints of game design.

Summary updated

BibTeX
@inproceedings{nasir2023practical,
  author = {Muhammad Umair Nasir and Julian Togelius},
  title = {{Practical PCG Through Large Language Models}},
  booktitle = {CoG},
  year = {2023},
  url = {https://openreview.net/forum?id=cz9P8p9SJS},
}
Figure