Skip to content

Instantly share code, notes, and snippets.

@weepy
Created May 31, 2009 18:13
Show Gist options
  • Save weepy/120973 to your computer and use it in GitHub Desktop.
Save weepy/120973 to your computer and use it in GitHub Desktop.
function fill(sq, end_condition) {
var matrix = {}
var queue = [sq]
while(queue.length > 0) {
var sq = queue.shift()
var ns = neighbours(sq, matrix)
if(end_condition ( ns ) {
return true
}
queue = queue.concat(ns)
matrix[key.join(",")] = 1
}
return false
}
function neighbours(sq, matrix) {
//get neighbours
var ret = []
var sqs = [[sq[0]+1,sq[1]], [sq[0]-1,sq[1]], [sq[0],sq[1]+1], [sq[0],sq[1]-1]]
for(var i in sqs) {
var s = sqs[i]
if( no_wall || on board && !matrix[s.join(",")])
ret.push(sq)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment