src/strategies/minimax.c
// Writes in a table NxN initialized with zeros all the paths from the position indicated.
Writes in a table NxN initialized with zeros all the paths from the position indicated.
Writes in a table NxN initialized with zeros all the paths from the position indicated .
int paths(struct strat_board *b, int t[N][N], char column, char line, int n, int p) {
    if ((b->players[(p + 1) % 2].c == column) && (b->players[(p + 1) % 2].l == line)) {
        t[line][column] = -1;
        if (is_passable(&b->board, column, line, 0)
            && ((t[line][column - 1] > n) || (t[line][column] == 0))) {
            t[line][column - 1] = n;
        }
        if (is_passable(&b->board, column, line, 1)
            && ((t[line - 1][column] > n) || (t[line][column] == 0))) {
            t[line - 1][column] = n;
        }
        if (is_passable(&b->board, column, line, 2)
            && ((t[line][column + 1] > n) || (t[line][column] == 0))) {
            t[line][column + 1] = n;
        }
        if (is_passable(&b->board, column, line, 3)
            && ((t[line + 1][column] > n) || (t[line][column] == 0))) {
            t[line + 1][column] = n;
        }
    } else if (t[line][column] && (t[line][column] < n)) {
        return 0;
    } else {
        t[line][column] = n;
    }
    return (   (is_passable(&b->board, column, line, 0)
                && paths(b, t, column - 1, line, n + 1, p))
            || (is_passable(&b->board, column, line, 1)
                && paths(b, t, column, line - 1, n + 1, p))
            || (is_passable(&b->board, column, line, 2)
                && paths(b, t, column + 1, line, n + 1, p))
            || (is_passable(&b->board, column, line, 3)
                && paths(b, t, column, line + 1, n + 1, p))
            );
}
int paths ( struct strat_board * b , int t [ N ] [ N ] , char column , char line , int n , int p ) { if ( ( b -> players [ ( p + 1 ) % 2 ] . c == column ) && ( b -> players [ ( p + 1 ) % 2 ] . l == line ) ) { t [ line ] [ column ] = -1 ; if ( is_passable ( & b -> board , column , line , 0 ) && ( ( t [ line ] [ column - 1 ] > n ) || ( t [ line ] [ column ] == 0 ) ) ) { t [ line ] [ column - 1 ] = n ; } if ( is_passable ( & b -> board , column , line , 1 ) && ( ( t [ line - 1 ] [ column ] > n ) || ( t [ line ] [ column ] == 0 ) ) ) { t [ line - 1 ] [ column ] = n ; } if ( is_passable ( & b -> board , column , line , 2 ) && ( ( t [ line ] [ column + 1 ] > n ) || ( t [ line ] [ column ] == 0 ) ) ) { t [ line ] [ column + 1 ] = n ; } if ( is_passable ( & b -> board , column , line , 3 ) && ( ( t [ line + 1 ] [ column ] > n ) || ( t [ line ] [ column ] == 0 ) ) ) { t [ line + 1 ] [ column ] = n ; } } else if ( t [ line ] [ column ] && ( t [ line ] [ column ] < n ) ) { return 0 ; } else { t [ line ] [ column ] = n ; } return ( ( is_passable ( & b -> board , column , line , 0 ) && paths ( b , t , column - 1 , line , n + 1 , p ) ) || ( is_passable ( & b -> board , column , line , 1 ) && paths ( b , t , column , line - 1 , n + 1 , p ) ) || ( is_passable ( & b -> board , column , line , 2 ) && paths ( b , t , column + 1 , line , n + 1 , p ) ) || ( is_passable ( & b -> board , column , line , 3 ) && paths ( b , t , column , line + 1 , n + 1 , p ) ) ) ; }
Writes in a table NxN initialized with zeros all the paths from the position indicated.
Writes in a table NxN initialized with zeros all the paths from the position indicated .