Created
May 31, 2009 18:13
-
-
Save weepy/120973 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 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