Skip to main content
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
  • 69.2k
2 votes

pset3 fifteen won

You are checking if everything is alright. And if the first part is alright you are returning true right away. This piece of code is exiting if the second box is correct without checking the rest of ...
Ricardo David Antonetti's user avatar
2 votes
Accepted

Problems with won function on pset3

You return true too early. You only check whether all the tiles are in the correct order, but you don't check the position of the empty tile. A quick fix would be to replace if (min == d*d) { ...
Blauelf's user avatar
  • 21k
1 vote
Accepted

fifteen won function timing out

I see a couple of issues, although I don't immediately see why it is "timing out". The code depends on two if statements that are NOT interdependent. Let's walk through the code to understand what ...
Cliff B's user avatar
  • 69.2k
1 vote

Won() function not working and gives error

Hmmm... where have I seen this before? Oh yeah..... http://cs50.stackexchange.com/questions/2448/how-to-solve-control-may-reach-end-of-non-void-function-error http://cs50.stackexchange.com/...
Cliff B's user avatar
  • 69.2k
1 vote

pset3 fifteen won kind of give up

There are more elegant implementations, but most notably: if(board[i][j] != n) { return false; n++; } The n++ is never performed. You probably meant ...
Blauelf's user avatar
  • 21k
1 vote

pset3 fifteen won

Basically, you code will always return true when 0 and 1 in the right positions, no matter where the other tiles are. Mistakes: You loop not from 0 to d - 1, but from 0 to d - 2 (i < d - 1). Thus,...
obesman's user avatar
  • 1,139
1 vote
Accepted

Pset3 Fifteen won function reorders correctly but finished with illegal move, what's wrong?

The following line has serious issues: if(board[i][j] != board[i][j-1] || board[i][j] != board[i+1][j-2]) If j == 0, then it's going to try to check board[i][-1], an invalid tile. This will ...
Cliff B's user avatar
  • 69.2k
1 vote
Accepted

pset3 check50 can't pass won for expected prompt input not exit code 0

Time for some tough love here. There are a lot of problems - almost every line of code. The error basically says that you're getting a premature false positive from win. Let's look at the if ...
Cliff B's user avatar
  • 69.2k
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
  • 69.2k
1 vote
Accepted

fifteen, won function does not seem to return if game one

You have a typo. Either that, or you made an error in your formula. if (board[i][j]!=1+j+d*j)
Cliff B's user avatar
  • 69.2k
1 vote

Won()- Pset 3- Game of Fifteen

A trick I like to use when debugging indexed ranges (for loops, for example) is to see what happens at the upper and lower bounds of the ranges. A lot of times, the code breaks down there.
ronga's user avatar
  • 1,415
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
Accepted

won function does not seem to return true (even though it should)

Why do you loop till j < d - 1 not j < d? For board 3*3, you miss board[0][2] so should return false for board[1][0]. However, I do not understand why you are stack in an infinite loop. You ...
obesman's user avatar
  • 1,139
1 vote

pset 3 won() function always return false

First, note that you change n only if something is wrong. Let's suppose that board [0][0] = 1 as it should be. Then, this condition else if (board[i][j] != n) { n = n+ (d*i)+j; ...
obesman's user avatar
  • 1,139
1 vote
Accepted

Pset3 Game of Fifteen Won Function

I suspect that a 4x4 can also generate false wins, given the right sequence of inputs. The problem is that the won() function, as written, can report a win when the tiles are in a certain order. If ...
Cliff B's user avatar
  • 69.2k
1 vote

Pset3 Game of Fifteen Won Function

A possible pseudocode for win would be: for row for column // in each movement, if the position of board [i] [j] coincides with // the expected value increases // the ...
MARS's user avatar
  • 5,179
1 vote
Accepted

won does not return exit code of 0

Well, the sandbox output says its working, but I'm thinking that it isn't the result of your program. Having said that, let's look at your won() code. In short, this code will always fail. It will ...
Cliff B's user avatar
  • 69.2k
1 vote
Accepted

game of fifteen won function (still!!) not working

You are definitely on the right track and are very close. Hmmm.... Let's look at the inside block of code: while(board[i][j] != board[d-1][d-1]) { if(board[...
Cliff B's user avatar
  • 69.2k
1 vote
Accepted

won returns illegal move when board reaches winning configuration

This won function won't work, imagine what would happen for i == d-1 and j == d-1 on a solved board. counter then would be d*d-1, and board[i][j]!=counter would be 0!=d*d-1, leading to the solved ...
Blauelf's user avatar
  • 21k

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