FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Another Bug in search.py (iterating over an `int` !) · Issue #826 · aimacode/aima-python · GitHub

Repository navigation

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

Description

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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


      Back | FazBrowse Home | New Git URL