-
-
Save myndzi/d31531dacdfafde5f7e7a903bb4c23bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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