예제 #1
0
 def test_a_star(self):
     b = [[4, 1, 2], [0, 5, 3], [7, 8, 6]]
     p = hw.TilePuzzle(b)
     self.assertEqual(p.find_solution_a_star(), ['up', 'right', 'right', 'down', 'down'])
예제 #2
0
 def test_a_star2(self):
     b = [[1, 2, 3], [4, 0, 5], [6, 7, 8]]
     p = hw.TilePuzzle(b)
     self.assertEqual(list(p.find_solution_a_star()), ['right', 'down', 'left', 'left', 'up',
                                                       'right', 'down', 'right', 'up', 'left',
                                                       'left', 'down', 'right', 'right'])
예제 #3
0
 def test_iddfs(self):
     b = [[4, 1, 2], [0, 5, 3], [7, 8, 6]]
     p = hw.TilePuzzle(b)
     solutions = p.find_solutions_iddfs()
     self.assertEqual(next(solutions), ['up', 'right', 'right', 'down', 'down'])
예제 #4
0
 def test_iddfs2(self):
     b = [[1, 2, 3], [4, 0, 8], [7, 6, 5]]
     p = hw.TilePuzzle(b)
     self.assertEqual(list(p.find_solutions_iddfs()), [['down', 'right', 'up', 'left', 'down', 'right'],
                                                       ['right', 'down', 'left', 'up', 'right', 'down']])
예제 #5
0
 def test_get_board(self):
     p = hw.TilePuzzle([[1, 2], [3, 0]])
     self.assertEqual(p.get_board(), [[1, 2], [3, 0]])
예제 #6
0
 def test_successors2(self):
     b = [[1, 2, 3], [4, 0, 5], [6, 7, 8]]
     p = hw.TilePuzzle(b)
     for move, new_p in p.successors():
         print move, new_p.get_board()
예제 #7
0
 def test_is_solved2(self):
     p = hw.TilePuzzle([[0, 1], [3, 2]])
     self.assertEqual(p.is_solved(), False)
예제 #8
0
 def test_is_solved(self):
     p = hw.TilePuzzle([[1, 2], [3, 0]])
     self.assertEqual(p.is_solved(), True)
예제 #9
0
 def test_get_board2(self):
     p = hw.TilePuzzle([[0, 1], [3, 2]])
     self.assertEqual(p.get_board(), [[0, 1], [3, 2]])