Hi.
I am making a Game of Life using 8x8 LED matrices and I need some way to check for stagnation in my arrays.
Here are my arrays. I use one array to hold the current values for the matrix and then I update the second buffer and display it.
// Keep the current matrix setup.
unsigned char buffer[8] = { B00000000,
B00000000,
B00000000,
B00000000,
B00111000,
B00000000,
B00000000,
B00000000
};
// Keep the next life cycle.
unsigned char buffer2[8] = {B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000,
B00000000
};
It can happen that the computation of the generations will become a loop between 2 or more frames (lets have an upper bound of 3 for now).
For example the pattern that is in buffer now will loop between two frames. When this happens I want to be able to detect it so I can randomize the array and start over.
Currently I have a method that checks if the previous frame is the same as the one computed and that works fine for when the display comes to a complete stop. That is, when there is no change between a previous frame and the current but that is all I can manage.
Here is the code for my current method:
boolean isSame(){
for(int i = 0; i < 8; i++){
if(!(buffer[i] == buffer2[i])){
return false;
}
}
return true;
}
Does someone know of a nice way to detect repetition between the frames?
Thanks.