Ask-Concurrent Example

Ask-Concurrent Example preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

code example 

Tagged by Reuven M. Lerner over 11 years ago

Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 5.0.4 • Viewed 686 times • Downloaded 73 times • Run 0 times
Download the 'Ask-Concurrent 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

Click to Run Model

turtles-own [done?]  ;; this is used only by GO-TURTLES-ALTERNATE

to setup
  clear-all
  ask patches with [pycor = 0] [
    sprout 1 [ set heading 0 ]
  ]
  reset-ticks
end 

to go
  ;; make a red patch in each column
  ask patches with [pycor = 0] [
    ask patch-at 0 (random world-height) [
      set pcolor red
    ]
  ]
  ;; have every turtle move forward until it
  ;; finds the red patch in its column
  go-turtles
  tick
end 

to go-turtles
  ask-concurrent turtles [
    while [pcolor != red] [ fd 1 ]
    set pcolor black
  ]
end 

;; Here's one way to do the same thing as GO-TURTLES but using
;; ASK instead of ASK-CONCURRENT.  The behavior of the turtles
;; is the same and the visual result (turtles working on their
;; task concurrently, rather than each completing its task
;; serially) is the same.  Note the use of a turtles-own variable.

to go-turtles-alternate
  ask turtles [ set done? false ]
  loop [
    let still-moving turtles with [not done?]
    if not any? still-moving [ stop ]
    ask still-moving [
      ifelse pcolor = red
        [ set pcolor black
          set done? true ]
        [ fd 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 Ask-Concurrent Example Download this version
Uri Wilensky over 14 years ago Ask-Concurrent Example Download this version

Attached files

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

This model does not have any ancestors.

This model does not have any descendants.