狩猎成功netlogo [英] Hunt success netlogo

查看:104
本文介绍了狩猎成功netlogo的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经编码好了海龟出门打猎,但是当他们发现猎物时,他们只是吃掉了,反而会为成功的机会增加一个数学因素,而不是总是100%

I have coded my turtles to go out and hunt, however when they find prey they simply eat it, is there anyway to add a mathematical factor for their chances of success instead of it always being 100%

基本上,当他们找到猎物时,掷骰子,看看是否可以食用.

essentially when they find prey, roll the dice and see if they can eat it.

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

推荐答案

是的,您可以生成一个随机数,然后仅在该随机数满足特定条件时执行kill命令.通常的方法是生成一个介于0和1之间的随机数(在NetLogo中为random-float 1),然后如果想要40%的概率,则执行类似if random-float 1 < 0.4 [ <what happens> ]的操作.

Yes, you can generate a random number and then only do the kill commands if that random number meets certain conditions. The usual way is to generate a random number between 0 and 1 (which is random-float 1 in NetLogo) and then do something like if random-float 1 < 0.4 [ <what happens> ] if you want 40% probability for example.

回应评论:

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

请尝试了解它的作用,并首先考虑自己的答案.如果您不了解任何命令的含义,或者任何命令序列的逻辑是什么,请不要继续操作.如果您在编写代码简单的过程中不学习,那么您将永远无法解决要构建的模型中需要做的更困难的事情.

Please make an attempt to understand what this is doing and think about the answer yourself first. If you don't understand what any command means, or what the logic is of any sequence of commands, do not move on until you do. If you don't learn while the code is easy, you will never be able to work out the more difficult things you need to do in the model you are building.

这篇关于狩猎成功netlogo的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆