Hot answers tagged

11 votes
Accepted

pset3 / move function

The move() function basically does 3 main things: receives the number on the tile to be move. validates the move. if the move is valid, it makes it and returns true. Otherwise, it returns false. ...
  • 17.4k
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 ...
  • 64.7k
3 votes
Accepted

Game of Fifteen - Move function issue

You have two serious problems here. First, your move() function defines int blank = board[d][d]; The array element board[d][d] doesn't exist because both indexes run from 0 to d-1. Anything with d ...
  • 64.7k
3 votes
Accepted

move function, pset3

Well, I don't know how to tell you this, but I plugged your move function into my code and it worked perfectly. I suspect that you have a problem elsewhere in your code. Have you altered something in ...
  • 64.7k
2 votes

Global variables to store the position of the blank space?

Declare hori and verti as global variables and initialize them to d - 1 just after init().
  • 171
2 votes
Accepted

Ball moving problems

The ball gets stuck in the paddle when the paddle hits the side of the ball. I'm not particularly sure how exactly you tried to implement if the ball is moving down move the ball up but my ...
  • 17.4k
2 votes
Accepted

All my moves entered are shown illegal, though code doesn't seem wrong... (PS3 - fifteen)

The thing is: The program has declared a global variable d already. //board dimension int d; In your program, there's another declaration of d, in your a b c d initialisation. Thus, your for ...
  • 36
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 ...
  • 3,036
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 ...
  • 1,223
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, ...
  • 20.7k
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 ...
  • 65
1 vote
Accepted

Game of Fifteen Move Function Duplicates Tile

It looks to me that your code is swapping tiles off the edge of the board. The code doesn't check whether an array index is out of range. Look at the following: if(!moved && board[...
  • 64.7k
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 ...
  • 64.7k
1 vote
Accepted

Fifteen.C Move Function Fails One Check50 Test

Look at the following: if ( board[row - 1][column] == 0 && row - 1 > 0 ) Why does row-1 have to be greater than 0? 0 is still valid. If this answers your question, please click on the ...
  • 64.7k
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 ...
  • 1,223
1 vote
Accepted

pset3: fifteen - problem with "move" function

The problem is with your if statements. In certain cases, you are trying to access array values that don't exist. Let's say the value at board[0][0] is 5. Will your first if statement be true? if (...
  • 44
1 vote

move in pset3 fifteen not working properly

This code will only change a tile adjacent to the target tile to 0. It won't actually swap the tiles. Once the code above finds the target tile in the board[][] array, it will choose one of the 4 ...
  • 64.7k
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 &...
  • 64.7k
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 ...
  • 64.7k
1 vote

PSET 3 - Fifteen - Move Function Not Working - Brain melted and not sure how to proceed. Please help

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 ...
1 vote
Accepted

Pset 3 Fifteen Move

The code is accessing memory outside of the board array. Note that the array board[x][y] is based on d. Both indexes x and y run from 0 to d-1. In the code, i and j are initialized as equal to d, so ...
  • 64.7k
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) ...
  • 64.7k
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) { ...
  • 64.7k
1 vote
Accepted

Game of fifteen move function won't swap tiles

It looks like your problem is in your decision to put everything inside the same nested for loops. Your swap depends on setting blanktile_X and blanktile_Y, the location of the blank tile. If the ...
  • 64.7k
1 vote

All my moves entered are shown illegal, though code doesn't seem wrong... (PS3 - fifteen)

What do you mean by "gdb cannot run on function declaration"? Do you mean you don't know how to parse command line input to gdb? Try running your program like this with gdb: >gdb ./fifteen hi ...
1 vote

Cannot implement swap function for fifteen pset3

Without completely giving it away: Why are you assigning 42 to the variable 'tile'? You want to store 42 in the board array, right? Not in the tile variable, right? So, you should be assigning 42 to ...
  • 185
1 vote
Accepted

pset-3 move function

You are storing your tile numbers in the board array, right? So you need to change the values in the board array. When you write: hold = tile; tile = symbol; symbol = hold; Does this change any ...
  • 185
1 vote

How and where to write code to check around tile? Pset3, Game of Fifteen

underscore = board[i][j]; You're assigning the value that is stored in that board position to an integer called underscore. At this point, underscore equals zero. This is the same issue you struck ...
  • 18.4k
1 vote

pset 3 game of fifteen: need help swapping tiles

If board[][] is an array that stores the board's current configuration and board[tracki2][trackj2] contains the tile, and you need to swap it with board[tracki1][trackj1], then you can do it in this ...
  • 3,336
1 vote
Accepted

pset3 - 4x4.txt winning sequence not working - problem with move function?

I assume you used d * d to represent the blank tile. Probably you should define a constant to represent the blank tile and you should also store the row and the column of the blank tile in global ...
  • 17.4k

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