Пример #1
0
def minimizer(state: dict, depth: int):
    if is_final(state) or depth == 0:
        return heur(state)

    value = inf

    for x in range(0, LINE_SIZE):
        if pos_is_playable(state, x, PLAYER_0):
            played = play(state, x, PLAYER_0)
            value = min(value, maximizer(played, depth - 1))

    return value
Пример #2
0
def minimax(state: dict, depth: int):
    to_play = -1
    value = -inf

    for x in range(0, LINE_SIZE):

        if pos_is_playable(state, x, PLAYER_1):
            played = play(state, x, PLAYER_1)
            game_value = minimizer(played, depth)
            if game_value > value:
                value = game_value
                to_play = x

    return to_play
Пример #3
0
def minimizer(state: dict, depth: int, alpha: float, beta: float):
    if is_final(state) or depth == 0:
        return heur(state)

    value = inf

    for x in range(0, LINE_SIZE):
        if pos_is_playable(state, x, PLAYER_0):
            played = play(state, x, PLAYER_0)
            value = min(value, maximizer(played, depth - 1, alpha, beta))

            if value <= alpha:
                return value

            beta = min(beta, value)

    return value