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
  • 68.8k
3 votes
Accepted

Pset 3: Fifteen - Moving up and down but not left or right?

So, it was a subtle problem and an easy mistake to make. Look at the limits on your 4 conditions: > 0 and < d. >0 works because it allows for swapping to array elements with 0 as an index. ...
Cliff B's user avatar
  • 68.8k
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
  • 68.8k
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
  • 68.8k
2 votes
Accepted

Pset3: strange problem while testing init() function

When you declare an array, such as board, you want to use the actual size of the array, without subtracting 1.
Levi Roth's user avatar
  • 188
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
  • 68.8k
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

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
  • 68.8k
2 votes
Accepted

pset3 fifteen's draw function problem

I just tested your code and got it working with a couple minor tweaks. My advice is to go look back at your global variables. Something you have in both those functions has been declared earlier in ...
Peter's user avatar
  • 1,412
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
  • 68.8k
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
  • 68.8k
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
  • 20.9k
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
  • 20.9k
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
  • 68.8k
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
  • 68.8k
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
  • 68.8k
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
  • 68.8k
1 vote

Pset 3, Move, What am I doing wrong?

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 ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

Pset3, Fifteen. Why isn't my code printing a new line after each [i] increment?

It is printing the line feed after each tile. It should only print after each row. Maybe you have placed the printf(\n) in the wrong place? What in the code defines the end of the row? What step ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

problem in drawing the board of game of fifteen

The reason that your second loop never ends is that it is an infinite loop. The loop starts when j == 1, and continues as long as that is true. Since there's nothing inside the loop that modifies j, ...
Cliff B's user avatar
  • 68.8k
1 vote

pset3 Game of Fifteen check50

This problem usually occurs for one of two reasons. It looks like you've hit both. The check50 program looks at the log file generated in main(), not the actual screen output to check the program. (...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

Pset3 game of 15 move function

The code never tests 0,0. In the search for tile, the first array element that is checked is board[0][1], continuing through the rest of the array. That means that the if (board[row][column] == tile) ...
Cliff B's user avatar
  • 68.8k
1 vote
Accepted

move function doesn't move blank tile sideways

Your code is a slight variation of the same problem. Look at the following block from your code: else if(board[i+1][j] == 0 && board[i+1][j] < d) { ...
Cliff B's user avatar
  • 68.8k

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