Skip to content

Instantly share code, notes, and snippets.

@Ram-N Ram-N/gist:5068470
Created Mar 1, 2013

Embed
What would you like to do?
# Are any of the 4 diagonally adjacent cells occupied?
isAnyDiagNeighboringCellOccupied <- function(m,n) {
canOccupy <- FALSE
diag.dir = c(1,3,6,8)
#traverse the vector of 4 elements
for(k in 1:4) {
xCheck = m + adjacells[diag.dir[k],1]
yCheck = n + adjacells[diag.dir[k],2]
if(!(outOfBounds(xCheck, yCheck))) {
if(area_df[xCheck, yCheck] >0 ) {
print(paste("area df of ", xCheck, yCheck, area_df[xCheck, yCheck]))
print(paste("(",m,",",n,")" ,"DIAGONAL neighbor of (", yCheck, "-", xCheck))
canOccupy <- TRUE
}
}
} #end of looping through k
return(canOccupy)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.