I have finished with Pset3 except for a tiny little bug. every move is somehow an Illegal Move. here's my code.
bool move(int tile)
{
// TODO
// find location of specified tile using linear search
int blankrow = d;
int blankcolumn = d;
for (int i =0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
int counter =0;
if (tile == board[i][j])
{
// check if move is legal or illegal
// so it IS a legal move.
// now swap it and keep track of da blank
if ( tile == board[blankrow+1][blankcolumn] || tile == board[blankrow-1][blankcolumn] || tile == board[blankrow][blankcolumn+1] || tile == board[blankrow][blankcolumn -1])
{
int exchange;
exchange = tile;
board[i][j] = board[blankrow][blankcolumn];
board[blankrow][blankcolumn] = tile;
blankrow = i;
blankcolumn = j;
return true;
}
else {
return false;
}
}
else {
counter++;
}
}
}
return false;
}