如何简化 ifelse 参数 Netlogo

How to simplify ifelse argument Netlogo

我有这段代码,但我收到错误“预期命令”我知道这肯定是括号问题,但我已经看过但无法弄清楚它在哪里,即使 netlogo 正在显示它。

第二个 If else 是错误突出显示的那个,带有 distancia agua 的那个。我认为更新鲜、更敏锐的眼睛可以立即发现它。提前致谢。

ifelse ambiente_natural[move-to one-of patches with [not any? other turtles in-radius 6 and pcolor = 55 and pycor < 80]ask patches in-radius (1 + random 2) [if pcolor != blue [set pcolor 35]]ask patches with [pycor > 80] [set pcolor 68]]
    [
      move-to one-of patches with 
      [not any? other turtles in-radius 6 and pcolor = 55]
      [ifelse distancia_agua <= 15 
        [ask patches in-radius (2 + random 2) 
          [if pcolor != blue 
            [set pcolor 35]
        ]
        ]
      
        [ifelse distancia_agua > 15 and distancia_agua <= 35 
          [ask patches in-radius (1 + random 2) [if pcolor != blue 
            [set pcolor 35]
          ]
          ]
        
          [if distancia_agua > 35 and <= 60 
            [ask patches in-radius 1 [if pcolor != blue 
              [set pcolor 35]
    ]
    ]
    ]
    ]
    ]
    ]

为了便于调试,您可能会发现拥有非常一致的结构很有帮助 - 然后您可以 highlight all your code and hit "Tab" 到 auto-format 并希望确定问题区域。这是其中一个版本——我评论了 似乎 有问题的两个地方:

globals [ ambiente_natural distancia_agua ]

to test
  ifelse ambiente_natural 
  ; Ifelse 1-1
  [
    move-to one-of patches with [not any? other turtles in-radius 6 and pcolor = 55 and pycor < 80] 
    ask patches in-radius (1 + random 2) [ 
      if pcolor != blue [set pcolor 35] 
    ]
    ask patches with [pycor > 80] [
      set pcolor 68
    ]
  ]
  ; Ifelse 1-2
  [
    move-to one-of patches with [not any? other turtles in-radius 6 and pcolor = 55]
    ; There was an extra brace here
    ifelse distancia_agua <= 15 
    ; Ifelse 2-1
    [ 
      ask patches in-radius (2 + random 2) [ 
        if pcolor != blue [
          set pcolor 35
        ]
      ]
    ]
    ; Ifelse 2-2
    [ 
      ifelse distancia_agua > 15 and distancia_agua <= 35 
      ; Ifelse 3-1
      [
        ask patches in-radius (1 + random 2) [
          if pcolor != blue [
            set pcolor 35
          ]
        ]
      ]
      ; Ifelse 3-2
      [   
        if distancia_agua > 35 and distancia_agua <= 60 [ ; This wasmissing the second "distancia_agua"
          ask patches in-radius 1 [
            if pcolor != blue [
              set pcolor 35
            ]
          ]
        ]
      ]
    ]
  ]
end