Exemplo n.º 1
0
    def test_get_updated_configuration(self):
        p = Puzzle(utils.board_from_file(file3))
        p_copy = copy.deepcopy(p)
        p2 = p.get_updated_configuration("up")
        p2_expected = Puzzle(utils.board_from_file(file4))

        self.assertEqual(p_copy, p)
        self.assertEqual(p2_expected, p2)
Exemplo n.º 2
0
from Puzzle import Puzzle
from PuzzleSolver import PuzzleSolver
import utils

file = "data/board2.txt"
p = Puzzle(utils.board_from_file(file))
logs = open("data/test.txt", "a")
solver = PuzzleSolver(p)
print(p)

y = input("Solve puzzle? (y/n): ")
if y == 'y' and p.is_solvable():
    solution = solver.a_star()
    for s in reversed(solution):
        logs.write(str(s))
        logs.write("\n\n")
    logs.write("Puzzle solved with " + str(len(solution)) + " steps.")
    logs.close()
    print("Puzzle solved.")
elif y != 'y':
    print("Solver quit.")
else:
    print("Puzzle is not solvable.")
Exemplo n.º 3
0
 def test_is_solvable_false(self):
     p = Puzzle(utils.board_from_file(file3))
     self.assertEqual(False, p.is_solvable())
Exemplo n.º 4
0
 def test_number_of_inversions(self):
     p = Puzzle(utils.board_from_file(file2))
     self.assertEqual(41, p.number_of_inversions())
Exemplo n.º 5
0
 def test_is_solvable2(self):
     p = Puzzle(utils.board_from_file(file2))
     self.assertEqual(True, p.is_solvable())