2

Simply put, if tile is in board[i][j], you need to check the positions directly above, below, and on either side for 0. In other words, board[i+1][j], board[i-1][j], board[i][j+1], board[i][j-1]. But since you're saying you are getting seg faults, I'm betting you already do this. There's another part to this. Along with checking these array elements, you ...


1

regarding move: if (board[j - 1][i] == 0) { // some code } else if (board[j + 1][i] == 0) { // some code } else if (board[j][i - 1] == 0) { // some code } else if (board[j][i + 1] == 0) { // some code } is it possible for j - 1, j + 1, i - 1, and/or i + 1 to be out of range? what would happen in that case? regarding init: If, ...


1

You have created an infinite loop through the improper use of the decrement operators. Look at the following: // switch numbers 2 and 1 board[j][i--] = 2; board[j--][i - 2] = 1; Both i and j control the inner and outer loops and are incremented on each pass of their respective loops. In these two operations, the code is ...


1

The fifteen.c file was distributed in the pset and was not supposed to be altered in any way. The only file that should be changed is helpers.c. Did you alter fifteen.c? Clearly, yes. That explains the error message. It isn't saying that your program executes and returns 1 or 0, it says that it didn't compile, so the compiler returned 1. The compile failed ...


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

Ok I figured this out. I was keeping track of my blank cell in the draw() function while replacing the '0' with a '_': if (board[row][col] == 0) { printf(" _ "); blank_row = row; blank_col = col; } However I found out that I could see how check50 works, for fifteen: https://github.com/cs50/check50/blob/pset3/checks/cs50/2017/x/fifteen/checks....


1

From the spec: Note that check50 assumes that your board’s blank space is implemented in board as 0; if you’ve chosen some other value, best to change to 0 for check50's sake.


1

First I would present you some basic concepts that you are lacking (seem like) about the concept of scope of variables in c. Later I will give you idea how you can solve your problem. A scope in any programming is a region of the program where a defined variable can have its existence and beyond that variable it cannot be accessed. There are three places ...


1

There are a few problems here. First, the test conditions all have a problem. Look at the first one, for example: if(tile == board[blankRow+1][blankCol] && tile != board[d+1][d]) As indexes for board[][], anything greater than d-1 is invlaid and will reference memory outside of the array or in another part of the array, depending on what the ...


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