WorldGenerator Update

The first obstacle to tackle with the PokeyGame idea was world generation – how do you generate a randomized world that can be traversed?  I ultimately decided to build a procedural level generator capable of churning out levels on demand, or according to a predefined structure and saved to a template file that can be read later.  This lead to the WorldGenerator class I’ll be demonstrating.  This is my first iteration, I’ve decided to come up with my own method, and then investigate other methods once I am happy with mine to see how it compares.

The class is defined, and the various level configuration parameters are parsed or given default values.  The parameters merit some explanation.

  • debug / silent / verbose  : essentially mutually exclusive, these options enable debugging-level log and console messages, or disable output altogether.  The debug option takes precedence over the  silent  and  verbose modes, and provides the most output.
  • fpath / conf : fpath  is the output path for the WorldGenerator template.   conf is the path to a Pokeyworks PokeyConfig file.
  • rand / x / y / z : These simply set the x, y, and z dimensions, or if  rand is  True these will be randomized (within a maximum z dimension of 10, and 50 for x and y.
  • app_logger : expects a Python logger.  If none is passed, one is automatically generated using the PokeyWorks.setup_logger() function.  The debug option has logical message additions as well as the maximum logging verbosity :
  • room_variance : sets the maximum room size range, the lowerbound is 3 tiles.  Must be greater than or equal to 3.
  • post_check : if  True , automatically checks the entire map after generating, and if the level cannot be passed with the chosen algorithm, it is regenerated.
  • path_alg : sets the pathfinder search algorithm.   A*, Greedy Best-First, and Breadth-First options are available, for a general map Greedy Best-First seems to perform best with the current map environment.

The last step is to record the start time.  The execution time is calculated by subtracting the  time.clock() return value at the end of execution, resulting in a floating point second value.

Gridlines

A major consideration is how exactly to represent the world.  Nested lists could be used, but Python has a much better tool for representing and indexing a grid – Dictionaries.  Using grid coordinate tuples – (x, y, z) – one can create a unique grid and access it easily via nested for loops or list comprehension statements.  A demonstration of this utility follows in the WorldGenerator.__str__()  method.

In this case, terminal ascii color codes are being used in the color.colorized attribute, and a map is printed.  An example of its output in my terminal :

floor1_no_path

The map pattern is generated by first populating a list of random waypoints.  On floor 1, a starting point and descent point are set, waypoints are added, hallways are generated to connect each waypoint, and rooms are randomly placed on each waypoint.  The same process is followed on each floor until the bottom floor, each connected by ascent and descent points, and the bottom floor containing an ascent point and an exit point.

Stay tuned for an update, including a more detailed explanation of this process and the WorldGenerator.path_avail_dirs() method.

Leave a Reply

Your email address will not be published. Required fields are marked *