2

My fifteen.c passes the following local tests by getting to "ftw!" in each case:

~/workspace/pset3/fifteen/ $ ./fifteen 3 < ~cs50/pset3/3x3.txt
~/workspace/pset3/fifteen/ $ ./fifteen 4 < ~cs50/pset3/4x4.txt

However check50 gives me some sad face timeouts:

~/workspace/pset3/fifteen/ $ check50 cs50/2017/x/fifteen
Connecting.........
Authenticating.....
Preparing...........
Uploading...........
Running checks...........
:) fifteen.c exists.
:) fifteen.c compiles.
:) 3x3 board: init initializes board correctly
:) 3x3 board: catches moving 8 an illegal move
:) 3x3 board: catches moving 1 as a legal move
:( 3x3 board: move blank up twice
    timed out while waiting for "8-7-0|5-4-6|2-1..."
:) 3x3 board: move blank left twice
:) 3x3 board: move blank left then right
:) 3x3 board: move blank up then down
:( 3x3 board: move up-up-left-down-down-left-up-up-right-down-down-right
    timed out while waiting for "4-1-7|8-2-6|5-3..."
:( 3x3 board: make sure none of 2, 4, 5, 6, 7, 8 move tile
    timed out while waiting for "Illegal move."
:) 3x3 board: move blank left (tile 1) then up (tile 4), then try to move tiles 1, 2, 6, 8
:( 3x3 board: make sure game is winnable
    timed out while waiting for "1-2-3|4-5-6|7-8..."
:( 4x4 board: make sure game is winnable
    timed out while waiting for "1-2-3-4|5-6-7-8..."

See https://cs50.me/checks/8d1291e5a0afa904e53647818bf44925f063b373 for more detail.

But, when I attempt the sad faces manually, the log file looks good to me, eg:

:( 3x3 board: move blank up twice
timed out while waiting for "8-7-0|5-4-6|2-1..."

Here's the log file - it looks good to me:

8|7|6
5|4|3
2|1|0
3
8|7|6
5|4|0
2|1|3
6
8|7|0
5|4|6
2|1|3

... so I don't know why the computer is timing out when looking for "8-7-0|5-4-6|2-1..."

NB These timeouts are consistent. They are always in the same place no matter how many times I run check50. I have also tried reducing the usleep pauses to usleep(5000) - ie very small pauses, but it doesn't help.

I also tried editing the logging so the strings match exactly what the output says it's looking for, ie

"8-7-0|5-4-6|2-1-3 "

rather than

8|7|0
5|4|6
2|1|3

But still it didn't help - I get the same errors.

Any thoughts?

  • Have you run update50? Reopened terminal window? If yes, then probably you need to show your code as no clue for now. – obesman Aug 8 '17 at 17:01
1

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;
    blank_col = col;
}

However I found out that I could see how check50 works, for fifteen: https://github.com/cs50/check50/blob/pset3/checks/cs50/2017/x/fifteen/checks.py

And they do something cheeky... In that file are some lines:

# Replace student's draw with our own        
self.include("simple_draw.c")
self.spawn("clang -S {} fifteen.c -o fifteen.S".format(cflags)).exit(0)
self.replace_fn("draw", "simple_draw", "fifteen.S")
...

Wow! The check50 tool replaces the student's draw() function with its own! So my tracking of the blank tile (in my draw function) was removed when check50 was being run.

So to resolve this I declared blank_row and blank_col as global variables (ie above and outside of all the functions), and moved the tracking to two places, firstly the init() function:

int blank_row;
int blank_col;

void init()
{
// Keep track of the blank cell
blank_row = d - 1;
blank_col = d - 1;
...

And secondly adding tracking to the move() function, updating the blank_row and blank_col with the blank cell's new coordinates after swapping the blank cell with the input number.

Lesson? Check the check50 code on github, and don't assume anything!

| improve this answer | |
  • I'd like to add, if you declare blank_row, blank_col variables in the init() function, you can't update the new coordinates. I tried using declaring them as global variables, but that also didn't work. What I did was that I got rid of the tracking function altogether, and I was able to just swap the blank and number in the move() function itself. By the way, this problem stumped me. It was smart of you to check the code and I was lucky to have found your post by google just after you posted it! Thanks for the lesson, and thanks for helping me find the solution! :) – Code Aug 9 '17 at 7:09
  • Hi @Code I found declaring them as global variables worked (I've edited my answer). – Antony Aug 9 '17 at 7:30
  • NB I just heard that the checks are being moved to here: github.com/cs50/checks/tree/master/cs50/2017/x/fifteen/check50 – Antony Aug 9 '17 at 14:43
  • 1
    Thanks for this. Had exactly the same problem. Assumed it was something to do with the checking code but didn't know where – user1480135 Aug 22 '17 at 11:43
  • Great help. Same problem here, banging my head for a good time before finding this! Maybe CS50 staff should put a hint in the exercise description, no?? – Daniel da Rocha Dec 2 '17 at 9:13

You must log in to answer this question.

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