def is_valid_position(board, position, direction, step):
    row, col = position
    invalid_values = [item.value for item \
                                        in [constants.Item.Rigid]]
    if utility.position_on_board(board, position) == False:
        return False

    if constants.Action(direction) == constants.Action.Stop:
        return True

    if constants.Action(direction) == constants.Action.Up:
        return row - step >= 0 and board[row - step][col] not in invalid_values

    if constants.Action(direction) == constants.Action.Down:
        return row + step < len(board) and board[
            row + step][col] not in invalid_values

    if constants.Action(direction) == constants.Action.Left:
        return col - step >= 0 and board[row][col - step] not in invalid_values

    if constants.Action(direction) == constants.Action.Right:
        return col + step < len(board[0]) and \
            board[row][col+step] not in invalid_values

    raise constants.InvalidAction("We did not receive a valid direction: ",
                                  direction)
Exemple #2
0
    def is_valid_direction(board, row, col, direction, invalid_values,
                           invalid_positions):
        '''Determins if a move is in a valid direction'''
        if constants.Action(direction) == constants.Action.Up:
            return row - 1 >= 0 and board[row -
                                          1][col] not in invalid_values and (
                                              row - 1,
                                              col) not in invalid_positions
        elif constants.Action(direction) == constants.Action.Down:
            return row + 1 < len(board) and board[
                row + 1][col] not in invalid_values and (
                    row + 1, col) not in invalid_positions
        elif constants.Action(direction) == constants.Action.Left:
            return col - 1 >= 0 and board[row][col -
                                               1] not in invalid_values and (
                                                   row, col -
                                                   1) not in invalid_positions
        elif constants.Action(direction) == constants.Action.Right:
            return col + 1 < len(
                board[0]) and board[row][col + 1] not in invalid_values and (
                    row, col + 1) not in invalid_positions
        elif constants.Action(direction) == constants.Action.Stop:
            return board[row][col] not in invalid_values and (
                row, col) not in invalid_positions

        raise constants.InvalidAction("We did not receive a valid direction: ",
                                      direction)
    def _is_valid_direction(board, row, col, direction, invalid_values=None):
        if invalid_values is None:
            invalid_values = [
                item.value
                for item in [constants.Item.Rigid, constants.Item.Wood]
            ]

        if constants.Action(direction) == constants.Action.Stop:
            return True

        if constants.Action(direction) == constants.Action.Up:
            return row - 1 >= 0 and board[row - 1][col] not in invalid_values

        if constants.Action(direction) == constants.Action.Down:
            return row + 1 < len(board) and board[row +
                                                  1][col] not in invalid_values

        if constants.Action(direction) == constants.Action.Left:
            return col - 1 >= 0 and board[row][col - 1] not in invalid_values

        if constants.Action(direction) == constants.Action.Right:
            return col + 1 < len(
                board[0]) and board[row][col + 1] not in invalid_values

        raise constants.InvalidAction("We did not receive a valid direction: ",
                                      direction)
Exemple #4
0
def get_next_position(position, direction):
    '''Returns the next position coordinates'''
    x, y = position
    if direction == constants.Action.Right:
        return (x, y + 1)
    elif direction == constants.Action.Left:
        return (x, y - 1)
    elif direction == constants.Action.Down:
        return (x + 1, y)
    elif direction == constants.Action.Up:
        return (x - 1, y)
    elif direction == constants.Action.Stop:
        return (x, y)
    elif direction == constants.Action.Bomb:
        return (x, y)
    raise constants.InvalidAction("We did not receive a valid direction.")
    def get_direction(position, next_position):
        if position == next_position:
            return constants.Action.Stop

        x, y = position
        next_x, next_y = next_position
        if x == next_x:
            if y < next_y:
                return constants.Action.Right
            else:
                return constants.Action.Left
        elif y == next_y:
            if x < next_x:
                return constants.Action.Down
            else:
                return constants.Action.Up
        raise constants.InvalidAction(
            "We did not receive a valid position transition.")