def process(self, packet: GameTickPacket): """Simplified preprocessing which just takes care of the car and game info that I need. Arguments: packet {GameTickPacket} -- The information packet from the game. """ # Car self.agent.pos = a3v( packet.game_cars[self.agent.index].physics.location) self.agent.rot = a3r( packet.game_cars[self.agent.index].physics.rotation) self.agent.vel = a3v( packet.game_cars[self.agent.index].physics.velocity) #self.agent.ang_vel = a3v(packet.game_cars[self.agent.index].physics.angular_velocity) #self.agent.dead = packet.game_cars[self.agent.index].is_demolished #self.agent.wheel_c = packet.game_cars[self.agent.index].has_wheel_contact #self.agent.sonic = packet.game_cars[self.agent.index].is_super_sonic #self.agent.jumped = packet.game_cars[self.agent.index].jumped #self.agent.d_jumped = packet.game_cars[self.agent.index].double_jumped #self.agent.boost = packet.game_cars[self.agent.index].boost self.agent.orient_m = orient_matrix(self.agent.rot) # Game info self.active = packet.game_info.is_round_active self.time = packet.game_info.seconds_elapsed self.dt = self.time - self.last_time self.last_time = self.time
def draw_debug(self): self.game_interface.renderer.begin_rendering() path = [ a3v(step.physics.location) for step in self.ball.predict.slices ] self.game_interface.renderer.draw_polyline_3d( path, self.game_interface.renderer.pink()) for drone in self.drones: if drone.role is not None: self.game_interface.renderer.draw_string_3d( drone.pos, 1, 1, drone.role.name, self.game_interface.renderer.white()) self.game_interface.renderer.end_rendering()
def setup(hive, packet, field_info, indices): """Sets up the variables and classes for the hivemind. Arguments: hive {Hivemind} -- The hivemind bot helper process. packet {GameTickPacket} -- Information about the game. field_info {FieldInfoPacket} -- Information about the game field. indices {set} -- Set containing the indices of each agent the hivemind controls. """ # Game info hive.time = 0.0 hive.dt = 1.0 / 120.0 hive.last_time = 0.0 hive.r_active = False hive.ko_pause = False hive.m_ended = False hive.gravity = -650.0 # Hivemind attributes hive.team = packet.game_cars[indices.copy().pop()].team hive.strategy = None # Creates Car objects for each car. hive.drones = [] hive.teammates = [] hive.opponents = [] for index in range(packet.num_cars): name = packet.game_cars[index].name if index in indices: hive.drones.append(Drone(index, hive.team, name)) elif packet.game_cars[index].team == hive.team: hive.teammates.append(Car(index, hive.team, name)) else: hive.opponents.append(Car(index, (hive.team + 1) % 2, name)) # Creates a Ball object. hive.ball = Ball() # Creates Boostpad objects. hive.l_pads = [] hive.s_pads = [] for i in range(field_info.num_boosts): pad = field_info.boost_pads[i] pad_type = hive.l_pads if pad.is_full_boost else hive.s_pads pad_obj = BoostPad(i, a3v(pad.location)) pad_type.append(pad_obj)
def setup(s, p, fi, indices): """Sets up the variables and classes for the hivemind. Arguments: s {BotHelperProcess (self)} -- The hivemind bot helper process. p {GameTickPacket} -- Information about the game. fi {FieldInfoPacket} -- Information about the game field. indices {set} -- Set containing the indices of each agent the hivemind controls. """ # Game info. s.dt = 1 / 120.0 s.last_time = 0.0 s.strategy = None # Creates Drone objects. s.drones = [] for index in indices: s.drones.append(Drone(index)) # Initialises hivemind attributes. s.team = p.game_cars[s.drones[0].index].team s.strategy = None # Creates Car objects for teammates and opponents. s.teammates = [] s.opponents = [] for index in range(p.num_cars): if index not in indices: if p.game_cars[index].team == s.team: s.teammates.append(Car(index)) else: s.opponents.append(Car(index)) # Creates a Ball object. s.ball = Ball() # Creates Boostpad objects. s.l_pads = [] s.s_pads = [] for i in range(fi.num_boosts): pad = fi.boost_pads[i] pad_type = s.l_pads if pad.is_full_boost else s.s_pads pad_obj = BoostPad(i, a3v(pad.location)) pad_type.append(pad_obj)
def setup(s, p): """Sets up the variables and classes for the hivemind. Arguments: s {BaseAgent} -- The hivemind bot helper process. p {GameTickPacket} -- Information about the game. fi {FieldInfoPacket} -- Information about the game field. """ # Game info. fi = s.get_field_info() s.dt = 1 / 120.0 s.last_time = 0.0 # Creates Car objects for all bots. s.teammates = [] s.opponents = [] for index in range(p.num_cars): if index == s.index: s.agent = Car(s.index) elif p.game_cars[index].team == s.team: s.teammates.append(Car(index)) else: s.opponents.append(Car(index)) s.agent.controller = None # Creates a Ball object. s.ball = Ball() # Creates Boostpad objects. s.l_pads = [] s.s_pads = [] for i in range(fi.num_boosts): pad = fi.boost_pads[i] pad_type = s.l_pads if pad.is_full_boost else s.s_pads pad_obj = BoostPad(i, a3v(pad.location)) pad_type.append(pad_obj) s.setup = True
def process(s, p): """Processes the gametick packet. Arguments: s {BotHelperProcess (self)} -- The process which is processing the packet. p {GameTickPacket} -- The game packet being processed. """ # Processing drone data. for drone in s.drones: drone.pos = a3v(p.game_cars[drone.index].physics.location) drone.rot = a3r(p.game_cars[drone.index].physics.rotation) drone.vel = a3v(p.game_cars[drone.index].physics.velocity) drone.ang_vel = a3v(p.game_cars[drone.index].physics.angular_velocity) drone.on_g = p.game_cars[drone.index].has_wheel_contact drone.sonic = p.game_cars[drone.index].is_super_sonic drone.boost = p.game_cars[drone.index].boost drone.orient_m = orient_matrix(drone.rot) drone.turn_r = turn_r(drone.vel) # Processing teammates. for teammate in s.teammates: teammate.pos = a3v(p.game_cars[teammate.index].physics.location) teammate.rot = a3r(p.game_cars[teammate.index].physics.rotation) teammate.vel = a3v(p.game_cars[teammate.index].physics.velocity) teammate.ang_vel = a3v( p.game_cars[teammate.index].physics.angular_velocity) teammate.on_g = p.game_cars[teammate.index].has_wheel_contact teammate.sonic = p.game_cars[teammate.index].is_super_sonic teammate.boost = p.game_cars[teammate.index].boost teammate.orient_m = orient_matrix(teammate.rot) teammate.turn_r = turn_r(teammate.vel) # Processing opponents. for opponent in s.opponents: opponent.pos = a3v(p.game_cars[opponent.index].physics.location) opponent.rot = a3r(p.game_cars[opponent.index].physics.rotation) opponent.vel = a3v(p.game_cars[opponent.index].physics.velocity) opponent.ang_vel = a3v( p.game_cars[opponent.index].physics.angular_velocity) opponent.on_g = p.game_cars[opponent.index].has_wheel_contact opponent.sonic = p.game_cars[opponent.index].is_super_sonic opponent.boost = p.game_cars[opponent.index].boost opponent.orient_m = orient_matrix(opponent.rot) opponent.turn_r = turn_r(opponent.vel) # Processing Ball data. s.ball.pos = a3v(p.game_ball.physics.location) s.ball.vel = a3v(p.game_ball.physics.velocity) s.ball.ang_vel = a3v(p.game_ball.physics.angular_velocity) # Ball prediction is being updated in the main file, i.e. hivemind.py. # Processing Boostpads. s.active_pads = [] for pad_type in (s.l_pads, s.s_pads): for pad in pad_type: pad.active = p.game_boosts[pad.index].is_active pad.timer = p.game_boosts[pad.index].timer if pad.active == True: s.active_pads.append(pad) # Processing other game info. s.time = p.game_info.seconds_elapsed s.dt = s.time - s.last_time s.last_time = s.time s.r_active = p.game_info.is_round_active s.ko_pause = p.game_info.is_kickoff_pause s.m_ended = p.game_info.is_match_ended
def process(hive, packet): """Processes the gametick packet. Arguments: hive {Hivemind} -- The process which is processing the packet. packet {GameTickPacket} -- The game packet being processed. """ # Processing game info. hive.time = packet.game_info.seconds_elapsed hive.dt = hive.time - hive.last_time hive.last_time = hive.time hive.r_active = packet.game_info.is_round_active hive.ko_pause = packet.game_info.is_kickoff_pause hive.m_ended = packet.game_info.is_match_ended hive.gravity = packet.game_info.world_gravity_z # Processing drone data. for drone in hive.drones: # From packet: drone.pos = a3v(packet.game_cars[drone.index].physics.location) drone.rot = a3r(packet.game_cars[drone.index].physics.rotation) drone.vel = a3v(packet.game_cars[drone.index].physics.velocity) drone.ang_vel = a3v( packet.game_cars[drone.index].physics.angular_velocity) drone.dead = packet.game_cars[drone.index].is_demolished drone.wheel_c = packet.game_cars[drone.index].has_wheel_contact drone.sonic = packet.game_cars[drone.index].is_super_sonic drone.jumped = packet.game_cars[drone.index].jumped drone.d_jumped = packet.game_cars[drone.index].double_jumped drone.boost = packet.game_cars[drone.index].boost # Calculated: drone.orient_m = orient_matrix(drone.rot) drone.turn_r = turn_r(drone.vel) # Processing teammates. for teammate in hive.teammates: # From packet: teammate.pos = a3v(packet.game_cars[teammate.index].physics.location) teammate.rot = a3r(packet.game_cars[teammate.index].physics.rotation) teammate.vel = a3v(packet.game_cars[teammate.index].physics.velocity) teammate.ang_vel = a3v( packet.game_cars[teammate.index].physics.angular_velocity) teammate.dead = packet.game_cars[teammate.index].is_demolished teammate.wheel_c = packet.game_cars[teammate.index].has_wheel_contact teammate.sonic = packet.game_cars[teammate.index].is_super_sonic teammate.jumped = packet.game_cars[teammate.index].jumped teammate.d_jumped = packet.game_cars[teammate.index].double_jumped teammate.boost = packet.game_cars[teammate.index].boost # Calculated: #teammate.orient_m = orient_matrix(teammate.rot) #teammate.turn_r = turn_r(teammate.vel) #teammate.predict = None # Processing opponents. for opponent in hive.opponents: # From packet: opponent.pos = a3v(packet.game_cars[opponent.index].physics.location) opponent.rot = a3r(packet.game_cars[opponent.index].physics.rotation) opponent.vel = a3v(packet.game_cars[opponent.index].physics.velocity) opponent.ang_vel = a3v( packet.game_cars[opponent.index].physics.angular_velocity) opponent.dead = packet.game_cars[opponent.index].is_demolished opponent.wheel_c = packet.game_cars[opponent.index].has_wheel_contact opponent.sonic = packet.game_cars[opponent.index].is_super_sonic opponent.jumped = packet.game_cars[opponent.index].jumped opponent.d_jumped = packet.game_cars[opponent.index].double_jumped opponent.boost = packet.game_cars[opponent.index].boost # Calculated: #opponent.orient_m = orient_matrix(opponent.rot) #opponent.turn_r = turn_r(opponent.vel) #opponent.predict = None # Processing Ball data. hive.ball.pos = a3v(packet.game_ball.physics.location) hive.ball.rot = a3r(packet.game_ball.physics.rotation) hive.ball.vel = a3v(packet.game_ball.physics.velocity) hive.ball.ang_vel = a3v(packet.game_ball.physics.angular_velocity) # Ball prediction is being updated in the main file, i.e. hivemind.py. # Processing Boostpads. hive.active_pads = [] for pad in hive.l_pads + hive.s_pads: pad.active = packet.game_boosts[pad.index].is_active pad.timer = packet.game_boosts[pad.index].timer if pad.active == True: hive.active_pads.append(pad)
def process(s, p): """Processes the gametick packet. Arguments: s {BaseAgent} -- The agent which is processing the packet. p {GameTickPacket} -- The game packet being processed. """ # Processing game info. s.time = p.game_info.seconds_elapsed s.dt = s.time - s.last_time s.last_time = s.time s.r_active = p.game_info.is_round_active s.ko_pause = p.game_info.is_kickoff_pause s.m_ended = p.game_info.is_match_ended # Processing agent data. s.agent.pos = a3v(p.game_cars[s.agent.index].physics.location) s.agent.rot = a3r(p.game_cars[s.agent.index].physics.rotation) s.agent.vel = a3v(p.game_cars[s.agent.index].physics.velocity) s.agent.ang_vel = a3v(p.game_cars[s.agent.index].physics.angular_velocity) s.agent.on_g = p.game_cars[s.agent.index].has_wheel_contact s.agent.sonic = p.game_cars[s.agent.index].is_super_sonic s.agent.boost = p.game_cars[s.agent.index].boost s.agent.orient_m = orient_matrix(s.agent.rot) s.agent.turn_r = turn_r(s.agent.vel) # Processing teammates. for teammate in s.teammates: teammate.pos = a3v(p.game_cars[teammate.index].physics.location) teammate.rot = a3r(p.game_cars[teammate.index].physics.rotation) teammate.vel = a3v(p.game_cars[teammate.index].physics.velocity) teammate.ang_vel = a3v( p.game_cars[teammate.index].physics.angular_velocity) teammate.on_g = p.game_cars[teammate.index].has_wheel_contact teammate.sonic = p.game_cars[teammate.index].is_super_sonic teammate.boost = p.game_cars[teammate.index].boost teammate.orient_m = orient_matrix(teammate.rot) teammate.turn_r = turn_r(teammate.vel) # Processing opponents. for opponent in s.opponents: opponent.pos = a3v(p.game_cars[opponent.index].physics.location) opponent.rot = a3r(p.game_cars[opponent.index].physics.rotation) opponent.vel = a3v(p.game_cars[opponent.index].physics.velocity) opponent.ang_vel = a3v( p.game_cars[opponent.index].physics.angular_velocity) opponent.on_g = p.game_cars[opponent.index].has_wheel_contact opponent.sonic = p.game_cars[opponent.index].is_super_sonic opponent.boost = p.game_cars[opponent.index].boost opponent.orient_m = orient_matrix(opponent.rot) opponent.turn_r = turn_r(opponent.vel) # Processing Ball data. s.ball.pos = a3v(p.game_ball.physics.location) s.ball.vel = a3v(p.game_ball.physics.velocity) s.ball.ang_vel = a3v(p.game_ball.physics.angular_velocity) s.ball.predict = s.get_ball_prediction_struct() # Processing Boostpads. s.active_pads = [] for pad_type in (s.l_pads, s.s_pads): for pad in pad_type: pad.active = p.game_boosts[pad.index].is_active pad.timer = p.game_boosts[pad.index].timer if pad.active == True: s.active_pads.append(pad)