def _change_player(game_state: namedtuple) -> namedtuple:
    """
    This function changes the current player in the game state and returns it.
    :rtype : othello namedtuple
    :param game_state: othello namedtuple
    """
    #print('_change_player)')
    if game_state.current_player == BLACK:
        game_state = game_state._replace(current_player=WHITE)

    else:
        game_state = game_state._replace(current_player=BLACK)

    return game_state
Esempio n. 2
0
def _change_player(game_state: namedtuple) -> namedtuple:
    """
    This function changes the current player in the game state and returns it.
    :rtype : othello namedtuple
    :param game_state: othello namedtuple
    """
    #print('_change_player)')
    if game_state.current_player == BLACK:
        game_state = game_state._replace(current_player=WHITE)

    else:
        game_state = game_state._replace(current_player=BLACK)

    return game_state
Esempio n. 3
0
def move(row:int, column:int, game_state: namedtuple) -> namedtuple:
    """
    This function will perform the given move the for the current player
    :rtype : othello namedtuple
    :param row: int
    :param column: int
    :param game_state: othello namedtuple
    """
    #print('move {},{} = {}'.format(row, column, game_state.game_board[row - 1][column - 1]))
    if row > len(game_state.game_board) or row < 1:
        raise InvalidMove

    if column > len(game_state.game_board[0]) or column < 1:
        raise InvalidMove

    if not _check_move(row, column, game_state):
        raise InvalidMove

    for number in range(_find_north(row, column, game_state)):
        game_state.game_board[(row - 1) - (number + 1)][(column - 1)] = game_state.current_player

    for number in range(_find_south(row, column, game_state)):
        game_state.game_board[(row - 1) + (number + 1)][(column - 1)] = game_state.current_player

    for number in range(_find_west(row, column, game_state)):
        game_state.game_board[(row - 1)][(column - 1) - (number + 1)] = game_state.current_player

    for number in range(_find_east(row, column, game_state)):
        game_state.game_board[(row - 1)][(column - 1) + (number + 1)] = game_state.current_player

    for number in range(_find_northwest(row, column, game_state)):
        game_state.game_board[(row - 1) - (number + 1)][(column - 1) - (number + 1)] = game_state.current_player

    for number in range(_find_northeast(row, column, game_state)):
        game_state.game_board[(row - 1) - (number + 1)][(column - 1) + (number + 1)] = game_state.current_player

    for number in range(_find_southwest(row, column, game_state)):
        game_state.game_board[(row - 1) + (number + 1)][(column - 1) - (number + 1)] = game_state.current_player

    for number in range(_find_southeast(row, column, game_state)):
        game_state.game_board[(row - 1) + (number + 1)][(column - 1) + (number + 1)] = game_state.current_player

    game_state.game_board[row - 1][column - 1] = game_state.current_player

    game_state = count_disk(game_state)

    game_state = _change_player(game_state)

    if not _check_player(game_state):
        game_state = _change_player(game_state)

        if _check_win(game_state):
            game_state = game_state._replace(win_result=_find_winner(game_state))

            return game_state

    return game_state
Esempio n. 4
0
def set_variable(var: namedtuple) -> namedtuple:
    """Sets the variable from the user input

    Args:
        var (namedtuple): namedtuple("Variable", ["name", "string", "content"])

    Returns:
        namedtuple: namedtuple with input set correcly.
    """
    return var._replace(content=input(f"Set variable {var.name}: "))
Esempio n. 5
0
def search_variable(var: namedtuple, vars: List[namedtuple], i: int,
                    session: sessionmaker):
    while True:
        show_variable(None)
        print("Enter variable name:")
        inp = input()
        if inp == "exit":
            break
        db_var = session.query(Variable).filter(Variable.name == inp).first()
        if db_var:
            print()
            print(f"Set {var.name} to {db_var.content}")
            vars[i] = var._replace(content=db_var.content)
            break
        else:
            print()
            print("Variable name not found")
            print("Enter new name or enter exit to leave")
        print()
    return vars
Esempio n. 6
0
def count_disk(game_state: namedtuple) -> namedtuple:
    """
    This function counts the disks on the game board and updates the game state and returns it.
    :rtype : othello namedtuple
    :param game_state: othello namedtuple
    """
    #print('_count_disk')
    black_count = 0
    white_count = 0

    for row in game_state.game_board:
        for cell in row:
            if cell == BLACK:
                black_count += 1

            if cell == WHITE:
                white_count += 1

    game_state = game_state._replace(black_score=black_count)
    game_state = game_state._replace(white_score=white_count)

    return game_state
def count_disk(game_state: namedtuple) -> namedtuple:
    """
    This function counts the disks on the game board and updates the game state and returns it.
    :rtype : othello namedtuple
    :param game_state: othello namedtuple
    """
    #print('_count_disk')
    black_count = 0
    white_count = 0

    for row in game_state.game_board:
        for cell in row:
            if cell == BLACK:
                black_count += 1

            if cell == WHITE:
                white_count += 1

    game_state = game_state._replace(black_score=black_count)
    game_state = game_state._replace(white_score=white_count)

    return game_state
Esempio n. 8
0
def avg_profit(company: namedtuple) -> namedtuple:
    summ = company.quarter_profit_1 + company.quarter_profit_2 + company.quarter_profit_3 + company.quarter_profit_4
    company = company._replace(avg=summ / 10)
    return company