NetLogo Turtle position

微笑、不失礼 提交于 2020-01-05 08:29:15

问题


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).

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.

Here is the code:

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

回答1:


This will make the robot turn the patch it is standing on black:

ask robots [ set pcolor black ]

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 ] ]

It does the same thing.



来源:https://stackoverflow.com/questions/19612328/netlogo-turtle-position

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!