Netlogo - "agents-here" 未按预期运行

Netlogo - "agents-here" not behaving as expected

感谢您早些时候对我的问题的意见。在这个模型中,船沿对角线穿过世界(不环绕,00 左下角,max-pycor 和 max-pxcor 49),20 条鱼在相反的对角线上移动。目的是让船计算它遇到的鱼(即 b 计数增加)并且鱼变黄。当鱼离开与船相同的区域时,它的颜色会变回蓝色。为了验证船的数量,每条鱼在遇到船时记录(即 f 计数增加)并且鱼的形状从星形变为圆形。当鱼不再与船在同一个区域时,鱼又变回星形。船不遇众鱼无所谓

在这个特定的 运行 上,设置了随机种子,当“船 0”和“鱼 18”相遇时(检查两者并在刻度 183),它们似乎在同一个补丁上,但相关计数没有增加,“鱼 18”没有改变形状或颜色。作为 NetLogo 的初学者,我忽略的“boats-here”、“fish-here”或“neighbors”的编码是否与代理的 xcor/ycor 相关?还是命令序列是问题的根源?再次感谢您考虑我的问题。

    globals [ starting-seed ]
    
    breed [boats boat]
    breed [fish a-fish]

    boats-own [b-count fuel]
    fish-own [f-count]

    to setup
      clear-all
      set starting-seed 91130056
      random-seed starting-seed
      reset-ticks

    create-boats 1
      [apply-boat-properties]

     create-fish 20
      [apply-fish-properties]

    end

    to apply-boat-properties
      ask boats
      [
        set color red
        set size 0.3
        set shape "star"
        setxy min-pxcor max-pycor
        set fuel 710
      ]
    end

    to apply-fish-properties
      ask fish
      [
        set color blue
        set size 0.3
        set shape "star"
        setxy random-xcor max-pycor
      ]
    end


    to go
     if (any? boats with [fuel <= 0 ])
      [ stop ]

      ask boats
      [
        follow-route1
        survey
      ]

      ask fish
      [
        check-if-boat
        move
      ]

      tick

    end


    to follow-route1
      ask boats
    [
        facexy 49 0
        fd 0.05
        pen-down
        set fuel fuel - 1
      ]
    end


    to survey
      ifelse any? fish-here                     ;; if boat on the same patch as a fish
      [ask fish-here [                          ;; ask the fish on this patch
        if shape = "star"[                      ;; with a "star" shape
          set shape "circle"                    ;; change shape to "circle" shape
       ask boats-here                           ;; ask boat on same patch to increase b-count
  [set b-count b-count + 1]]
      ]
      ]
                                                   ;; otherwise
        [ask fish-on neighbors [                   ;; ask fish on neighbouring 8 patches
          if shape = "circle"[                     ;; if the fish has a "circle" shape
            set shape "star" ]                     ;; change that shape to "star" shape
      ]]
    end


    to move
      ask fish
     [
        set heading 225
        fd 0.0025

      ]
    end

    to check-if-boat
      ifelse any? boats-here                     ;; if boats on same patch as the fish
      [
          ask fish-here with [color = blue]      ;; ask the blue fish to change to yellow
        [ set color yellow
          set f-count f-count + 1]               ;; and increase f-count by 1
      ]
      [ask fish-here with [color = yellow]       ;; otherwise ask yellow fish to go blue
          [set color blue
    ] ]

    end

对于您的具体示例,它们根本不在同一个补丁上。鱼 18 在 7 43,而船在 6 43。您可以使用 ask boat 0 [show patch-here] 快速查看。在第 184 个刻度,它们分别穿过 6 42 和 7 42,没有一个踩到同一个补丁。

我看到的另一个问题是有时鱼会改变颜色但不会改变形状。 这里的问题是事情发生的顺序。目前是: 船移动 => 船扫描 => 鱼移动 => 鱼扫描。 正因为如此,在船已经扫描过那块区域并确定那里没有鱼之后,一条鱼可以移动到那块区域上。或者一条鱼离开了一块区域,就再也看不到扫描它的那艘船了。 只需将其更改为船移动 => 鱼移动 => 船扫描 => 鱼扫描即可解决此问题。

目前还有一种边缘情况,即船和鱼可能同时远离彼此,导致船无法将鱼的形状设置回星形。