# Moore & Von Neumann Example

### 1 collaborator

Uri Wilensky (Author)

### Tags

code example

Tagged by Reuven M. Lerner about 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 744 times • Downloaded 67 times • Run 0 times

Click to Run Model

```globals [nearby]

to setup
clear-all
;; use a global variable to store the offsets list so we
;; don't have to compute the same list (for a particular
;; radius) over and over again
ifelse neighborhood-type = "Von Neumann"
[ set nearby von-neumann-offsets radius include-central-patch? ]
[ set nearby moore-offsets radius include-central-patch? ]
;; Now whenever a turtle or patch wants to refer
;; to its neighborhood, it says "patches at-points nearby".
;; A quick example:
sprout 1 [
;; see the entry for AT-POINTS in the NetLogo Dictionary
set pcolor [color] of myself
]
set color white
]
]
end

;; The next two procedures generate the lists of offsets that we pass to
;; AT-POINTS.
;;
;; When you paste this code into your model, if you know that you always
;; want to include the center, or never want to include it, you can remove
;; that parameter to make the code shorter.

;; examples of usage:
;; > print moore-offsets 1 true
;; [[-1 1] [1 1] [-1 -1] [-1 0] [1 0] [0 1] [0 0] [0 -1] [1 -1]]
;; > print von-neumann-offsets 1 true
;; [[0 1] [-1 0] [1 0] [0 0] [0 -1]]
;; for larger radii the results lists get long fast!

to-report moore-offsets [n include-center?]
let result [list pxcor pycor] of patches with [abs pxcor <= n and abs pycor <= n]
ifelse include-center?
[ report result ]
[ report remove [0 0] result ]
end

to-report von-neumann-offsets [n include-center?]
let result [list pxcor pycor] of patches with [abs pxcor + abs pycor <= n]
ifelse include-center?
[ report result ]
[ report remove [0 0] result ]
end

; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.
```

There are 10 versions of this model.

Uri Wilensky almost 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky over 11 years ago Updated version tag Download this version
Uri Wilensky over 12 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky almost 14 years ago Moore & Von Neumann Example Download this version
Uri Wilensky almost 14 years ago Moore & Von Neumann Example Download this version

## Attached files

File Type Description Last updated
Moore & Von Neumann Example.png preview Preview for 'Moore & Von Neumann Example' about 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.