如何让乌龟检查补丁集

时间:2018-03-02 14:32:39

标签: netlogo

我有一套乌龟,我的目的是检查一个补丁集,如果那套补丁上有任何固定的乌龟,我希望原来的乌龟停下来, 基本上是盒子交叉的情况。

我试过将补丁的含义设置为十字路口并尝试进行检查十字路口功能

交叉道路由:

制作
;create crossroads
ask patches with [(
pxcor mod 40 = 31 or pxcor mod 40 = 32 or pxcor mod 40 = 33 or pxcor mod 40 = 34 or pxcor mod 40 = 35 or pxcor mod 40 = 36 or pxcor mod 40 = 37 or pxcor mod 40 = 38 or pxcor mod 40 = 39 or pxcor mod 40 = 0 or pxcor mod 40 = 1 or pxcor mod 40 = 2 or pxcor mod 40 = 3 or pxcor mod 40 = 4 or pxcor mod 40 = 5)
and (
pycor mod 44 = 35 or pycor mod 44 = 36 or pycor mod 44 = 37 or pycor mod 44 = 38 or pycor mod 44 = 39 or pycor mod 44 = 40 or pycor mod 44 = 41 or pycor mod 44 = 42 or pycor mod 44 = 43 or pycor mod 44 = 0 or pycor mod 44 = 1 or pycor mod 44 = 2 or pycor mod 44 = 3 or pycor mod 4 = 4 or pycor mod 44 = 5)] [
set pcolor grey
 set meaning "crossroad"
]

我还尝试过使用补丁集检查前面的补丁但是我无法让它工作

to check-crossroad
let in-crossroad (patch-set patch-ahead 8 patch-ahead 7 patch-ahead 6 patch-ahead 5 patch-ahead 4 patch-ahead 3 patch-ahead 2 patch-ahead 1 patch-left-and-ahead 26 3 patch-right-and-ahead 26 3 )
let car3-oncrossroad one-of cars3-on in-crossroad

if [meaning] of patch-ahead 4 = "crossroad" and will-stop? = "maybe"
if [used] of patch-set in-crossroad and will-stop? = "yes"
end

1 个答案:

答案 0 :(得分:1)

使用member?可能会让海龟检查交叉点上是否存在其他海龟,如果没有则可以自由移动到交叉点。使用此设置:

globals [ box-to-check ]

to setup
  ca
  set box-to-check patches with [
    pxcor > -3 and pxcor < 3 and
    pycor > -3 and pycor < 3 
  ]
  ask box-to-check [
    set pcolor grey - 2
  ]
  crt 10 [ 
    setxy ( random 15 - 20 ) one-of [ -1 0 1 ]
    set heading 90
  ]
  crt 10 [ 
    setxy one-of [ -1 0 1 ] ( random 15 - 20 )
    set heading 0
  ]
  reset-ticks
end

使用这些记者进行交叉检查和基本移动程序以获得良好的衡量标准:

to-report other-turtles-on-junction
  let o-turtles other turtles with [ member? patch-here box-to-check ]
  report o-turtles 
end

to move
  if not any? other turtles-on patch-ahead 1 [
    move-to patch-ahead 1
  ]
end

然后让你的海龟在他们即将进入交界处的时候检查那个记者:

to go
  ask turtles [
    ifelse member? patch-ahead 1 box-to-check [
      if not any? other-turtles-on-junction [
        move
      ]
    ] [
      move
    ]
  ]
  tick   
end

希望这会给你一些想法,但请记住,你需要摆弄以适应多个路口等事情。