Exemplo n.º 1
0
def find_path(startpoint, endpoint, ground, method='astar'):
	import AStar
	
	path = []
	if method=='astar':
		astar = AStarJS( ground )
		path = astar.findPath(startpoint,endpoint)
		"""
		astar = AStar.AStar(AStar.SQ_MapHandler(grid,len(ground[0]),len(ground)))
		start = AStar.SQ_Location(startpoint[0],startpoint[1])
		end = AStar.SQ_Location(endpoint[0],endpoint[1])
		# Find path
		p = astar.findPath(start,end)
		for n in p.nodes:
			path.append( [n.location.x, n.location.y] )
		"""
	return path
Exemplo n.º 2
0
            print __doc__
            sys.exit(0)
        if o in ("-p", "--p"):
            load_game()
            ground = load_ground(game)
            """
			grid = []
			for y,xs in ground.items():
				#l = []
				for x,v in xs.items():
					if v[0:4]=="wall":
						grid.append( 1 )
					else:
						grid.append( 0 )
			"""
            startpoint = [2, 2]
            endpoint = [5, 5]
            """
			astar = AStar.AStar(AStar.SQ_MapHandler(grid,len(ground[0]),len(ground)))
			start = AStar.SQ_Location(startpoint[0],startpoint[1])
			end = AStar.SQ_Location(endpoint[0],endpoint[1])
			"""
            start = self.startpoint
            end = self.endpoint
            astar = AStarJS(ground)
            p = astar.findPath(start, end)
            # for n in p.nodes:
            # 	print "x:%d y:%d" % (n.location.x, n.location.y)
            sys.exit(0)
    srv.run()
Exemplo n.º 3
0
            print __doc__
            sys.exit(0)
        if o in ("-p", "--p"):
            load_game()
            ground = load_ground(game)
            """
			grid = []
			for y,xs in ground.items():
				#l = []
				for x,v in xs.items():
					if v[0:4]=="wall":
						grid.append( 1 )
					else:
						grid.append( 0 )
			"""
            startpoint = [2, 2]
            endpoint = [5, 5]
            """
			astar = AStar.AStar(AStar.SQ_MapHandler(grid,len(ground[0]),len(ground)))
			start = AStar.SQ_Location(startpoint[0],startpoint[1])
			end = AStar.SQ_Location(endpoint[0],endpoint[1])
			"""
            start = self.startpoint
            end = self.endpoint
            astar = AStarJS(ground)
            p = astar.findPath(start, end)
            #for n in p.nodes:
            #	print "x:%d y:%d" % (n.location.x, n.location.y)
            sys.exit(0)
    srv.run()