...

/

Creating Drunkard’s Walk Maps

Creating Drunkard’s Walk Maps

Learn how to create a walking map and the drunkard will keep digging until it is done.

Drunkard’s Walk produces very natural-looking caverns worn away by erosion. It works by randomly placing a drunken miner on a solid map. The miner digs randomly, carving pathways into the map. Eventually, the miner either passes out, exceeding their maximum number of turns, or exits the map. We then check to see if the map is ready by counting the number of open tiles. If it isn’t ready, we spawn another drunken miner until the map is sufficiently open. The algorithm’s name arises from the random nature of the drunken movement. The algorithm may be visualized as follows:

Let’s start building a drunkard’s walk map.

Implement the boilerplate

Create a new file named map_builder/drunkard.rs and include it in map_builder/mod.rs using mod drunkard. Once again, we need to create the minimal boilerplate code to implement our MapArchitect trait:

Press + to interact
use crate::prelude::*;
use super::MapArchitect;
pub struct DrunkardsWalkArchitect {}
impl MapArchitect for DrunkardsWalkArchitect {
fn new(&mut self, rng: &mut RandomNumberGenerator) -> MapBuilder {
let mut mb = MapBuilder{
map : Map::new(),
rooms : Vec::new(),
monster_spawns : Vec::new(),
player_start : Point::zero(),
amulet_start : Point::zero()
};
mb
}
}

With the basic structure in place, let’s add some drunken miners.

Carve caverns with drunken miners

We need to decide how far a miner can stumble before they pass out. Lower numbers tend to give less open maps; larger numbers tend toward more open spaces. Add a constant to the top ofmap_builder/drunkard.rs so we can tweak this number:

Press + to interact
const STAGGER_DISTANCE: usize = 400;

Now that we’ve the tunable parameter in place, we’ll create a new function, implemented by ... ...