Cellular automata generator

Interesting cave systems can be created using ROT.Map.Cellular, a generator which simulates a cellular automaton. Using this generator is a bit more complex, because it offers richer features and is more configurable.

Apart from the traditional width and height arguments, ROT.Map.Cellular accepts also a configuration object with the following optional keys:

It is also possible to initialize/set values for the first generation of cells. Two methods are provided:

It is possible (and desirable) to call the create method repeatedly: every call will create a new generation. There is no need to specify a callback, if you only want to advance into next generation, without actually retrieving the current map data. By default, the born and survive options are set according to this Roguebasin article.

ROT.Map.Cellular uses the following callback values:

var w = 80, h = 40; var map = new ROT.Map.Cellular(w, h); /* cells with 1/2 probability */ map.randomize(0.5); /* generate and show four generations */ for (var i=0; i<4; i++) { var display = new ROT.Display({width:w, height:h, fontSize:4}); SHOW(display.getContainer()); map.create(display.DEBUG); }
var w = 100, h = 60; var display = new ROT.Display({width:w, height:h, fontSize:6}); SHOW(display.getContainer()); /* custom born/survive rules */ var map = new ROT.Map.Cellular(w, h, { born: [4, 5, 6, 7, 8], survive: [2, 3, 4, 5] }); map.randomize(0.9); /* generate fifty iterations, show the last one */ for (var i=49; i>=0; i--) { map.create(i ? null : display.DEBUG); }