Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Creating Level Generators
You can create a level generator by creating a class called LevelGenerator.java that inherits from core.generator.AbstractLevelGenerator.java. The class should implement two essential functions:
- public LevelGenerator(GameDescription game, ElapsedCpuTimer elapsedTimer): constructor function to initialize any data that will be used during the level generation.
- public String generateLevel(GameDescription game, ElapsedCpuTimer elapsedTimer): this function is responsible for generating a level for the supplied game. The generated level should be returned in form of string where each character should be from the level mapping section.
Also you can use your own level mapping but you need to implement the following function:
- public HashMap<Character, ArrayList<String>> getLevelMapping(): this function should return a hashmap that helps decode the current generated level.
Both required functions are supplied with the following objects:
- GameDescription game: The GameDescription is a class that allows querying about the current game sprites such as avatar sprites (getAvatar()), movable sprites (getMoving()), ...etc. Also, you can get the interaction between any two sprites (getInteraction(String stype1, String stype2)), available actions for the agent (getAvailableActions()), termination conditions (getTerminationConditions()), level mapping (getLevelMapping()), and forward model to use it to test a certain level (testLevel(String level)).
- ElapsedCpuTimer elapsedTimer: The ElapsedCpuTimer is a class that allows querying for the remaining CPU time the generator has to return a level. You can query for the number of milliseconds passed since the method was called (elapsedMillis()) or the remaining time until the timer runs out (remainingTimeMillis()). Exiting these functions after the timer has finished (when remainingTimeMillis() ≤ 0) would make this generator to be disqualified in the game being played.
The generateLevel function should return a string that describe the generated level. The number of rows describe the height of the level, while the maximum length of the row is considered the width of the level. Each character describes all the objects positioned at this tile position. The characters can be decoded using the level mapping supplied by the GameDescription object. If you want to use your own characters you should supply a getLevelMapping function.
The next pages show some sample level generators that could be found with the framework: