Skip to content

Commit

Permalink
Update solver15.py
Browse files Browse the repository at this point in the history
  • Loading branch information
CAVIND46016 authored Dec 2, 2023
1 parent 5e3bffb commit 580f24d
Showing 1 changed file with 6 additions and 18 deletions.
24 changes: 6 additions & 18 deletions Artificial Intelligence/solver15/solver15.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
from copy import deepcopy

FINAL_CANONICAL_CONFIGURATION = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15, 0]
]
FINAL_CANONICAL_CONFIGURATION = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 0]]


class ShortSequenceSolver15:
Expand Down Expand Up @@ -35,11 +30,7 @@ def read_check_input_file(self, filename):

with open(filename, "r") as file_handle:
self.initial_state = [
[
int(j) for j in i
] for i in [
line.split() for line in file_handle
]
[int(j) for j in i] for i in [line.split() for line in file_handle]
]

self.is_solvable = self.is_puzzle_solvable(self.initial_state)
Expand Down Expand Up @@ -195,12 +186,7 @@ def solve(self):
"""

if self.is_solvable:
return self.solve_a_star(
self.initial_state,
self.explored_set,
self.moves,
g_cost=1
)
return self.solve_a_star(self.initial_state, self.explored_set, self.moves, g_cost=1)

def solve_a_star(self, state, explored_state, moves, g_cost):
"""
Expand Down Expand Up @@ -249,7 +235,9 @@ def __str__(self):
if self.is_solvable:
if self.moves:
output_str = ""
output_str += "\n".join(str(row) for row in [self.initial_state] + self.explored_set)
output_str += "\n".join(
str(row) for row in [self.initial_state] + self.explored_set
)
output_str += "\n\nSEQUENCE OF MOVES:\n" + " ".join(self.moves)
return output_str

Expand Down

0 comments on commit 580f24d

Please sign in to comment.