Check50 gives me this error:
:( 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
I'm assuming the problem is with my won function, please check it out and let me know which part you think is the problem
/**
* Returns true if game is won (i.e., board is in winning configuration),
* else false.
*/
bool won(void)
{
int counter = 1;
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (counter < d * d - 1)
counter++;
if (board[d - 1][d - 1] != 0)
return false;
if(board[i][j] > board[i + 1][j] && i + 1 < d)
return false;
}
}
return true;
}
This is my move function:
bool move(int tile)
{
// TODO
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (tile == board[i][j])
{
board[i][j] = tile;
{
if (board[i - 1][j] == 0 && i - 1 >= 0)
{
tile = board[i - 1][j];
board[i - 1][j] = board[i][j];
board[i][j] = tile;
return true;
}
if (board[i + 1][j] == 0 && i + 1 <= d - 1)
{
tile = board[i + 1][j];
board[i + 1][j] = board[i][j];
board[i][j] = tile;
return true;
}
if (board[i][j - 1] == 0 && j - 1 >= 0)
{
tile = board[i][j - 1];
board[i][j - 1] = board[i][j];
board[i][j] = tile;
return true;
}
else if (board[i][j + 1] == 0 && j + 1 <= d - 1)
{
tile = board[i][j + 1];
board[i][j + 1] = board[i][j];
board[i][j] = tile;
return true;
}
}
}
}
}
return false;
}
Many thanks