# PSET3 'Illegal Move" coming up for legal moves as well! Almost done!

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;
}
``````

The initial position of blank tile is `board[d-1][d-1]`, not `board[d][d]`.

Other issues:

1. When checking tiles around the blank one, you go outside of the board borders, if the blank tile touches the border. For example, for the first move, the blank tile is at the right bottom corner. You check `board[blankrow+1][blankcolumn]` and `board[blankrow][blankcolumn+1]` that are outside the board.

2. You declare `int exchange`. What for?