I'm trying to code Conway's game of Life on a Raspberry Pi Pico using the Arduino IDE and C++.
When I try to pass the 2d array of individual cells into the function, the compiler returns an error message of "cannot convert Conway_Cell[64][32] into Conway_Cell(*)[32]. I can't find any information about why the function is doing this. I believe it's a pointer issue but am not sure. I haven't knowingly introduced pointers anywhere in the project.
I know that the code is inefficient and unoptimized, but I wanted to get it working before worrying about opimisation.
void GameOfLifeUpdate(Conway_Cell gridmain[col][row], Conway_Cell gridback[col][row], Adafruit_Protomatter matrix){
gridCurrent[col][row] = gridmain[col][row];
gridStorage[col][row] = gridback[col][row];
for (int i = 0; i < col; i++) {
for (int k = 0; k < row; k++){
int neighbours = 0;
while (neighbours < 5){
if(i-1 > 0 & k+1 < 64 ) {neighbours += gridCurrent[i-1][k+1].State;};
if(i-1 > 0) {neighbours += gridCurrent[i-1][k].State;};
if(i-1 > 0 & k-1 > 0) {neighbours += gridCurrent[i-1][k-1].State;};
if(k+1 < 64) {neighbours += gridCurrent[i][k+1].State;};
if(k-1 > 0) {neighbours += gridCurrent[i][k-1].State;};
if(i+1 < 64 & k-1 > 0) {neighbours += gridCurrent[i+1][k-1].State;};
if(i+1 < 64) {neighbours += gridCurrent[i+1][k].State;};
if(i+1 < 64 & k+1 < 64) {neighbours += gridCurrent[i+1][k+1].State;};
}
if(gridCurrent[i][k].State == true){
switch (neighbours){
case 0 && 1:
gridStorage[i][k].Die();
break;
case 2 && 3:
gridStorage[i][k].Live();
break;
case 4:
gridStorage[i][k].Die();
break;
default:
break;
}
}
else if (neighbours == 3){
gridStorage[i][k].Live();
}
}
}
gridCurrent[col][row] = gridStorage[col][row];
for (int i = 0; i < col; i++) {
for (int k = 0; k < row; k++){
if(gridCurrent[i][k].State == true){
matrix.drawPixel(i, k, matrix.color565(255, 255, 255));
}
else{
matrix.drawPixel(i, k, matrix.color565(169, 169, 169));
}
}
}
}
void loop() {
GameOfLifeUpdate(gridCurrent[col][row], gridStorage[col][row], matrix)
}
