首页 > 解决方案 > `is-agent?` 和 `is-turtle?` 之间的区别

问题描述

is-agent?我相信这一定是一个简单的问题,但我还没有发现和原语之间的区别is-turtle?,以及何时应该使用一个而不是另一个。

标签: netlogo

解决方案


海龟、补丁和链接都是代理。因此,is-agent?将返回true其中任何一个。但是补丁和链接显然不是海龟,所以is-turtle?会返回false这些。

breed [ ghouls ghoul ]

to test
  clear-all
  create-turtles 1
  create-ghouls 1
  ask turtle 0 [ create-link-to turtle 1 ]

  show is-agent? turtle 0   ; true
  show is-agent? ghoul 1    ; true
  show is-agent? patch 0 0  ; true
  show is-agent? link 0 1   ; true

  show is-turtle? turtle 0  ; true
  show is-turtle? ghoul 1   ; true
  show is-turtle? patch 0 0 ; false
  show is-turtle? link 0 1  ; false

  show is-ghoul? turtle 0   ; false
  show is-ghoul? turtle 1   ; true
end    

因此,如果您试图将代理与数字、字符串和真/假值等内容区分开来,您可以使用is-agent?. 当你真的,肯定想和海龟打交道时,使用is-turtle?.


推荐阅读