1

I was going to check my solution to pset3 fifteen with check50 while I received two failure errors on the console (on the last 3x3 and 4x4 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
:) 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
:) 3x3 board: make sure none of 2, 4, 5, 6, 7, 8 move tile
:) 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
    expected "Tile to move:", not "\x1b[2J\x1b[0;0..."
:( 4x4 board: make sure game is winnable
    timed out while waiting for program to exit

I really can't get the point of the failure. I double checked my solution and it seems to me that everything works fine.

This is the won() code I wrote (99 is the "_" character):

bool won(void)
{
    int count = 0;
    int prev = 0;
    int max_tile = (d * d) - 1;

    for(int i = 0; i < d; i++)
    {
        for(int j = 0; j < d; j++)
        {
            if(prev < board[i][j])
            {
                prev = board[i][j];
                count += 1;
            }
        }
    }

    if(count == max_tile -1 && board[d-1][d-1] == 99)
    {
        return true;
    }

    return false;

}

Can someone give me advice on how to fix these two errors? Thank you in advance!

1

Looks like it's just not finishing the game.

Let's say that d=3. That means that max_tile = (3*3) - 1 = 8. Then, the following test has to evaluate to true to register a win:

if(count == max_tile -1 && board[d-1][d-1] == 99)

It seems to me that if it's a win, then count would be 9. Then, the first test would fail because 9 does not equal 8-1.

Looks like the problem lies in the if statement. Seems like you could also get a false positive.

Just out of curiosity, what did you get when you manually tested the program???

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

| improve this answer | |

You must log in to answer this question.

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