Level Generation Through Large Language Models

Graham Todd, Sam Earle, Muhammad Umair Nasir, Michael Cerny Green, Julian Togelius · DOI

Abstract

This paper investigates the capacity of Large Language Models (LLMs) to generate functional 2D video game levels by treating spatial layouts as 1D text sequences. Using the puzzle game Sokoban as a benchmark, the study evaluates how autoregressive models like GPT-2 and GPT-3 handle the transition from natural language to structured spatial logic. The findings suggest that while LLMs can reliably produce playable and novel levels, their success is primarily driven by dataset scale rather than prior natural language pretraining. Furthermore, larger models demonstrate a superior ability to generalize from limited data, offering a potential solution to the data scarcity challenges inherent in procedural content generation (PCG).

Introduction

Procedural Content Generation via Machine Learning (PCGML) has traditionally relied on models designed for spatial data, such as Convolutional Neural Networks (CNNs) or Generative Adversarial Networks (GANs). However, the rise of Large Language Models (LLMs) presents an alternative: treating level design as a sequence prediction task. This approach poses significant questions regarding representational mismatch—whether a model trained on linear text can internalize the 2D spatial constraints and functional requirements of a game—and data scarcity, as high-quality game level datasets are far rarer than natural language corpora.

Methodology

The authors represent Sokoban levels as 1D strings by concatenating rows of ASCII characters (e.g., # for walls, @ for the player, and $ for boxes). Level generation is then framed as an autoregressive sequence prediction task.

To evaluate the models, the researchers utilized four primary metrics:

  • Playability: Solvability of the level, verified via an A* search agent.
  • Novelty: Distinctness from the training set, measured by string edit distance.
  • Diversity: Variation among the generated levels themselves.
  • Controllability: The model's ability to adhere to specific constraints provided in a natural language prompt.

To isolate the impact of pretraining, the study compared three GPT-2 variants: one pretrained on English text, one on Java code, and one with no pretraining (random initialization).

Datasets

The research utilized two distinct datasets to test scaling and generalization:

  1. Boxoban: A large-scale dataset containing 438,000 procedurally generated 10x10 levels. This was used to establish scaling laws by training models on subsets ranging from 0.1% to 100% of the data.
  2. Microban: A small dataset of 282 human-authored levels. To test low-data regimes, the authors created augmented versions using spatial flips and rotations.

Key Results and Discussion

The Role of Pretraining and Scaling

Contrary to expectations, pretraining on natural language or code did not significantly improve performance. The untrained GPT-2 model performed comparably to its pretrained counterparts, suggesting that the spatial logic of Sokoban is sufficiently distinct from human language that the models must learn the domain-specific rules from scratch.

However, performance was highly sensitive to data volume. On the full Boxoban dataset, GPT-2 variants achieved a composite score (measuring novelty, playability, and diversity) of approximately 0.53 to 0.56. When the training data was reduced to 0.1%, the score plummeted to 0.01, illustrating that LLMs in PCG follow similar scaling laws to those seen in NLP.

Controllability: Observable vs. Emergent

The models showed a bifurcated ability to follow prompts. They achieved 100% accuracy when asked to control "observable" metrics, such as the specific percentage of empty floor space. Conversely, they struggled with "emergent" metrics, such as a specific solution length, achieving only 17% accuracy. This indicates that while LLMs can master surface-level statistical distributions, they struggle with deep logical planning and the functional consequences of tile placement.

Model Size and Generalization

One of the most significant findings was the performance gap between GPT-2 and GPT-3 (Davinci) in low-data environments. On the augmented Microban dataset, GPT-2 failed to generalize, scoring only 0.04. In contrast, GPT-3 achieved a score of 0.51, suggesting that the massive parameter counts of larger models allow them to extract meaningful patterns from very small datasets—a critical requirement for practical game development applications.

Limitations and Future Work

The study identifies several bottlenecks for LLM-based level generation. The reliance on massive datasets like Boxoban is currently a barrier, as most games do not possess such extensive level libraries. Additionally, the use of string edit distance as a novelty metric is limited, as minor character changes can fundamentally alter a puzzle's logic.

Future research directions include training models on multi-game datasets to leverage cross-domain generalization and employing Reinforcement Learning (RL) to improve the models' adherence to complex functional constraints and gameplay dynamics.

Summary updated

BibTeX
@inproceedings{todd2023level,
  author = {Graham Todd and Sam Earle and Muhammad Umair Nasir and Michael Cerny Green and Julian Togelius},
  title = {{Level Generation Through Large Language Models}},
  booktitle = {FDG},
  year = {2023},
  doi = {10.1145/3582437.3587211},
}
Figure