// RandomWalkCave draws a map in the destination grid using drunk walking. It
// performs a certain number of approximately equal length random walks,
// digging using the given cell, until a certain filling percentage (given by a
// float between 0 and 1) is reached. It returns the number of digged cells.
// If more than one walk is done, the result is not guaranteed to be connected
// and has to be made connected later.
RandomWalkCave draws a map in the destination grid using drunk walking. It
performs a certain number of approximately equal length random walks,
digging using the given cell, until a certain filling percentage (given by a
float between 0 and 1) is reached. It returns the number of digged cells.
If more than one walk is done, the result is not guaranteed to be connected
and has to be made connected later.
// RandomWalkCave draws a map in the destination grid using drunk walking . It // performs a certain number of approximately equal length random walks // digging using the given cell until a certain filling percentage ( given by a // float between 0 and 1 ) is reached . It returns the number of digged cells . // If more than one walk is done the result is not guaranteed to be connected // and has to be made connected later .
func (mg MapGen) RandomWalkCave(walker RandomWalker, c Cell, fillp float64, walks int) int {
	if fillp > 0.9 {
		fillp = 0.9
	}
	if fillp < 0.01 {
		fillp = 0.01
	}
	max := mg.Grid.Size()
	maxdigs := int(float64(max.X*max.Y) * fillp)
	digged := mg.Grid.Count(c)
	digs := digged
	wlkmax := maxdigs - digged
	if walks > 0 {
		wlkmax /= walks
	}
	for digs < maxdigs {
		p := gruid.Point{mg.rand(max.X), mg.rand(max.Y)}
		sc := mg.Grid.At(p)
		if c == sc {
			continue
		}
		mg.Grid.Set(p, c)
		digs++
		wlkdigs := 1
		outDigs := 0
		lastInRange := p
		for digs < maxdigs && wlkdigs <= wlkmax {
			q := walker.Neighbor(p)
			if !mg.Grid.Contains(p) && mg.Grid.Contains(q) && mg.Grid.AtU(q) != c {
				p = lastInRange
				continue
			}
			p = q
			if mg.Grid.Contains(p) {
				if mg.Grid.AtU(p) != c {
					mg.Grid.Set(p, c)
					digs++
					wlkdigs++
				}
				lastInRange = p
			} else {
				outDigs++
			}
			if outDigs > wlkmax || outDigs > 150 {
				outDigs = 0
				p = lastInRange
			}
		}
	}
	return digs - digged
}
func ( mg MapGen ) RandomWalkCave ( walker RandomWalker , c Cell , fillp float64 , walks int ) int { if fillp > 0.9 { fillp = 0.9 } if fillp < 0.01 { fillp = 0.01 } max := mg . Grid . Size ( ) maxdigs := int ( float64 ( max . X * max . Y ) * fillp ) digged := mg . Grid . Count ( c ) digs := digged wlkmax := maxdigs - digged if walks > 0 { wlkmax /= walks } for digs < maxdigs { p := gruid . Point { mg . rand ( max . X ) , mg . rand ( max . Y ) } sc := mg . Grid . At ( p ) if c == sc { continue } mg . Grid . Set ( p , c ) digs ++ wlkdigs := 1 outDigs := 0 lastInRange := p for digs < maxdigs && wlkdigs <= wlkmax { q := walker . Neighbor ( p ) if ! mg . Grid . Contains ( p ) && mg . Grid . Contains ( q ) && mg . Grid . AtU ( q ) != c { p = lastInRange continue } p = q if mg . Grid . Contains ( p ) { if mg . Grid . AtU ( p ) != c { mg . Grid . Set ( p , c ) digs ++ wlkdigs ++ } lastInRange = p } else { outDigs ++ } if outDigs > wlkmax || outDigs > 150 { outDigs = 0 p = lastInRange } } } return digs - digged }
RandomWalkCave draws a map in the destination grid using drunk walking.
RandomWalkCave draws a map in the destination grid using drunk walking .