Skip to content
Snippets Groups Projects
Commit afc238af authored by Jan Grewe's avatar Jan Grewe
Browse files

tweak stuck evolution detection

parent f9f1c2fd
No related branches found
No related tags found
No related merge requests found
......@@ -18,7 +18,7 @@ uint16_t gameEra = 0;
uint16_t currentTick;
uint16_t finalTicks;
uint16_t cellsAliveNow;
uint16_t cellsAliveBefore;
uint8_t cellsAliveBeforeList[9];
uint8_t noEvolutionTicks;
uint8_t noEvolutionTicksLimit = 100;
......@@ -31,7 +31,7 @@ void setupGame()
gameEra++;
currentTick = 0;
finalTicks = 0;
cellsAliveBefore = 0;
memset(cellsAliveBeforeList, 0, sizeof(cellsAliveBeforeList));
noEvolutionTicks = 0;
randomSeed(analogRead(34));
createRandomMatrix(currentGame);
......@@ -128,6 +128,25 @@ void addGlider()
createGlider(random(SCREEN_HEIGHT), random(SCREEN_WIDTH), currentGame);
}
bool isGameEvolving()
{
bool isEvolving = true;
if (
// check for 2-tick oscillators
cellsAliveNow == cellsAliveBeforeList[1] ||
// check for 3-tick oscillators
cellsAliveNow == cellsAliveBeforeList[2])
{
isEvolving = false;
}
memcpy(cellsAliveBeforeList + 1, cellsAliveBeforeList, sizeof(cellsAliveBeforeList) - sizeof(cellsAliveBeforeList[8]));
cellsAliveBeforeList[0] = cellsAliveNow;
return isEvolving;
}
void gameLoop()
{
if (runGame == false)
......@@ -151,19 +170,15 @@ void gameLoop()
else // not gameOver
{
if (cellsAliveNow >= cellsAliveBefore - 5 &&
cellsAliveNow <= cellsAliveBefore + 5)
if (isGameEvolving())
{
noEvolutionTicks++;
noEvolutionTicks = 0;
}
else
{
noEvolutionTicks = 0;
noEvolutionTicks++;
}
cellsAliveBefore = cellsAliveNow;
if (noEvolutionTicks > noEvolutionTicksLimit)
{
finalTicks = currentTick - noEvolutionTicksLimit;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment