比较两种不同海龟品种的属性

comparing attributes of 2 different turtles breed

我有2个海龟面包:

globals [ max-applicant ]
breed [ applicants applicant ]
breed [ investors investor ]

applicants-own [ ask-amount applied? industry country-of-origin funded? ]
investors-own [ allowed-industries-list allowed-countries-list no-of-applicants-funded ]

我想根据投资者是否被允许与申请人的行业和原籍国做生意来进行交易。投资者只能根据max-applicant价值

进行有限数量的交易

在下面的代码中,我尝试 select 一个未达到最大交易限额的投资者,然后 select 一个满足 select 条件的申请人]ed 投资者和基金申请人:

to close-deal
  let investorPerson one-of investors-here with [no-of-applicants-funded < max-applicant]
  if investorPerson != nobody  [
    ask investorPerson  [
      let applicantPerson one-of applicants-here with [
        industry member? [allowed-industries] and country-of-origin member? [allowed-countries] of myself
      ]
      if applicantPerson != nobody  [
        ask applicantPerson [
          set funded? TRUE
        ]
      ]
      set no-of-applicants-funded no-of-applicants-funded + 1
      
    ]
  ]
end

此代码没有 运行。这是设计此操作的正确方法吗?

好像有两个问题:

  1. 参见heremember?的语法:它是成员?值列表,而在您的代码中您有值成员?列表.
  2. 在您使用 member? 的两个布尔语句的第一个中,您省略了应该解决 [allowed-industries].
  3. of myself

结合以上两点,你应该有:

let applicantPerson one-of applicants-here with [
        (member? industry [allowed-industries] of myself) AND (member? country-of-origin [allowed-countries] of myself)
      ]

括号的使用和布尔运算符的大写是可选的,只是我自己的风格选择。

旁注:请注意,您要求 investorPerson

set no-of-applicants-funded no-of-applicants-funded + 1

如果确实存在 applicantPerson,则在执行的命令块之外;即即使 applicantPerson = NOBODY.

,您的投资者也会增加 no-of-applicants-funded