Reputation: 1
I'm currently working on adapting "The Game of Life" code in 3D for a final in my CS class for high school, and I'm looking for a keyword similar to "random-float" that will have the same effect in netlogo. For reference, here is the link to the netlogo manual for the "random-float" keyword: http://ccl.northwestern.edu/netlogo/docs/dict/random-float.html
if anyone could help me out, it would be very much appreciated.
Upvotes: 0
Views: 49
Reputation: 10301
I think you're okay to convert this more or less directly to 3D without using a different primitive- random-float
or random
should still do the trick. Essentially, in the 2D version the density is determined by getting each cell to randomly draw a number between 0 and 100, and compare that to the value in the initial-density
slider. If the number drawn is less than the initial-density
, the cell is "born." So, you can basically do the same thing in 3D- with this simplified setup:
to setup
ca
ask patches [
; if a random number between 0 and 100 is less than
; 5, become a "live" cell. Otherwise, become a dead cell.
ifelse random-float 100 < 5
[ cell-birth ]
[ cell-death ]
]
reset-ticks
end
to cell-birth
set pcolor green
end
to cell-death
set pcolor black
end
That gives something like:
So, to get the density to vary you can just modify the 5
(or add a slider as was done in the original 2D life. If I instead do 50:
to setup
ca
ask patches [
ifelse random-float 100 < 50
[ cell-birth ]
[ cell-death ]
]
reset-ticks
end
I get a much denser 3D world:
I hope that helps!
Upvotes: 2