Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Another Bug in search.py (iterating over an int !) #826

Closed
@goswami-rahul

Description

@goswami-rahul

the function find_blank_square() is iterating over an int.
In line 422. Here's the code:

def find_blank_square(self, state):
        """Return the index of the blank square in a given state"""
        for row in len(state):
            for column in len(row):
                if state[row][column] == 0:
                    index_blank_square = (row, column)
        return index_blank_square

len(state) and len(row) will always return an int.
I wonder how it passed the tests.

Edit: Found two more such cases!
in line 477

    def goal_test(self, state):
        """Given a state, return True if state is a goal state or False, otherwise"""
        for row in len(state):
            for column in len(row):
                if state[row][col] != self.goal[row][column]:
                    return False
        return True

and in line 496

    def h(self, state):
        """Return the heuristic value for a given state. Heuristic function used is 
        h(n) = number of misplaced tiles."""
        num_misplaced_tiles = 0
        for row in len(state):
            for column in len(row):
                if state[row][col] != self.goal[row][column]:
                    num_misplaced_tiles += 1
        return num_misplaced_tiles

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions