Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Last active Dec 14, 2015
Embed
What would you like to do?
# Are any of the 4 direct N E W S adjacent cells occupied?
isAnyOfNEWSCellsOccupied <- function(m,n) {
canOccupy <- FALSE
NEWSdir = c(2,4,5,7)
#traverse the vector of 4 elements
for(k in 1:4) {
xCheck = m + adjacells[NEWSdir[k],1]
yCheck = n + adjacells[NEWSdir[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,")" ,"NEWS 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