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