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 ...
1
vote
Accepted
PSET3 fifteen - part of move is not working and 1 and 2 switch
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] == ...
1
vote
Accepted
What's wrong with my pset 3 fifteen.c code?e
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-...
1
vote
Accepted
pset3 fifteen.c not working with check50: "expected exit code 0, not 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 ...
1
vote
Accepted
PSET3: Every move is ilegal, no matter what
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 ...
1
vote
Accepted
pset3 fifteen.c passes local tests but fails check50 with timeouts
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;
...
1
vote
Accepted
pset3 fifteen check50 correct / not correct
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
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
fifteen.c × 17pset3 × 12
fifteen × 8
game-of-fifteen × 7
check50 × 2
move × 2
cs50x × 1
error × 1
pset × 1
won × 1
init × 1
compile-error × 1
syntax × 1
illegalmove × 1
expected-output × 1
notcompiling × 1
arguments × 1