I think my code works fine in the terminal but this is what I get in check50:
:) fifteen.c exists :) fifteen.c compiles :) init initializes 3x3 board correctly :) init initializes 4x4 board correctly :) 3x3 board, move blank up twice :) 3x3 board, move blank left twice :) 3x3 board, move blank left then right :) 3x3 board, move blank up then down :) 3x3 board, move up-up-left-down-down-left-up-up-right-down-down-right :( 3x3 board, from start try to move tile 2, 4, 5, 6, 7, 8 \ expected prompt for input, not exit code of 0 :( 3x3 board, move blank left (tile 1) then up (tile 4), then try to move tiles 1, 2, 6, 8 :( 3x3 board, move blank up (tile 3), then try tile 2 \ expected file to be of length 58, not 40 :( 3x3.txt wins the 3x3 board \ expected an exit code of 0, not a prompt for input :( 4x4.txt wins the 4x4 board \ expected an exit code of 0, not a prompt for input
it seems the problem is with the move function so here is my move function :
bool move(int tile)
{
//tile row
int tiler ;
//tile column
int tilec ;
if( tile < 1 || tile > d*d -1 )
{
return false ;
}
for( int row = 0 ; row < d ; row++ )
{
for(int column = 0 ; column < d ; column++ )
{
if ( tile == board[row][column] )
{
tiler = row ;
tilec = column ;
break ;
}
}
}
// moving happens here
if (( tiler == blankr +1 || tiler == blankr -1 || tilec == blankc + 1 || tilec == blankc - 1) && (tilec == blankc || tiler == blankr ))
{
board[blankr][blankc] = tile ;
blankr = tiler ;
blankc = tilec ;
board[blankr][blankc] = 0 ;
return true ;
}
return false ;
}