MapGenerator¶
- class MapGenerator(width: int, height: int, wall: npt.DTypeLike, floor: npt.DTypeLike, dirs: DIRS = DIRS.DIR8, rng: random.Random = None, dtype: npt.DTypeLike = None)¶
Bases:
objectBase class for all other map generators to inherit from.
- Parameters:
width – Width of the map
height – Height of the map
wall – What to set for wall tiles
floor – What to set for floor tiles
dirs – How many directions of movement entity’s have
rng – Random generator to use when making decisions
dtype – Arrays will be generated with this dtype set, if provided
- fill(value) npt.NDArray¶
Makes and returns a new map full of the given value.
- Parameters:
value – The value to fill the new map with.
- Returns:
The new map
- generate_map() npt.NDArray¶
Generate a map using the derived generator.
Subclasses must override this function.
- Raises:
NotImplementedError – Someone either misused this class or forgot to override this function.
- get_neighborhood(tile_map: npt.NDArray, tile: Tile) int¶
Returns the number of wall tiles in a given tile’s neighborhood.
A neighborhood is defined as the tiles within two movements of the specified tile. For a rectangular grid map with movement in 8 directions, this is the 5x5 grid centered on the specified tile.
- Parameters:
tile_map – The map in which the tile lives
coordinates – The coordinates of the tile
- Returns:
The number of walls in the neighborhood
- get_neighbors(tile_map: npt.NDArray, tile: Tile, directions: list[tuple[int, int]]) int¶
Returns the number of walls which neighbor a given tile.
By default, this counts neighbors in all 8 tiles which touch the specificed tile. Custom direcitons can be supplied to support maps of other shapes.
- Parameters:
tile_map – The map in which the tile lives
tile – The Tile whose neighbors to count
directions – The relative coordinates of all the tiles to check
- Returns:
The number of neighboring walls
- property dimensions: tuple[int, int]¶
The dimensions of the map