Skip to content

Instantly share code, notes, and snippets.

@myndzi
Created December 30, 2018 19:21
Show Gist options
  • Select an option

  • Save myndzi/d31531dacdfafde5f7e7a903bb4c23bb to your computer and use it in GitHub Desktop.

Select an option

Save myndzi/d31531dacdfafde5f7e7a903bb4c23bb to your computer and use it in GitHub Desktop.
function Cell(val) {
this.empty = false;
this.value = val;
}
Cell.prototype.reset = function () {
this.empty = true;
this.value = null;
};
var grid = []
for (var x=0; x<10; x++) {
grid[x] = []
for (var y=0; y<10; y++) {
grid[x][y] = new Cell(1);
}
}
floodFill = function(grid, x, y) {
if (x < 0 || x >= 10) return
if (y < 0 || y >= 10) return
if (!grid[x][y].empty) return
grid[x][y].reset()
floodFill(grid, x, y + 1)
floodFill(grid, x + 1, y)
floodFill(grid, x, y - 1)
floodFill(grid, x - 1, y)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment