在以下代码中,当我们执行hatch 1
时,哪个品种具有新的乌龟-stars
?或没有品种-仅继承last-one?
变量
breed [stars a-star]
stars-own [
last-one?
]
create-stars 1
[
set color brown
set heading 0
hatch 1
[
set color green fd 1
set last-one? false ;; don't remember
]
]
答案 0 :(得分:3)
使用hatch
,新乌龟的所有属性值都与父代完全相同。其中包括breed
,这是乌龟自动拥有的属性(非常类似于大小,x-cor等)。这是代码的略微扩展版本,可以显示您的答案,还可以显示如何直接使用breed
作为属性。
breed [stars a-star]
stars-own [
last-one?
]
to setup
clear-all
create-stars 1
[ set color brown
set heading 0
hatch 1
[ set color green fd 1
set last-one? false ;; don't remember
]
]
type "Number of stars: " print count stars
type "Number of other turtles: " print count turtles with [breed != stars]
end