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

Fixed small errors in EightPuzzle class by SandersLin · Pull Request #987 · aimacode/aima-python · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 4 additions & 4 deletions search.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,8 @@ def astar_search(problem, h=None):
class EightPuzzle(Problem):

""" The problem of sliding tiles numbered from 1 to 8 on a 3x3 board,
where one of the squares is a blank. A state is represented as a 3x3 list,
where element at index i,j represents the tile number (0 if it's an empty square) """
where one of the squares is a blank. A state is represented as a tuple of length 9,
where element at index i represents the tile number at index i (0 if it's an empty square) """

def __init__(self, initial, goal=(1, 2, 3, 4, 5, 6, 7, 8, 0)):
""" Define goal state and initialize a problem """
Expand Down Expand Up @@ -472,8 +472,8 @@ def check_solvability(self, state):

inversion = 0
for i in range(len(state)):
for j in range(i, len(state)):
if state[i] > state[j] != 0:
for j in range(i+1, len(state)):
if (state[i] > state[j]) and state[i] != 0 and state[j]!= 0:
inversion += 1

return inversion % 2 == 0
Expand Down

Back | FazBrowse Home | New Git URL