Exemplo n.º 1
0
    def printOptimalPath(self):
        print "\n---------------------Optimal Path---------------------"
        x = 0
        y = 0
        currNode = self.world[y][x]
        while currNode.getDirection() != '*':
            print currNode
            if currNode.getDirection() == 'U':
                y += 1
            elif currNode.getDirection() == 'D':
                y -= 1
            elif currNode.getDirection() == 'L':
                x -= 1
            if currNode.getDirection() == 'R':
                x += 1
            currNode = self.world[y][x]

if __name__ == '__main__':
    wb = WorldBuilder()
    try:
        w = wb.readWorld(sys.argv[1])
    except:
        w = wb.readWorld("World1MDP.txt")
    try:
        epsilon = float(sys.argv[2])
    except:
        epsilon = 0.5
    ms = MarkovSolver(w, epsilon)
    ms.findPolicy()
Exemplo n.º 2
0
            score += 7
        elif world[curr[1]][curr[0]] == '1':
            score += 2
    return score

def readChoices():
    print "\n--------------------------------------------"
    print "1:   Solve world 1 with Manhattan heuristic."
    print "2:   Solve world 1 with custom heuristic."
    print "3:   Solve world 2 with Manhattan heuristic."
    print "4:   Solve world 2 with custom heuristic."
    print "q:   Quit"
    print "--------------------------------------------"

if __name__ == '__main__':
    wb = WorldBuilder()
    ms = MazeSolver()
    world1 = wb.readWorld(1)
    world2 = wb.readWorld(2)
    running = True
    while (running):
        readChoices()
        userInput = str(raw_input('> '))
        if userInput == 'q':
            running = False
        elif userInput == '1':
            ms.solveMaze((0, 0), (9, 7), world1, manhattanHeuristic)
        elif userInput == '2':
            ms.solveMaze((0, 0), (9, 7), world1, customHeuristic)
        elif userInput == '3':
            ms.solveMaze((0, 0), (9, 7), world2, manhattanHeuristic)