2

My code works when using the 3*3.txt as well as when I play it, but it is not accepted by check50. Here are my check50 errors:

:) fifteen.c exists
:) fifteen.c compiles
:( init initializes 3x3 board correctly
   \ expected "8" character 1 of line 1, not "0"
:( init initializes 4x4 board correctly
   \ expected file to be of length 38, not 36
:| 3x3 board, move blank up twice
   \ can't check until a frown turns upside down
:| 3x3 board, move blank left twice
   \ can't check until a frown turns upside down
:| 3x3 board, move blank left then right
   \ can't check until a frown turns upside down
:| 3x3 board, move blank up then down
   \ can't check until a frown turns upside down
:| 3x3 board, move up-up-left-down-down-left-up-up-right-down-down-right
   \ can't check until a frown turns upside down
:| 3x3 board, from start try to move tile 2, 4, 5, 6, 7, 8
   \ can't check until a frown turns upside down
:| 3x3 board, move blank left (tile 1) then up (tile 4), then try to move tiles 1, 2, 6, 8
   \ can't check until a frown turns upside down
:| 3x3 board, move blank up (tile 3), then try tile 2
   \ can't check until a frown turns upside down
:| 3x3.txt wins the 3x3 board
   \ can't check until a frown turns upside down
:| 4x4.txt wins the 4x4 board
   \ can't check until a frown turns upside down
https://sandbox.cs50.net/checks/69bb5ce34c824c44844eed970f85d74a

and here is my code:

http://pastebin.com/3k3JWFrw Thanks in advance.

2

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 appears to be working perfectly (although I didn't test thoroughly.)

The problem is an interaction between your code and the check50 code. The best explanation I can give is this. Your code displays the board[][] array from bottom to top and right to left, but check50 expects it to be used top to bottom and left to right. There's an assumption in the design of the pset that board[0][0] is the upper left corner, not the lower right.

Here's where you get in trouble. You initialize bottom to top AND you display it with draw() from bottom to top. In other words, say that d=3. The first row in the array, represented by board[0][x] is displayed at the bottom by your draw() and board[2][x] is displayed at the top. Unfortunately, check50 doesn't look at the actual output from draw(), it looks at the contents of the log.txt file, which is written out by main, top to bottom and left to right. check50 sees that the board has been initialized 0 to 8 instead of 8 to 0. Since this fails, the rest of the tests are not done.

So, while your code actually meets the spec as written, it won't pass. :-( I think you're going to have to rework it to conform to what was expected. Points for a new and original "problem" though!!!! ;-)

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance.

  • Wow. Thanks. Was a simple fix- had to swap the d-1 and 0 on my for loops, plus the >= to <= and it works fine now. – mmoore Jun 7 '16 at 21:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .