本文整理汇总了Python中bzrc.BZRC.get_othertanks方法的典型用法代码示例。如果您正苦于以下问题:Python BZRC.get_othertanks方法的具体用法?Python BZRC.get_othertanks怎么用?Python BZRC.get_othertanks使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bzrc.BZRC
的用法示例。
在下文中一共展示了BZRC.get_othertanks方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_othertanks [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)
示例2: AStar
# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_othertanks [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)
#.........这里部分代码省略.........