Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. patches-own
  2. [
  3. owner ;; turtle who claims patch for territory
  4. benefit ;; i.e., food
  5. avoiding ;; turtle who is avoiding this patch
  6. ]
  7.  
  8. turtles-own
  9. [
  10. start-patch ;; my territory center
  11. destination ;; my next patch to claim
  12. territory ;; patches I own
  13. blacklist ;; my agentset of patches to avoid
  14. ]
  15.  
  16. to pick-patch
  17. if patch-here = start-patch [ set destination highest-value ]
  18. if destination != nobody [ travel ]
  19. end
  20.  
  21. to travel
  22. ;; there are a number of actions here, but the relevant one is:
  23. ;; check if owned, and avoid it:
  24. if patch-here != destination
  25. [ if owner != nobody ;; if it's owned...
  26. [ if owner != self ;; and not by me...
  27. [ avoid-obstacle
  28. move-to start-patch ]
  29. ]
  30. ]
  31. end
  32.  
  33. to avoid-obstacle
  34. ask destination [ set avoiding myself ]
  35. set blacklist (patches with [avoiding = myself])
  36. end
  37.  
  38. to-report highest-value ;; <--- source of error since using "blacklist"
  39. let available-destinations edge-patches with [blacklist != myself]
  40. report max-one-of available-destinations ([benefit-to-me / cost-to-me])
  41. end
  42.  
  43. to-report benefit-to-me
  44. report mean [benefit] of patches in-radius 2
  45. end
  46.  
  47. to-report cost-to-me
  48. report distance [start-patch] of myself
  49. end
  50.  
  51. to-report edge-patches
  52. report (patch-set [neighbors4] of territory) with [owner = nobody]
  53. end
  54.  
  55. to-report highest-value
  56. let available-destinations edge-patches with [avoiding != myself]
  57. report max-one-of available-destinations ([benefit-to-me / cost-to-me])
  58. end
  59.  
  60. to avoid-obstacle
  61. ask destination
  62. [ let now-avoiding myself
  63. set avoiding (turtle-set avoiding now-avoiding) ]
  64. set blacklist (patch-set blacklist patches with [avoiding = myself])
  65. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement