user2923389
user2923389

Reputation: 141

NetLogo Turtle position

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

Upvotes: 1

Views: 1175

Answers (1)

Seth Tisue
Seth Tisue

Reputation: 30453

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.

Upvotes: 1

Related Questions