Using Unconditional Diffusion Models in Level Generation for
Super Mario Bros.
Abstract
This study introduces a novel methodology for generating levels in the iconic video game Super Mario Bros.
using a diffusion model based on a UNet architecture.
The model is trained on existing levels, represented
as a categorical distribution, to accurately capture thegame’s fundamental mechanics and design principles.
The proposed approach demonstrates notable successin producing high-quality and diverse levels, with asignificant proportion being playable by an artificial
agent. This research emphasizes the potential of diffusion models as an efficient tool for procedural content
generation and highlights their potential impact on thedevelopment of new video games and the enhancementof existing games through generated content.

1

Introduction

The ever-evolving landscape of the video game industry has led to the development of increasingly complex and engaging games that captivate players worldwide. A crucial aspect of game development is generating innovative and challenging levels that provide
rich and immersive gaming experiences. Procedural
content generation (PCG) has emerged as a potent
technique for crafting such levels, automating the design process while preserving diversity and intricacy [1].
PCG refers to the algorithmic creation of game content,such as levels, characters, or storylines, using rules orprocedures that ensure variety and adaptability [1].
Among numerous approaches to PCG, employing deepneural networks (DNNs) has shown immense potential in generating high-quality and captivating content[2]. This study investigates the application of diffusion models, a largely uncharted deep learning method
within the realm of PCG, for level generation in theiconic video game Super Mario Bros. (SMB).
SMB, launched in 1985, holds a prominent position as a culturally and historically significant game.
Its straightforward yet enthralling gameplay, centeredaround platforming mechanics, tile-based level design,and varied game elements, persistently attracts researchers in PCG and artificial intelligence [3]. Numerous PCG techniques have been utilized to generate levels for SMB, including genetic algorithms [4],Markov chains [5], and DNNs [6, 7, 8, 9]. Nevertheless,the quest for more efficient and productive methods
to produce high-quality, engaging levels persists.
Recently, diffusion models have garnered substantial interest in the deep learning community due totheir capacity to generate realistic and high-quality
samples across various domains, such as images, text,
and audio [10]. These models function by modeling thedata generation process as a continuous diffusion pro-cess, capturing the underlying structures and patterns
present in the input data [11]. This approach offers thepotential for more stable and accurate content generation compared to other DNNs, for instance, generative
adversarial networks (GANs) [12]. Although the application of diffusion models within the context of PCG
in video games remains unexplored, their content generation capability in other domains suggests they may
offer a promising alternative to existing techniques.
This study applies an unconditional diffusion model
to level generation for SMB, utilizing a categorical
distribution representation to model the data. We
train the model on a dataset of existing levels, enabling
it to accurately capture the essential game mechanics
and design principles. By evaluating the generated
levels in terms of quality, diversity, and playability,
we aim to demonstrate the effectiveness of diffusion
models as a novel approach to PCG in video games.
This research holds substantial implications for theacademic and game development communities. By introducing diffusion models as a potential tool in PCG,
our work expands the current understanding of deeplearning techniques applied to game design. Furthermore, the successful application of diffusion models inlevel generation may influence the development of new
video games and the enhancement of existing games
by providing a new avenue for content generation. Ultimately, we hope the insights gained from this study
will inspire further research on diffusion models andtheir potential applications in the rapidly evolving
domain of video games and artificial intelligence.

2

Related Work

This section reviews relevant literature on diffusion
models and PCG employing deep learning, focusing
on SMB level generation.

2.1

Diffusion Models

Sohl-Dickstein et al. [11] laid the foundation for
diffusion models by proposing a deep unsupervised
learning approach based on nonequilibrium thermodynamics. Their approach involved training deep networks using diffusion processes, allowing for the discovery of hierarchical structures in the input data. This
work pioneered the use of diffusion processes in deeplearning.
Ho et al. [10] introduced Denoising Diffusion Probabilistic Models (DDPM), which utilized a continuous
diffusion process to model the data generation process.
The approach captured the underlying structures andpatterns in the input data, resulting in stable and accurate content generation. Their model was conditioned
on input data and a noise schedule and used a seriesof denoising steps to reverse the diffusion process.

Figure 1: The directed graphical model: forward and reverse diffusion
Dhariwal and Nichol [12] demonstrated that diffusion models could outperform Generative Adversarial
Networks (GANs) in image synthesis, further solidifying the potential of diffusion models in content generation. The authors proposed a new sampling algorithm,
which reduced the required number of denoising steps
and made the generation process more efficient.

2.2 PCG employing Deep Learning Techniques

Summerville and Mateas [6] utilized Long ShortTerm Memory (LSTM) networks to generate levels
for SMB, treating them as strings and demonstrating
the potential of recurrent neural networks in PCG.
The LSTM-based approach could capture long-range
dependencies in level design but was limited in its
ability to represent spatial relationships between gameelements.
Volz et al. [7] employed Deep Convolutional Generative Adversarial Networks (DCGANs) to evolve Mariolevels in the latent space. This approach allowed forthe generation of diverse and engaging content byleveraging the adversarial training process of GANs.
Nonetheless, DCGANs could suffer from mode collapse
and training instability, leading to a limited variety ofgenerated levels.
Sarkar and Cooper [8] explored the use of Variational Autoencoders (VAEs) for sequential segmentbased level generation and blending. The VAE-based
approach provided a compact and continuous latent
representation of level segments, enabling smooth level
generation and blending. One limitation of VAEs was
the potential for blurry or less detailed content due tothe minimization of reconstruction loss.
More recently, Sudhakaran et al. [9] proposed MarioGPT, a fine-tuned GPT-2 model specifically designed
for generating tile-based game levels, focusing on SMB
as a use case. The study demonstrated the potentialof combining Large Language Models (LLMs) withdiversity-driven algorithms like novelty search for openended content generation. Despite limitations in generalizability, MarioGPT offered a promising approachto controllable and diverse PCG systems.
While existing literature illustrates some successful
implementations of different deep learning techniquesin level generation, the use of diffusion models in therealm of PCG remains largely unexplored.

3

Proposed Approach

3.1

Data Collection and Representation

Our training data consists of levels from the Video
Game Level Corpus (VGLC) [13], with a focus on
two variations of the game: SMB 1 and 2 (Japan).
While raw image data of the levels are present, VGLC
also provides the levels in the form of long text files,
representing different level components with uniquecharacters and necessitating preliminary processing.
Discrepancies exist between the two versions, such asinconsistent level heights, varying numbers of uniquesprites, and divergent encoding formats. We apply
a series of uniformization procedures to resolve theinconsistencies. Subsequently, We partition the standardized text files into uniformly-shaped segments byemploying a rolling window. This approach results inlevel segments measuring 14x14 units and containing
11 distinct sprites. We further encode these segments
and transform them into arrays with dimensions of
11x14x14 using one-hot encoding. We represent thelevels as a categorical distribution where the 11 uniquetokens (sprites) are considered and the probability ofeach token occurring in a level is modeled.

3.2

Model Architecture

We present an adaptation of the unconditional diffusion model based on a UNet [14] architecture with
self-attention mechanisms and temporal embedding.
Self-Attention The self-attention mechanism is a vital component of our model, improving its capacity to capture spatial and temporal dependencies
within the input data. Our architecture integrates Performer [15] self-attention layers leveraging the Fast Attention Via positive Orthogonal
Random features (FAVOR+) algorithm to reduce
the quadratic complexity of self-attention to linear
complexity. Although Performer architectures are
more commonly applied to natural language processing tasks, recent advancements in transformerbased models like Vision Transformers (ViT) [16]and DETR (DEtection TRansformer) [17] show
the potential for using transformers, including
Performer, in image-related tasks.
The placement of self-attention layers after eachdownsampling and upsampling layer enables themodel to process long-range dependencies andmaintain spatial coherence throughout the network. By leveraging Performer self-attention, themodel can effectively learn and utilize both local
and global contextual information, leading to improved performance in spatio-temporal prediction
tasks while maintaining lower memory usage andcomputational cost.
Double Convolution The double convolution module consists of two consecutive convolutional
layers, each followed by a group normalization[18] layer and a Gaussian Error Linear Unit(GELU) [19] activation function. Group normalization maintains stable distributions of the activations, improving the overall training stability.
The GELU activation function introduces nonlinearity to the model, enhancing its capacity tolearn complex patterns in the input data.
This combination of layers extracts and processes
both high-level and low-level features from the
input data, effectively preserving spatial coherence and contributing to improved performance inspatio-temporal prediction tasks. Furthermore, aresidual connection can be optionally introduced
between the input and output of the module toenhance the model’s learning capability and facilitate gradient flow during backpropagation.
Down and Up Blocks The Down and Up blocks
are responsible for encoding and decoding the
input features, respectively. The Down block consists of a max-pooling layer followed by double
convolution layers. Additionally, an embedding
layer is used to incorporate the time information t into the Down block. The Up block uses
transposed convolution layers that ensure the appropriate upsampling of the input tensor. The
Up block concatenates the skip connection fromthe corresponding Down block and applies double
convolution layers. Similar to the Down block, anembedding layer is employed to incorporate thetime information t into the Up block.
UNet The UNet is a key component of the proposedmodel, employing a symmetric encoder-decoderarchitecture to facilitate the learning of spatiotemporal features in the input data. The model
begins with an initial double convolution module to process the input, followed by a series of
Down blocks, each incorporating Performer selfattention layers for improved spatial and temporal context representation. The bottleneck is
composed of three double convolution modules,
designed to capture high-level abstractions. The
decoding path consists of a series of Up blocks,
again with Performer self-attention layers, enabling the model to recover spatial details fromthe compressed feature representation. The final
convolutional layer maps the output to the desired
number of channels. Throughout the architecture,
positional encoding is employed to incorporatetime information, allowing the model to effectively
capture temporal dependencies for improved prediction performance in spatio-temporal tasks.

Figure 2: UNet architecture

3.3

Training Process

The training process for our model is inspired by thetraining and sampling algorithms of DDPM. The corecomponents of the training process include defining anoise schedule, applying forward diffusion to corrupt
data samples, training a neural network to perform
reverse diffusion by learning a denoising function, andgenerating new samples by iteratively applying thelearned function [10]. We adapt these components
to suit the task of level generation for SMB. Whilemaintaining the overall training flow, our model adopts
novel approaches and methods tailored to the uniquerequirements of our task.

4

Experiments

4.1

Methodology

Our proposed model incorporates several novel components that distinguish it from DDPM.
• Categorical data representation: We represent the levels using one-hot encoding, enabling
the model to learn and generate levels as categorical data. This representation is more suitable fordiscrete-level generation tasks and allows us toutilize a multi-class cross-entropy loss function.
• Reconstruction loss: To address the issue ofpreserving low-level details, we introduce a reconstruction loss term during the training process,encouraging the model to generate levels withgreater fidelity to the original structure. The reconstruction loss is implemented as a negative
log-likelihood, which, due to the categorical data
representation, essentially becomes a multi-classcross-entropy loss. This loss function, with its
equation as below, assists the model in learning
effective denoising functions by calculating thenegative log probabilities of the original levels
given the reconstructed levels.
N

Lrec = −

H

W

1 XXX
log Pθ (Onij |xnij )N n=1 i=1 j=1

N represents the batch size, H and W the height
and width of the levels, xnij and Onij the generated and original blocks, respectively, at position

(i, j) in the n-th sample, and Pθ (Onij |xnij ) the
probability of the original block given the generated block under the parameterized model.
• Beta scheduling schemes: We experiment withdifferent beta scheduling schemes, specifically linear, quadratic, and sigmoid scheduling, to investigate their impact on the quality and diversity of
the generated levels.
• Per-sprite temperature scaling: To balance
the representation of different sprite types andbetter control the sampling of individual sprites,
we employ per-sprite temperature scaling and temperature adjustment. Temperature adjustment
is achieved by taking the n-th root of the sprite
counts and normalizing each by dividing by thecount of the least frequent sprite. We experimentwith three distinct values of n: 2, 4, and 8. Lower
values of n promote coarse temperature adjustments, resulting in high-variation samples, while
higher values of n encourage fine temperatureadjustments, leading to low-variation samples.

4.2

Results and Evaluation

4.2.1

Qualitative Evaluation

Figure 3: Random levels generated
Figure 3 shows a random sampling of levels utilizing quadratic scheduling and moderate temperaturescaling, which led to the fastest convergence and thelowest overall loss after training for 500 epochs. The
sampled levels appear to accurately capture SMB’s
design principles and are mostly hard to distinguishfrom existing levels using human visual perception.

4.2.2

Quantitative Evaluation

We evaluate the diversity and playability of two
versions of our approach, quadratic beta schedulingwith moderate and coarse temperature scaling. We set
MarioGPT as our baseline. The metrics are average
edit distance between pairs of levels, coverage, whichis the proportion of levels having another level withina specified distance threshold, and playability, which isthe proportion solvable by an A* artificial agent. Table 1 reveals that coarse temperature scaling achieves
the highest diversity, having the largest average edit
distance and lowest coverage value, although with thecost of reduced playability. The moderate temperaturescaling approach strikes a more balanced compromise
between diversity and playability, with only slightly
lower playability than the baseline (70% vs. 74%).
Table 1: Qualitative Evaluation

5

Metrics

Moderate
temp. scale

Coarsetemp. scale

MarioGPT

Edit distance

41.89

61.89

50.78

Coverage

0.33

0.02

0.2

Playability

0.70

0.62

0.74

Discussion and Conclusion

We introduced a novel SMB level generation approach using a diffusion model with the UNet architecture and Performer self-attention layers. Our model
incorporates unique techniques, such as categorical
data representation, reconstruction loss, and per-sprite
temperature scaling, fostering high-quality and diverse
SMB levels adhering to design principles.
Our evaluation explored the impact of beta scheduling schemes and per-sprite temperature adjustmentson performance. Qualitatively, the generated levels
effectively captured original design principles. Quantitatively, both evaluated versions exhibited varying
levels of diversity, maintaining a balanced trade-off
despite having slightly lower playability than the MarioGPT baseline. Refined temperature adjustments andfurther training may enhance performance, generatinglevels closely resembling actual levels while preserving
high diversity and playability.
This research sets the stage for future work, including investigations of different noise schedules, optimization techniques, and self-attention mechanisms
for efficient level generation. Manipulating per-sprite
temperatures may enable generating levels favoringcertain sprites, broadening the current random level
generation scope. Additionally, assessing our model’s
performance in other 2D platformers or diverse gamegenres is worth further exploration.
In conclusion, our diffusion model provides a newperspective in the PCG domain, showcasing the potential of advanced deep learning techniques for SMB
level generation. Capturing spatial and temporal relationships within SMB levels, our approach generates
diverse, high-quality levels exhibiting both playability
and visual fidelity, highlighting our substantial contribution to the field.

References[1] Noor Shaker, Julian Togelius, and Mark J. Nelson.
Procedural Content Generation in Games. Springer
International Publishing, 1st edition, 2016.
[2] Jialin Liu, Sam Snodgrass, Ahmed Khalifa, Sebastian Risi, Georgios N Yannakakis, and Julian Togelius.
Deep learning for procedural content generation. Neural Computing and Applications, 33(1):19–37, 2021.

[3] Jordan Pearson. Why artificial intelligence researchers
PMLR, 2015.
love ’super mario bros.’, Oct 2015.
[12] Prafulla Dhariwal and Alexander Nichol. Diffusion[4] Lucas Ferreira, Leonardo Pereira, and Claudio Toledo.
models beat gans on image synthesis. Advances in
A multi-population genetic algorithm for procedural
Neural Information Processing Systems, 34:8780–8794,
generation of levels for platform games. In Proceed2021.
ings of the Companion Publication of the 2014 Annual[13] Adam James Summerville, Sam Snodgrass, Michael
Conference on Genetic and Evolutionary ComputaMateas, and Santiago Ontanón. The vglc: The video
tion, pages 45–46, 2014.
game level corpus. arXiv preprint arXiv:1606.07487,[5] Sam Snodgrass and Santiago Ontañón. A hierarchical2016.
approach to generating maps using markov chains.
[14] Olaf Ronneberger, Philipp Fischer, and Thomas Brox.
In Proceedings of the AAAI Conference on Artificial
U-net: Convolutional networks for biomedical imIntelligence and Interactive Digital Entertainment,
age segmentation. In Medical Image Computing andvolume 10, pages 59–65, 2014.
Computer-Assisted Intervention–MICCAI 2015: 18th
[6] Adam Summerville and Michael Mateas. Super marioInternational Conference, Munich, Germany, Octoberas a string: Platformer level generation via lstms.
5-9, 2015, Proceedings, Part III 18, pages 234–241.
arXiv preprint arXiv:1603.00930, 2016.
Springer, 2015.
[7] Vanessa Volz, Jacob Schrum, Jialin Liu, Simon M[15] Krzysztof Choromanski, Valerii Likhosherstov, David
Lucas, Adam Smith, and Sebastian Risi. Evolving
Dohan, Xingyou Song, Andreea Gane, Tamas Sarlos,
mario levels in the latent space of a deep convolutionalPeter Hawkins, Jared Davis, Afroz Mohiuddin, Lukasz
generative adversarial network. In Proceedings ofKaiser, et al. Rethinking attention with performers.
the genetic and evolutionary computation conference,arXiv preprint arXiv:2009.14794, 2020.
pages 221–228, 2018.
[16] Alexey Dosovitskiy, Lucas Beyer, Alexander Kolesnikov,[8] Anurag Sarkar and Seth Cooper. Sequential segmentDirk Weissenborn, Xiaohua Zhai, Thomas Unterthiner,
based level generation and blending using variational
Mostafa Dehghani, Matthias Minderer, Georg Heigold,
Sylvain Gelly, et al. An image is worth 16x16 words:
autoencoders. In Proceedings of the 15th International
Transformers for image recognition at scale. arXiv
Conference on the Foundations of Digital Games,
preprint arXiv:2010.11929, 2020.
pages 1–9, 2020.
[17] Nicolas Carion, Francisco Massa, Gabriel Synnaeve,[9] Shyam Sudhakaran, Miguel González-Duque, Claire
Nicolas Usunier, Alexander Kirillov, and Sergey Zagoruyko.
Glanois, Matthias Freiberger, Elias Najarro, and SeEnd-to-end object detection with transformers. In
bastian Risi. Mariogpt: Open-ended text2level generComputer Vision–ECCV 2020: 16th European Conation through large language models. arXiv preprint
ference, Glasgow, UK, August 23–28, 2020, ProceedarXiv:2302.05981, 2023.
ings, Part I 16, pages 213–229. Springer, 2020.
[10] Jonathan Ho, Ajay Jain, and Pieter Abbeel. Denoising[18] Yuxin Wu and Kaiming He. Group normalization. In
diffusion probabilistic models. Advances in Neural
Proceedings of the European conference on computer
Information Processing Systems, 33:6840–6851, 2020.
vision (ECCV), pages 3–19, 2018.
[11] Jascha Sohl-Dickstein, Eric Weiss, Niru Maheswaranathan,[19]
Dan Hendrycks and Kevin Gimpel. Gaussian error
and Surya Ganguli. Deep unsupervised learning uslinear units (gelus). arXiv preprint arXiv:1606.08415,
ing nonequilibrium thermodynamics. In International
2016.
Conference on Machine Learning, pages 2256–2265.