Skip to content

Instantly share code, notes, and snippets.

@boompig
Created March 25, 2014 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boompig/9762890 to your computer and use it in GitHub Desktop.
Save boompig/9762890 to your computer and use it in GitHub Desktop.
function doSearch(colourMap, G) {
var open = [[0, 0]];
var pt, x, y, col;
while (open.length > 0) {
do {
if (open.length > 0) {
pt = open.pop();
x = pt[0];
y = pt[1];
} else {
console.log("done");
return;
}
} while (G[x][y] === BURN);
col = G[x][y];
bfs(x, y, col, open, G);
colourMap[col] += 1;
drawGraph();
showColourMap(colourMap);
}
}
function bfs(x, y, col, borderPoints, G) {
var candidates = [[x, y]];
var pt, neighbours;
while (candidates.length > 0) {
pt = candidates.pop();
x = pt[0];
y = pt[1];
if (G[x][y] === col) {
// burn this point
G[x][y] = BURN;
neighbours = getNeighbours(x, y, G);
candidates.push.apply(candidates, neighbours);
} else if (G[x][y] !== BURN) {
borderPoints.push([x, y]);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment