允许乌龟在特定补丁周围移动

时间:2015-03-17 18:12:28

标签: 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 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

这可能吗?

1 个答案:

答案 0 :(得分:1)

我确信有很多方法可以解决这个问题。这是一个简单的:

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
相关问题