won works for a 3x3, then it will work for a 4x4.
So that means your issue is probably in the
init function. When you play the game
./fifteen 4 do you see this at the beginning of log.txt:
15|14|13|12 11|10|9|8 7|6|5|4 3|1|2|0
in other words, did you remember to swap the 1 & 2 tiles in your init?