Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. breed [cleaners cleaner]
  2.  
  3. to step ;; один шаг моделирования
  4. if member? patch-here patches with [ dirt? ] ;; если текущий квадрат содержит пыль
  5. [
  6.     suck
  7. ]
  8. if pcolor != red
  9. [
  10.     if count patches with [pcolor = red] > 0
  11.     [
  12.         face min-one-of (patches with [pcolor = red]) [distance-nowrap myself]
  13.         fd 1
  14.     ]        
  15. ]
  16. end
  17.  
  18. patches-own [ dirt? ]
  19.  
  20. to Setup
  21. clear-all
  22. ask patches
  23. [
  24.     ifelse random-float 10 < 1
  25.     [ set-dirt true ]
  26.     [ set-dirt false ]
  27. ]
  28. create-cleaners 1
  29. [
  30.     setxy min-pxcor min-pycor
  31.     set heading 90
  32.     set color green
  33. ]
  34. end
  35.  
  36. to go
  37. if count patches with [pcolor = red] > 0
  38. [  
  39.     ask cleaners [ step ]
  40.     tick
  41. ]    
  42. end
  43.  
  44. to set-dirt [ val? ]
  45. set dirt? val?
  46. ifelse val?
  47.     [ set pcolor red ]
  48.     [ set pcolor 2 + (pxcor mod 2) + (pycor mod 2) ]
  49. end
  50.  
  51. to suck
  52. ask patch-here [ set-dirt false ]
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement