NetLogo龟的位置 [英] NetLogo Turtle position
问题描述
我真的是NetLogo编程的新手,我需要一点帮助.我有一个任务,我做了大部分.剩下要做的就是使机器人在迷宫中行走.机器人只能在黑色补丁上行走(紫色补丁代表障碍物).
I'm really new at programming in NetLogo and i need a little help. I have an assignment and i did most of it. The thing left to do is to make robot walk in labyrinth. Robot can walk only on a black patches (violet patches represent the obstacles).
因此,我需要帮助的事情是将机器人放置在迷宫的中心-我必须使用在此放置补丁"来完成它(...我在"stvori-agenta"过程中做了一些不同的操作)并将机器人站立的那个补丁标记为黑色.因此,之后我只能在黑色补丁上编写机器人运动的程序.
So, the thing i need help with is to position robot in the center of the labyrinth - i must do it with "patch-here" (...i did it little bit differently in procedure "stvori-agenta") and mark that patch on which robot stands as black. So, afterwards i could write procedures for robots movements only on a black patches.
这是代码:
breed [robots robot]
to crtaj-zidove
ask patches with
[
( pxcor = max-pxcor)
or (pxcor = min-pxcor)
or ( pycor = max-pycor)
or (pycor = min-pycor) ]
[ set pcolor violet]
end
to labirint
ask n-of 15 patches with [ pcolor != violet ] [
set pcolor violet]
end
to stvori-agenta
set-default-shape robots "robot"
ask patch 5 5 [ sprout-robots 1 ]
ask turtles [
set heading 0
set color grey
]
end
to setup
clear-all
crtaj-zidove
labirint
stvori-agenta
end
推荐答案
这将使机器人将其站立的补丁变成黑色:
This will make the robot turn the patch it is standing on black:
ask robots [ set pcolor black ]
您说您必须使用patch-here
.实际上这并不是必需的,因为海龟可以直接访问它们站立的补丁.但您也可以将其写为:
You say you must use patch-here
. That isn't actually necessary, since turtles have direct access to the patches they are standing on. But you could also write it as:
ask robots [ ask patch-here [ set pcolor black ] ]
它做同样的事情.
这篇关于NetLogo龟的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!