狩猎成功 netlogo
Hunt success netlogo
我已经为我的海龟编写了外出狩猎的代码,但是当它们发现猎物时,它们只是简单地吃掉它,无论如何要为它们的成功机会添加一个数学因素,而不是总是 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 和 1 之间的随机数(在 NetLogo 中是 random-float 1
),然后如果你想要 40% 的概率,则执行类似 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
请先尝试理解这是在做什么,然后自己思考答案。如果您不理解任何命令的含义,或者任何命令序列的逻辑是什么,请在理解之前不要继续。如果你在代码简单的时候不学习,你将永远无法解决你正在构建的模型中需要做的更困难的事情。
我已经为我的海龟编写了外出狩猎的代码,但是当它们发现猎物时,它们只是简单地吃掉它,无论如何要为它们的成功机会添加一个数学因素,而不是总是 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 和 1 之间的随机数(在 NetLogo 中是 random-float 1
),然后如果你想要 40% 的概率,则执行类似 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
请先尝试理解这是在做什么,然后自己思考答案。如果您不理解任何命令的含义,或者任何命令序列的逻辑是什么,请在理解之前不要继续。如果你在代码简单的时候不学习,你将永远无法解决你正在构建的模型中需要做的更困难的事情。