示例#1
0
 def test_unique_states_seen(self):
     astar = AStar(lambda x, y: 1, manhattan, Board(3, [1, 2, 3,
                                                        4, 5, 6,
                                                        7, 8, 0]), Board(3, [1, 2, 0,
                                                                             4, 5, 3,
                                                                             7, 8, 6]))
     self.assertEqual(19, astar.unique_states_seen())
示例#2
0
 def test_shortest_moves(self):
     astar = AStar(lambda x, y: 1, manhattan, Board(3, [1, 2, 3,
                                                        4, 5, 6,
                                                        7, 8, 0]), Board(3, [1, 2, 0,
                                                                             4, 5, 3,
                                                                             7, 8, 6]))
     self.assertEqual([Board.Move.UP, Board.Move.UP], astar.moves())
示例#3
0
 def solution(self):
     astar = AStar(lambda x, y: 1, lambda x, y: 1,
                   Board(self._n, self._root), Board.goal(self._n))
     moves_str = "".join(str(move) for move in astar.moves())
     return rapport_tiles(self._n, self._root) + \
            f"Solution: {len(astar.moves())}, " + moves_str + "\n" + \
            f"States seen: {astar.unique_states_seen()}\n"
示例#4
0
 def test_shortest_max_moves_needed(self):
     astar = AStar(lambda x, y: 1, manhattan, Board(3, [1, 2, 3,
                                                        4, 5, 6,
                                                        7, 8, 0]),
                   Board(3, [1, 2, 3,
                             4, 0, 8,
                             7, 6, 5]))
     self.assertEqual([Board.Move.UP,
                       Board.Move.LEFT,
                       Board.Move.DOWN,
                       Board.Move.RIGHT,
                       Board.Move.UP,
                       Board.Move.LEFT,
                       ],
                      astar.moves())
示例#5
0
 def test_init(self):
     self.assertIsNotNone(AStar(lambda x: 1, manhattan, Board(3, [1,2,3,4,5,6,7,8,0]),  Board(3, [1,2,3,4,5,6,7,8,0])))
示例#6
0
 def test_shortest_with_one_move_needed(self):
     astar = AStar(lambda x, y: 1, manhattan, Board(3, [1, 2, 3, 4, 5, 6, 7, 8, 0]), Board(3, [1, 2, 3, 4, 5, 6, 7, 0, 8]))
     self.assertEqual([Board.Move.LEFT],
                      astar.moves())