如何在netlogo中使用view2.5d:turtle视图

如何在netlogo中使用view2.5d:turtle视图,netlogo,Netlogo,当我尝试在view2.5d扩展中使用view2.5d:turtle视图时,我总是得到NullPointerExpection extensions [view2.5d] turtles-own[ energy ] to setup ca create-turtles 50[ set color red setxy random-xcor random-ycor set energy random 1000 ] create-turtles 50[ set

当我尝试在view2.5d扩展中使用view2.5d:turtle视图时,我总是得到NullPointerExpection

extensions [view2.5d]

turtles-own[
  energy
]

to setup
  ca
  create-turtles 50[
  set color red
  setxy random-xcor random-ycor
  set energy random 1000
  ]
  create-turtles 50[
  set energy random 1000
  setxy random-xcor random-ycor
  ]
  view2.5d:turtle-view "test" turtles [the-turtle -> [energy] of the-turtle]
  reset-ticks
end
错误消息:

错误(NullPointerException) 当观察者运行VIEW2.5D时:TURTLE-VIEW 由过程设置调用 通过“设置”按钮调用

NetLogo无法向您提供有关此错误的详细信息。请报告问题 在,或bugs@ccl.northwestern.edu,然后粘贴
此窗口的内容将显示在您的报告中。

如果有其他人遇到此窗口,则它是。该链接提供了扩展的修复版本

有关用法的快速示例,请从模型库中打开狼羊捕食模型,并在代码选项卡中进行以下更改:

  • 在第一行添加
    扩展[view2.5d]
  • 设置
    过程中,将
    视图2.5d:turtle view“wsp”turtles[t->[energy]of t]
    添加到
    重置刻度
    后的行中,就在
    结束
    之前。《匿名记者》(anonymous reporter)的
    [t->[energy]决定了2.5d视图中海龟的“高度”
    
  • go
    过程结束时,在
    结束之前的
    显示标签之后添加
    view2.5d:update-turtle-view“wsp”turtles
上面显示了如何将view2.5d添加到使用turtles的现有模型中。以下是便于复制/粘贴的完整代码

extensions [ view2.5d ]

globals [ max-sheep ]  ; don't let sheep population grow too large
; Sheep and wolves are both breeds of turtle.
breed [ sheep a-sheep ]  ; sheep is its own plural, so we use "a-sheep" as the singular.
breed [ wolves wolf ]
turtles-own [ energy ]       ; both wolves and sheep have energy
patches-own [ countdown ]

to setup
  clear-all

  ifelse netlogo-web? [set max-sheep 10000] [set max-sheep 30000]

  ; Check model-version switch
  ; if we're not modeling grass, then the sheep don't need to eat to survive
  ; otherwise the grass's state of growth and growing logic need to be set up
  ifelse model-version = "sheep-wolves-grass" [
    ask patches [
      set pcolor one-of [ green brown ]
      ifelse pcolor = green
        [ set countdown grass-regrowth-time ]
      [ set countdown random grass-regrowth-time ] ; initialize grass regrowth clocks randomly for brown patches
    ]
  ]
  [
    ask patches [ set pcolor green ]
  ]

  create-sheep initial-number-sheep  ; create the sheep, then initialize their variables
  [
    set shape  "sheep"
    set color white
    set size 1.5  ; easier to see
    set label-color blue - 2
    set energy random (2 * sheep-gain-from-food)
    setxy random-xcor random-ycor
  ]

  create-wolves initial-number-wolves  ; create the wolves, then initialize their variables
  [
    set shape "wolf"
    set color black
    set size 2  ; easier to see
    set energy random (2 * wolf-gain-from-food)
    setxy random-xcor random-ycor
  ]
  display-labels
  reset-ticks

  view2.5d:turtle-view "wsp" turtles [ t -> [energy] of t ]

end

to go
  ; stop the simulation of no wolves or sheep
  if not any? turtles [ stop ]
  ; stop the model if there are no wolves and the number of sheep gets very large
  if not any? wolves and count sheep > max-sheep [ user-message "The sheep have inherited the earth" stop ]
  ask sheep [
    move
    if model-version = "sheep-wolves-grass" [ ; in this version, sheep eat grass, grass grows and it costs sheep energy to move
      set energy energy - 1  ; deduct energy for sheep only if running sheep-wolf-grass model version
      eat-grass  ; sheep eat grass only if running sheep-wolf-grass model version
      death ; sheep die from starvation only if running sheep-wolf-grass model version
    ]
    reproduce-sheep  ; sheep reproduce at random rate governed by slider
  ]
  ask wolves [
    move
    set energy energy - 1  ; wolves lose energy as they move
    eat-sheep ; wolves eat a sheep on their patch
    death ; wolves die if our of energy
    reproduce-wolves ; wolves reproduce at random rate governed by slider
  ]
  if model-version = "sheep-wolves-grass" [ ask patches [ grow-grass ] ]
  ; set grass count patches with [pcolor = green]
  tick
  display-labels

  view2.5d:update-turtle-view "wsp" turtles

end

to move  ; turtle procedure
  rt random 50
  lt random 50
  fd 1
end

to eat-grass  ; sheep procedure
  ; sheep eat grass, turn the patch brown
  if pcolor = green [
    set pcolor brown
    set energy energy + sheep-gain-from-food  ; sheep gain energy by eating
  ]
end

to reproduce-sheep  ; sheep procedure
  if random-float 100 < sheep-reproduce [  ; throw "dice" to see if you will reproduce
    set energy (energy / 2)                ; divide energy between parent and offspring
    hatch 1 [ rt random-float 360 fd 1 ]   ; hatch an offspring and move it forward 1 step
  ]
end

to reproduce-wolves  ; wolf procedure
  if random-float 100 < wolf-reproduce [  ; throw "dice" to see if you will reproduce
    set energy (energy / 2)               ; divide energy between parent and offspring
    hatch 1 [ rt random-float 360 fd 1 ]  ; hatch an offspring and move it forward 1 step
  ]
end

to eat-sheep  ; wolf procedure
  let prey one-of sheep-here                    ; grab a random sheep
  if prey != nobody  [                          ; did we get one?  if so,
    ask prey [ die ]                            ; kill it, and...
    set energy energy + wolf-gain-from-food     ; get energy from eating
  ]
end

to death  ; turtle procedure (i.e. both wolf nd sheep procedure)
  ; when energy dips below zero, die
  if energy < 0 [ die ]
end

to grow-grass  ; patch procedure
  ; countdown on brown patches: if reach 0, grow some grass
  if pcolor = brown [
    ifelse countdown <= 0
      [ set pcolor green
        set countdown grass-regrowth-time ]
      [ set countdown countdown - 1 ]
  ]
end

to-report grass
  ifelse model-version = "sheep-wolves-grass" [
    report patches with [pcolor = green]
  ]
  [ report 0 ]
end


to display-labels
  ask turtles [ set label "" ]
  if show-energy? [
    ask wolves [ set label round energy ]
    if model-version = "sheep-wolves-grass" [ ask sheep [ set label round energy ] ]
  ]
end



; Copyright 1997 Uri Wilensky.
; See Info tab for full copyright and license.
extensions[view2.5d]
全球[最大绵羊];不要让羊的数量增长太多
; 绵羊和狼都是乌龟的品种。
品种[绵羊a羊];绵羊本身就是复数,所以我们用“a-sheep”作为单数。
繁殖[狼]
海龟拥有[能量];狼和羊都有能量
补丁自己[倒计时]
设置
清除所有
如果有其他网络标志?[设置最大绵羊10000只][设置最大绵羊30000只]
; 检查型号版本开关
; 如果我们不为草建模,那么绵羊就不需要吃东西来生存
; 否则,需要建立草的生长状态和生长逻辑
ifelse模型版本=“绵羊-狼-草”[
询问补丁[
将pcolor设置为[绿棕色]之一
ifelse pcolor=绿色
[设置倒数计时草再生时间]
[设置倒数随机草再生时间];为棕色斑块随机初始化草再生时钟
]
]
[
询问修补程序[将pcolor设置为绿色]
]
创建绵羊初始数量;创建羊,然后初始化它们的变量
[
定形“羊”
将颜色设置为白色
设置大小为1.5;更易于查看
设置标签颜色为蓝色-2
随机设置能量(2只羊从食物中获得)
setxy随机xcor随机ycor
]
创建狼群初始数量狼群;创建狼群,然后初始化它们的变量
[
设定形状“狼”
将颜色设置为黑色
设置大小2;更易于查看
随机设置能量(2*狼从食物中获得)
setxy随机xcor随机ycor
]
显示标签
重置滴答声
视图2.5d:海龟视图“wsp”海龟[t->[energy]of t]
终止
外带
; 停止模拟没有狼或羊
如果没有?乌龟[停]
; 如果没有狼,羊的数量变得非常多,停止模型
如果没有?狼和数羊>最大羊[用户消息“羊继承了地球”停止]
问羊[
移动
如果model version=“sheep-wolfs-grass”[;在这个版本中,绵羊吃草,草生长,移动需要消耗绵羊的能量
设置能量-1;仅当运行羊-狼-草模型版本时,才扣除羊的能量
吃草;羊只吃草,如果运行羊狼草模型版本
死亡;羊饿死只有在奔跑的羊狼草模型版本
]
繁殖绵羊;绵羊以滑块控制的随机速率繁殖
]
问狼[
移动
设置能量-1;狼在移动时会失去能量
吃羊;狼在他们的地盘上吃羊
死亡;如果我们缺乏能量,狼就会死亡
繁殖狼;狼以受滑块控制的随机速率繁殖
]
如果model version=“绵羊-狼-草”[询问补丁[种植草]]
; 使用[pcolor=green]设置草地数面片
打上钩
显示标签
视图2.5d:更新海龟视图“wsp”海龟
终止
移动;海龟手术
rt随机50
lt随机50
fd 1
终止
吃草;绵羊程序
; 羊吃草,把草地变成棕色
如果pcolor=绿色[
设置颜色为棕色
设定能量+绵羊从食物中获得能量;绵羊通过进食获得能量
]
终止
繁殖绵羊;绵羊程序
如果随机浮动100<绵羊繁殖[掷骰子]看你是否会繁殖
设置能量(能量/2);在父代和子代之间分配能量
图案填充1[rt random float 360 fd 1];图案填充子代并将其向前移动1步
]
终止
繁殖狼;沃尔夫程序
如果随机浮动100<狼繁殖,掷骰子看你是否会繁殖
设置能量(能量/2);在父代和子代之间分配能量
图案填充1[rt random float 360 fd 1];图案填充子代并将其向前移动1步
]
终止
吃羊;沃尔夫程序
让我们在这里捕食一只羊;随便抓一只羊
如果是猎物!=没有人,我们有吗,
要求猎物[死亡];杀死它,然后。。。
设定能量+狼从食物中获得的能量;从进食中获得能量
]
终止
死亡;海龟程序(即狼和羊程序)
; 当能量降到零下时,死亡
如果能量<0[死亡]
终止
种草;修补程序
; 棕色斑块倒计时:如果达到0,种植一些草
如果pcolor=棕色[

如果有人能上传一个view2.5d的例子:turtle视图利用率,这将非常有帮助。