Wall Following Example

Wall Following Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 239 times • Downloaded 36 times • Run 0 times
Download the 'Wall Following Example' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

turtles-own [direction]  ;;  1 follows right-hand wall,
                         ;; -1 follows left-hand wall

to setup
  clear-all
  ;; make some random walls for the turtles to follow.
  ;; the details aren't important.
  ask patches [ if random-float 1.0 < 0.04 [ set pcolor brown ] ]
  ask patches with [pcolor = brown] [ ask patches in-radius random-float 3 [ set pcolor brown ] ]
  ask patches with [count neighbors4 with [pcolor = brown] = 4] [ set pcolor brown ]
  ;; now make some turtles. SPROUT puts
  ;; the turtles on patch centers
  ask n-of 40 patches with [pcolor = black] [
    sprout 1 [
      if count neighbors4 with [pcolor = brown] = 4 [ die ]  ;; trapped!
      set size 2              ;; bigger turtles are easier to see
      set pen-size 2          ;; thicker lines are easier to see
      face one-of neighbors4  ;; face north, south, east, or west
      ifelse random 2 = 0
        [ set direction 1     ;; follow right hand wall
          set color blue ]
        [ set direction -1    ;; follow left hand wall
          set color green ]
    ]
  ]
  reset-ticks
end 

to go
  ask turtles [ walk ]
  tick
end 

to walk  ;; turtle procedure
  ;; turn right if necessary
  if not wall? (90 * direction) and wall? (135 * direction) [ rt 90 * direction ]
  ;; turn left if necessary (sometimes more than once)
  while [wall? 0] [ lt 90 * direction ]
  ;; move forward
  fd 1
end 

to-report wall? [angle]  ;; turtle procedure
  ;; note that angle may be positive or negative.  if angle is
  ;; positive, the turtle looks right.  if angle is negative,
  ;; the turtle looks left.
  report brown = [pcolor] of patch-right-and-ahead angle 1
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.

Uploaded by When Description Download
Uri Wilensky over 11 years ago Updated to NetLogo 5.0.4 Download this version
Uri Wilensky about 12 years ago Updated version tag Download this version
Uri Wilensky almost 13 years ago Updated to NetLogo 5.0 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky over 14 years ago Model from NetLogo distribution Download this version
Uri Wilensky over 14 years ago Wall Following Example Download this version
Uri Wilensky over 14 years ago Wall Following Example Download this version

Attached files

File Type Description Last updated
Wall Following Example.png preview Preview for 'Wall Following Example' over 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.