Exemplo n.º 1
0
 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()
Exemplo n.º 2
0
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()
Exemplo n.º 3
0
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))
    
    gridVisualizer = GridFilter(-400,800,-400,800,0.9,0.97)
    
    agent = Agent(bzrc)

    prev_time = time.time()

    # Run the agent
    try:
        gridVisualizer.init_window(801, 801)
        while True:
            time_diff = time.time() - prev_time
            gridVisualizer = agent.tick(time_diff, gridVisualizer)
            if (time_diff >= 1):
                gridVisualizer.update_grid()
                gridVisualizer.draw_grid()
                prev_time = time.time()
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
Exemplo n.º 4
0
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()
    # thread = threading.Thread(target=init_window, args=(int(800),int(800)))
    # thread.start()
    init_window(int(800),int(800))
    # Run the agent
    try:
        while True:
            time_diff = time.time() - prev_time
            agent.tick(time_diff)
            draw_grid(time_diff > 10)
            if time_diff > 10:
                prev_time = time.time()
    except (KeyboardInterrupt, SystemExit):
        print "Exiting due to keyboard interrupt."
        bzrc.close()
        draw_grid(True)
Exemplo n.º 5
0
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()
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
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()
Exemplo n.º 8
0
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()
Exemplo n.º 9
0
Arquivo: kalman.py Projeto: jy19/CS470
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))

    print "Starting agent: Kalman Filter shooter"
    agent = KalmanTank(bzrc)

    prev_time = time.time()

    # Run the agent
    try:
        while True:
            now = time.time()
            time_diff = now - prev_time
            agent.tick(time_diff)
            prev_time = now
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
Exemplo n.º 10
0
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()
Exemplo n.º 11
0
def main():
    # Process CLI arguments.
    try:
        execname, host, port, use_penalized_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 enablepenalties" % sys.argv[0]
        sys.exit(-1)

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

    use_penalized_mode = use_penalized_mode == "1"  # convert into a boolean
    print "use_penalized_mode is %d" % use_penalized_mode
    agent = Agent(bzrc, use_penalized_mode)

    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()
Exemplo n.º 12
0
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()
Exemplo n.º 13
0
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()
Exemplo n.º 14
0
def main():
    # Process CLI arguments.
    try:
        execname, host, port, foodSupply = 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))

    gridPlotter = GridFilter()
    cc = CommandCenter(bzrc, foodSupply,gridPlotter)
    gridPlotter.init_window(800, 800,cc.tick)

    prev_time = time.time()

    # Run the agent
    try:
        while True:
            time_diff = time.time() - prev_time
            action = threading.Thread(target =cc.tick, args=[time_diff])
            action.start()
            action.join()
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
Exemplo n.º 15
0
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()
Exemplo n.º 16
0
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)

    # Run the agent
    try:
        #agent.plot_attractive()
        #agent.plot_repulsive()
        #agent.plot_tangential()
        agent.plot_sum()
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
Exemplo n.º 17
0
    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()
Exemplo n.º 18
0
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()
Exemplo n.º 19
0
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()
    prev_time_shoot = time.time()
    
    wait = 8
    # Run the agent
    try:
        while True:
            if time.time() > prev_time_shoot + 2:
                agent.tick(time.time() - prev_time_shoot, True)
                prev_time_shoot = time.time()
            if time.time() > prev_time + wait:
                went_straight = agent.tick(time.time() - prev_time)
                wait = 3 if went_straight else 8
                prev_time = time.time()
            
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
Exemplo n.º 20
0
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 = basicAgent(bzrc)

    init_window(800,800)
    # Run the agent
    try:
        tickCounter = 0
        prev_time = time.time()
        while True:
            time_diff = time.time() - prev_time
            prev_time = time.time()
            agent.tick(time_diff)
            if tickCounter % 10 == 0:
                draw_grid()
                update_grid(numpy.array(zip(*agent.beliefMap)))
                #update_grid(numpy.array(agent.beliefMap))
            tickCounter = tickCounter + 1
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
Exemplo n.º 21
0
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()
Exemplo n.º 22
0
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()
Exemplo n.º 23
0
def main():
	# Process CLI arguments.
	try:
		execname, host, port, search = 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))

	if search == 'b':
		agent = VisibilityGraphAgent(bzrc, BreadthFirstSearch(False))
	elif search == 'd':
		agent = VisibilityGraphAgent(bzrc, DepthFirstSearch(False))
	elif search == 'a':
		agent = VisibilityGraphAgent(bzrc, AStarSearch(False))
	else:
		print >>sys.stderr, 'bad search value. must be a d or b'
		sys.exit(-1)

	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()
Exemplo n.º 24
0
def main():
    # Process CLI arguments.
    try:
        #noise needs to be passed into the necessary functions
        execname, host, port, psi, noise = sys.argv
    except ValueError:
        execname = sys.argv[0]
        print >>sys.stderr, '%s: incorrect number of arguments' % execname
        print >>sys.stderr, 'usage: %s hostname port psi noise' % sys.argv[0]
        sys.exit(-1)

    # Connect.
    #bzrc = BZRC(host, int(port), debug=True)
    gridPlotter = GridFilter()
    bzrc = BZRC(host, int(port))
    nexus = Nexus(bzrc, int(psi), int(noise),gridPlotter)
    gridPlotter.init_window(800, 800,nexus.tick)

    prev_time = time.time()

    # Run the agent
    try:
        while True:
            time_diff = time.time() - prev_time
            action = threading.Thread(target =nexus.tick, args=[time_diff])
            action.start()
            action.join()
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
Exemplo n.º 25
0
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()
Exemplo n.º 26
0
Arquivo: pigeon.py Projeto: jy19/CS470
def main():
    # Process CLI arguments.
    try:
        execname, host, port, pigeon_type = 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))

    if pigeon_type == 'constant':
        # constant pigeon
        print 'Starting agent: Constant-velocity Pigeon'
        agent = PredictablePigeon(bzrc)
    elif pigeon_type == 'wild':
        # wild pigeon
        print 'Starting agent: Wild Pigeon'
        agent = WildPigeon(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()
Exemplo n.º 27
0
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()
Exemplo n.º 28
0
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()
Exemplo n.º 29
0
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()
Exemplo n.º 30
0
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()
Exemplo n.º 31
0
	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))
Exemplo n.º 32
0
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()
Exemplo n.º 33
0
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()
Exemplo n.º 34
0
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))
    
    constants = bzrc.get_constants()

    agent = Agent(bzrc)

    prev_tick = time.time()
    vel_tick = time.time()
    viz_tick = time.time()
    calulateVel = False
    velStep = .25
    vizStep = 1.0
    step = .001

    # Run the agent
    try:
        while True:
            newtime = time.time()
            time_diff = newtime - prev_tick
            vel_diff = newtime - vel_tick
            viz_diff = newtime - viz_tick
            if vel_diff >= velStep:
                calulateVel = True
                vel_tick = newtime
            if time_diff >= step:
                agent.tick(time_diff, calulateVel, velStep)
                prev_tick = newtime
                calulateVel = False
            if viz_diff >= vizStep:
                agent.updateVisualization()
                viz_tick = newtime
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
Exemplo n.º 35
0
	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)
Exemplo n.º 36
0
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()
Exemplo n.º 37
0
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()
Exemplo n.º 38
0
 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()
Exemplo n.º 39
0
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()
    step = .001
    
    # Do you want to control 1 tank or all of the tanks on a team?
    #ctrl = 'one'
    ctrl = 'all'
    
    # Run the agent
    try:
        while True:
            time_diff = time.time() - prev_time
            # Only do something if the set interval has passed
            if time_diff >= step:
                if ctrl is 'one': # This call the tickOne method for controlling 1 tank
                    agent.tickOne(step)
                    prev_time = time.time()
                elif ctrl is 'all': # This call the tickAll method for controlling all the tanks
                    agent.tickAll(step)
                    prev_time = time.time()
                else:
                    print >>sys.stderr, 'This shouldn\'t happen!!'
                    sys.exit(-1)
                
    except KeyboardInterrupt:
        print "Exiting due to keyboard interrupt."
        bzrc.close()
Exemplo n.º 40
0
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()
Exemplo n.º 41
0
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()
Exemplo n.º 42
0
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()
Exemplo n.º 43
0
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()
Exemplo n.º 44
0
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)
Exemplo n.º 45
0
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()
Exemplo n.º 46
0
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