// CellularAutomataCave generates a map using a cellular automata algorithm.
// You can provide the initial wall filling percentage, and then sets of rules
// to be applied in a certain number of iterations. The result is not
// guaranteed to be connected.
//
// The algorithm is based on:
// http://www.roguebasin.com/index.php?title=Cellular_Automata_Method_for_Generating_Random_Cave-Like_Levels
CellularAutomataCave generates a map using a cellular automata algorithm.
You can provide the initial wall filling percentage, and then sets of rules
to be applied in a certain number of iterations. The result is not
guaranteed to be connected.


// CellularAutomataCave generates a map using a cellular automata algorithm . // You can provide the initial wall filling percentage and then sets of rules // to be applied in a certain number of iterations . The result is not // guaranteed to be connected . // // The algorithm is based on : // http : // www . roguebasin . com / index . php?title = Cellular_Automata_Method_for_Generating_Random_Cave - Like_Levels
func (mg MapGen) CellularAutomataCave(wall, ground Cell, winit float64, rules []CellularAutomataRule) int {
	if winit > 0.9 {
		winit = 0.9
	}
	if winit < 0.1 {
		winit = 0.1
	}
	max := mg.Grid.Size()
	mg.Grid.FillFunc(func() Cell {
		f := mg.Rand.Float64()
		if f < winit {
			return wall
		}
		return ground
	})
	bufgd := NewGrid(max.X, max.Y)
	for _, rule := range rules {
		if rule.WCutoff2 >= 25 {
			mg.applyRuleWithoutW2(wall, ground, bufgd, rule)
		} else if rule.WCutoff1 <= 0 {
			mg.applyRuleWithoutW1(wall, ground, bufgd, rule)
		} else {
			mg.applyRule(wall, ground, bufgd, rule)
		}
	}
	count := mg.Grid.Count(ground)
	return count
}
func ( mg MapGen ) CellularAutomataCave ( wall , ground Cell , winit float64 , rules [ ] CellularAutomataRule ) int { if winit > 0.9 { winit = 0.9 } if winit < 0.1 { winit = 0.1 } max := mg . Grid . Size ( ) mg . Grid . FillFunc ( func ( ) Cell { f := mg . Rand . Float64 ( ) if f < winit { return wall } return ground } ) bufgd := NewGrid ( max . X , max . Y ) for _ , rule := range rules { if rule . WCutoff2 >= 25 { mg . applyRuleWithoutW2 ( wall , ground , bufgd , rule ) } else if rule . WCutoff1 <= 0 { mg . applyRuleWithoutW1 ( wall , ground , bufgd , rule ) } else { mg . applyRule ( wall , ground , bufgd , rule ) } } count := mg . Grid . Count ( ground ) return count }
CellularAutomataCave generates a map using a cellular automata algorithm.
CellularAutomataCave generates a map using a cellular automata algorithm .