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 = BritAgent(bzrc) prev_time = time.time() # Run the agent try: flags = bzrc.get_flags() print flags[0].color except KeyboardInterrupt: print "Exiting due to keyboard interrupt." bzrc.close()
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 = BritAgent(bzrc) prev_time = time.time() # Run the agent try: flags = bzrc.get_flags() print flags[0].color except KeyboardInterrupt: print "Exiting due to keyboard interrupt." bzrc.close()
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)
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()
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) return self.grid[x][y] def get_cell_by_cell(self, c): return self.grid[int(c[0])][int(c[1])]