0

The last output of some of the tests fail.

The first failure was: 3x3 move blank up twice.

My log.txt is identical to the log.txt of the staff solution and I do not have the word "file" in any of my added code.

The two log files are below:

My log.txt

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

EOF

Staff log.txt

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

EOF

In response to robert_x44 below is the cs50 output and after is the draw function. I did cut and paste but something seems to get lost between Windows 7 and Linux.

check50 art-pileggi
cs50/2017/x/fifteen
:) fifteen.c exists.
Log 
Checking that fifteen.c exists... 
:) fifteen.c compiles.
Log 
running sed -i='' '/#include <unistd.h>/a \ #define usleep(x)' fifteen.c... 
running clang -std=c11 -S -std=c99 -Wall -Werror -Wno-deprecated-declarations fifteen.c -o fifteen.S... 
checking that program exited with status 0... 
running sed -i='' -e 's/callq   _draw/callq _simple_draw/g' fifteen.S... 
running sed -i='' -e 's/callq   draw/callq  simple_draw/g' fifteen.S... 
running clang -std=c11 -std=c99 -Wall -Werror -Wno-deprecated-declarations -o fifteen simple_draw.c fifteen.S -lcs50 -lm... 
checking that program exited with status 0... 
:) 3x3 board: init initializes board correctly
Log 
running ./fifteen 3... 
checking for output "8-7-6|5-4-3|2-1-0 "... 
checking for output "Tile to move:"... 
:) 3x3 board: catches moving 8 an illegal move
Log 
running ./fifteen 3... 
sending input 8... 
checking for output "Illegal move."... 
checking for output "8-7-6|5-4-3|2-1-0 "... 
checking for output "Tile to move:"... 
:) 3x3 board: catches moving 1 as a legal move
Log 
running ./fifteen 3... 
sending input 1... 
checking for output "8-7-6|5-4-3|2-0-1 "... 
checking for output "Tile to move:"... 
:( 3x3 board: move blank up twice
did not find output "8-7-0|5-4-6|2-1..." 

Log 
running ./fifteen 3... 
sending input 3... 
checking for output "8-7-6|5-4-0|2-1-3 "... 
sending input 6... 
checking for output "8-7-0|5-4-6|2-1-3 "... 
:) 3x3 board: move blank left twice
Log 
running ./fifteen 3... 
sending input 1... 
checking for output "8-7-6|5-4-3|2-0-1 "... 
sending input 2... 
checking for output "8-7-6|5-4-3|0-2-1 "... 
:) 3x3 board: move blank left then right
Log 
running ./fifteen 3... 
sending input 1... 
checking for output "8-7-6|5-4-3|2-0-1 "... 
sending input 2... 
checking for output "8-7-6|5-4-3|2-1-0 "... 
:) 3x3 board: move blank up then down
Log 
running ./fifteen 3... 
sending input 3... 
checking for output "8-7-6|5-4-0|2-1-3 "... 
sending input 3... 
checking for output "8-7-6|5-4-3|2-1-0 "... 
:( 3x3 board: move up-up-left-down-down-left-up-up-right-down-down-right
did not find output "4-1-7|8-2-6|5-3..." 

Log 
running ./fifteen 3... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "4-1-7|8-2-6|5-3-0"... 
:( 3x3 board: make sure none of 2, 4, 5, 6, 7, 8 move tile
did not find output "Illegal move." 

Log 
running ./fifteen 3... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Illegal move."... 
checking for output "8-7-6|5-4-3|0-2-1 "... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Illegal move."... 
checking for output "8-7-6|5-4-3|0-2-1 "... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Illegal move."... 
:) 3x3 board: move blank left (tile 1) then up (tile 4), then try to move tiles 1, 2, 6, 8
Log 
running ./fifteen 3... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "8-7-6|5-0-3|2-4-1"... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Illegal move."... 
sending input 2... 
checking for output "Illegal move."... 
sending input 6... 
checking for output "Illegal move."... 
sending input 8... 
checking for output "8-7-6|5-0-3|2-4-1"... 
:( 3x3 board: make sure game is winnable
did not find output "1-2-3|4-5-6|7-8..." 

Log 
running ./fifteen 3... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "1-2-3|4-5-6|7-8-0 "... 
:( 4x4 board: make sure game is winnable
did not find output "1-2-3-4|5-6-7-8..." 

Log 
running ./fifteen 4... 
checking for output "15-14-13-12|11-10-9-8|7-6-5-4|3-2-1-0 "... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 10... 
checking for output "Tile to move:"... 
sending input 9... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 10... 
checking for output "Tile to move:"... 
sending input 9... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 13... 
checking for output "Tile to move:"... 
sending input 12... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 13... 
checking for output "Tile to move:"... 
sending input 12... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 13... 
checking for output "Tile to move:"... 
sending input 12... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 12... 
checking for output "Tile to move:"... 
sending input 9... 
checking for output "Tile to move:"... 
sending input 15... 
checking for output "Tile to move:"... 
sending input 1... 
checking for output "Tile to move:"... 
sending input 2... 
checking for output "Tile to move:"... 
sending input 3... 
checking for output "Tile to move:"... 
sending input 4... 
checking for output "Tile to move:"... 
sending input 12... 
checking for output "Tile to move:"... 
sending input 9... 
checking for output "Tile to move:"... 
sending input 13... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 9... 
checking for output "Tile to move:"... 
sending input 13... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 9... 
checking for output "Tile to move:"... 
sending input 13... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 15... 
checking for output "Tile to move:"... 
sending input 10... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 9... 
checking for output "Tile to move:"... 
sending input 13... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 9... 
checking for output "Tile to move:"... 
sending input 13... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 15... 
checking for output "Tile to move:"... 
sending input 10... 
checking for output "Tile to move:"... 
sending input 5... 
checking for output "Tile to move:"... 
sending input 9... 
checking for output "Tile to move:"... 
sending input 13... 
checking for output "Tile to move:"... 
sending input 15... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 12... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 12... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 15... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 10... 
checking for output "Tile to move:"... 
sending input 6... 
checking for output "Tile to move:"... 
sending input 7... 
checking for output "Tile to move:"... 
sending input 8... 
checking for output "Tile to move:"... 
sending input 12... 
checking for output "Tile to move:"... 
sending input 15... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 10... 
checking for output "Tile to move:"... 
sending input 15... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 12... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 15... 
checking for output "Tile to move:"... 
sending input 10... 
checking for output "Tile to move:"... 
sending input 14... 
checking for output "Tile to move:"... 
sending input 15... 
checking for output "Tile to move:"... 
sending input 11... 
checking for output "Tile to move:"... 
sending input 12... 
checking for output "1-2-3-4|5-6-7-8|9-10-11-12|13-14-15-0"... 

empty_x and empty_y are populated in draw.

/**
 * If tile borders empty space, moves tile and returns true, else
 * returns false.
 */

#define SWAP_SQUARES_RETURN board[empty_x][empty_y] = tile; \
                            board[tile_x][tile_y] = 0; \
                            return (true)
bool move(int tile) {
    int tile_x, tile_y;
    if ((tile < 1) // tile number too low
    || (tile >= d * d)) // tile number too high
        return (false); // return illegal move
    tile_x = empty_x;
    for (tile_y = 0; tile_y < d; tile_y++) {
        if (board[tile_x][tile_y] == tile) { // tile in empty's column
            if ((tile_y + 1 == empty_y) // empty in next square to tile in column
            || (tile_y - 1 == empty_y)) {
                SWAP_SQUARES_RETURN; // make move
            }
        else // tile in column but not next to empty square
            return (false);
        }
    }
    tile_y = empty_y;
    for (tile_x = 0; tile_x < d; tile_x ++) {
        if (board[tile_x][tile_y] == tile) { // tile in empty's row
            if ((tile_x + 1 == empty_x) // empty in next square to tile in row
            || (tile_x - 1 == empty_x)) {
                SWAP_SQUARES_RETURN;
            }
        else // time in row but not next to empty equare
            return (false);
        }
    }
}
6
  • 1
    I'm not sure there's enough information here to help you. It may help to paste the exact output from check50. Also, it may help to show all of the tests that failed (if it's not too many), as it may help narrow down the problem.
    – robert_x44
    Sep 13 '17 at 19:39
  • As request by 1: Sep 14 '17 at 2:41
  • ChrisG, If it was you that properly formatted my post then I thank you. Can you please tell me how you did it so next time I can do it properly. Sep 14 '17 at 12:56
  • @ChrisG If it was you that properly formatted my post then I thank you. Can you please tell me how you did it so next time I can do it properly. Sep 14 '17 at 13:09
  • @robert_x44 I have updated the post to contain the check50 output. The failures are all related to the final position of output of a test. Sep 14 '17 at 14:42
0

In your swap sequence, you forgot to update the empty tile's position before returning:

                            board[empty_x][empty_y] = tile; \
                            board[tile_x][tile_y] = 0; \
                            empty_x = tile_x; \
                            empty_y = tile_y; \
                            return (true)

Also, I'd like to see a final return false; at the end of move, which would be reached if blank tile and the tile to move shared neither row nor column. If I remember correctly, not returning from a function in C returns an undefined value (might be 0/false, or anything previously stored at that position in memory).

2
  • I was updating the empty location in "draw". I moved the empty init to "init", and moved the update where you indicated. It worked. Apparently the "draw " is not a reliable function to update the empty when running check50. Sep 14 '17 at 20:26
  • The draw function is not meant to change anything but print to the screen. The reason why you can do about anything in your draw (whatever you consider an appropriate representation of the board) is that it's not used for check50. It's replaced by a different implementation between some compile steps (the sed calls perform that on an intermediate representation of the compiled code).
    – Blauelf
    Sep 15 '17 at 13:23
0

I was initializing and updating the empty square location in "draw". I moved the empty init to "init". I moved the empty location update to "move". It appears that the "draw" function is an unreliable location to update the empty tile location.

1
  • The check50 program replaces your draw function with a generic draw so you can optionally change how the board is displayed (for example using ANSI escape sequences as linked in the hints). Their draw function lets them test the app no matter how you drew the board. The key is implementing the functions exactly as the specification (and comments in the fifteen.c file) state. As you found, move needs to update the empty tile, and init has to initialize it. This is all because they replace your draw function before testing - so your draw can't do anything but... draw.
    – robert_x44
    Sep 14 '17 at 22:16

You must log in to answer this question.

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