Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
728 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...