0
bool won(void)
{
    int counter = 1;
    for (int i = 0; i < d; i++)
    {
        for (int j = 0; j< d; j++)
        {
            while (board[i][j] != board[d-1][d-1] && counter != d*d-1)
            {
                if (board [i][j] == counter && counter < (d * d))
                {
                    counter++;
                }
            }
        }
    }
    return false;
}

I have tried placing a "return true;" statement in the above code in several places using different condition methods to no success. When I check with ./fifteen 3 < ~cs50/pset3/3x3.txt it either immediately returns true after the board is drawn, or the game finishes and returns false, or the game gets stuck immediately after drawing the board. Suggestions?

0

Follow the execution of the game, for example with gdb. Figure out when and where the game could be considered won. For one thing the return true; statement should go after won() has checked if every tile is in the correct place.

| improve this answer | |

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .