NetLogo:如何在特定条件下使用 "ifelse" 语法中的 "with" 语法进行构建?
NetLogo: How to build using the "with" syntax in the "ifelse" syntax with specific conditions?
如何为 "ifelse" 语句构建语法,该语句在指定的补丁中有一只海龟,并让海龟确定海龟的颜色是否为指定颜色?以下是示例代码,但它不起作用。顺便说一下,我想使用 "max-pxcor - 1".
来构建它
ifelse count turtles-on patch (max-pxcor - 1) with [color = red] = 1[ ;The following code is omitted
(1) 补丁 X Y 符号选择特定补丁,但您尚未提供 pycor
。因此,我假设您想要 pxcor
具有正确值的任何补丁。这些补丁中有多少是红色的? (2) 如果您没有选择带有其标识符的补丁程序,那么您正在使用补丁程序集而不是补丁程序,即使该集中只有一个补丁程序。如果需要从补丁集中获取补丁,则需要 one-of
.
如果您真的想识别该补丁以便对其进行处理,那么这种方法将补丁与海龟分开,因此具有合理的可读性:
let wanted-patch one-of patches with [pxcor = max-pxcor - 1 and color = red]
ifelse count turtles-on wanted-patch = 1
[
但你也可以这样做:
ifelse any? patches with [pxcor = max-pxcor - 1 and
color = red and
count turtles-here = 1]
[
如果你真的想要补丁集,那么右边所有红色补丁栏上的海龟总数为 1(所以一个补丁上有 1 个,其他补丁上有 0 个),那么:
ifelse count (turtles-on patches with [pxcor = max-pxcor - 1 and color = red]) = 1
[
对于最后一个,为了便于阅读,() 是可选的。
如何为 "ifelse" 语句构建语法,该语句在指定的补丁中有一只海龟,并让海龟确定海龟的颜色是否为指定颜色?以下是示例代码,但它不起作用。顺便说一下,我想使用 "max-pxcor - 1".
来构建它ifelse count turtles-on patch (max-pxcor - 1) with [color = red] = 1[ ;The following code is omitted
(1) 补丁 X Y 符号选择特定补丁,但您尚未提供 pycor
。因此,我假设您想要 pxcor
具有正确值的任何补丁。这些补丁中有多少是红色的? (2) 如果您没有选择带有其标识符的补丁程序,那么您正在使用补丁程序集而不是补丁程序,即使该集中只有一个补丁程序。如果需要从补丁集中获取补丁,则需要 one-of
.
如果您真的想识别该补丁以便对其进行处理,那么这种方法将补丁与海龟分开,因此具有合理的可读性:
let wanted-patch one-of patches with [pxcor = max-pxcor - 1 and color = red]
ifelse count turtles-on wanted-patch = 1
[
但你也可以这样做:
ifelse any? patches with [pxcor = max-pxcor - 1 and
color = red and
count turtles-here = 1]
[
如果你真的想要补丁集,那么右边所有红色补丁栏上的海龟总数为 1(所以一个补丁上有 1 个,其他补丁上有 0 个),那么:
ifelse count (turtles-on patches with [pxcor = max-pxcor - 1 and color = red]) = 1
[
对于最后一个,为了便于阅读,() 是可选的。