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)) bayes = Bayes() constants = bzrc.get_constants() bayes.self_not_obs_given_not_occ(float(constants['truenegative'])) bayes.set_obs_given_occ(float(constants['truepositive'])) agent = Agent(bzrc, bayes) prev_time = time.time() # 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()
def main(): # Process CLI arguments. try: execname, host, port, mode = sys.argv except ValueError: execname = sys.argv[0] print >>sys.stderr, '%s: incorrect number of arguments' % execname print >>sys.stderr, 'usage: %s hostname port [sit|const|wild]' % sys.argv[0] sys.exit(-1) bzrc = BZRC(host, int(port)) cur_time = time.time() agent = PigeonAgent(bzrc, mode, cur_time) # Run the agent try: while True: cur_time = time.time() agent.behave(cur_time) except KeyboardInterrupt: print "Exiting due to keyboard interrupt." agent.stop() bzrc.close()
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()
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()
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 = PFAgent(bzrc) agent.tick() plot_single(agent.calculate_obstacles_force, agent.obstacles, 'obstacles.png') plot_single(agent.calculate_goal_force, agent.obstacles, 'goal.png') plot_single(agent.calculate_random_force, agent.obstacles, 'random.png') plot_single(agent.calculate_tangential_force, agent.obstacles, 'tangential.png') plot_single(agent.get_forces_on_tank, agent.obstacles, 'combined.png') print("finished") 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)) # 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()
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: while True: time_diff = time.time() - prev_time agent.tick(time_diff) 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)) # initialize the visualization stuff world_size = int(bzrc.get_constants()['worldsize']) viz = KalmanViz(world_size) # create our agent (just assume it's the first tank on our team) agent = KalmanFilterAgent(bzrc, 0, viz) prev_time = time.time() # Run the agent try: while True: time_diff = time.time() - prev_time prev_time = time.time() agent.tick(time_diff) except KeyboardInterrupt: print "Exiting due to keyboard interrupt." bzrc.close() viz.destroy()
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) #print "Running Tyler & Morgan's Super Smart Flag Capturer" numpy.set_printoptions(precision=3, suppress=True) # Connect. #bzrc = BZRC(host, int(port), debug=True) bzrc = BZRC(host, int(port)) agent = Agent(bzrc) prev_time = time.time() # Run the agent try: while True: new_time = time.time() time_diff = new_time - prev_time prev_time = new_time agent.tick(time_diff) 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_list = [] for tank in bzrc.get_mytanks(): agent_list.append(DumbAgent(bzrc, tank, time.time())) move_time = 4 # Run the agent try: while True: cur_time = time.time() for agent in agent_list: if agent.is_moving == False and agent.is_rotating == False: agent.full_throttle(cur_time) if agent.is_moving == True: if (cur_time - agent.last_move_time) >= move_time: agent.stop_tank() move_time = random.randrange(3, 8) if agent.is_rotating == False and agent.is_moving == False: agent.start_left_rotate(cur_time) if agent.is_rotating == True: if (cur_time - agent.last_rotate_time) >= 1.5: agent.stop_tank() if (cur_time - agent.last_shoot_time) >= agent.shoot_interval: agent.shoot() agent.shoot_interval = (random.randrange(2, 3) - .5) except KeyboardInterrupt: print "Exiting due to keyboard interrupt." for agent in agent_list: agent.stop_tank() bzrc.close()
def main(): # Process CLI arguments. try: execname, host, port, display = sys.argv except ValueError: execname = sys.argv[0] print >> sys.stderr, '%s: incorrect number of arguments' % execname print >> sys.stderr, 'usage: %s hostname port fieldToDisplay' % sys.argv[ 0] sys.exit(-1) bzrc = BZRC(host, int(port)) v = Visualizer(bzrc, display) v.visualize()
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) #agent.elapsed_time = prev_time = time.time() time_diff = 0 #print "Moving Time: %d" % agent.moving_time # Run the agent try: while True: #print "Elapsed Time: %f" % time_diff agent.tick(time_diff) #for flag in agent.flags: #print flag.x, flag.y, flag.color, flag.poss_color # time_diff = time.time() - prev_time # if time.time() - agent.elapsed_time > agent.shooting_time: # print "Shoot!" # agent.tick(time_diff, False, True) # agent.shooting_time = agent.set_shooting_time() # agent.elapsed_time = time.time() # if time_diff > agent.moving_time: # print "Turning 60 degrees." # if time_diff < agent.moving_time + 0.83: # agent.tick(time_diff, True, False) # else: # agent.moving_time = agent.set_moving_time() # prev_time = time.time() # print "Moving Time: %d" % agent.moving_time # else: # agent.tick(time_diff, False, False) 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 = Agent(bzrc)
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) burn_in = 0 # Run the agent try: while True: #start = time.time() if agent.tick_count > agent.step_size: agent.tick_count = 1 if burn_in < agent.burn_in: burn_in += 1 else: if check_criterion(agent.step_size, agent.buffer, agent.tick_count): agent.fire = True agent.tick_count = 1 else: agent.fire = False agent.tick_count += 1 agent.tick() #end = time.time() #diff.append(float(end - start)) #if tick_count == 20: # print "average time in a tick: %.2f" % (sum(diff)/len(diff)) 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)) # 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()
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 = KAgent(bzrc) init_window(int(agent.constants['worldsize']), int(agent.constants['worldsize'])) # print 'init complete' prev_time = time.time() # Run the agent try: global tic tic = 0 while True: t = time.time() time_diff = t - prev_time prev_time = t agent.tick(time_diff) agent.doUpdate() if (tic == 10): if (time.time() - agent.aliveTime) > 60: agent._kalman.resetSigmaT() agent.aliveTime = time.time() print 'reset sigmaT' update_grid(numpy.array(zip(*agent.grid.grid))) draw_grid() tic = 0 tic += 1 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)) 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()
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)) tanks_per_team = len(bzrc.get_mytanks()) tank_agents = [0] * tanks_per_team # currently this section is hard coded for 10 tanks # ****************************** for i in range(3): #print i tank_agents[i] = KAgent(bzrc, i) for i in range(3,10): tank_agents[i] = PFAgent(bzrc, i) for i in range(10,10): tank_agents[i] = MAgent(bzrc, i) # ****************************** #agent = PFAgent(bzrc) prev_time = time.time() # Run the agent try: while True: time_diff = time.time() - prev_time for agent in tank_agents: agent.tick(time_diff) 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)) #bzrc = BZRC(host, 35001) agent = KalmanAgent(bzrc) prev_time = time.time() # Run the agent count = 0 try: while True: time_diff = time.time() - prev_time if(time_diff >= t): prev_time = time.time() agent.tick() count += 1 if (count > 20): count = 0 agent.Kfilter.reset() except KeyboardInterrupt: print "Exiting due to keyboard interrupt." bzrc.close()
FILENAME = 'fields.gpi' # Size of the world (one of the "constants" in bzflag): WORLDSIZE = 800 # How many samples to take along each dimension: SAMPLES = 25 # Change spacing by changing the relative length of the vectors. It looks # like scaling by 0.75 is pretty good, but this is adjustable: VEC_LEN = 0.75 * WORLDSIZE / SAMPLES # Animation parameters: ANIMATION_MIN = 0 ANIMATION_MAX = 500 ANIMATION_FRAMES = 50 FLAG_INT = 0 OTHER_TANK = 20 BZRC = BZRC('localhost', 50101) # print 'got here' time.sleep(2) # print 'done sleeping' mytanks, othertanks, flags, shots = BZRC.get_lots_o_stuff() f = othertanks[OTHER_TANK] # commands = [] # command = Command(FLAG_INT, 1,.5, False) # commands.append(command) # results = BZRC.do_commands(commands) # print f.color # print 'flag x = ' + str(f.x) # print 'flag y = ' + str(f.y) ######################################################################## # Field and Obstacle Definitions