I managed to write a swap function before attempting "fifteen" , but within the context of writing the "move" function, I just can't get it to work, despite following the same format. When I swap, it replaces the blank tile, but the other tile remains the same. What is going wrong?!

(I currently have the blank tile as 42, so I can print it as a char and it comes out as a *)

enter image description here

  • There is another flaw in your code that will make it not work in some cases. Think of tiles on the edges of the board and the corners. What happens when you found your tile in the top left corner (ie, i=0 and j=0)? Now you check if(board[i-1][j])... caboom! SEGFAULT... cuz 0-1 = -1... well, maybe not SEGFAULT, but it won't work :) Just my 2 cents
    – Hedgehog
    Oct 28 '14 at 2:48
  • And isn't fifteen the part of pset3 for 2013? 2014 has breakout.
    – Jedi18
    Oct 23 '15 at 12:15

Without completely giving it away:

Why are you assigning 42 to the variable 'tile'? You want to store 42 in the board array, right? Not in the tile variable, right? So, you should be assigning 42 to the board[?][?].

BTW, you don't need the 'temp' variable at all. In the last 4 if() statements you are assigning 'tile' to 'temp' and then straight away 'temp' to board[...][...]. The 'tile' is already acting as a temp variable, so you can just assign it directly to the board[...][...] in those 4 statements.

So, now you just have to assign new value to board[i][j].

You must log in to answer this question.

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