N*N augmented tic tac toe rewind problems (in C)

61 Views Asked by At

I had an assignment to do an N by N tic tac toe where you win by losing, and it has a rewind mechanism (goes back an odd number of turns.) I've tried implementing the rewind mechanism, by using a 2 by N squared matrix but it didn't work - it erases things "from the beginning" and notifies me of "core dumps". here's my revised code (fixed a different issue) - I would love a few tips on how to solve this issue.

int undo_most_recent(char board[N][N], int n, int log[N * N][2], int* p_of_m, int i)
{
    if ( (i % 2 == 0) && (*p_of_m + i <= 0))
    {
        print_error();
        return(Error);
    }
    while ((*p_of_m > 0) && (i < 0))
    {
        board[(log[*p_of_m][0])][(log[*p_of_m][1])] = '_';
        log[*p_of_m][0] = 0;
        log[*p_of_m][1] = 0;
        (*p_of_m)--;
        i++;
        printf(" p_of_m is: %d", *p_of_m);
    }
    print_board(board, n);
    return(Success);
}

Here's a link to the entire code - https://pastebin.com/qGHbWB56

0

There are 0 best solutions below