gpt4 book ai didi

simulation - 避免带有海龟网络标志的补丁

转载 作者:行者123 更新时间:2023-12-01 17:04:58 26 4
gpt4 key购买 nike

任何人都可以帮我解决这个问题吗?我试图模拟一种情况,其中乌龟会随机坐在长凳上(红色斑 block ),如果长凳被占用,它会找到另一个。1只海龟:1 block

breed [kids kid]

breed [adults adult]

breed [oldies old]

kids-own [step]

adults-own [step]

oldies-own [step]

to setup

__clear-all-and-reset-ticks

ask patches [setup-world]

set-default-shape turtles "person"

create-kids number-of-kids

create-adults number-of-adults

create-oldies number-of-oldies

ask kids[

set color green
set size 1
setxy -10 0
set heading random-float 90
rt 45 - random-float 90]

ask adults[

set color orange
set size 1
setxy -10 0
set heading random-float 45
rt 45 - random-float 90]



to setup-world

set pcolor white

if ( pxcor = 10 ) and ( pycor < 10 and pycor > -11 ) [ set pcolor brown ]

if ( pxcor = -10 ) and ( pycor < 10 and pycor > 1 ) [ set pcolor brown ]

if ( pxcor = -10 ) and ( pycor < -1 and pycor > -11 ) [ set pcolor brown ]

if ( pycor = 10 ) and ( pxcor < 11 and pxcor > -11 ) [ set pcolor brown ]

if ( pycor = -10 ) and ( pxcor < 10 and pxcor > -11 ) [ set pcolor brown ]


if ( pxcor = 8 ) and ( pycor < 8 and pycor > 2 ) [ set pcolor red ]

if ( pxcor = 8 ) and ( pycor < -2 and pycor > -8 ) [ set pcolor red ]

end


to go

ask kids[

if pcolor = red and not any? other turtles-here[
move-to patch-here
stop]
fd 1

ifelse pcolor = red and any? other turtles-here
[rt random 90]
[fd 1]



]



ask adults[

if pcolor = red and not any? other turtles-here[
move-to patch-here
stop]
fd 1

ifelse pcolor = red and any? other turtles-here
[rt random 90]
[fd 1]



]







tick



end

最佳答案

您已经以正确的方式完成了大部分编码,我已经测试了您的代码,除了适用于 child 和成人的 go 函数中的第二个条件外,它工作正常。

做同样事情的一种方法是添加一个乌龟变量,例如坐?变量并在初始化时使其为假,如果乌龟坐在长凳上则使其为真。而且只问假坐的乌龟?寻找另一个长凳。

   turtles-own [seated?]

ask kids with [not seated? ][


rt random 10
fd 1

if pcolor = red and not any? other turtles-here [
move-to patch-here
set seated? true]


]



ask adults with [not seated?]
[
rt random 10
fd 1
if pcolor = red and not any? other turtles-here[
move-to patch-here
set seated? true]
]

我通过显示每个区域中海龟的数量来测试代码,每个红色补丁中只有一只海龟

ask patches with [pcolor = red ][set plabel count turtles-here]

关于simulation - 避免带有海龟网络标志的补丁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20842888/

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