1 of 21

Procedural Content Generation for Computer Games

Labs 2 - Mario

Vojtěch Černý

cerny@gamedev.cuni.cz

2 of 21

Prerequisites

  • Java 11 or newer
    • Make sure your PATH and JAVA_HOME env. variables point to it
  • Windows / Mac / Linux
  • Python 3 (NEW)
  • (Recommended) IntelliJ IDEA
    • Community edition suffices
    • As a student you can get Ultimate by just entering your student number

3 of 21

About Mario

  • First side-scrolling Mario platformer is Super Mario Bros (1985)
  • Made on NES

4 of 21

Mario as a framework

  • Nintendo is (always) very protective about their creations
  • Infinite Mario Bros (2008)
    • Java clone, procedurally generates levels
    • Markus Persson
  • Mario AI Framework (2009)
    • Sergey Karakovskiy, Julian Togelius
    • customized Infinite Mario Bros
    • used for AI / PCG competitions and some research

5 of 21

Mario as a framework

  • Mario AI Framework, 10th anniversary (2019)
  • Available from http://marioai.org

  • Improvements:
    • Contains a forward model
    • Has several AIs and level generators implemented
    • Storing levels as human-readable files
    • Original NES graphics

6 of 21

Technical info

  • Levels are standardly 150 x 16 tiles
  • Robin Baumgarten’s agent uses A* - should be “somewhat” universal AI
    • It isn‘t, really
    • Also, he‘s quite slow

7 of 21

The challenges

  • How do you recognize a good level in Mario?

8 of 21

The Homework

Create a level generator for Mario with some level of indirectness!

Possible options (non-exhaustive list):

  • Assemble levels from building blocks
  • Use template instantiation
  • Use grammars
  • Predetermine # of gaps, # of enemies, and generate accordingly

9 of 21

The Repository

Start with the mario-levels repo, which contains a Gradle buildsystem to run Mario

Using IntelliJ IDEA as IDE is highly recommended

Two main files:

  • RunGame.kt (runnable by ./gradlew singleRun)
    • Runs the generator (set in the file) with an A* agent
  • GatherMetrics.kt (runnable by ./gradlew generateCSV)
    • Performs a number (default 100) runs, evaluates some metrics into a CSV file

10 of 21

Making it work

  • Clone the mario-levels repo
  • Try running ./gradlew singleRun
  • Try running ./gradlew generateCSV
  • Run python in src/main/python/make_graphs.csv
  • Check if you have graphs generated out/generator.png

11 of 21

The Task

Part 1 - Create a generator Class

  • If you use Java, create a generator in:
    • src/main/java/levelGenerators
  • If you use Kotlin, create a generator in:
    • src/main/kotlin/levelGenerators

  • Observe examples in those folders
  • Again, create something you would be happy to put in your game
    • Put details into the levels (enemies, pipes, etc.)

12 of 21

The Task

Part 2 – Create an evaluation metric of Mario levels

Copy one of

  • Java -> src/main/java/metrics/JumpMetricJava.java
  • Kotlin -> src/main/kotlin/metrics/JumpMetric.kt

and modify it to make your own!

Criteria: Make something you would be happy to write about!

13 of 21

The Task

Part 3 – Plot your generator performance with your metric

To plot graphs, all that should be needed is to:

  • Add you metric in src/main/kotlin/GatherMetrics.kt
  • Generate CSV in src/main/python/data by running

./gradlew generateCSV

  • Run plotting in python in src/main/python/make_graphs.py

Plot graphs of linearity vs. your metric on your, notch and benWeber generators (see slide 18)

14 of 21

Discuss your results

  • Interpret what the graphs are showing
  • Which generator seems best?

15 of 21

Criteria

  • Create a generator with some level of indirectness
  • The levels should be beatable
    • You may try to use Baumgarten agent to validate
    • (but even he fails on some fairly trivial obstacles)
  • Simple agent by Sergey Karakovski should not be able to finish them

16 of 21

Points

Level generator – 2 points (indirect representation, good difficulty)

Metric and graphs to evaluate – 1 points

1 bonus point – create a level which you can win, but Robin Baumgarten agent does not

bonus points are added to exam points, but do not count towards the 13 points required for lab credit

17 of 21

Acceptable solution:

made from building blocks

18 of 21

Mine

Notch

Ben Weber

Acceptable solution:

made from building blocks

19 of 21

Another option – Your experiment!

  • If there’s something cool you would like to try in Mario / platformers generation, let’s discuss it and it may become your homework!

  • It should still be (at least in part) level generation

  • Examples:
    • Grammar system for platformers

20 of 21

Submission details

  • Send your solutions to cerny@gamedev.cuni.cz
  • Prefix the subject with “NAIL123-HW2”
  • Submit:
    • two files of Kotlin or Java (human-readable, commented)
      • one implementing the generator and the metric
      • If you want to use more classes, use internal ones
    • at least 3 screenshots of generated levels
    • plots of metrics (plot linearity vs. your metric for each of your generator, notch and benWeber)
    • comment the results in the plots, why they look like they do
    • describe all you have tried, what worked or didn’t, the problems you faced
    • how much time you spent with the project (will not be part of evaluation)

  • Deadline is 30.3.
    • If you need more time, talk/write to me before the deadline

21 of 21

Questions / Problems

  • You can always e-mail me at cerny@gamedev.cuni.cz

  • One final recommendation:

Allocate more than one session to work on the project. If you get stuck on some issue, it’s good to clear your head for a bit and return to it later.