0

So after weeks of struggle, i'm happy to say i finally completed this pset last night. the WON function took me a while as i couldn't figure out how to account for the final tile as blank, but somehow came to the conclusion that using an OR statement gets me there. Even though the code works and passes the check, i questioned whether my if statement was flawless or not, i couldn't think of any situations where it would fail, but maybe another set of eyes could see something i do not? Will my WON function always work? thank you

    bool won(void)
{

int x = 1;
// go through each tile from 1 to d-1//

for (int i = 0; i < d; i++)
    {
       for (int j = 0; j < d; j++)
            {
                if(board[i][j] == x ||board[i][j] == 0 )
                    {
                    x++;
                    }

                else{
                    return false;}
            }


    }

return true;
}

 //end of game//
0

My first thought was the same, that it seemed flawed. But, after thinking it through, it should always work. If 0 is in the correct position, it works fine. If 0 appears anywhere else, the OR statement will pass even though the 0 is in the wrong position, BUT, the very next tile will have the wrong value, so the first part of the test,board[i][j] == x will fail. So, it will ultimately result in a correct result.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

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