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