Skip to main content
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

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 ...
Martin Kleiven's user avatar
2 votes

pset3 fifteen what am I doing wrong with my move function

Resolved! I was watching week 4s lecture and realised that my swap didn't make sense, I was expecting the program to switch two values at the same time. So I used a temp variable to store the value ...
Sofia's user avatar
  • 65
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
1 vote
Accepted

Move function do not working

In board[i-1][j]==0 && i>0, the i>0 is meant to be a guard, it would have to be performed before you access board[i-1][j]. && will evaluate its left side first, and if the result ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Game Of Fifteen Moving

You'd have to protect your code against non-existent coordinates. So instead of if (board[m -1][n] == 0) do if (m > 0 && board[m -1][n] == 0) because if m>0, then m-1 is still in ...
Blauelf's user avatar
  • 21k
1 vote

PSET3- Game of fifteen, function move();

This is a common problem. The code is going off the edge of the board. Look at the following: if (board[row][column+1] == blank){ Let's assume d=3 and column=2. What is at board[row][column+1]? ...
Cliff B's user avatar
  • 69.3k
1 vote
Accepted

PSET3 'Illegal Move" coming up for legal moves as well! Almost done!

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 ...
obesman's user avatar
  • 1,139
1 vote
Accepted

Fifteen - help please, I can't find the problem in my code for move and won

Thanks to @Cliff B for editing. It was impossible to read before. To @Genevie. Move(). if (board[i][j] == 0) { blank = board[i][j]; } What it is for? blank is already equals 0. This part of ...
obesman's user avatar
  • 1,139
1 vote

The tile doesnt swap or move when i use this code!

Why is this line, board[r][c]=t-1; in the move() function? It will reassign values to every tile on the board. It looks like a remnant of a cut and paste from init(). The code needs to find the ...
Cliff B's user avatar
  • 69.3k
1 vote
Accepted

"Expected Expression" Error on Move Function

These are all syntax errors. In the case of the first two, it's an incorrect initialization, more or less. I'll explain. in order to use the {...} technique, you have to do this at the same time as ...
Cliff B's user avatar
  • 69.3k
1 vote
Accepted

Game of Fifteen Not Swapping Tiles and Allowing Illegal Movies

In move () you are reading out of bounds. For example On a 3x3 board if j is 0 you will read j-1. This goes for the whole perimeter of the board. You need to account for these bounds. You also need ...
Ryan McCauley's user avatar
1 vote
Accepted

Pset3 (Game of Fifteen): The tiles won't swap... ("Illegal move")

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 (...
Blauelf's user avatar
  • 21k
1 vote
Accepted

Game of Fifteen - Move Function - getting wrong coordinates?

(new reply as I misread!) You would expect when tile==3, that x,y is 1,2 : 0,0 0,1 0,2 1,0 1,1 1,2 2,0 2,1 2,2 Remember, it's row,col so what you are seeing is correct. (Your init is doing the ...
curiouskiwi's user avatar
  • 18.7k
1 vote

cs50 pset3 move

It's the else ifs. Let's take a 3x3 board, first move, tile 1. It gets here if (tile == board[i][j]) when i = 2 and j = 1. if (i > 0) evaluates to true, so it goes into the code block. It doesn't ...
DinoCoderSaurus's user avatar
1 vote

Move function on pset3

There's a comment above move: /** * If tile borders empty space, moves tile and returns true, else * returns false. */ So swap only if tile and 0 are next to each other, and return true after ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

What is wrong with move function?

There are several problems. First, it allows for an invalid tile: if(tile > d*d If the tile is d*d, it's invalid. Second, it looks for the blank tile off the edge of the board with i+1, j-1, etc. ...
Cliff B's user avatar
  • 69.3k
1 vote
Accepted

pset3, move function !! Please Help?

You might want to get rid of the first set of nested loops: for(int i=0; i<d; i++) { for(int j=0; j<d; j++) { if(board[i][j] == 0) { blank = board[i][j]; ...
Ricardo David Antonetti's user avatar
1 vote
Accepted

My program returns false even when I input a correct value for tile

When you use the OR operator, it only takes one of the conditions to be true for the block to be executed. Since there is only one tile and four adjacent spaces, 3 of those conditions will always ...
Yuri Laguardia's user avatar
1 vote

pset3 move: won't move tiles in the same row

The move() code seems to be working fine. In looking at your output (the raw form, not the version that Stack reformatted before I edited it to show as output), it looks to me that maybe you have a ...
Cliff B's user avatar
  • 69.3k
1 vote

pset3 fifteen move creates double numbers

you are swapping values of tile and board[i][j] instead of board[i][j] and other adjacent square which contains tile.
Gaurav Jhamnani's user avatar

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