1

After making a swap, remember to return true. return 0; is same as return false;, so your function never returns something else. Don't swap the tile_row and blank_row variables. Those have no meaning outside of move, so your board never changes state. Instead, change board[tile_row][tile_col] to 0 and board[blank_row][blank_col] to tile. Some room for ...


1

The initial position of blank tile is board[d-1][d-1], not board[d][d]. Other issues: When checking tiles around the blank one, you go outside of the board borders, if the blank tile touches the border. For example, for the first move, the blank tile is at the right bottom corner. You check board[blankrow+1][blankcolumn] and board[blankrow][blankcolumn+1] ...


1

You use 0-based indexing (the C standard) in some places (move, won), but 1-based indexing in others (init, draw). You use a strange variable blank. This variable is initially of undefined value (could even be read before receiving a defined value), and the only value that could ever be assigned to it is 0. You have an equally strange variable tile_move. ...


1

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 ...


1

I believe that your problem lies in how you are assigning tileloc. When you say tileloc = board[i][j], what you are really doing is taking whatever value is in that index of the array and assigning that to tileloc; that is to say, you are making tileloc equal to the value being searched for. I recommend creating two variables that represent the row and ...


1

The problem is indeed in won(). Because of all the changes you made to main, I replaced it with the original version (which doesn't need any changes) so that I could isolate the problems. The won() function has 3 problems. First, it checks the tiles by comparing to the value stored in count. Unfortunately, you initialized it at 0 when it should start at 1....


Only top voted, non community-wiki answers of a minimum length are eligible