In the 'Won' function I tried to do two things: check if the array is in order and to cater to the blank space (underscore in my case)
I used the counter method to check if each cell corresponds to an increasing counter.
I divided my code into two parts:
One, checking if board[d - 1][d - 1] == '_'
. Here is my sub-code:
int counter = 1;
int underscore = d * d;
if (board[d - 1][d - 1] == '_')
{
// assigning the value d*d to the last cell
board[d - 1][d - 1] = underscore;
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (board[i][j] != counter)
{
counter++;
// reassigning the _
board[d - 1][d - 1] = '_';
return false;
}
}
}
}
In this above code my logic was to convert the value of dd cell to an integer value of dd so that my counter check can find a value equal to that of the value of counter at that cell.
Second, if board[d - 1][d - 1] != '_'
. Here is my sub-code:
else
{
for (int i = 0; i < d; i++)
{
for (int j = 0; j < d; j++)
{
if (board[i][j] != counter)
{
counter++;
return false;
}
}
}
}
Lastly, I end the code with the below return value just before closing the won function.
return true;
On executing the command ./fifteen 3 < ~cs50/pset3/3x3.txt
I got the following output
My program seems to be running well except the declaration of victory part. The return value seems to be always false.
Can you please suggest any modification of the logic/code to make this work?