This is my code for identifying the blank tile:
bool move(int tile)
{
int temp;
int didSwap;
int blankTile = 0;
// search for blank tile
for(int row = 0; row < d; row++)
{
for(int col = 0; col < d; col++)
{
if(board[row][col] == 0)
{
board[row][col] = blankTile;
}
}
}
// check that tile is not too big or too small
if(tile > d * d - 1 || tile < 1)
{
return false;
}
// Search if tile is adjacent to blank tile. If so, swap it.
for(int row = 0; row < d; row++)
{
didSwap = 0;
for(int col = 0; col < d; col++)
{
if(tile == blankTile[row+1][col] && tile != blankTile[d+1][d])
{
temp = blankTile;
blankTile = tile;
tile = temp;
didSwap = 1;
return true;
}
else if(tile == blankTile[row-1][col] && tile != blankTile[d-1][d])
{
temp = blankTile;
blankTile = tile;
tile = temp;
didSwap = 1;
return true;
}
else if(tile == blankTile[row][col+1] && tile != blankTile[d][d+1])
{
temp = blankTile;
blankTile = tile;
tile = temp;
didSwap = 1;
return true;
}
else if(tile == blankTile[row][col-1] && tile != blankTile[d][d+1])
{
temp = blankTile;
blankTile = tile;
tile = temp;
didSwap = 1;
return true;
}
else
{
return false;
}
}
}
}
My thinking is now that I have attributed the value of '0' which is my blank tile to variable, 'blankTile', that I will now be able to check if 'tile' is adjacent to it. If so, I will be able to swap the tiles.
Is that right?
For some reason, I am getting the error that ' error: subscripted value is not an array, pointer, or vector' every time I write: 'blankTile[row+1][col]' or similar.
Any ideas?
Thanks!