Struct DrunkardWalkSettings
Settings for the Drunkard's Walk map generation algorithm, invoked via ProceduralMapGenerator. Controls the walker population, fill target, individual step behaviour, and the random events that spawn or destroy walkers during the walk.
Inherited Members
Namespace: Scylla.Core.Util.ProceduralMapGen
Assembly: ScyllaCore.dll
Syntax
public readonly struct DrunkardWalkSettings
Remarks
The Drunkard's Walk algorithm operates by launching one or more autonomous agents (walkers) that move randomly across a wall-filled grid and carve floor cells as they go. The following parameters govern walker behaviour:
- TargetFillRatio - the algorithm terminates when the fraction of grid cells that are floor reaches this value, or when MaxSteps total steps have been executed, whichever comes first.
-
ChunkSize - when
1, only the walker's current cell is carved; when3, a 3×3 area centred on the walker is carved. Larger chunks increase fill rate and produce wider open areas. -
ForwardBias - at each step a walker either continues in its
previous direction (with probability
ForwardBias) or chooses a new random direction. A value of0produces fully random walks; a value of1produces straight tunnels. - SpawnChance and DestroyChance - at each step, a new walker may be spawned at a random existing walker's position, and a random walker may be destroyed. At least one walker is always kept alive.
Use the static presets (Default, OpenCaves,
TightTunnels) as starting points. All fields are readonly;
use Lerp(DrunkardWalkSettings, DrunkardWalkSettings, float) to smoothly transition between configurations.
Constructors
DrunkardWalkSettings(float, int, int, int, float, float, float)
Initializes a new DrunkardWalkSettings with explicit control over all walker behaviour parameters.
Declaration
public DrunkardWalkSettings(float targetFillRatio = 0.4, int maxSteps = 10000, int maxWalkers = 5, int chunkSize = 1, float forwardBias = 0.5, float spawnChance = 0.05, float destroyChance = 0.02)
Parameters
| Type | Name | Description |
|---|---|---|
| float | targetFillRatio | Target fraction of grid cells to carve to floor. Must be in |
| int | maxSteps | Hard upper limit on total walker steps across all walkers. Defaults to
|
| int | maxWalkers | Maximum number of concurrent walkers. Defaults to |
| int | chunkSize | Number of cells carved per walker step. |
| float | forwardBias | Probability in |
| float | spawnChance | Per-step probability in |
| float | destroyChance | Per-step probability in |
Fields
ChunkSize
Number of grid cells carved to floor on each individual walker step. A value of
1 carves only the cell directly occupied by the walker. A value of
3 carves a 3×3 area centred on the walker's current cell, producing wide
open passages and faster fill. Values are clamped to the grid boundary so no
out-of-bounds access occurs.
Declaration
public readonly int ChunkSize
Field Value
| Type | Description |
|---|---|
| int |
Default
A balanced preset that produces moderately-filled, varied cave networks with a mix of open areas and narrow passages. Uses single-cell carving, moderate forward bias, and modest spawn/destroy probabilities.
Declaration
public static readonly DrunkardWalkSettings Default
Field Value
| Type | Description |
|---|---|
| DrunkardWalkSettings |
Remarks
Specific values: TargetFillRatio=0.4, MaxSteps=10000, MaxWalkers=5,
ChunkSize=1, ForwardBias=0.5, SpawnChance=0.05, DestroyChance=0.02.
DestroyChance
Per-step probability in the range [0, 1] that a randomly selected walker
is destroyed. A minimum of one walker is always preserved; destruction is skipped
when only a single walker remains regardless of this probability. Higher values
cause the active walker count to fluctuate more and can produce more localised,
concentrated floor regions.
Declaration
public readonly float DestroyChance
Field Value
| Type | Description |
|---|---|
| float |
ForwardBias
Probability in the range [0, 1] that a walker continues in the same
direction it moved on the previous step rather than choosing a new random
direction. A value of 0.0 produces a fully random walk with equal
probability for all four orthogonal directions each step. A value of
1.0 makes walkers travel in straight lines until they hit a grid boundary.
Intermediate values produce biased random walks; 0.5 gives a reasonable
balance between meandering and directional movement.
Declaration
public readonly float ForwardBias
Field Value
| Type | Description |
|---|---|
| float |
MaxSteps
Hard upper limit on the total number of individual walker steps that may be taken
across all walkers combined. Acts as a safety valve to prevent infinite loops on
grids where TargetFillRatio cannot be reached (for example due to
border clamping or very small grids). Should be set high enough that normal runs
reach the fill target before hitting this limit; the default of 10000 is
adequate for grids up to approximately 100×100.
Declaration
public readonly int MaxSteps
Field Value
| Type | Description |
|---|---|
| int |
MaxWalkers
The maximum number of walkers that may exist simultaneously. New walkers can only be spawned when the current count is below this ceiling. Higher walker counts increase exploration spread and produce more branching, irregular cave shapes. At least one walker always exists throughout the entire walk; this limit only constrains spawning of additional walkers via SpawnChance.
Declaration
public readonly int MaxWalkers
Field Value
| Type | Description |
|---|---|
| int |
OpenCaves
A preset that generates wide-open cavern environments with a high fill ratio, large chunk carving, and many concurrent walkers. Suitable for action-oriented levels that need generous open space for combat or exploration.
Declaration
public static readonly DrunkardWalkSettings OpenCaves
Field Value
| Type | Description |
|---|---|
| DrunkardWalkSettings |
Remarks
Specific values: TargetFillRatio=0.55, MaxSteps=15000, MaxWalkers=8,
ChunkSize=3, ForwardBias=0.3, SpawnChance=0.08, DestroyChance=0.03.
SpawnChance
Per-step probability in the range [0, 1] that a new walker is spawned at
a randomly selected existing walker's current position. The new walker inherits
no direction and chooses randomly on its first step. Spawning only occurs when
the current walker count is below MaxWalkers.
Declaration
public readonly float SpawnChance
Field Value
| Type | Description |
|---|---|
| float |
TargetFillRatio
The fraction of all grid cells that should be carved to floor before the algorithm
terminates. Must be in the range [0.1, 0.9]. The algorithm stops as soon
as the current floor cell count divided by total cell count reaches or exceeds this
value, or when MaxSteps is exhausted. Higher values produce more
open, traversable levels; lower values produce sparser networks of passages.
Declaration
public readonly float TargetFillRatio
Field Value
| Type | Description |
|---|---|
| float |
TightTunnels
A preset that generates sparse networks of narrow, winding tunnels by using a low fill target, single-cell carving, high forward bias, and few walkers. Suitable for claustrophobic underground passages or supply-line maps.
Declaration
public static readonly DrunkardWalkSettings TightTunnels
Field Value
| Type | Description |
|---|---|
| DrunkardWalkSettings |
Remarks
Specific values: TargetFillRatio=0.3, MaxSteps=8000, MaxWalkers=3,
ChunkSize=1, ForwardBias=0.75, SpawnChance=0.03, DestroyChance=0.01.
Methods
Lerp(DrunkardWalkSettings, DrunkardWalkSettings, float)
Linearly interpolates between two DrunkardWalkSettings instances and returns the blended result.
Declaration
public static DrunkardWalkSettings Lerp(DrunkardWalkSettings a, DrunkardWalkSettings b, float t)
Parameters
| Type | Name | Description |
|---|---|---|
| DrunkardWalkSettings | a | The start settings returned when |
| DrunkardWalkSettings | b | The end settings returned when |
| float | t | Interpolation factor in the range |
Returns
| Type | Description |
|---|---|
| DrunkardWalkSettings | A new DrunkardWalkSettings whose fields are blended between
|
Remarks
Float fields (TargetFillRatio, ForwardBias, SpawnChance, DestroyChance) are interpolated continuously. Integer fields (MaxSteps, MaxWalkers, ChunkSize) are interpolated and rounded to the nearest integer.
t is clamped to [0, 1] before any calculation.