Hello, I am making "game of life" implementation that, when cell has:
- two live neighbours I make object of class CCellB
- two live neighbours I make object of class CCellA
- when has >3 or <2 I make object of class CCellX (dead)
Class CCell
is base of CCellA
, CCellB
, CCellX
arr
is previous state of game, temp
will be new arr at the end.
My problem is:
That works fine, until I change new CCell();
to new CCellB();
:
CCell ***temp = allocateArray();
for(int i = 0; i < n; i++)
{
for(int j = 0; j < m; j++)
{
nAmount = arr[i][j]->countAliveNeighbor();
if(nAmount == 3)
{
temp[i][j] = new CCellA();
temp[i][j]->alive = 1;
}else if(nAmount == 2)
{
temp[i][j] = new CCell(); // HERE, WHEN I CHANGE IT TO CCELLB IT DON'T WORKS
temp[i][j]->alive = arr[i][j]->alive;
}else if((nAmount >= 4)||(nAmount < 2))
{
temp[i][j] = new CCellX();
}
}
}
Then it seems don't work properly... Seems like neighbours are not count properly, Cell with 4,5 neighbours still alive alive var is member of base class - CCell, all is public, please help!