Parallel processing 让多只海龟同时移动

Parallel processing 让多只海龟同时移动,parallel-processing,netlogo,Parallel Processing,Netlogo,这个项目的想法是什么:我们有看门狗、绵羊、狼。我的羊在一个福特,狼从外面来,当进入福特,看门狗开始移动。狼吃羊,羊吃草,看门狗应该吓唬狼(尚未实施) 我的问题:所有的海龟一次移动一只 我想要的:我想让它们在每次滴答声中同时移动 代码: breed [sheeps sheep] breed [wolves wolf] breed [watchdogs watchdog] turtles-own [attacked?] globals [counter attack sheep-

这个项目的想法是什么:我们有看门狗、绵羊、狼。我的羊在一个福特,狼从外面来,当进入福特,看门狗开始移动。狼吃羊,羊吃草,看门狗应该吓唬狼(尚未实施)

我的问题:所有的海龟一次移动一只

我想要的:我想让它们在每次滴答声中同时移动

代码

    breed [sheeps sheep]
breed [wolves wolf]
breed [watchdogs watchdog]

turtles-own [attacked?]

globals [counter
  attack
  sheep-energy
  wolf-energy
  grass-counter
  lifespan
  age
  num-attacks
  death-countdown]

to set-variables-shapes
  set lifespan 365 * 10
    set-default-shape sheeps "sheep"
    set-default-shape watchdogs "dog"
    set-default-shape wolves "wolf"
     set sheep-energy 200
     set wolf-energy 400
     set death-countdown 60
end

to setup
  clear-all
 set-variables-shapes
 create-fold
 spawn-animals
  reset-ticks

end

to go

   ask turtles [
     move
   ]
    respawn-grass

  ask sheeps [
    if ( pcolor != green or pcolor != brown) [
      move-to one-of patches with [ pcolor = green or pcolor = brown] ;; If i change this with turn-around (procedure), all sheeps die at once.
    ]
    eat-grass
    reproduce
    sheep-status
    death
 show sheep-energy
  ]

  ask wolves [
    attack-sheep
    if (xcor < 5 and xcor > -14 and ycor < 15 and ycor > -5 ) [

      ask watchdogs [
    move
    if ( pcolor != green or pcolor != brown ) [
      move-to one-of patches with [ pcolor = green]
    ]
      ]
    ]
  ]

tick
end

to create-fold
  ask patches [
    if (pxcor < 6 and pxcor > -15 and pycor < 16 and pycor > -6)[
      set pcolor grey]
    if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5) [
      set pcolor green]
   ]

end


to sheep-status
  if (pcolor = brown) [
    set sheep-energy sheep-energy - (life-from-food / 2)]
  if attacked?
  [set color red]

 end


to attack-sheep
    ask other sheeps in-radius (size)[
      set attacked? true
        set color red
    ]

end
to reproduce
  if (age = lifespan / 10) [
    hatch-sheeps 40 [
      hatch-options
      ]
  ]
end

to eat-grass
  if (pcolor = green)[
    set pcolor brown
    set sheep-energy sheep-energy + life-from-food
  ]
end

to respawn-grass
  ask patches [
  if pcolor = brown [
    ifelse grass-counter = 0 [
      set pcolor green
      set grass-counter grass-respawn-timer
    ]
    [ set grass-counter grass-counter - 1]
  ]
  ]
  end
to death
  sheep-death-timer
  if (sheep-energy <= 0)
  [die]
  ;;if (age >= lifespan) [die]
  sheep-explode

end

to sheep-death-timer
  if (attacked?)[
  set death-countdown death-countdown - 1

  if (death-countdown  <= 30)
  [set color black]
  if (death-countdown <= 0)
  [die]
  ]
end

to sheep-explode
  if (sheep-energy >= 10000)[
  hatch-sheeps 20 [
    hatch-options]
  die
  ]
end

to hatch-options
  set sheep-energy 200
      set age 1
      set attacked? false
  end

to move
  fd 1
  rt random 90
  lt random 90
end

to spawn-animals
   create-wolves number-of-wolves [
      set color red
      setxy 10 -10
      set size 1.3
      ask patch 10 -10[
        Set plabel "Wolves"]
  ]
  create-sheeps number-of-sheeps [
     if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5 )[
        setxy -4.5 5]
     ask patch -4.5 15 [
       Set plabel "Sheeps"]
  set color white
  set attacked? false
   ]
 create-watchdogs number-of-dogs [
    if (pxcor < 5 and pxcor > -14 and pycor < 15 and pycor > -5 )[
    setxy  -4.5 5
    set size 1.3]
  set color blue
  ]
end
to turn-around
  fd -1
  rt 180
end
品种[绵羊]
繁殖[狼]
品种[看门狗]
海龟自己的[被攻击的?]
全局[计数器]
袭击
绵羊能量
狼能源
草地计数器
寿命
年龄
num攻击
死亡倒计时]
设置变量形状的步骤
设置寿命365*10
将默认形状的绵羊设置为“绵羊”
设置默认形状监视器“dog”
将默认形状设置为“狼”
设置绵羊能量200
设置狼能量400
设置死亡倒计时60
终止
设置
清除所有
设置变量形状
创建折叠
产卵动物
重置滴答声
终止
外带
问海龟[
移动
]
再生草
问羊[
如果(颜色!=绿色或颜色!=棕色)[
用[pcolor=green或pcolor=brown];;移动到其中一个面片;如果我用掉头(过程)更改此面片,则所有绵羊都会立即死亡。
]
吃草
复制
绵羊地位
死
显示绵羊的活力
]
问狼[
攻羊
如果(xcor<5和xcor>-14和ycor<15和ycor>-5)[
问看门狗[
移动
如果(颜色!=绿色或颜色!=棕色)[
使用[pcolor=绿色]移动到其中一个面片
]
]
]
]
打上钩
终止
创建折叠
询问补丁[
如果(pxcor<6和pxcor>-15和pycor<16和pycor>-6)[
设置颜色[灰色]
如果(pxcor<5和pxcor>-14和pycor<15和pycor>-5)[
设置颜色[绿色]
]
终止
羊的地位
if(颜色=棕色)[
设置绵羊能量绵羊能量-(食物中的生命/2)]
如果受到攻击?
[设置颜色为红色]
终止
攻羊
询问其他羊的半径(大小)[
被攻击?是的
设置颜色为红色
]
终止
复制
如果(年龄=寿命/10)[
孵化绵羊40[
图案填充选项
]
]
终止
吃草
如果(颜色=绿色)[
设置颜色为棕色
设置绵羊能量绵羊能量+食物生命
]
终止
使草重生
询问补丁[
如果pcolor=棕色[
ifelse草地计数器=0[
将颜色设置为绿色
设置草计数器草再生计时器
]
[设置草地计数器草地计数器-1]
]
]
终止
至死
绵羊死亡计时器
如果(绵羊能量=寿命)[死亡]
绵羊爆炸
终止
绵羊死亡计时器
如果(被攻击?)[
设置死亡倒计时死亡倒计时-1
如果(死亡倒计时-14和pycor<15和pycor>-5)[
setxy-4.5]
询问补丁-4.5 15[
设置“羊圈”]
将颜色设置为白色
设置攻击?错误
]
创建看门狗数量[
如果(pxcor<5和pxcor>-14和pycor<15和pycor>-5)[
setxy-4.5
套装尺寸1.3]
设置颜色为蓝色
]
终止
转身
fd-1
rt 180
终止
您可以使用

ask-concurrent sheeps [move ]
使每个sheep代理同时移动,但这不重要,他们实际上不建议您使用它。

NetLogo中没有“同时”这样的东西。NetLogo是单线程的,不支持并行处理

如果所有的代理都在同一个滴答声中移动,你可以认为这是“在同一时间”,因为这一切都发生在滴答声的过程中


但是在一个滴答声中,特工们一次只能移动一个。你应该单独询问你关于绵羊早死的问题。
ask concurrent
不会这样做。特工们还是一次移动一个。(解释
ask concurrent
的实际功能相当困难,这也是我们从不推荐它的部分原因。)谢谢!设法了解了更多关于NetLogo的信息,我最终明白这是不可能的。:)