Created
March 25, 2014 14:23
-
-
Save boompig/9762890 to your computer and use it in GitHub Desktop.
This file contains 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 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