В этом примере настройки:
to setup
ca
crt 10 [
set color one-of [ blue green red yellow ]
]
print most-frequent-color turtles
reset-ticks
end
Вы можете использовать процедуру to-report
, чтобы сделать это - подробности в комментариях:
to-report most-frequent-color [ agentset_ ]
; get all colors of the agentset of interest
let all-colors [color] of agentset_
; get only the unique values
let colors-used remove-duplicates all-colors
; use map/filter to get frequencies of each color
let freqs map [ m -> length filter [ i -> i = m ] all-colors ] colors-used
; get the position of the most frequent color (ties broken randomly)
let max-freq-pos position ( max freqs ) freqs
; use that position as an index for the colors used
let max-color item max-freq-pos colors-used
report max-color
end