如何在Netlogo中使用半径中的to命令来帮助海龟寻找食物,以及如何随着时间的推移再生食物?
我正在尝试在NetLogo中执行以下操作:如何在Netlogo中使用半径中的to命令来帮助海龟寻找食物,以及如何随着时间的推移再生食物?,netlogo,Netlogo,我正在尝试在NetLogo中执行以下操作: 让海龟(大象)寻找食物 让植物在每一边慢慢繁殖,一边在另一边之前 让海龟(大象)留在世界范围内 保持海龟(大象)直立 我基本上想做的是让我们的海龟(大象)在一边吃东西,然后寻找食物到另一边。如果他们被车撞了,他们会死的。我们希望它们在两边来回交叉,这样它们都会随着时间的推移死去。我们已经尝试使用seek food原语,但它不适用于我们的模拟。我们还让海龟们使用bounce原语呆在地球上,但在当前的代码中,它们会再次到处移动。至于食物再生,我们已经尝试使
breed [ elephants elephant ]
breed [ cars car ]
breed [ plants plant ]
turtles-own [
speed
speed-limit
speed-min
]
to setup
clear-all
setup-patches
setup-elephants
setup-cars
setup-plants
reset-ticks
end
to setup-patches
ask patches [
ifelse (pycor > -2) and (pycor < 2)
[ set pcolor black ]
[ set pcolor green ]
]
end
to setup-elephants
ask n-of number-of-elephants (patches with [ pycor < -4 ])
[ sprout-elephants 1
[ set shape "elephant"
set color 4
set size 4
]
]
end
to setup-cars
ask n-of number-of-cars (patches with [ pcolor = black ])
[ sprout-cars 1
[ set shape "car"
set color 105
set size 2
set heading 90
]
]
end
to setup-plants
ask n-of number-of-plants (patches with [ pcolor = green ])
[ sprout-plants 1
[ set shape "plant"
set color 62
set size 1
]
]
end
to go
ask elephants [
bounce forward 1
]
ask cars [
set xcor random-xcor
set heading 90
forward 1
move-elephants
move-cars
eat-plants
kill-elephants
]
end
to bounce
if abs pxcor = max-pxcor
[ set heading ( - heading ) ]
if abs pycor = max-pycor
[ set heading ( 180 - heading ) ]
end
to move-elephants
ask elephants [
right random 360
forward 1
]
end
to move-cars
set speed 0.1
set speed-limit 0.1
end
to eat-plants
ask elephants
[ let prey one-of plants-here
if prey != nobody [ask prey [die]]
]
end
to kill-elephants
ask cars
[ let prey one-of elephants-here
if prey != nobody [ask prey [die]]
]
end
繁殖[大象]
品种[汽车]
繁殖[植物]
乌龟自己的[
速度
限速
最小速度
]
设置
清除所有
安装补丁
设置大象
设置车辆
种植
重置滴答声
结束
设置修补程序
询问补丁[
ifelse(pycor>-2)和(pycor<2)
[将颜色设置为黑色]
[将颜色设置为绿色]
]
结束
安置大象
询问n-大象数量(带有[pycor<-4]的补丁)
[发芽大象1
[设置形状“大象”
设置颜色4
套装尺寸4
]
]
结束
安装汽车
询问n-车辆数量(带有[pcolor=黑色]的补丁)
[萌芽汽车1
[设置形状“汽车”
设置颜色105
2号套餐
设置标题90
]
]
结束
植树
询问n-植物数量(带有[pcolor=绿色]的斑块)
[发芽植物1
[设定形状“植物”
设置颜色62
1号套餐
]
]
结束
外带
问大象[
向前弹跳1
]
问车[
设置xcor随机xcor
设置标题90
转发1
移动大象
搬家
吃植物
杀象
]
结束
弹跳
如果abs pxcor=最大pxcor
[设置标题(-标题)]
如果abs pycor=最大pycor
[设定标题(180-标题)]
结束
移动大象
问大象[
右随机360
转发1
]
结束
搬家
设定速度为0.1
将速度限制设置为0.1
结束
吃植物
问大象
[让我们捕食这里的一种植物
如果猎物!=没人[问猎物[死]]
]
结束
杀象
问车
让我们在这里捕食一头大象
如果猎物!=没人[问猎物[死]]
]
结束
这段代码有几个问题,因此我将尝试排除更明显的逻辑问题,看看这是否能让您专注于一个特定的问题。请注意,您真的应该更加循序渐进地构建代码-添加一种行为(例如移动大象、移动汽车、吃东西或其他),并确保在添加下一种行为之前该行为有效
勾选
ask cars[ask大象[]]
来吃植物和杀死大象,这将使这些事情在每次滴答声中发生很多次breed [ elephants elephant ]
breed [ cars car ]
breed [ plants plant ]
turtles-own
[ speed
speed-limit
speed-min
]
to setup
clear-all
setup-patches
setup-elephants
setup-cars
setup-plants
reset-ticks
end
to go
ask elephants
[ bounce
forward 1
]
ask cars [ forward 1 ]
move-elephants
eat-plants
kill-elephants
tick
end
to bounce
if abs pxcor = max-pxcor
[ set heading ( - heading ) ]
if abs pycor = max-pycor
[ set heading ( 180 - heading ) ]
end
to move-elephants
ask elephants
[ right random 360
forward 1
]
end
to eat-plants
ask elephants
[ let prey one-of plants-here
if prey != nobody [ask prey [die]]
]
end
to kill-elephants
ask cars
[ let prey one-of elephants-here
if prey != nobody [ask prey [die]]
]
end
to setup-patches
ask patches [
ifelse (pycor > -2) and (pycor < 2)
[ set pcolor black ]
[ set pcolor green ]
]
end
to setup-elephants
ask n-of 20 (patches with [ pycor < -4 ])
[ sprout-elephants 1
[ set shape "wolf"
set color 4
set size 4
]
]
end
to setup-cars
ask n-of 20 (patches with [ pcolor = black ])
[ sprout-cars 1
[ set shape "car"
set color 105
set size 2
set heading 90
set speed 0.1
set speed-limit 0.1
]
]
end
to setup-plants
ask n-of 50 (patches with [ pcolor = green ])
[ sprout-plants 1
[ set shape "plant"
set color 62
set size 1
]
]
end
繁殖[大象]
品种[汽车]
繁殖[植物]
乌龟自己的
[速度
限速
最小速度
]
设置
清除所有
安装补丁
设置大象
设置车辆
种植
重置滴答声
结束
外带
问大象
[弹跳
转发1
]
询问汽车[前进1]
移动大象
吃植物
杀象
打上钩
结束
弹跳
如果abs pxcor=最大pxcor
[设置标题(-标题)]
如果abs pycor=最大pycor
[设定标题(180-标题)]
结束
移动大象
问大象
[右随机360
转发1
]
结束
吃植物
问大象
[让我们捕食这里的一种植物
如果猎物!=没人[问猎物[死]]
]
结束
杀象
问车
让我们在这里捕食一头大象
如果猎物!=没人[问猎物[死]]
]
结束
设置修补程序
询问补丁[
ifelse(pycor>-2)和(pycor<2)
[将颜色设置为黑色]
[将颜色设置为绿色]
]
结束
安置大象
询问n-20(带有[pycor<-4]的补丁)
[发芽大象1
[设定形状“狼”
设置颜色4
套装尺寸4
]
]
结束
安装汽车
询问n-20(带有[pcolor=黑色]的贴片)
[萌芽汽车1
[设置形状“汽车”
设置颜色105
2号套餐
设置标题90
设定速度为0.1
将速度限制设置为0.1
]
]
结束
植树
询问n-50(带有[pcolor=绿色]的贴片)
[发芽植物1
[设定形状“植物”
设置颜色62
1号套餐
]
]
结束
这段代码有几个问题,因此我将尝试排除更明显的逻辑问题,看看这是否能让您专注于一个特定的问题。请注意,您真的应该更加循序渐进地构建代码-添加一种行为(例如移动大象、移动汽车、吃东西或其他),并确保在添加下一种行为之前该行为有效
勾选
询问汽车[询问大象[]
来吃植物和杀死大象