Netlogo 允许海龟在特定的区域内移动

Netlogo 允许海龟在特定的区域内移动,netlogo,Netlogo,我想建立一个有医院的城市模型。有人,有人是特定医院的员工 我希望员工的移动距离不超过他们工作的医院的最大距离 persons-own [ hospital-employees? ; true if work in hospital hospital-position-cordx ; xcor of the hospital where he works hospital-position-cordy ; ycor of the hospital where he

我想建立一个有医院的城市模型。有人,有人是特定医院的员工

我希望员工的移动距离不超过他们工作的医院的最大距离

persons-own [
 hospital-employees?        ; true if work in hospital
 hospital-position-cordx    ; xcor of the hospital where he works
 hospital-position-cordy    ; ycor of the hospital where he works
]

to move 
 ; they can move only around the hospital (max distance 5 patch)
 ask persons with[hospital-employees?][
  ...........
 ]
 ; other people can move free
 ask persons with[not hospital-employees?][
  rt random 180
  lt random 180
  fd 1
 ]
end

这可能吗?

我相信有很多方法可以解决这个问题。这里有一个简单的例子:

breed [hospitals hospital]
breed [employees employee]
employees-own [my-hospital]

to setup
  clear-all
  set-default-shape hospitals "house"
  set-default-shape employees "person"
  ask n-of 5 patches [
    sprout-hospitals 1 [
      hatch-employees 5 [
        set my-hospital myself
      ]
    ]
  ]
  reset-ticks
end

to go
  let max-distance 5
  ask employees [
    ifelse distance my-hospital > max-distance - 1 [
      face my-hospital
    ] [
      rt random 180
      lt random 180
    ]
    fd 1
  ]
end