/** * @class Cellular automaton map generator * @augments ROT.Map * @param {int} [width=ROT.DEFAULT_WIDTH] * @param {int} [height=ROT.DEFAULT_HEIGHT] * @param {object} [options] Options * @param {int[]} [options.born] List of neighbor counts for a new cell to be born in empty space * @param {int[]} [options.survive] List of neighbor counts for an existing cell to survive * @param {int} [options.topology] Topology 4 or 6 or 8 */ ROT.Map.Cellular = function(width, height, options) { ROT.Map.call(this, width, height); this._options = { born: [5, 6, 7, 8], survive: [4, 5, 6, 7, 8], topology: 8 }; for (var p in options) { this._options[p] = options[p]; } this._dirs = ROT.DIRS[this._options.topology]; this._map = this._fillMap(0); } ROT.Map.Cellular.extend(ROT.Map); /** * Fill the map with random values * @param {float} probability Probability for a cell to become alive; 0 = all empty, 1 = all full */ ROT.Map.Cellular.prototype.randomize = function(probability) { for (var i=0;i= this._width || x < 0 || y >= this._width) { continue; } result += (this._map[x][y] == 1 ? 1 : 0); } return result; }