src/strategies/minimax.c
// Writes in the table successors all the board states that can occured after a move on the board b
// and returns the number of these successors.
Writes in the table successors all the board states that can occured after a move on the board b
and returns the number of these successors.
Writes in the table successors all the board states that can occured after a move on the board b and returns the number of these successors .
int find_successors(struct strat_board *b, struct strat_board **successors, int p) {
    int n = 0;
    int t[N][N];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            t[i][j] = 0;
        }
    }
    paths(b, t, b->players[p].c, b->players[p].l, 0, p);
    t[b->players[p].l][b->players[p].c] = -1;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (t[i][j] == 1) {
                (*successors)[n] = *b;
                move_pawn_strat(&(*successors)[n], j, i, p);
                n++;
                *successors = realloc(*successors, sizeof(struct strat_board) * (n + 1));
            }
        }
    }
    b->mark = board_value(b, p);
    if (((p == get_current_player(&b->board)) && (b->mark < 0))
        || ((p == (get_current_player(&b->board) + 1) % 2) && (b->mark > 0))) {
        if (remaining_bridges(&b->board, p) > 0) {
            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    if (is_blockable(&(b->board), j, i, 1)) {
                        (*successors)[n] = *b;
                        place_wall(&((*successors)[n].board), j, i, 1);
                        (*successors)[n].players[p].c = j;
                        (*successors)[n].players[p].l = i;
                        (*successors)[n].players[p].d = 1;
                        n++;
                        *successors = realloc(*successors, sizeof(struct strat_board) * (n + 1));
                    }
                    if (is_blockable(&(b->board), j, i, 0)) {
                        (*successors)[n] = *b;
                        place_wall(&((*successors)[n].board), j, i, 0);
                        (*successors)[n].players[p].c = j;
                        (*successors)[n].players[p].l = i;
                        (*successors)[n].players[p].d = 0;
                        n++;
                        *successors = realloc(*successors, sizeof(struct strat_board) * (n + 1));
                    }
                }
            }
        }
    }
    return n;
}
int find_successors ( struct strat_board * b , struct strat_board * * successors , int p ) { int n = 0 ; int t [ N ] [ N ] ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { t [ i ] [ j ] = 0 ; } } paths ( b , t , b -> players [ p ] . c , b -> players [ p ] . l , 0 , p ) ; t [ b -> players [ p ] . l ] [ b -> players [ p ] . c ] = -1 ; for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( t [ i ] [ j ] == 1 ) { ( * successors ) [ n ] = * b ; move_pawn_strat ( & ( * successors ) [ n ] , j , i , p ) ; n ++ ; * successors = realloc ( * successors , sizeof ( struct strat_board ) * ( n + 1 ) ) ; } } } b -> mark = board_value ( b , p ) ; if ( ( ( p == get_current_player ( & b -> board ) ) && ( b -> mark < 0 ) ) || ( ( p == ( get_current_player ( & b -> board ) + 1 ) % 2 ) && ( b -> mark > 0 ) ) ) { if ( remaining_bridges ( & b -> board , p ) > 0 ) { for ( int i = 0 ; i < N ; i ++ ) { for ( int j = 0 ; j < N ; j ++ ) { if ( is_blockable ( & ( b -> board ) , j , i , 1 ) ) { ( * successors ) [ n ] = * b ; place_wall ( & ( ( * successors ) [ n ] . board ) , j , i , 1 ) ; ( * successors ) [ n ] . players [ p ] . c = j ; ( * successors ) [ n ] . players [ p ] . l = i ; ( * successors ) [ n ] . players [ p ] . d = 1 ; n ++ ; * successors = realloc ( * successors , sizeof ( struct strat_board ) * ( n + 1 ) ) ; } if ( is_blockable ( & ( b -> board ) , j , i , 0 ) ) { ( * successors ) [ n ] = * b ; place_wall ( & ( ( * successors ) [ n ] . board ) , j , i , 0 ) ; ( * successors ) [ n ] . players [ p ] . c = j ; ( * successors ) [ n ] . players [ p ] . l = i ; ( * successors ) [ n ] . players [ p ] . d = 0 ; n ++ ; * successors = realloc ( * successors , sizeof ( struct strat_board ) * ( n + 1 ) ) ; } } } } } return n ; }
Writes in the table successors all the board states that can occured after a move on the board b
and returns the number of these successors.
Writes in the table successors all the board states that can occured after a move on the board b and returns the number of these successors .
// moves // bridges // vertical //horizontal