1
Fork 0
mirror of https://github.com/Steffo99/turtle007.git synced 2024-11-25 06:24:20 +00:00

Importa progetto dal vecchio repository

This commit is contained in:
Cookie 2020-05-05 17:19:09 +02:00 committed by Stefano Pigozzi
parent f44f19392e
commit 10a68ee5a8

View file

@ -1,12 +1,15 @@
breed [ants ant] breed [ants ant]
patches-own [pheromone food nest distance-from-nest] patches-own [pheromone food poison nest distance-from-nest]
ants-own [carrying-food] ants-own [carrying-food]
to setup to setup
clear-all clear-all
reset-ticks reset-ticks
setup-nest ask patches [
p-setup-nest
]
setup-food setup-food
setup-poison
setup-ants setup-ants
ask patches [p-paint-patch] ask patches [p-paint-patch]
ask ants [t-paint-ant] ask ants [t-paint-ant]
@ -14,23 +17,21 @@ end
to p-paint-patch to p-paint-patch
set pcolor black set pcolor black
if show-pheromone [ ifelse pheromone >= 0
set pcolor scale-color pheromone-color pheromone pheromone-min pheromone-max [ set pcolor scale-color pheromone-color pheromone 0 pheromone-max]
] [ set pcolor scale-color poison-color pheromone 0 pheromone-min]
if show-distance [ if food = 1 [
; 35 * sqrt(2) = ~50
set pcolor scale-color distance-color distance-from-nest 0.1 50
]
if show-food and food = 1 [
set pcolor food-color set pcolor food-color
] ]
if show-nest and nest = 1 [ if nest = 1 [
set pcolor nest-color set pcolor nest-color
] ]
if poison = 1 [
set pcolor poison-color
]
end end
to t-paint-ant to t-paint-ant
set hidden? not show-ants
ifelse carrying-food = 1 [ ifelse carrying-food = 1 [
set color ant-carrying-color set color ant-carrying-color
][ ][
@ -38,12 +39,6 @@ to t-paint-ant
] ]
end end
to setup-nest
ask patches [
p-setup-nest
]
end
to p-setup-nest to p-setup-nest
ifelse (distancexy nest-x nest-y) < nest-size [ ifelse (distancexy nest-x nest-y) < nest-size [
set nest 1 set nest 1
@ -67,6 +62,19 @@ to p-add-food [x y s]
] ]
end end
to setup-poison
ask patches [
p-add-poison poison-x-1 poison-y-1 poison-size-1
p-add-poison poison-x-2 poison-y-2 poison-size-2
]
end
to p-add-poison [x y s]
if (distancexy x y) < s [
set poison 1
]
end
to setup-ants to setup-ants
set-default-shape ants "bug" set-default-shape ants "bug"
create-ants ants-qty create-ants ants-qty
@ -101,7 +109,7 @@ to t-rotate-pheromone
let pleft t-pheromone-left let pleft t-pheromone-left
let pcenter t-pheromone-center let pcenter t-pheromone-center
let pright t-pheromone-right let pright t-pheromone-right
if (pleft >= 0.05 and pleft <= 2) or (pcenter >= 0.05 and pcenter <= 2) or (pright >= 0.05 and pright <= 2)[ if ((pleft >= 0.05 and pleft <= 2) or (pleft <= -0.05 and pleft >= -2)) or ((pcenter >= 0.05 and pcenter <= 2) or (pcenter <= -0.05 and pcenter >= -2)) or ((pright >= 0.05 and pright <= 2) or (pright <= -0.05 and pright >= -2))[
ifelse pleft > pright and pleft > pcenter [ ifelse pleft > pright and pleft > pcenter [
left 45 left 45
][ ][
@ -140,6 +148,10 @@ to-report t-is-over-food
report ([food] of patch-here = 1) report ([food] of patch-here = 1)
end end
to-report t-is-over-poison
report ([poison] of patch-here = 1)
end
to-report t-is-over-nest to-report t-is-over-nest
report ([nest] of patch-here = 1) report ([nest] of patch-here = 1)
end end
@ -158,6 +170,21 @@ to t-try-pick-up-food
] ]
end end
to t-pick-up-poison
ask patch-here [
set poison 0
]
t-subtract-pheromone
die
rt 180
end
to t-try-pick-up-poison
if carrying-food = 0 and t-is-over-poison [
t-pick-up-poison
]
end
to t-drop-food to t-drop-food
set carrying-food 0 set carrying-food 0
rt 180 rt 180
@ -175,6 +202,12 @@ to t-add-pheromone
] ]
end end
to t-subtract-pheromone
ask patch-here [
set pheromone pheromone - 240
]
end
to t-work to t-work
ifelse carrying-food = 1 [ ifelse carrying-food = 1 [
t-rotate-nest t-rotate-nest
@ -186,6 +219,7 @@ to t-work
right random random-angle right random random-angle
fd 1 fd 1
t-try-pick-up-food t-try-pick-up-food
t-try-pick-up-poison
t-try-drop-food t-try-drop-food
end end
@ -201,11 +235,11 @@ end
GRAPHICS-WINDOW GRAPHICS-WINDOW
8 8
10 10
726 584
729 587
-1 -1
-1 -1
10.0 8.0
1 1
10 10
1 1
@ -226,9 +260,9 @@ ticks
30.0 30.0
BUTTON BUTTON
730 590
10 10
860 735
43 43
NIL NIL
setup setup
@ -243,10 +277,10 @@ NIL
1 1
SLIDER SLIDER
730 590
115 100
902 762
148 133
nest-size nest-size
nest-size nest-size
1 1
@ -258,10 +292,10 @@ patches
HORIZONTAL HORIZONTAL
INPUTBOX INPUTBOX
905 765
90 75
955 815
150 135
nest-x nest-x
0.0 0.0
1 1
@ -269,10 +303,10 @@ nest-x
Number Number
INPUTBOX INPUTBOX
960 820
90 75
1010 870
150 135
nest-y nest-y
0.0 0.0
1 1
@ -280,32 +314,32 @@ nest-y
Number Number
INPUTBOX INPUTBOX
1015 875
90 75
1100 960
150 135
nest-color nest-color
12.0 23.0
1 1
0 0
Color Color
INPUTBOX INPUTBOX
1015 875
155 140
1100 960
215 200
food-color food-color
43.0 44.0
1 1
0 0
Color Color
INPUTBOX INPUTBOX
905 765
155 140
955 815
215 200
food-x-1 food-x-1
21.0 21.0
1 1
@ -313,10 +347,10 @@ food-x-1
Number Number
INPUTBOX INPUTBOX
960 820
155 140
1010 870
215 200
food-y-1 food-y-1
0.0 0.0
1 1
@ -324,10 +358,10 @@ food-y-1
Number Number
INPUTBOX INPUTBOX
905 765
220 205
955 815
280 265
food-x-2 food-x-2
-21.0 -21.0
1 1
@ -335,10 +369,10 @@ food-x-2
Number Number
INPUTBOX INPUTBOX
960 820
220 205
1010 870
280 265
food-y-2 food-y-2
-21.0 -21.0
1 1
@ -346,10 +380,10 @@ food-y-2
Number Number
INPUTBOX INPUTBOX
905 765
285 270
955 815
345 330
food-x-3 food-x-3
-28.0 -28.0
1 1
@ -357,10 +391,10 @@ food-x-3
Number Number
INPUTBOX INPUTBOX
960 820
285 270
1010 870
345 330
food-y-3 food-y-3
28.0 28.0
1 1
@ -368,10 +402,10 @@ food-y-3
Number Number
SLIDER SLIDER
730 590
180 165
902 762
213 198
food-size-1 food-size-1
food-size-1 food-size-1
0 0
@ -383,10 +417,10 @@ patches
HORIZONTAL HORIZONTAL
SLIDER SLIDER
730 590
245 230
902 762
278 263
food-size-2 food-size-2
food-size-2 food-size-2
0 0
@ -398,10 +432,10 @@ patches
HORIZONTAL HORIZONTAL
SLIDER SLIDER
730 590
310 295
902 762
343 328
food-size-3 food-size-3
food-size-3 food-size-3
0 0
@ -413,20 +447,20 @@ patches
HORIZONTAL HORIZONTAL
TEXTBOX TEXTBOX
760 620
465 490
910 770
483 508
NIL NIL
11 11
0.0 0.0
1 1
SLIDER SLIDER
730 590
435 460
902 762
468 493
diffusion-pct diffusion-pct
diffusion-pct diffusion-pct
0 0
@ -438,10 +472,10 @@ diffusion-pct
HORIZONTAL HORIZONTAL
SLIDER SLIDER
730 590
470 495
902 762
503 528
evaporation-pct evaporation-pct
evaporation-pct evaporation-pct
0 0
@ -453,9 +487,9 @@ evaporation-pct
HORIZONTAL HORIZONTAL
BUTTON BUTTON
730 590
45 45
793 660
78 78
tick tick
go go
@ -470,9 +504,9 @@ NIL
1 1
BUTTON BUTTON
795 665
45 45
858 735
78 78
NIL NIL
go go
@ -487,54 +521,54 @@ NIL
1 1
INPUTBOX INPUTBOX
905 765
350 10
1010 870
410 70
ants-qty ants-qty
1000.0 100.0
1 1
0 0
Number Number
INPUTBOX INPUTBOX
1015 875
350 10
1100 960
410 70
ant-color ant-color
15.0 3.0
1 1
0 0
Color Color
INPUTBOX INPUTBOX
1105 965
350 10
1190 1050
410 70
ant-carrying-color ant-carrying-color
18.0 6.0
1 1
0 0
Color Color
INPUTBOX INPUTBOX
1105 965
415 465
1205 1065
475 525
pheromone-min pheromone-min
0.1 -5.0
1 1
0 0
Number Number
INPUTBOX INPUTBOX
1105 1070
480 465
1205 1170
540 525
pheromone-max pheromone-max
5.0 5.0
1 1
@ -542,10 +576,10 @@ pheromone-max
Number Number
INPUTBOX INPUTBOX
1015 875
415 465
1100 960
475 525
pheromone-color pheromone-color
65.0 65.0
1 1
@ -553,10 +587,10 @@ pheromone-color
Color Color
PLOT PLOT
735 1055
575 10
935 1255
725 160
Ants with food Ants with food
Ticks Ticks
Ants Ants
@ -571,10 +605,10 @@ PENS
"with-food" 1.0 0 -1069655 true "" "plot count ants with [carrying-food = 1]" "with-food" 1.0 0 -1069655 true "" "plot count ants with [carrying-food = 1]"
PLOT PLOT
940 1055
575 165
1140 1255
725 315
Patches with food Patches with food
Ticks Ticks
Patches Patches
@ -588,93 +622,113 @@ false
PENS PENS
"default" 1.0 0 -7171555 true "" "plot count patches with [food = 1]" "default" 1.0 0 -7171555 true "" "plot count patches with [food = 1]"
TEXTBOX
865
10
1380
76
TODO: nuovi grafici e aggiunte belline!
11
0.0
1
SWITCH
360
735
530
768
show-pheromone
show-pheromone
0
1
-1000
SWITCH
185
735
355
768
show-ants
show-ants
0
1
-1000
SWITCH
10
735
180
768
show-nest
show-nest
0
1
-1000
SWITCH
535
735
705
768
show-food
show-food
0
1
-1000
INPUTBOX INPUTBOX
1105 965
90 75
1190 1050
150 135
distance-color distance-color
135.0 135.0
1 1
0 0
Color Color
SWITCH
710
735
880
768
show-distance
show-distance
1
1
-1000
INPUTBOX INPUTBOX
905 765
415 465
1010 870
475 525
random-angle random-angle
45.0 45.0
1 1
0 0
Number Number
INPUTBOX
875
335
960
395
poison-color
15.0
1
0
Color
SLIDER
590
360
760
393
poison-size-1
poison-size-1
0
15
4.0
1
1
patches
HORIZONTAL
INPUTBOX
765
335
815
395
poison-x-1
13.0
1
0
Number
INPUTBOX
820
335
870
395
poison-y-1
-18.0
1
0
Number
SLIDER
590
420
760
453
poison-size-2
poison-size-2
0
15
4.0
1
1
NIL
HORIZONTAL
INPUTBOX
765
400
815
460
poison-x-2
-14.0
1
0
Number
INPUTBOX
820
400
870
460
poison-y-2
14.0
1
0
Number
@#$#@#$#@ @#$#@#$#@
## WHAT IS IT? ## WHAT IS IT?