Esempio n. 1
0
def game_over(board):
    """
    1: num_pieces >=4
    2: num_pieces = 1 -> 1 wins
    """

    b_counter = 0
    w_counter = 0
    for i in range(64):
        if board[i] == "b" or board[i] == "B":
            b_counter += 1
        elif board[i] == "w" or [i] == "W":
            w_counter += 1

    state = State(board, Turn.WHITE, [])

    if w_counter == 0 or (b_counter > 3 and w_counter < 2) or len(state.get_states()) == 0:
        print("GAME OVER! You lost!")
        return True

    if b_counter == 0 or (w_counter > 3 and b_counter < 2):
        print("CONGRATS! You won!")
        return True

    return False
Esempio n. 2
0
def move_function(state: State):
    """
    Return best computer move
    """

    best_move = None
    val = -10000
    depth = 5
    for state in state.get_states():
        score = alpha_beta(state, depth, -10000, 10000, True)
        if score > val:
            val, best_move = score, state.move

    return best_move
Esempio n. 3
0
def validate_move(coordinates_input: str, board: list):
    # noinspection PyBroadException
    try:
        tokens = coordinates_input.split()
        src, dest = int(tokens[0]), int(tokens[1])
    except Exception:
        return None

    move = [src, dest]
    state = State(board, Turn.WHITE, [])
    legal_moves = [el.move for el in state.get_states()]
    print(f'Available moves: {legal_moves}')
    if move in legal_moves:
        return move
    else:
        return None