我已经将我的海龟编码出去捕猎,但是当他们发现猎物他们只是吃它时,无论如何都要为他们成功的机会增加一个数学因素,而不是总是100%
基本上当他们找到猎物时,掷骰子,看看他们是否能吃掉它。
to search ;when wolf is hungry
set energy energy - 1
fd v-wolf
if random 600 = 1 ;; frequency of turn
[ ifelse random 2 = 0 ;; 50:50 chance of left or right
[ rt 15 ] ;; could add some variation to this with random-normal 45 5
[ lt 15 ]] ;; so that it samples from a dist with mean 45 SD 5
;; check if it can see a prey/food item
;; here i think we probably pick one of several possible prey
;; that are detectable randomly using the one-of command.
;; We should probably select the nearest one instead, but
;; i cant code that off the top of my head
if any? prey in-radius smell [set heading towards one-of prey in-radius smell]
if energy < 0 [die]
end
To eat ;to kill prey and eat it
let kill one-of prey-here in-radius smell
;move-to (need to code it so they move toward prey in a radius
;need to code in a variable for success too
if kill != nobody
[ask kill [ die ]
set energy energy + 10000]
end
答案 0 :(得分:3)
是的,你可以生成一个随机数,然后只有当该随机数符合某些条件时才执行kill命令。通常的方法是生成一个介于0和1之间的随机数(在NetLogo中为if random-float 1 < 0.4 [ <what happens> ]
)然后执行类似to eat
let kill one-of prey-here in-radius smell
if kill != nobody and random-float 1 < 0.4
[ ask kill [ die ]
set energy energy + 10000 ]
end
的操作,例如,如果您想要40%的概率。
回应评论:
$("#myModal").modal({
backdrop: false
});
请尝试了解这是做什么的,并先自己思考答案。如果你不理解任何命令的含义,或者任何命令序列的逻辑是什么,那么在你做之前不要继续。如果您在代码很简单的情况下不学习,那么您将永远无法解决您正在构建的模型中需要执行的更困难的事情。