0 down vote favorite
I am doing CS50 course now. I am trying to finish program fifteen. I have no idea what is wrong with won part of code.
I guess the problem is with that part of code:
if (win[d-1][d-1] == d*d)
{
win[d-1][d-1] = 0;
return true;
}
I am trying to create a win matrix with proper configuration of numbers allowing to win the game and compare the win matrix with board matrix. If two arrays are the same, game is finished.
below I attach all code for won function:
/**
* Returns true if game is won (i.e., board is in winning configuration),
* else false.
*/
bool won(void)
int win[DIM_MAX][DIM_MAX];
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (win[d-1][d-1] == d*d)
{
win[d-1][d-1] = 0;
return true;
}
if (board[i][j] != win[i][j])
{
return false;
}
win[i][j] = d*i + j + 1;
}
}
return true;
I cannot figure out why function doesn't give value true for won function to quit the game.
Here is what console prints after using check50:
:( 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
https://sandbox.cs50.net/checks/82c365cf5e614352a8a745b6f246aa93