I have been able to successfully draw the board with the correct configuration, but when I try to implement move(), I cannot get the values of tile to swap with the blank space. As it currently stands, the program recognizes a legal vs illegal move. Help would be much appreciated!
Relevant code from move() is below.
bool move(int tile)
{
blankX = d - 1;
blankY = d - 1;
if (board[blankX][blankY - 1] == tile && j >= 0)//check tile to left
of blank and not out of bounds
{
//swap tiles
blankY = blankY + 1;
int temp = blankY;
blankY = tile;
tile = temp;
return true;
}
else if (board[blankX][blankY + 1] == tile && j < d) //check if tile is to the right of blank and not out of bounds
{
//swap tiles
blankY = blankY + 1;
int temp = blankY;
blankY = tile;
tile = temp;
return true;
}
else if (board[blankX + 1][blankY] == tile && i < d) //check if tile is below blank and not out of bounds
{
//swap tiles
blankX = blankX + 1;
int temp = blankX;
blankX = tile;
tile = temp;
return true;
}
else if (board[blankX - 1][blankY] == tile && i >= 0) //check if tile is above blank and not out of bounds
{
//swap tiles
blankX = blankX - 1;
int temp = blankX;
blankX = tile;
tile = temp;
return true;
}
else
{
return false;
}
return false;}