Skip to content

IPositionSelector

George Aleksandrovich edited this page Aug 15, 2019 · 1 revision

An IPositionSelector is an interface that chooses which position to place a Feature in the current generation step.

Labrys comes with one concrete implementation: RandomPositionSelector, which randomly chooses any open boundary position in the current dungeon's grid.

Initialize(ReadOnlyGrid grid)

A hook for initialization. The grid passed in is a readonly view of the dungeon at the start of the generation process, which should only contain the starting room.

Select(ReadOnlyGrid currentGrid)

Called once per generation step. The return value of this call is some position in the Grid.

The expected use case is that a dungeon is built up incrementally, meaning that at each step of generation, every room touches at least one other room (i.e., the dungeon is a single connected component). As a result, Grid has a method, Grid#GetBoundary(), which returns every open position in the grid that is touching an existing room.

In theory, however, any position in the grid can be returned. There are a few things to consider when returning positions:

  • If a position is occupied by a room, then the generation step will fail to place any new rooms down. This means that the generation step will do nothing. Thus, it only makes sense to return unoccupied positions.
  • If a position returned is not on the boundary of the current dungeon (i.e., not in the list returned by Grid#GetBoundary()), then Labrys makes no guarantees that the dungeon will be connected. This means that you could have a group of rooms that you cannot reach from another group of rooms.

Clone this wiki locally