I want to run a set of scenarios in netlogo using behavior space where n number of competing turtles use different decision rules. What i mean by that is lets say i want to measure a metric in a coin-toss scenario where each player is programmed to call heads or tails at every tick i.e. in a 2 turtle situation player A always call heads and player B always calls tails.
When the number of turtles is more than 3 there will cases where ABC or ACB or BCD will call heads while the other calls tails. In essence HHTH is the same as HHHT.
So what i want to do in short is to filter only for the unique occurences, without considering the position of H or T in the sample space i.e. I want only those cases where there is only 1H and 3T, 2H & 2T, 3H & 1T.
Thanks in advance for the help. Regards.
Your question as asked does not seem to involve behavior space. To count the heads in a list use the table
extension. (The example you give is binary and has fixed length sequences, so the number of heads determines the number of tails, so you only need to count one of them.)
extensions [table]
to-report nHeads01 [#lst]
let _t table:counts #lst
report ifelse-value (table:has-key? _t "H") [
table:get _t "H" ;case sensitive ...
][
0
]
end
For example, we can generate some random sequences of length 4 (from your example) and filter for those with length 2 (or anything else).
to-report randomHT [#n]
report n-values #n [[?] -> one-of ["H" "T"]]
end
to test
let _xss n-values 20 [[?] -> randomHT 4] ;20 lists to filter
print filter [[?] -> (2 = nHeads01 ?)] _xss ;print those with 2 heads
end
If you are storing the sequences as strings, you can install the string extension and explode
the strings before using the above code, or you can follow NetLogo read in file as list of characters to convert strings to character lists. E.g.,
to-report nHeads02 [#str]
let _lst map [[?] -> item ? #str] n-values length #str [[?] -> ?]
report nHeads01 _lst
end