def neighbors(self, node): """ Given a node, return a sequence of Arcs usable from this node. """ ACTIONS = tuple(('U', 'D', 'L', 'R')) lst = [] for action in ACTIONS: next_pos = next_position(node, action) if Board.legal_position(self.board, next_pos): lst.append(Arc(node, next_pos, 1, action)) return lst
def neighbors(self, node): """ Given a node, return a sequence of Arcs usable from this node. """ arcs = [] ACTIONS = tuple(('U', 'D', 'L', 'R')) for action in ACTIONS: next_pos = next_position(node, action) if Board.legal_position(self.board, next_pos): newArc = Arc(node, next_pos, cost=1, action=action) arcs.append(newArc) return arcs
""" from bloxorz_problem import BloxorzProblem from bloxorz import Board import searchGeneric import searchBFS import os import glob if __name__ == "__main__": #board_names = glob.glob("boards/*.blx") board_names = glob.glob("boards/carolina.blx") for board_name in board_names: print("Loading board file %s" % (board_name, )) with open(board_name) as file: board = Board.read_board(file) bp0 = BloxorzProblem(board) searcher = searchGeneric.AStarMultiPruneSearcher(bp0) result = searcher.search() if result is None: print("For board %s, found no solution!" % (board_name, )) continue sequence = [arc.action for arc in result.arcs()] print( "For board %s, found solution with length %d using %d expansions" % (board_name, len(sequence), searcher.num_expanded)) print() print()