Published
Edited
Aug 31, 2019
Importers
15 stars
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
TILES = [
['EMPTY', SPACE],
// key, char, turns to if expand up, right, down, left, rotated 180°
['O', '◽︎', 'T', 'R', 'B', 'L', 'O'],
['T', '╨', null, 'TR', 'TB', 'TL', 'B'],
['R', '╞', 'TR', null, 'RB', 'RL', 'L'],
['B', '╥', 'TB', 'RB', null, 'BL', 'T'],
['L', '╡', 'TL', 'RL', 'BL', null, 'R'],
['RB', '╔', 'TRB', null, null, 'RBL', 'TL'],
['BL', '╗', 'TBL', 'RBL', null, null, 'TR'],
['TR', '╚', null, null, 'TRB', 'TRL', 'BL'],
['TL', '╝', null, 'TRL', 'TBL', null, 'RB'],
['TB', '║', null, 'TRB', null, 'TBL', 'TB'],
['RL', '═', 'TRL', null, 'RBL', null, 'RL'],
['TRB', '╠', null, null, null, 'TRBL', 'TBL'],
['TBL', '╣', null, 'TRBL', null, null, 'TRB'],
['TRL', '╩', null, null, 'TRBL', null, 'RBL'],
['RBL', '╦', 'TRBL', null, null, null, 'TRL'],
['TRBL', '╬', null, null, null, null, 'TRBL'],
['NEG', SPACE],
]
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function findMutations (board, w = boardSize, h = w) {
const potentials = []
for (let index = 0, len = board.length; index < len; index++) {
const tile = board[index];

if (tile !== TILE_INDEX.EMPTY) {
continue;
}
const row = Math.floor(index / w)
const col = index % w
// Can this tile connect with the one under it?
if (row < h - 1) {
const underIndex = index + w
const under = TILES[board[underIndex]]
if (under[OVER]) {
// A mutation is represented as [this index, this tile, that index, that change tile]
potentials.push([index, UNDER, underIndex, TILE_INDEX[under[OVER]]])
}
}
// Over
if (row > 0) {
const overIndex = index - w
const over = TILES[board[overIndex]]
if (over[UNDER]) {
potentials.push([index, OVER, overIndex, TILE_INDEX[over[UNDER]]])
}
}
// Right
if (col < w - 1) {
const rightIndex = index + 1
const rightward = TILES[board[rightIndex]]
if (rightward[LEFT]){
potentials.push([index, RIGHT, rightIndex, TILE_INDEX[rightward[LEFT]]])
}
}
// Left
if (col > 0) {
const leftIndex = index - 1
const leftward = TILES[board[leftIndex]]
if (leftward[RIGHT]){
potentials.push([index, LEFT, leftIndex, TILE_INDEX[leftward[RIGHT]]])
}
}
};
return potentials;
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more