当前位置: 首页>>代码示例>>Python>>正文


Python BZRC.get_obstacles方法代码示例

本文整理汇总了Python中bzrc.BZRC.get_obstacles方法的典型用法代码示例。如果您正苦于以下问题:Python BZRC.get_obstacles方法的具体用法?Python BZRC.get_obstacles怎么用?Python BZRC.get_obstacles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bzrc.BZRC的用法示例。


在下文中一共展示了BZRC.get_obstacles方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_obstacles [as 别名]
	def __init__(self):
		# Process CLI arguments.
		try:
			execname, host, port = sys.argv
		except ValueError:
			execname = sys.argv[0]
			print >>sys.stderr, '%s: incorrect number of arguments' % execname
			print >>sys.stderr, 'usage: %s hostname port' % sys.argv[0]
			sys.exit(-1)

		# Connect.
		#bzrc = BZRC(host, int(port), debug=True)
		__bzrc__ = BZRC(host, int(port))
		
		realobs = __bzrc__.get_obstacles()
		enemies = __bzrc__.get_othertanks()
		bases = __bzrc__.get_bases()
		flags = __bzrc__.get_flags()

		AGENT = Agent(__bzrc__)
		
		
		plotter = Plot()
		
		plotter.plotToFile(realobs)
		
		plotter.appendToFile(flags, enemies)
		
		self.obstacles = __bzrc__.get_obstacles()
		self.mytanks = __bzrc__.get_mytanks()
		self.othertanks = __bzrc__.get_othertanks()
		self.flags = __bzrc__.get_flags()
		self.bases = __bzrc__.get_bases()
		self.enemycolors = []
		for tank in othertanks:
			if tank.color not in self.enemycolors:
				self.enemycolors.append(tank.color)
		
		vector = self.get_vector(0, 0)
		
		#s = raw_input(tanks)
		
		#plotter.plotToFile(plotter.draw_points(flags, "flags"))
		
		plotter.animate(realobs)
开发者ID:itcropper,项目名称:tanks,代码行数:47,代码来源:potentialFields.py

示例2: main

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_obstacles [as 别名]
def main():
    # Process CLI arguments.
    try:
        execname, host, port = sys.argv
    except ValueError:
        execname = sys.argv[0]
        print >>sys.stderr, '%s: incorrect number of arguments' % execname
        print >>sys.stderr, 'usage: %s hostname port' % sys.argv[0]
        sys.exit(-1)

    # Connect.
    # bzrc = BZRC(host, int(port), debug=True)
    bzrc = BZRC(host, int(port))

    path_finder = PathFinder(bzrc, 0)
    remove_old_plot_files()

    ### Depth First Search Visualizations ###
    path = path_finder.get_depth_first_search_path()
    plot_single(path, bzrc.get_obstacles(), '../plots/dfs_plots/dfs.png')

    snapshots = path_finder.search_snapshots
    plot_snapshots(snapshots, "../plots/dfs_plots/dfs", bzrc.get_obstacles())

    ### Breadth First Search Visualizations ###
    path = path_finder.get_breadth_first_search_path()
    plot_single(path, bzrc.get_obstacles(), '../plots/bfs_plots/bfs.png')

    snapshots = path_finder.search_snapshots
    plot_snapshots(snapshots, "../plots/bfs_plots/bfs", bzrc.get_obstacles())

    ### A* Visualizations ###
    path = path_finder.get_a_star_path()
    plot_single(path, bzrc.get_obstacles(), '../plots/a_star_plots/a_star.png')

    snapshots = path_finder.search_snapshots
    plot_snapshots(snapshots, "../plots/a_star_plots/a_star", bzrc.get_obstacles())


    print("finished")
    bzrc.close()
开发者ID:thyer,项目名称:CS470,代码行数:43,代码来源:show_path.py

示例3: AStar

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_obstacles [as 别名]
class AStar(object):

    def __init__(self):
        self.op = []
        heapq.heapify(self.op)
        self.cl = set()
        localhost = "localhost"
        self.path = []
        self.grid = Grid(port=int(33172))
        self.bz = BZRC(host="localhost", port=int(33172))
        self.obstacles = self.bz.get_obstacles()
        self.othertanks = self.bz.get_othertanks()

    def init_grid(self):

        walls = self.grid.get_grid()

        self.start = self.grid.get_cell_tuple(self.grid.start)
        self.end = self.grid.get_cell_tuple(self.grid.goal)

        #print type(self.start)

    '''
    @param cell
    @returns heuristic value H
    '''
    def get_heuristic(self, cell):

        return __HEURISTIC__ * math.sqrt((abs(cell.x - self.end.x)**2 + abs(cell.y - self.end.y)**2))

    def get_cell(self, x, y):
        """
        Returns a cell from the cells list

        @param x cell x coordinate
        @param y cell y coordinate
        @returns cell
        """

        cell = self.grid.get_cell(x,y)

        #print "Location: ", cell.x, cell.y

        return cell

    def get_adjacent_cells(self, cell):
        """
        Returns adjacent cells to a cell. Clockwise starting
        from the one on the right.

        @param cell get adjacent cells for this cell
        @returns adjacent cells list 
        """

        #vert & horizantal
        cells = []
        if cell.x + 1 < self.grid.right :
            cells.append(self.get_cell(cell.x+1, cell.y))
        if cell.y - 1 >= self.grid.bottom:
            cells.append(self.get_cell(cell.x, cell.y-1))
        if cell.x - 1 >= self.grid.left:
            cells.append(self.get_cell(cell.x-1, cell.y))
        if cell.y + 1 < self.grid.top:
            cells.append(self.get_cell(cell.x, cell.y+1))

        #diagonal
        if cell.x + 1 < self.grid.right and cell.y + 1 < self.grid.top:
            cells.append(self.get_cell(cell.x+1, cell.y+1))

        if cell.x - 1 >= self.grid.left and cell.y - 1 >= self.grid.bottom:
            cells.append(self.get_cell(cell.x-1, cell.y-1))

        if cell.x - 1 >= self.grid.left and cell.y  + 1< self.grid.top:
            cells.append(self.get_cell(cell.x-1, cell.y+1))

        if cell.x + 1 < self.grid.right and cell.y - 1 >= self.grid.bottom:
            cells.append(self.get_cell(cell.x+1, cell.y-1))

        #print cells
        return cells


    def display_path(self):
        cell = self.end
        
        while cell.parent is not self.start:
            cell = cell.parent
            self.path.append((cell.x, cell.y))
            #print 'path: cell: %d,%d' % (cell.x, cell.y)
        

    def update_cell(self, adj, cell):
        """
        Update adjacent cell

        @param adj adjacent cell to current cell
        @param cell current cell being processed
        """
        adj.cost = cell.cost + __travel_cost__
        adj.heuristic = self.get_heuristic(adj)
#.........这里部分代码省略.........
开发者ID:itcropper,项目名称:tanks,代码行数:103,代码来源:aStar.py

示例4: generate_field_function

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_obstacles [as 别名]
def generate_field_function(scale):
    def function(x, y):
        '''User-defined field function.'''
        # vector, shoot = pfagent.master_field_gen.vector_at(x, y)
        # vector, shoot = pfagent.return_to_base.vector_at(x, y)
        vec, shoot = pfagent.vector_at("capture", x, y)

        return vec.x, vec.y
        # return x, y

    return function


# OBSTACLES = [((0, 0), (-150, 0), (-150, -50), (0, -50)),
#              ((200, 100), (200, 330), (300, 330), (300, 100))]
OBSTACLES = bzrc.get_obstacles()

########################################################################
# Helper Functions

def gpi_point(x, y, vec_x, vec_y):
    '''Create the centered gpi data point (4-tuple) for a position and
    vector.  The vectors are expected to be less than 1 in magnitude,
    and larger values will be scaled down.'''
    r = (vec_x ** 2 + vec_y ** 2) ** 0.5
    if r > 1:
        vec_x /= r
        vec_y /= r
    return (x - vec_x * VEC_LEN / 2, y - vec_y * VEC_LEN / 2,
            vec_x * VEC_LEN, vec_y * VEC_LEN)
开发者ID:keith-mcqueen,项目名称:bzragent,代码行数:32,代码来源:fields2.py


注:本文中的bzrc.BZRC.get_obstacles方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。