Look Ahead Example

Look Ahead Example preview image

1 collaborator

Uri_dolphin3 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 605 times • Downloaded 76 times • Run 0 times
Download the 'Look Ahead 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

;;  This procedure sets up the patches and turtles

to setup
  ;;  Clear everything.
  clear-all

  ;;  This will create a "checkerboard" of blue patches.  Every third patch will be
  ;;  blue (remember modulo gives you the remainder of a division).
  ask patches with [pxcor mod 3 = 0 and
                    pycor mod 3 = 0]
    [ set pcolor blue ]

  ;;  This will make the outermost patches blue.  This is to prevent the turtles
  ;;  from wrapping around the world.  Notice it uses the number of neighbor patches rather than
  ;;  a location. This is better because it will allow you to change the behavior of the turtles
  ;; by changing the shape of the world (and it is less mistake-prone)
  ask patches with [count neighbors != 8]
    [ set pcolor blue ]

  ;;  This will create turtles on 200 randomly chosen
  ;;  black patches.
  ask n-of 200 (patches with [pcolor = black])
  [
    sprout 1
      [ set color red ]
  ]
  reset-ticks
end 

;;  This procedure makes the turtles move

to go
  ask turtles
  [
    ;;  This important conditional determines if they are about to walk into a blue
    ;;  patch.  It lets us make a decision about what to do BEFORE the turtle walks
    ;;  into a blue patch.  This is a good way to simulate a wall or barrier that turtles
    ;;  cannot move onto.  Notice that we don't use any information on the turtle's
    ;;  heading or position.  Remember, patch-ahead 1 is the patch the turtle would be on
    ;;  if it moved forward 1 in its current heading.
    ifelse [pcolor] of patch-ahead 1 = blue
      [ lt random-float 360 ]   ;; We see a blue patch in front of us. Turn a random amount.
      [ fd 1 ]                  ;; Otherwise, it is safe to move forward.
  ]
  tick
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 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 Look Ahead Example Download this version
Uri Wilensky almost 14 years ago Look Ahead Example Download this version

Attached files

File Type Description Last updated
Look Ahead Example.png preview Preview for 'Look Ahead Example' about 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.