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


Python BZRC.get_mytanks方法代码示例

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


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

示例1: main

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_mytanks [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))

    # Create our army
    agents = []
    index = 0
    for tank in range(len(bzrc.get_mytanks())):
        agent = StraightLineAgent(bzrc, index)
        agents.append(agent)
        index += 1

    # Run the agent
    try:
        while True:
            for agent in agents:
                agent.tick()

    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
开发者ID:thyer,项目名称:CS470,代码行数:33,代码来源:StraightLineAgent.py

示例2: main

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_mytanks [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))

    agent = Agent(bzrc)

    prev_time = time.time()

    # Run the agent
    try:

        # initialize all the tanks to 'not turning'
        mytanks = bzrc.get_mytanks()
        for tank in mytanks:
            print tank.index
            agent.angleset.append(False)
            agent.startangle.append(0)

        while True:
            time_diff = time.time() - prev_time
            prev_time += time_diff
            agent.tick(time_diff)
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
开发者ID:lwthatcher,项目名称:CS-470,代码行数:37,代码来源:dumbagent.py

示例3: main

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_mytanks [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))
    agents = []
    index = 0
    for tank in bzrc.get_mytanks():
        agent = PathAgent(bzrc, index)
        agents.append(agent)
        index += 1

    prev_time = time.time()

    # Run the agent
    try:
        while True:
            time_diff = time.time() - prev_time
            prev_time = time.time()
            for agent in agents:
                agent.tick(time_diff)
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
开发者ID:thyer,项目名称:CS470,代码行数:34,代码来源:PathAgent.py

示例4: main

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_mytanks [as 别名]
 def main(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))
     mytanks = bzrc.get_mytanks()
     for i in range(len(mytanks)):
         if i < 8:
             if i < 5:
                 self.tanks.append(SuperUberAgent(bzrc,mytanks[i],"a"))
             else:
                 self.tanks.append(SuperUberAgent(bzrc,mytanks[i],"d"))  
         else:
             self.tanks.append(BayesAgent(bzrc,mytanks[i],self.grid, self.obsList))
     
        
     try:
         while True:
             self.tick(self.tanks,bzrc)
            
     except KeyboardInterrupt:
         print "Exiting due to keyboard interrupt."
         bzrc.close()
开发者ID:Altair3,项目名称:Tanks,代码行数:34,代码来源:Driver.py

示例5: main

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_mytanks [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))

    agent = Agent(bzrc)
    prev_time = time.time()

    start = bzrc.get_mytanks()[0]
    goal = next(flag for flag in bzrc.get_flags() if flag.color == 'green')

    agent.init_screen()
    agent.refresh_screen()

    #agent.test_occgrid()
    #agent.uniform_search(start, goal)
    #agent.greedy_search(start, goal)
    # agent.depth_first(start, goal)
    #agent.breadth_first(start, goal)
    #agent.iterative_search(start, goal)
    
    path = agent.run(5)
    for i in range(len(path)):
        if i < len(path) - 1:
            print "set arrow from", str(path[i][0]) + ', ' + str(path[i][1]), "to ", str(path[i + 1][0]) + ', ' + str(path[i + 1][1]), "as 2"
    print "plot NaN notitle"
    
    #print time.time() - prev_time
    return

    
    

    # Run the agent
    try:
        while True:
            time_diff = time.time() - prev_time
            agent.tick(time_diff)
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
开发者ID:itcropper,项目名称:tanks,代码行数:52,代码来源:displaypathfindingagent.py

示例6: __init__

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_mytanks [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

示例7: main

# 需要导入模块: from bzrc import BZRC [as 别名]
# 或者: from bzrc.BZRC import get_mytanks [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))

    # Set up the occupancy grid and visualization
    world_size = int(bzrc.get_constants()['worldsize'])
    occupancy_grid = OccupancyGrid(world_size + 1, .97, .1, 50)
    viz = GFViz(occupancy_grid, world_size)

    # Create our army
    agents = []
    index = 0
    for tank in range(len(bzrc.get_mytanks())-5):
        agent = GridFilterAgent(bzrc, occupancy_grid, index)
        agents.append(agent)
        index += 1

    # Run the agent
    try:
        counter = 0
        while True:  # TODO: While our occupancy grid isn't "good enough"
            for agent in agents:
                agent.tick()
            if counter % 10 == 0:
                viz.update_grid(occupancy_grid.get_grid())
            counter += 1

        # Our occupancy grid is "good enough", enter an eternal loop so the visualization will be visible
        viz.loop_eternally()

    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
开发者ID:thyer,项目名称:CS470,代码行数:45,代码来源:GridFilterAgent.py

示例8: Grid

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

	def __init__(self, port):

		self.bzrc = BZRC("localhost", int(port))
		self.grid = self.bzrc.get_occgrid(0)

		#print self.grid

		
		self.height = len(self.grid[1])
		self.width  = len(self.grid[1][3])

		self.bottom = int(self.grid[0][0])
		self.top = self.bottom + self.height

		self.left = int(self.grid[0][0])
		self.right = self.left + self.width

		# print "Left: " , self.left
		# print 'Right: ', self.right
		# print 'Top: ', self.top
		# print 'Bottom: ', self.bottom


		#print self.height, self.width

		self.number_grid = self.grid[1:][0]

		#print self.number_grid

		self.grid = []

		self.goal =  (int(self.bzrc.get_flags()[2].x), int(self.bzrc.get_flags()[2].y))
		# print "Goal: ", self.goal
		self.start = (int(self.bzrc.get_mytanks()[0].x), int(self.bzrc.get_mytanks()[0].y))
		# print "START: " , self.start


	'''
	@param goal: tuple(x, y)
	@returns grid of cell objects
	'''
	def get_grid(self):

		xList = []
		
		for x in range(self.height):
			#g = raw_input(self.number_grid[y])
			yList = []

			for y in range(self.width):

				reachable = True

				if self.number_grid[x][y] == 1:
					reachable = False
				else:
					reachable = True
					#print "reachable at: " + str(x) + " : " + str(y)

				cell = Cell(self.left + x, self.bottom + y, reachable, self.distance(self.left + x, self.right + y, self.goal))
				
				if (self.left + x, self.top + y) == self.goal:
					cell.end = True

				#s = raw_input("Goal Location: " + str(x + self.left) + " : " + str(y + self.bottom) + " : " + str(self.number_grid[y][x]))

				yList.append(cell)


			xList.append(yList)

		#print len(yList), len(xList)

		self.grid = xList

		return y
				
	def distance(self, x, y, goal):
		return math.sqrt((abs(x - goal[0])**2 + (abs(y - goal[1])**2)))

	def get_cell(self, x, y):

		x = int(x + self.right)
		y = int(y + self.top)

		#print "Get Cell: ", x, y

		try:
			return self.grid[x][y]
		except(IndexError):
			print "Max is: " + str(len(self.grid)) + ", " + str(len(self.grid[0]))
			print "Error on: Index: " + str(x) + ", " + str(y)
			sys.exit(0)

	def get_cell_tuple(self, xy):
		x = int(xy[0] + self.right)
		y = int(xy[1] + self.top)

#.........这里部分代码省略.........
开发者ID:itcropper,项目名称:tanks,代码行数:103,代码来源:occGrid.py


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