选择海龟中最普遍的两种颜色并列出它们

Selecting the two most widespread colors among turtles and list them

我卡在了一个简单的程序上。我有一个包含两种海龟品种的模型:公民和政府。我想请政府:1)计算并列出每种颜色,有多少公民有这种颜色? 2) 最常见的两种颜色是什么? 3)将颜色添加到列表中,4)查看邻居是否在列表中具有相同的两个项目。我需要前 3 点的帮助。

我试过以下记者

to-report frequency [i lst]
  report length filter [? = i] list
end

我试过这个代码

to top-ideas
  ask governments [
    let x citizens with [idcit = [idgov] of myself]  ;; this are the citizens of controlled by the government
    let xlist [5 15 25 35 45 55 65 85 95 125] ;; this is my list of possible colors
    foreach sort xlist [ ask ? [ 
        let y count x with [color = ?]]]]
  end

此代码不完整。您对如何进行有什么建议吗?

感谢您的帮助。

编辑:删除附加问题

使用 table 扩展程序可以更有效地完成计数,但这会让您入门:

breed [gvts gvt]
breed [cits cit]

gvts-own [most-common] ;get rid of id
cits-own [my-gvt]  ; use the gvt rather than an id

globals [all-colors]  ;avoid repeated list creation

to setup
  ca
  set all-colors [5 15 25 35 45 55 65 85 95 125]
  create-gvts 2
  create-cits 25 [
    set color one-of all-colors
    set my-gvt one-of gvts
  ]
end

to top-ideas
  ask gvts [
    let _mine cits with [my-gvt = myself]  ;no ids
    let _cts color-counts-desc _mine
    set most-common map first sublist _cts 0 2
  ]
end

to-report color-counts-desc [#agts]  ;most of the answer is HERE
  let _cs [color] of #agts
  let _cts map [list ? (freq ? _cs)] all-colors
  report sort-by [last ?1 >= last ?2] _cts
end

;;this is from the documentation for reduce
;; count the number of occurrences of an item in a list
to-report freq [#x #lst]
  report reduce
    [ifelse-value (?2 = #x) [?1 + 1] [?1]] (fput 0 #lst)
end