Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Netlogo, can a list of boolean variables be converted from true/false to 1/0?

I am creating a list of boolean values that represent a set of patches with the following code, where "obstacle" is a boolean property of the patch that says whether or not it is an obstacle and "map-area" is a list of specific patches.

set cell-walls map [ p -> [ obstacle ] of p] map-area

Then I print cell-walls to a text file, and it will print [ true true false true ... ]. I need it to print [ 1 1 0 1 ... ] instead.

Maybe I can replace elements in the list, or create a new list by iterating over this one and adding a 1 or 0 for each element. I'm not sure how to accomplish this in Netlogo. Help is appreciated! :)

like image 408
moogie Avatar asked Oct 23 '25 17:10

moogie


1 Answers

If you only ever have true or false values, you could probably get away with something like:

to boolean-to-numeric
  let bool [ true false true ]
  let bool2 map [ i -> ifelse-value ( i = true ) [ 1 ] [ 0 ] ] bool 
  print bool2
end

But do note that the above will report 0 for any values other than true, not just for false.

like image 111
Luke C Avatar answered Oct 27 '25 01:10

Luke C