(board, position, direction, invalid_values=None)
Determins if a move is in a valid direction
Determins if a move is in a valid direction
Determins if a move is in a valid direction
def is_valid_direction(board, position, direction, invalid_values=None):
    '''Determins if a move is in a valid direction'''
    row, col = position
    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)
def is_valid_direction ( board , position , direction , invalid_values = None ) : row , col = position 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 )