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);
}
}
}
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.