gpt4 book ai didi

netlogo - 设定海龟的年龄

转载 作者:行者123 更新时间:2023-12-01 11:33:25 30 4
gpt4 key购买 nike

我让我的海龟拥有自己的 age 作为它们的变量之一,并且我将 age 设置为 ticks 以便我的海龟在达到一定数量的 ticks 时变老。然而,这会导致所有海龟同时老化(比如 ticks = 5 时),而不管它们是何时创建的。

有什么方法可以让年龄从海龟创建时开始吗?因此,如果海龟在第 5 个刻度创建,它的年龄从零开始,但仍然等于 1 个刻度的长度?

是的!对不起!这是我在将其放入实际模型之前一直在玩的代码

breed [kids kid]
breed [adults adult]
breed [elderlies elderly]

turtles-own [age
z]

to setup
clear-all
create-kids 10
[setxy random-xcor random-ycor]
set-default-shape kids "fish"
create-adults 10
[setxy random-xcor random-ycor]
set-default-shape adults "person"
set-default-shape elderlies "cow"

clear-output
reset-ticks
end

to go
ask kids [birthday
move]
ask adults [birthday
reproduce-adults
move]
tick
end

to birthday
set age ticks
if age > 5 [set breed adults]
if age > 10 [set breed elderlies]
if age > 15 [die]
end

to reproduce-adults
set z random 100
if z > 65
[ hatch-kids 1]
end

to move
rt random 360
fd 1
end

最佳答案

在您的go 过程中,包括ask turtles [increment-age],其中

to increment-age
set age (1 + age)
end

关于netlogo - 设定海龟的年龄,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29997530/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com