Reinforcement Learning – Lua script analysis, Part 1

The MarI/O project (https://github.com/mam91/Neat-Genetic-Mario) is structured into five Lua files and a pool of neural network states. The five Lua files in question are labeled ‘config’, ‘game’, ‘mario-neat’, ‘mathFunctions’ and ‘spritelist’. In this blog, I will take a closer look on four of them – ‘mario-neat’ will be next week’s topic due to its immense size.

The config Lua file is very straightforward. It contains…

  • Variables that point to relevant folders such as the pool folder and the emulator folder.
  • A list of states that will be loaded when the program starts, where each state represents a different level in the game. This is interesting because based on this setup, we can assume that the neural network could develop differently based on the first level it interacts with.
  • A variable that provides a power-up when the level starts, which might influence the learning rate of the AI.
  • A list of configuration variables for the evolutionary computation part of NEAT, which include a population number (cells to develop), mutation and crossover chance, a step size (indicator for how much progress is allowed in one step. Too low and the process takes forever, too high and the results are inaccurate) and a maximum for nodes (they populate continuously throughout the process; when this variable is reached, a new generation starts).
  • A list of buttons used by the AI.
  • Helper variables for the visual representation.

 

  The spritelist Lua file is both straightforward as well as easy to read. It contains lists of all sprites (2D textures the game was built with) the AI could encounter. In detail, it contains…

  • A list of neutral sprites the AI can interact with without negative or positive effects (e.g. jumping dolphins, flying platforms, vines).
  • A list of good sprites that carry a value for the AI (e.g. coins, 1-ups, goal points).
  • A list of bad sprites that the AI should learn to avoid (i.e. all enemies)
  • An initialization function that puts all sorts of sprites into one list.
  • A list of neutral sprites that are generated by other sprites (e.g. smoke trails, water bubbles).
  • A list of bad sprites that are generated by other sprites (e.g. a hammer, a baseball)
  • An initialization function that puts the generated sprites into a separated list.

 

  The mathFunctions Lua file is the shortest (and simplest) file. It contains…

  • A definition of a sigmoid function, which is a go-to function for most AI tasks.
  • A function labeled ‘squashDistance’, which is a helper function that supports finding the right input.

 

  The game Lua file is a collection of functions that are required for interaction with the game. In detail, it contains functions for…

  • Tracking the position of the player on the screen.
  • Keeping track of the current amount of coins.
  • Keeping track of the current in-game score.
  • Keeping track of / updating the current amount of lives.
  • Keeping track of / updating the current power-up state.
  • Indicating taken damage.
  • Calculating inputs and input deltas. Both are used to evaluate the network.

 

 

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

drei × 4 =