Can anyone see the issue here? It moves "5" from the start position ok, but when it comes to "1" it is just two blank tiles in adjacent squares ("1" disappears). Obviously there is some issue with the "move" function here. Can you help me please?
bool move(int tile)
{
int t;
//int xrow; int xcol; int orow; int ocol;
for (int xrow = 0; xrow < d; xrow++)
{
for (int xcol = 0; xcol < d; xcol++)
{
if (board [xrow][xcol] == tile)
{
if (board [xrow - 1][xcol] == 0)
{
t = board [xrow][xcol];
board [xrow][xcol] = board [xrow - 1][xcol];
board [xrow - 1][xcol] = t;
return true;
}
else if (board [xrow + 1][xcol] == 0)
{
t = board [xrow][xcol];
board [xrow][xcol] = board [xrow + 1][xcol];
board [xrow + 1][xcol] = t;
return true;
}
else if (board [xrow][xcol - 1] == 0)
{
t = board [xrow][xcol];
board [xrow][xcol] = board [xrow][xcol - 1];
board [xrow][xcol - 1] = t;
return true;
}
else if (board [xrow][xcol + 1] == 0)
{
t = board [xrow][xcol];
board [xrow][xcol] = board [xrow][xcol + 1];
board [xrow][xcol + 1] = t;
return true;
}
else
{
return false;
}
}
}
}
return false;
}