NoviceMan wrote on Apr 6th, 2009, 8:04am:if you could explain what you mean when you say seed my 256 array at the top with my rules.
well, you pretty much have it here:
Quote:Im trying to create a random rule with the array
int rule[] = new int[256];
and assign the elements of the rule to be 1 or 0. Im trying to make a random assignment that will set 10% of the values to 1 using the random() command.
which is simply a case of
int rule = new int[256]; // int is way too big, 1 bit will do
then you can either set 26 (ie 10% of 256) random items to 1
for (i = 0 ; i < 26 ; i++) {
rule[random(255)] = 1; // index might need to be an integer
}
or go through all the rules and set them randomly with 10% chance
for (i = 0 ; i < 256 ; i++) {
// 1 chance in 10
if (random(10) < 1) {
rule[i] = 1;
} else {
rule[i] = 0;
}
(might be an idea to have a set list of these initially - easier to debug than something that keeps changing randomly)
now for each iteration new[x][y] = rule[v]; where v is the value of the neighbours.
you don't need your n == 1 || n == 2... condition (which won't work anyway!)
um, there's no equivalent in this scheme for the
" Each cell with two or three neighbors survives.
For a space that is 'empty' or 'unpopulated'
Each cell with three neighbors becomes populated. "
rules - the new cell appears to depend solely on the value of its neighbours and its current state doesn't seem to matter.