def render(self): circle = rendering.Circle(self.center, 12) circle.set_color(self.color[0], self.color[1], self.color[2]) if self.loading() > 0: self.env.viewer.add_onetime_text("to_load: {0}, loaded: {1}".format(int(self.to_load), int(self.loaded)), \ 10, self.center.x, self.center.y) return super().render() + [circle]
def render(self): return [rendering.Circle(self.point, 2)]
def render(self): circle = rendering.Circle(self.center, 12) circle.set_color(self.color[0], self.color[1], self.color[2]) return super().render() + [circle]
def __init__(self): # initialize robot movement parameters Move.ticks_until_astar_recalc = 25 delta = 40 # offset of graph points from wall corners # delta = ((((Robot.width / 2) ** 2) + ((Robot.height / 2) ** 2))) ** .5 + 1 #radius of robot + 1 (divide by 2 is deliberate) # Record time self.game_time = 0 self.finished = False self.characters = { "obstacles": [], "zones": [], "robots": [], "bullets": [], } # Initialize teams BLUE = Team("BLUE", self.pygame_rendering) RED = Team("RED", self.pygame_rendering) BLUE.enemy, RED.enemy = RED, BLUE self.my_team, self.enemy_team = BLUE, RED # Initialize robots # my_robot = AttackRobot(self, BLUE, Point(780, 100), 135) my_robot = AttackRobot(self, BLUE, Point(780, 100), 135) enemy_robot = AttackRobot(self, RED, Point(50, 450), 0) # enemy_robot = AttackRobot("ASDWOPR", self, RED, Point(50, 450), 0, ignore_angle=True) # bugged spot with closest point unreachable # my_robot = AttackRobot(self, BLUE, Point(365.917389, 355.968720), 312.700132) # enemy_robot = KeyboardRobot("ASDWOPR", self, RED, Point(419.475727, 80.330731), 132.700132, ignore_angle=True) my_robot.load(40) enemy_robot.load(40) self.characters['robots'] = [my_robot, enemy_robot] # my_robot2 = AttackRobot(self, BLUE, Point(20, 100), 0) # enemy_robot2 = AttackRobot(self, RED, Point(780, 450), 180) # self.characters['robots'] += [my_robot2, enemy_robot2] for i in range(len(self.characters['robots'])): self.characters['robots'][i].id = i # Defining course obstacles self.characters['obstacles'] = [ Obstacle(p[0], p[1], p[2]) for p in [(Point(325, 0), 25, 100), ( Point(450, 400), 25, 100), (Point(350, 238), 100, 25), (Point(580, 100), 100, 25), (Point(120, 375), 100, 25), (Point(140, 140), 25, 100), (Point(635, 260), 25, 100)] ] # Team start areas self.starting_zones = [ StartingZone(p[0], p[1]) for p in [(Point(0, 0), BLUE), (Point(700, 0), BLUE), (Point(0, 400), RED), (Point(700, 400), RED)] ] self.defense_buff_zones = [ DefenseBuffZone(p[0], p[1], self) for p in [(Point(120, 275), BLUE), (Point(580, 125), RED)] ] self.loading_zones = [ LoadingZone(p[0], p[1], self) for p in [(Point(350, 400), BLUE), (Point(350, 0), RED)] ] self.characters['zones'] = self.starting_zones + self.defense_buff_zones + \ self.loading_zones if self.rendering: self.init_rendering() elif self.pygame_rendering: self.init_pygame_rendering() # Init movement network G = nx.Graph() # delta declaration at the top of this function self.network_points = [] id = 0 for block in self.characters['obstacles'] + [ self.enemy_team.loading_zone ]: vertices = block.get_vertices() delta_bases = [(-1, -1), (1, -1), (1, 1), (-1, 1)] for i in range(4): delta_x, delta_y = delta_bases[ i] # abs(i - 1.5) // 1.5 * 2 - 1, i // 2 * 2 - 1 delta_x *= delta delta_y *= delta point = vertices[i].move(delta_x, delta_y) if self.is_legal(point): self.network_points.append(point) G.add_node(id) point.id = id id += 1 self.network_edges = [] for i in range(len(self.network_points)): for j in range(i + 1, len(self.network_points)): p_i, p_j = self.network_points[i], self.network_points[j] if p_i.dis(p_j) <= 250 and self.direct_reachable_forward( p_i, p_j, my_robot, ignore_robots=True): self.network_edges.append((p_i, p_j)) G.add_edge(p_i.id, p_j.id, weight=p_i.dis(p_j)) # remove edges that go through enemy loading zone (assign valid edges to appropriate team) # RED.extra_weighted_edge = (0, 8, G[0][8]['weight']) #TODO # BLUE.extra_weighted_edge = (2, 14, G[2][14]['weight']) #TODO # G.remove_edge(0, 8) #TODO # G.remove_edge(2, 14) #TODO self.master_network = G if self.display_visibility_map: for e in self.network_edges: edge = rendering.PolyLine([e[0].to_list(), e[1].to_list()], False) self.viewer.add_geom(edge) for p in self.network_points: geom = rendering.Circle(p, 5) self.viewer.add_geom(geom)
def seed(self, seed=None): self.np_random, seed = seeding.np_random(seed) return [seed] def __init__(self): # Record time self.game_time = 0 self.finished = False """ State: [0]: game_time. Total number of steps elapsed. Equivalent to game_time/50 seconds [1]: number of robots on each team [2-41]: state of 4 robots. non-existant robots are 0 padded. 9 numbers each [2-3]: x, y coord of center of robot [4]: robot angle in degrees [5]: robot gun angle relative to front in degrees [6]: bullet count [7]: remaining number of rounds of shooting cooldown [8]: remaining number of rounds of defense buff [9]: flag=1 if robot is shooting 0 otherwise [10]: remaining health [11]: robot type index [42-51]: state of two defense zones. [42]: flag=1 if can be activated 0 otherwise [43-46]: number of seconds the zone has been touched by each robot [52-57]: state of two loading zones. [52]: number of refills available [53]: number of bullets not yet poured from previous refill [54]: number of bullets loaded into the current robot [58-297]: state of 60 bullets. [58-59]: x, y coord of bullet [60]: direction of bullet in radian [61]: id of bullet's master robot """ self.characters = { "obstacles": [], "zones": [], "robots": [], "bullets": [], } action_space: The Space object corresponding to valid actions observation_space: The Space object corresponding to valid observations reward_range: A tuple corresponding to the min and max possible rewards # Initialize teams BLUE = Team("BLUE", self.pygame_rendering) RED = Team("RED", self.pygame_rendering) BLUE.enemy, RED.enemy = RED, BLUE self.my_team, self.enemy_team = BLUE, RED # Initialize robots my_robot = AttackRobot(self, BLUE, Point(780, 100), 180) # my_robot = AttackRobot(self, BLUE, Point(780, 100), 180) my_robot2 = AttackRobot(self, BLUE, Point(20, 100), 0) enemy_robot = KeyboardRobot("ASDWOPR", self, RED, Point(50, 450), 0) enemy_robot2 = AttackRobot(self, RED, Point(780, 450), 180) # enemy_robot = JoystickRobot(self, RED, Point(50, 450), 0) # my_robot.load(40) enemy_robot.load(40) self.characters['robots'] = [my_robot, enemy_robot] self.characters['robots'] += [my_robot2, enemy_robot2] for i in range(len(self.characters['robots'])): self.characters['robots'][i].id = i # Defining course obstacles self.characters['obstacles'] = [Obstacle(p[0], p[1], p[2]) for p in [(Point(325, 0), 25, 100), (Point(450, 400), 25, 100), (Point(350, 238), 100, 25), (Point(580, 100), 100, 25), (Point(120, 375), 100, 25), (Point(140, 140), 25, 100), (Point(635, 260), 25, 100)]] # Team start areas self.starting_zones = [StartingZone(p[0], p[1]) for p in [(Point(0, 0), BLUE), (Point(700, 0), BLUE), (Point(0, 400), RED), (Point(700, 400), RED)]] self.defense_buff_zones = [DefenseBuffZone(p[0], p[1], self) for p in [ (Point(120, 275), BLUE), (Point(580, 125), RED)]] self.loading_zones = [LoadingZone(p[0], p[1], self) for p in [ (Point(350, 400), BLUE), (Point(350, 0), RED)]] self.characters['zones'] = self.starting_zones + self.defense_buff_zones + \ self.loading_zones if self.rendering: self.init_rendering() elif self.pygame_rendering: self.init_pygame_rendering() # Init movement network G = nx.Graph() delta = 40 self.network_points = [] id = 0 for block in self.characters['obstacles'] + [self.enemy_team.loading_zone]: for i in range(4): delta_x, delta_y = abs(i - 1.5) // 1.5 * 2 - 1, i // 2 * 2 - 1 delta_x *= -delta delta_y *= delta point = block.vertices[i].move(delta_x, delta_y) if self.is_legal(point): self.network_points.append(point) G.add_node(id) point.id = id id += 1 self.network_edges = [] for i in range(len(self.network_points)): for j in range(i + 1, len(self.network_points)): p_i, p_j = self.network_points[i], self.network_points[j] if self.direct_reachable_forward(p_i, p_j, my_robot, True): self.network_edges.append(LineSegment(p_i, p_j)) G.add_edge(p_i.id, p_j.id, weight=p_i.dis(p_j)) self.network = G if self.display_visibility_map: for e in self.network_edges: edge = rendering.PolyLine([e.point_from.to_list(), e.point_to.to_list()], False) self.viewer.add_geom(edge) for p in self.network_points: geom = rendering.Circle(p, 5) self.viewer.add_geom(geom)