Can anyone explain to me what is asked from us in move function regarding pset3? I've finished init and draw, it compiles and prints on terminal exactly as it should. But I don't know what is my task on move function, I understand that we should swap underscore(0) and tile number that we are given, but what next? Any help would be much appreciated..

2 Answers 2


There's a comment above move:

 * If tile borders empty space, moves tile and returns true, else
 * returns false. 

So swap only if tile and 0 are next to each other, and return true after the swap, else return false.


To solve that function first I locate the tile in the 2D array now depending on what part of the board the tile is it will "look" for the empty space(0) next to it. Note that if a tile is lets say on the top left of the board(i=0, j=0)it can only be compared to the index to right of if or below it because there's no i=-1 or j=-1 also theres no i>=d or j>=d. So i anticipated tht different circumstances a tile could be in and compared to its possible adjacente tiles, if the zero is in fact next to it a simple swap of values, and return true. Hope this helps!

You must log in to answer this question.

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