def get_first_level_actions(gcb: Board) -> List[TetrisAction]: first_empty_p = Point(0, 0) while not first_empty_p.is_out_of_board(): if gcb.get_element_at(first_empty_p).get_char() == EMPTY: break first_empty_p = first_empty_p.shift_right(1) fig_point = gcb.get_current_figure_point() diff = fig_point.get_x() - first_empty_p.get_x() actions = [] if diff > 0: actions = [TetrisAction.LEFT] * diff if diff < 0: actions = [TetrisAction.RIGHT] * -diff actions.append(TetrisAction.DOWN) return actions
def board_to_list(gcb: Board) -> list: list_of_dot = [] for y in range(17, -1, -1): is_row_empty = True for x in range(0, 18): if gcb.get_element_at(Point(x, y)).get_char() != ".": list_of_dot.append((x, y)) is_row_empty = False if is_row_empty: break if (8, 0) in list_of_dot: list_of_dot.remove((8, 0)) if (8, 1) in list_of_dot: list_of_dot.remove((8, 1)) if (9, 0) in list_of_dot: list_of_dot.remove((9, 0)) if (9, 1) in list_of_dot: list_of_dot.remove((9, 1)) return list_of_dot