Hi please see code on this link: http://pastebin.com/wJy0PWZ7
Every move is illegal and I don't know why...
CS50 Stack Exchange is a question and answer site for students of Harvard University's CS50. It only takes a minute to sign up.Sign up to join this community
There are about 3 major issues in the code. First, the closing curly brace of the outer for loop is in the wrong place. It follows the actual swap code, so the earlier code that locates the blank and tile entries never executes more than the top row. Because of the placement of return statements, it never gets to the second row.
Second, in the code block that's commented as
// determine if tile move is out of bounds, there is a
return true; statement. Because this code block must execute a return, either true or false, no further code will ever execute.
Finally, when it actually performs the 'swap', it never sets the location of the tile is never reset to the blank. Having said that, the code here can be simplified. Since you know the values to be placed in board for both tile and blank, you could simply assign board[blankrow][blankcol]=tile and board[tilerow][tilecol]=0.
This should get you going. If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)