예제 #1
0
    def getSuccessors(self, currNode):

        successors = []

        currRow = currNode.getRow()
        currCol = currNode.getCol()

        # checking to the North
        if self.isValidRowCol(currRow - 1, currCol):
            if self.mazeRows[currRow - 1][currCol] == self.passableTile:
                successors.append(PathNode(currRow - 1, currCol, currNode))
        # checking to the East
        if self.isValidRowCol(currRow, currCol + 1):
            if self.mazeRows[currRow][currCol + 1] == self.passableTile:
                successors.append(PathNode(currRow, currCol + 1, currNode))
        # checking to the South
        if self.isValidRowCol(currRow + 1, currCol):
            if self.mazeRows[currRow + 1][currCol] == self.passableTile:
                successors.append(PathNode(currRow + 1, currCol, currNode))
        # checking to the West
        if self.isValidRowCol(currRow, currCol - 1):
            if self.mazeRows[currRow][currCol - 1] == self.passableTile:
                successors.append(PathNode(currRow, currCol - 1, currNode))

        return successors
예제 #2
0
 def read_paths(self, input_file):
     """ 
     Reads inputFile given at the command line and places the contents of 
     each line into the path field found in each PathNode object. The order 
     is the same as found in the text file. Adds the PathNode object to the 
     temp_path starting at temp_path[1].
     
     :param input_file: The file to read the data from.
     """
     try:
         with open(input_file) as file_to_read:
             for line in file_to_read:
                 self.temp_path.append(PathNode(line))
     except IOError:
         print(input_file, 'could not be found')
         exit(1)
예제 #3
0
파일: Tree.py 프로젝트: ngwidener/Tree351
    def populate_tree(self, index=0, new_parent=None):
        """
        Populates the tree
        :param index: the number i starting at 0 and incrementing with each node
        :param new_parent: A new node
        :return: the current_node in the tree
        """
        current_node = PathNode(self.path_list[index])
        if (index == 0):
            self.root = current_node

        if (index == len(self.path_list) - 1):
            self.last_node = current_node
        current_node.set_parent(new_parent)

        if (index * 2 + 1 < len(self.path_list)):
            current_node.set_left_child(
                self.populate_tree(index * 2 + 1, current_node))
        if (index * 2 + 2 < len(self.path_list)):
            current_node.set_right_child(
                self.populate_tree(index * 2 + 2, current_node))

        return current_node
예제 #4
0
    def populate_tree(self, index=1, new_parent=None):
        '''
        Creates a PathNode object for each Path in dfs_paths and sets their
        parent and child links.

        @param index: The index of the path in dfs_paths. Defaults to 1.
        @param new_parent: The PathNode that will be the parent of the node
                           created. Defaults to None.
        '''
        current_node = PathNode(self.dfs_paths[index])
        if (index == 1):
            self.root = current_node
        if (index == len(self.dfs_paths) - 1):
            self.last_node = current_node
        current_node.set_parent(new_parent)
        if (index*2 < len(self.dfs_paths)):
            current_node.set_left_child(self.populate_tree(index*2, current_node))
        if (index*2+1 < len(self.dfs_paths)):
            current_node.set_right_child(self.populate_tree(index*2+1, current_node))
        return current_node
예제 #5
0
파일: Tree.py 프로젝트: ngwidener/Tree351
    def populate_tree(self, index=0, new_parent=None):
        """
        Populates the tree
        :param index: the number i starting at 0 and incrementing with each node
        :param new_parent: A new node
        :return: the current_node in the tree
        """
        current_node = PathNode(self.path_list[index])
        if index == 0:
            self.root = current_node

        if index == len(self.path_list) - 1:
            self.last_node = current_node
        current_node.set_parent(new_parent)

        if index * 2 + 1 < len(self.path_list):
            current_node.set_left_child(self.populate_tree(index * 2 + 1, current_node))
        if index * 2 + 2 < len(self.path_list):
            current_node.set_right_child(self.populate_tree(index * 2 + 2, current_node))

        return current_node
예제 #6
0
from Maze import Maze
from PathNode import PathNode

assignmentPath = "/Users/stoudenmiersh/Documents/CofC_Classes/CSCI_280/Assignment5/"

filename = "MapData.txt"

maze = Maze(assignmentPath + filename)

maze.print()

startRow = eval(input("Enter start row: "))
startCol = eval(input("Enter start col: "))
goalRow = eval(input("Enter goal row: "))
goalCol = eval(input("Enter goal col: "))

startNode = PathNode(startRow, startCol)
goalNode = PathNode(goalRow, goalCol)

maze.findPath(startNode, goalNode)

path = maze.buildPath(goalNode)

print("Solution from path", startNode, "to", goalNode)

for node in path:

    print(node)

print("Path length is", len(path))