Not sure map thing

Worms clone would be cool, but the platform AI would be a nightmare. You could make a cheeky survival game out of it possibly.

by Sam Fereday

HTML

<script src="https://ondras.github.io/rot.js/rot.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/chance/1.0.12/chance.min.js"></script>
<div id="output"></div>

CSS

.cell {
  display: block;
  position: absolute;
  transition: all 0.2s ease;
  font-size: 0.8em;
  font-family: consolas;
  text-align: center;
  color: #aaa;
  background: #fff;
}

.cell-mode-0 {
  background: #888;
}

.cell-mode-1 {
  background: #333;
  cursor: pointer;
}

.cell-mode-1:hover {
   background: #990000;
}

.occupy {
  background: #990000;
}

.spawn {
  background: #009900;
}

.pickup {
  background: #009999;
}

JavaScript

// Phaser notes
/*
Luckily phaser does have the ability to parse a tilemap based on an array that you pass to it:
https://phaser.io/examples/v2/tilemaps/create-from-array
However what might be a bit crap is wiring it in to what's been made below. So you can still do the neighbour scores and all that, but instead of the element creation bit below, that 'might' be the best place to actually map all of the tiles in the game.
From that point you can still parse the air tiles as you normally would using the initial mapping data, because at that point the tiles don't really care. It's just a simple case of getting hold of coordinates.
*/

// Warven Dwarves - Map Generator
// http://ondras.github.io/rot.js/manual/#map/cellular
// https://www.pinterest.co.uk/pin/74239093838147170/?autologin=true&utm_campaign=category_rp&e_t=e4685ccc924448e8b97f572bad361a89&utm_content=74239093838147170&utm_source=31&utm_term=5&utm_medium=2012
const TILETYPE = {
	AIR: 0,
  ROCK: 1
}

const MAPCONFIG = {
	w: 36,
  h: 36 * 4,
  r: 0.5,
  smoothing: 8
}

// Tile object
class Tile {

	constructor(x, y, value, score) {
  	this.x = x;
    this.y = y;
    this.value = value;
    this.score = score;
  }
  
  setScore(n) {
  	this.score = n;
  }

}

// Helpers.
const flatten = list => list.reduce(
  (a, b) => a.concat(Array.isArray(b) ? flatten(b) : b), []
);

const scoreTile = (above, right, below, left, valueNeeded) => {
    let sum = 0;
    if (above === valueNeeded) sum += 1;
    if (left === valueNeeded) sum += 2;
    if (below === valueNeeded) sum += 4;
    if (right === valueNeeded) sum += 8;
    return sum;
}

const getTile = (x, y, tiles) => {
	// Highly un-optimized, it'd be better to use quad-trees for such large searches.
	return tiles.find(tile => tile.x === x && tile.y === y);
}

const getTileRaw = (x, y, tiles) => {
	// Highly un-optimized, it'd be better to use quad-trees for such large searches.
  return x < 0 || x > tiles.length - 1 || y < 0 || y > tiles[x].length - 1 ? null :...