def expand(self, tile): for outcome in Mover.possible_moves(tile): if (outcome.layout == Tile().layout): return outcome.history if (self.original.layout != outcome.layout and (tile.history == [] or outcome.layout != tile.history[-1])): self.queue.insert(outcome, self.gofH(outcome) + len(tile.history))
def test_mover_returns_all_the_possible_next_moves(self): moveStates = [[[1, 0, 3], [8, 2, 4], [7, 6, 5]], [[1, 2, 3], [0, 8, 4], [7, 6, 5]], [[1, 2, 3], [8, 4, 0], [7, 6, 5]], [[1, 2, 3], [8, 6, 4], [7, 0, 5]]] results = [] for tile in Mover.possible_moves(Tile()): results.append(tile.layout) self.assertEqual(results, moveStates)
def test_mover_returns_all_the_possible_next_moves_for_edges(self): moveStates = [[[0, 2, 3], [1, 8, 4], [7, 6, 5]], [[1, 2, 3], [8, 0, 4], [7, 6, 5]], [[1, 2, 3], [7, 8, 4], [0, 6, 5]]] target = Tile() target = Mover.move_left(target) results = [] for tile in Mover.possible_moves(target): results.append(tile.layout) self.assertEqual(results, moveStates)