Skip to main content
4 votes
Accepted

Fifteen move not working in last row only

A very common problem. Look at the following: else if (i < d && board[i + 1][j] == 0) This code attempts to swap with a tile that is off the edge of the board. If i = d-1, then what is ...
Cliff B's user avatar
  • 69k
3 votes
Accepted

PSET 3: Game of fifteen. Everything in the board is equal to zero

You only need to delete this and the code will work: int board[d][d]; The reason is that the global variable board is declared above and can be used by any function int board[DIM_MAX][DIM_MAX]; ...
obesman's user avatar
  • 1,139
3 votes

A wierd error in won function (fifteen)

the hint is in 1-2-3|4-5-6|0-7-8 ie 1 2 3 4 5 6 0 7 8 Your won function will say that's a winning position, which it isn't. That same sort of scenario doesn't occur during the 4x4 gameplay. To ...
curiouskiwi's user avatar
  • 18.7k
2 votes
Accepted

pset3 fifteen adjacent check not working

It fails because 3 out of 4 of your if conditions are wrong.
Cliff B's user avatar
  • 69k
2 votes
Accepted

pset3 fifteen - how to check if tile is adjacent to 0/"_"?

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 ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

Pset3 Fifteen: Draw and/or Init Function Problem

You cannot check if number is even with if (d/2 == 0) use % sign (remainder sign). Number is even if you divide the number with 2 and remainder becomes 0. for example if (d%2 == 0) { //...
Wafeeq's user avatar
  • 549
2 votes
Accepted

Pset3 Fifteen Check50 not Working

Wow, this is something I've never seen before. Congratulations! ;-) Your code is both right and wrong at the same time! :-D Yes, your code displays correctly and looks perfectly correct. It also ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

Am I going about Init() correctly?

It looks good (not a guarantee) right up until the end. What do you think will happen when you try to assign a string to an int? Instead, leave the 0 in place for the blank tile here, and use the ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

Error in dependency - pset3 fifteen

Assuming it does compile, the move function has a couple of serious flaws. First, given the math used, the tests should be comparing to d, not d-1. This error is preventing anything on the right side ...
Cliff B's user avatar
  • 69k
2 votes

Pset3/Fifteen/Init Function - Problem with 1 and 2 swap

Actually, the swap shouldn't be inside any for loop. You only want to do the swap once. Putting it inside any loop does it multiple times. Since the swap only depends on the value of d, and nothing ...
Cliff B's user avatar
  • 69k
2 votes

PSET3 Game of Fifteen move() Problem

To check if a tile is adjacent to the tile the user requested to move to with indices you simply use an if statement with the condition you wish to check for, which is then followed by something like ...
kluvin's user avatar
  • 1,223
2 votes
Accepted

PSET3 Game of Fifteen move() Problem

@M.Kleiven's tips are interesting, but I just looked at my solution, and I did not need to use pointers to check if a tile is outside the board. Here's what I did, in pseudo-code: // initialize board ...
hotwebmatter's user avatar
  • 3,050
2 votes

Fifteen: Error in a function I haven't touched yet

I couldn't find anything about this and I ended solving the problem a few minutes after posting the question: for some reason, the MakeFile file had been wiped out and was empty. I uploaded the ...
Ch. Katsidonis's user avatar
2 votes
Accepted

pset3: Help with Fifteen Move function

I think it's ok to search for both tile and empty tile, though you could maintain global variable(s) to store the position of the empty tile, some even keep track of the positions of all tiles, ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

Pset3 - Game of Fifteen - init function

You use local stack variable for the board, local variables will be deleted on leaving the function, should probably use a global variable. Local variables of same name shadow global ones (compiler ...
Blauelf's user avatar
  • 21k
2 votes
Accepted

Game of Fifteen pset3 - won() function works, but why?

Think about what happens in various scenarios. First, the first if test checks that 0 is in the last tile. If it isn't, the code returns false, so from there on, 0 must be in the last tile. Keep this ...
Cliff B's user avatar
  • 69k
2 votes
Accepted

Long numbers appearing when trying to retrieve element of 2D array - Game of Fifteen, pset3

Delete this: int board[d][d]; The reason is that board has already been declared globally int board[DIM_MAX][DIM_MAX] and filled with values by init(). Int board[d][d] declares new, local variable ...
obesman's user avatar
  • 1,139
2 votes
Accepted

Won()- Pset 3- Game of Fifteen

What happens at i == j == (d-1)? That's the last tile and it should equal 0, but your test will fail because of that. If that answers your question, please click on the check mark to accept. Let's ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

PSet 3 - Game of fifteen - draw tile gives weird output

The board[][] array is a global variable. In both functions, the code is creating a shadow array called board[][]. int board[DIM_MAX][DIM_MAX]; By redeclaring the board array in each function, it ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

problem while playing game of fifteen

There is a problem with your draw() function. Specifically in the code ` // prints blank tile if ( i == (dimen - 1) && j == (dimen - 1)) { printf("%2c",'_')...
dLopez's user avatar
  • 122
1 vote
Accepted

Pset3, move function doesn't compile

For your code to compile, move has to return a value in every case. Your code will currently only return something if the else statement executes. This is because the function is "non-void", or not ...
kluvin's user avatar
  • 1,223
1 vote
Accepted

CS50 Game of fifteen, Move Function, checking for legal move

Right idea to check limits of t and i, but the wrong choices for limits. For example, with if (board[i][t+1] == 0 && t < d ), t+1 must be less than d, not t. If d is 3 and t is 2, then t+1=...
Cliff B's user avatar
  • 69k
1 vote

Check50 initialising error pset3

check50 has a lot of dependencies in order to work. One of them is that the blank tile is stored as 0 in the board[][] array. Your code appears to change that to -1, which takes up an extra ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

Pset 3 : Game of fifteen. Help understanding the error message

Try generating a 3x3 board and make the same moves check50 did, you should be able to spot the error. If this answers your question please mark as answered.
thomas's user avatar
  • 167
1 vote
Accepted

Game of fifteen

Check50 depends on the log.txt file being processed correctly. The code for that was already created and correct in the distro file. That code depends on the board[][] array being populated by the ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

Pset3 draw function outputs zeroes or random numbers

Without seeing the entirety of the code, it's very difficult to know what's happening. Having said that, I am concerned about some things here. First, in the original code distribution, board was a ...
Cliff B's user avatar
  • 69k
1 vote
Accepted

pset 3 - can't get to move anything

This code is half-right. It does work, but it allows for diagonal swaps. You need to check for the condition where posx = blankx AND posy=blanky. If you are getting illegal move for valid moves, ...
Cliff B's user avatar
  • 69k
1 vote

Why does the variables passed on as arguments don't maintain their modified values?

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 ...
Wafeeq's user avatar
  • 549
1 vote
Accepted

pset3 - Game of Fifteen can move in basic directions, but not in combinations of moves

Right idea, wrong test. Look at the following: } else if (board[x][y-1] == 0 && y-1 <= d-1) { // left of tile ... } else if (board[x-1][y] == 0 &...
Cliff B's user avatar
  • 69k
1 vote
Accepted

expected an exit code of 0, not a prompt for input WON

HINT: What is the value of the lower right hand corner tile supposed to be when the game is won? What is your code looking for? If this answers your question, please click on the check mark to ...
Cliff B's user avatar
  • 69k

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