//---------------------------------------------------------------------------
bool stage1(pState state, int x, int y, pState *nbr, int nbrCount,
int feaMode)
// count live neighbours (called in onTick)
{
if (feaMode!=feaContinue) return true;
// store # live neighbours in state[1]
state[1] = 0;
for (int i=0; i<nbrCount; i++) state[1] += nbr[i][0];
return true;
}
//---------------------------------------------------------------------------
bool stage2(pState state, int x, int y, pState *nbr, int nbrCount,
int feaMode)
// update alive/dead state (called in onTick)
{
if (feaMode!=feaContinue) return true;
// Conway's game of Life
if (state[1] == 3) state[0] = 1;
else if (state[1] != 2) state[0] = 0;
// else no change (count==2)
return true;
}
//---------------------------------------------------------------------------
void __stdcall onTick(double &time)
{
forEachAgent(stage1); // count live neighbours
forEachAgent(stage2); // update alive/dead state
// next line not required
// time++;
}
//---------------------------------------------------------------------------