Skip to content

Sample Constructive Level Generator

Raluca D. Gaina edited this page Feb 12, 2018 · 2 revisions

This level generator utilizes the information presented in the GameDescription object to generate better designed levels. For example if the avatar sprite is of type FlakAvatar or HorizontalAvatar (special types of avatar where the avatar can only move horizontally), it should be placed either at the top or the bottom of the level. The generator analyzes the GameDescription object using the GameAnalyzer.

Steps applied in the Constructive generator for Pacman: (1) Build a Level Layout (2) Add an Avatar Sprite (3) Add Harmful Sprites (4) Add Collectible and Other Sprites

The level generator utilizes the information provided by the GameAnalyzer to generate a well-formed level. The above figure summarizes the core steps done by this approach. The generation procedure is divided into four core steps with a pre-processing step and a post-processing step:

  1. (Pre-processing) Calculate Cover Percentages: This step calculates the percentage of tiles in the generated level that should be covered with sprites. It also calculates that percentage for each different sprite category. The total cover percentage is directly proportional to the number of collectible sprites, and it is inversely proportional to the number of harmful sprites and the number of sprites that are created by other sprites. All categories have a percentage directly proportional to the summation of the priority values of each sprite in each category.

  2. Build a Level Layout: This step only takes place when there are solid sprites. It picks a random solid sprite and surrounds the level with that sprite. Based on the calculated solid percentage it fills the internal level with solid sprites that are connected to each other without blocking any area.

  3. Add an Avatar Sprite: This step places a randomly picked avatar sprite to a random free location.

  4. Add Harmful Sprites: This step adds harmful sprites to the game based on the calculated harmful percentage. If the harmful sprite is a moving sprite, the generator chooses a free location away from the avatar sprite but if the sprite is a static sprite, the generator chooses any random free location.

  5. Add Collectible and Other Sprites: This step places randomly picked sprites to randomly free locations. The number of added sprites depends on their cover percentages.

  6. (Post-processing) Fix Goal Sprites: This step makes sure that the number of goal sprites are greater than the number specified in the termination set for that sprite type; sprites are added until this is the case. \end{enumerate}

Table of Contents:

Clone this wiki locally