Netlogo - 随机选择
我是编程新手,非常感谢您的帮助。 在此模型中,我想创建一家公司,如果满足特定条件,可以随机选择 btw 2 个选项。最好的方法是什么? 我尝试过这个,但它不起作用。
if profit < 0 [
set color red
let choice random 2 (
choice = 0 [ move-to min-one-of patches [costs]]
choice = 1 [ set price (price + 1) ])
]
感谢您的帮助!
I am new to programming and I would really appreciate the help.
In this model, I want to create a company that can randomly choose btw 2 choices if a certain condition is met. What would be the best way to do it?
I tried this but it is not working.
if profit < 0 [
set color red
let choice random 2 (
choice = 0 [ move-to min-one-of patches [costs]]
choice = 1 [ set price (price + 1) ])
]
Thanks for the help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您需要一个 IFELSE 语句。与
IF
类似,IFELSE
评估一个测试,一个应生成 TRUE 或 FALSE 的表达式。当测试结果为 TRUE 时,IF
运行代码块。 IFELSE 有两个代码块。第一个将在测试为 TRUE 时运行,第二个将在测试为 FALSE 时运行。如果您愿意,还可以使用两个 IF 语句。
两个 IF(顺序 IF)
IFELSE
请注意,这里我们只需要一个测试:(choice = 0),因为只有两个选项。如果 choice 不是 0,那么它一定是 1。
IFELSE(两个以上选项)
如果有两个以上选项,那么我们可以使用另一种形式的 ifelse,让我们可以使用多个测试。此表格必须完全包含在 ( 和 ) 中
Looks like you need an
IFELSE
statement. LikeIF
,IFELSE
evaluates a test, an expression that should produce either TRUE or FALSE.IF
runs the code block when the test produces TRUE. IFELSE has two code blocks. The first will run when the test is TRUE, the second will run when the test is FALSE.You could also use two IF statements, if you wanted to.
TWO IFs (Sequential IFs)
IFELSE
Note that here we only need one test: (choice = 0), because there are only two options. If choice is not 0, then it must be 1.
IFELSE (more than two options)
If there were more than two options, then we can use another form of ifelse that lets us use multiple tests. This form must be entirely wrapped in ( and )