Skip to content

Instantly share code, notes, and snippets.

@rigibun
Last active December 11, 2015 02:09
Show Gist options
  • Save rigibun/4528716 to your computer and use it in GitHub Desktop.
Save rigibun/4528716 to your computer and use it in GitHub Desktop.
function Putable(board, x, y, turn){
var count = 0;
for(var i = -1; i <= 1; i++){
for(var j = -1; j <= 1; j++){
if(i == 0 && j == 0) continue;
if(board[y + i][x + j] == 3 - turn){
var k = i;
var l = j;
var incount = 0;
while(1){
if(board[y + k][x + l] != 3 - turn){
if(board[y + k][x + l] == turn)
count += incount;
break;
}
else{
incount++;
k += i;
l += j;
}
}
}
}
}
if(count > 0) return true;
else return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment