Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
726 views
in Technique[技术] by (71.8m points)

netlogo - Turtles must not cross the "world" boarder

In my Netlogo project the turtles (circles, that simulate tables in a restaurant) are not allowed to cross the worlds boarder, since there is the wall of the restaurant. Before setup the user can choose the tables diameter. I tried the following:

if xcor < (size / 2) or xcor > (32 - (size / 2)) [ find_new_spot ]

if ycor < (size / 2) or ycor > (32 - (size / 2)) [ find_new_spot ]

The idea was that if the xcor is smaler than the radius of the table, it has to find a new spot. Same goes with the ycor. But this does not work. Is there anything missing?

My Netlogo world is set up like the following:

  • Location of origin: corner (bottom left)
  • max-pxcor: 32
  • min-pxcor: 0
  • max-pycor: 32
  • min-pycor: 0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It's possible that they did find a new spot, but the new spot was also too close to the wall. You can debug that by putting a line into your find_new_spot procedure that tells you the location at the beginning of the procedure and then again at the end of the procedure. If that is your problem, then you need it to keep moving until it find an allowed spot, so you need a while loop.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...