【问题标题】:Netlogo - Turtle-Patch interaction with string-variableNetlogo - Turtle-Patch 与字符串变量的交互
【发布时间】:2022-10-23 14:26:27
【问题描述】:

我需要 Netlogo 的帮助:当海龟与当前放置的补丁进行交互时,补丁变量(它是一个字符串)决定海龟变量(它是一个整数)是否增长。例如:

turtles-own [weight]
patches-own [food]

to setup
  clear-all
  create-turtles 1 [
    setxy random-xcor random-ycor
  ]
  ask patches[
    if pxcor >= 0 [set pcolor green 
      set food "Fries" ]
   
     if pxcor < 0 [set pcolor blue
      set food "Burger" ] 
  ]
  reset-ticks
end

to go
  increase-weight
  walk-around
  tick
end

to walk-around
  ask turtles [
    right random 120 - 60 
    fd 0.1
  ]
end

to increase-weight
  ask turtles [
    if food != "fries" [
      set weight (weight + 1)]
    if food != "burger" and  [
      set weight (weight  + 10)]
  ]
end

问题是turles的重量增加了11而不是1或10的值。我猜它的补丁在这里!?但我无法让它运行。

非常感谢

【问题讨论】:

  • 想想什么会导致增加11

标签: netlogo agent-based-modeling


【解决方案1】:

你很亲密。您需要在 if 语句中使用 patch-here,并在括号中使用 patch 变量的名称,如下所示:

  to increase-weight
  ask turtles 
  [
    if [food] of patch-here = "fries" 
      [set weight (weight + 1)]
    if [food] of patch-here = "burger" 
      [set weight (weight  + 10)]
  ]
  end

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-22
    相关资源
    最近更新 更多