In Move(int dir):
for (d=2;d>-1;d--){
for (e=2;e>-1;e--){
if (puzzle[d][e]==0){
BposX=d;
BposY=e;
}
}
The other ones have their boundaries kept at 3 and 0, as changing these does not seem to fix any issues and in fact causes some new ones:
In setState():
for (a=3;a>0;a--){
for (b=3;b>0;b--){
puzzle[a][b]=c;
c++;
}
}
In printState():
for (g=3;g>0;g--){
for (w=3;w>0;w--){
if (puzzle[g][w]!=0){
Serial.print(puzzle[g][w]);
}
else{
Serial.print("b");
}
}
Serial.println();
}
Those are the only three places that access array bounds of any type.