我的 ifelse 语句的结果取决于 true/false 的操作?

发布于 2024-09-03 14:54:11 字数 890 浏览 7 评论 0原文

目前,我正在为卡车构建一条在我的 netlogo 土地内行驶的路线。 当卡车靠近其应送货的商店区域时,卡车需要改变其动作。

但是,我的 ififelse 语句似乎响应不佳,答案取决于输出。通过一些测试:

*turtles> ifelse ((patch (first dirx) (first diry)) = one-of neighbors4) [write "11"] [write "22"]
 "11"*

*turtles> ifelse ((patch (first dirx) (first diry)) = one-of neighbors4) [write "111"] [write "122"]
"122"*

*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "111"] [write "122"]
 "122"*

*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "11"] [write "12"]
 "12"*

*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "11"] [write "22"]
 "11"*

请注意,在这段时间我没有移动我的卡车,我使用指挥中心来询问这些问题(从海龟卡车的角度)。

我对此很困惑。因为我唯一改变的是行动(写什么)。这不应影响真/假陈述本身。

有人知道这里发生了什么以及为什么 ifelse 的反应很奇怪吗?

Currently I am building a route for a truck to drive inside my netlogo-land.
When the truck is next to the shop-patch where it should deliver, the truck needs to change its actions.

However my if or ifelse statement does not seem to respond well and the answer depends on the output. With some tests:

*turtles> ifelse ((patch (first dirx) (first diry)) = one-of neighbors4) [write "11"] [write "22"]
 "11"*

*turtles> ifelse ((patch (first dirx) (first diry)) = one-of neighbors4) [write "111"] [write "122"]
"122"*

*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "111"] [write "122"]
 "122"*

*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "11"] [write "12"]
 "12"*

*turtles> ifelse (patch (first dirx) (first diry)) = one-of neighbors4 [write "11"] [write "22"]
 "11"*

Please note that during this time I do not move my truck, I use the command center to ask these questions (from turtle truck perspective).

I am very confused about this. As the only thing I change is the action (what to write). This should not impact the true/false statement itself.

Does anybody have any clue what is going on here and why the ifelse responds strange?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

纵性 2024-09-10 14:54:11

这是因为 one-of 随机选择其参数之一并返回该参数。

neighbors4 返回一个包含 4 个补丁的主体集(海龟补丁的 N、S、E 和 W)。因此,one-of Neighbors4 将从这 4 个邻居中随机选择,因此每次调用它时它可能会返回不同的值。

It's because the one-of randomly chooses one of its arguments and returns that one.

neighbors4 returns an agentset with 4 patches (the ones N,S,E, and W of the turtle's patch). Thus, one-of neighbors4 will randomly choose from among these 4, so it might return a different value each time you call it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文