State Machine Example

State Machine 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 324 times • Downloaded 44 times • Run 0 times
Download the 'State Machine 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 [
  next-task  ;; task the turtle will run during this tick
  steps      ;; ...unless this number is greater than zero, in which
             ;; case this tick, the turtle just moves forward 1
]

to setup
  clear-all
  set-default-shape turtles "bug"
  ;; randomly distribute wood chips
  ask patches [
    if random-float 100 < density
      [ set pcolor yellow ]
  ]
  ;; randomly distribute termites
  crt number [
    set color white
    setxy random-xcor random-ycor
    set next-task task search-for-chip
    set size 5  ;; easier to see
  ]
  reset-ticks
end 

to go
  ask turtles
    [ ifelse steps > 0
        [ set steps steps - 1 ]
        [ run next-task
          wiggle ]
      fd 1 ]
  tick
end 

to wiggle  ;; turtle procedure
  rt random 50
  lt random 50
end 

to search-for-chip   ;; turtle procedure -- "picks up chip" by turning orange
  if pcolor = yellow
    [ set pcolor black
      set color orange
      set steps 20
      set next-task task find-new-pile ]
end 

to find-new-pile  ;; turtle procedure -- look for yellow patches
  if pcolor = yellow
    [ set next-task task put-down-chip ]
end 

to put-down-chip  ;; turtle procedure -- finds empty spot & drops chip
  if pcolor = black
   [ set pcolor yellow
     set color white
     set steps 20
     set next-task task get-away ]
end 

to get-away  ;; turtle procedure -- get out of yellow pile
  if pcolor = black
    [ set next-task task search-for-chip ]
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 State Machine Example Download this version
Uri Wilensky over 14 years ago State Machine Example Download this version

Attached files

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

This model does not have any ancestors.

This model does not have any descendants.