From 5f1bc91934cc0990c5cc51341f6d9485f57b18b7 Mon Sep 17 00:00:00 2001 From: Lorenzo Balugani Date: Tue, 5 May 2020 17:38:47 +0200 Subject: [PATCH] Importa progetto dal vecchio repository --- Progetto.nlogo | 177 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 174 insertions(+), 3 deletions(-) diff --git a/Progetto.nlogo b/Progetto.nlogo index b2620eb..9aa2711 100644 --- a/Progetto.nlogo +++ b/Progetto.nlogo @@ -1,6 +1,8 @@ breed [ants ant] patches-own [pheromone food nest distance-from-nest] -ants-own [carrying-food] +ants-own [carrying-food hunger] + +globals [food-in-nest] to setup clear-all @@ -42,6 +44,7 @@ to setup-nest ask patches [ p-setup-nest ] + set food-in-nest 0 end to p-setup-nest @@ -76,6 +79,7 @@ end to t-setup-ant set color ant-color set carrying-food 0 + set hunger 0 setxy nest-x nest-y fd nest-size end @@ -160,6 +164,7 @@ end to t-drop-food set carrying-food 0 + set food-in-nest food-in-nest + 1 rt 180 end @@ -175,10 +180,27 @@ to t-add-pheromone ] end +to t-set-hunger + if random-float 100 < hunger-increase-pct[ + set hunger hunger + hunger-per-tick + ] +end + +to t-try-eat-food + if carrying-food = 1[ + set hunger 0 + set carrying-food 0 + ] + if t-is-over-nest and food-in-nest > 0[ + set hunger 0 + set food-in-nest food-in-nest - 1] +end + to t-work - ifelse carrying-food = 1 [ + ifelse carrying-food = 1 or (hunger >= hunger-threshold and enable-hunger)[ t-rotate-nest - t-add-pheromone + if carrying-food = 1[ + t-add-pheromone] ][ t-rotate-pheromone ] @@ -187,6 +209,18 @@ to t-work fd 1 t-try-pick-up-food t-try-drop-food + t-set-hunger + if hunger >= hunger-threshold and enable-hunger [ + t-try-eat-food + if hunger >= hunger-max [ + die] + ] +end + +to p-respawn-food + if random-float 100 < food-respawn-pct[ + setup-food + ] end to go @@ -196,6 +230,9 @@ to go diffuse pheromone (diffusion-pct / 100) ask patches [p-paint-patch] ask ants [t-paint-ant] + if enable-food-respawn and ticks mod food-ticks = 0[ + p-respawn-food + ] end @#$#@#$#@ GRAPHICS-WINDOW @@ -675,6 +712,140 @@ random-angle 0 Number +SWITCH +10 +775 +180 +808 +enable-hunger +enable-hunger +0 +1 +-1000 + +SWITCH +185 +775 +355 +808 +enable-food-respawn +enable-food-respawn +0 +1 +-1000 + +INPUTBOX +1195 +90 +1280 +150 +food-ticks +1500.0 +1 +0 +Number + +SLIDER +1285 +90 +1322 +280 +food-respawn-pct +food-respawn-pct +0 +100 +0.0 +1 +1 +% +VERTICAL + +INPUTBOX +1195 +155 +1280 +215 +hunger-per-tick +0.1 +1 +0 +Number + +INPUTBOX +1195 +220 +1280 +280 +hunger-threshold +30.0 +1 +0 +Number + +INPUTBOX +1195 +285 +1280 +345 +hunger-max +35.0 +1 +0 +Number + +PLOT +1145 +575 +1345 +725 +Food in Nest +NIL +NIL +0.0 +10.0 +0.0 +10.0 +true +false +"" "" +PENS +"default" 1.0 0 -16777216 true "" "plot food-in-nest" + +PLOT +1350 +575 +1550 +725 +Ants +NIL +NIL +0.0 +10.0 +0.0 +10.0 +true +true +"" "" +PENS +"Alive" 1.0 0 -2674135 true "" "plot count turtles" +"Dead" 1.0 0 -16777216 true "" "plot (ants-qty - count turtles)" +"Starving" 1.0 0 -817084 true "" "plot count turtles with [hunger > hunger-threshold]" + +SLIDER +1325 +91 +1362 +281 +hunger-increase-pct +hunger-increase-pct +0 +100 +21.0 +1 +1 +% +VERTICAL + @#$#@#$#@ ## WHAT IS IT?