Skip to content

Instantly share code, notes, and snippets.

@Ram-N
Last active December 14, 2015 09:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ram-N/5068453 to your computer and use it in GitHub Desktop.
Save Ram-N/5068453 to your computer and use it in GitHub Desktop.
# 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