Reputation: 1
I'm trying to build a virus simulator, and I want to make my turtles immune after a certain amount of ticks of being sick. However, I have no idea how to count ticks after I've infected them. I'd like for them to be sick for x ticks, and then be healthy again (and not be able to get infected for a second time). Is there any way to count the ticks after I've infected them, or is there another solution to my problem?
Upvotes: 0
Views: 223
Reputation: 1181
You can simply save the "date" of infection for each turtle, e.g. set infection-date ticks
.
If then the time since the infection (ticks - infection-date
) if bigger than x, you can set a variable like immune?
to true. To avoid infection of immune turtles, simply use if not immune? [...]
Here's a minimal running example. Note that ticks-sick
is uncommented, since I used a slider in the view for setting its value.
turtles-own
[
infected?
infection-date
immune?
]
globals
[
; ticks-sick
]
to setup
ca
reset-ticks
crt 10
[
setxy random-xcor random-ycor
set infected? False
set immune? False
set infection-date "NA"
show-status
]
end
to go
tick
ask one-of turtles
[
get-infected
]
ask turtles
[
update-status
show-status
]
end
to get-infected
if not immune?
[
set infected? True
set infection-date ticks
]
end
to update-status
if not (infection-date = "NA")
[
if infected? and (ticks - infection-date) >= ticks-sick
[
set infected? False
set immune? True
]
]
end
to show-status
ifelse infected?
[ set color red]
[
ifelse immune?
[ set color blue]
[set color green]
]
end
Upvotes: 2