0
bool won(void)

{ int count = 0; for(int row=0;row < d;row++) { for(int column=0;column < d;column++)

    {
        count++;


            if(board [row][column] == count %(d * d) && count <= (d * d))
             {

                 return true;
             }










    }
}
 return false;

}

0

A possible pseudocode for win would be:

for row
    for column
        // in each movement, if the position of board [i] [j] coincides with  
        //  the expected value increases
        // the counter in 1 if some value differs from the expected we left won
        if board[i][j] == expected value
        count++
        else 
          return false

        // if at the end of the loop count matches the number of tiles, we are 
        //in the winning configuration  
       if count == d*d -1
       return true 

The trick is expected value, there is a simple arithmetic relationship between i, j and d that gives us such relationship for example in the winning configuration:

board[0][0] = 1
board[0][1] = 2

etc... I let you find this relationship

2
  • Thankyou very much for the suggestion but i am stiil confused....i have made some changes in my code...can u please take a look at it. – Indranee Saha May 16 '17 at 4:19
  • You can publish a new post with your code – MARS May 16 '17 at 19:52

You must log in to answer this question.

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