def __init__(self, team, name, position=Point(0, 0), bearing=0, timescaled=True): self.team = team self.name = name self.position = position self.bearing = 0 self.left_missile = True self.right_missile = True self.LASER_COOLDOWN = 5 # How many ticks before a laser can be fired again. self.last_laser_world_tick = 0 self.dead = False self.health = 90 # About 3 laser hits self.commands = [] self.score = 0 # Scoring mechanism so that we can track how well an agent is performing in the game. self.timescaled = timescaled # True if the rewards decrease as more time goes by in the simulation. self.discount_factor = 0.9 # Discount factor for rewards occuring in the future (IE: rewards farther away are worth less than immediate rewards) self.rewards = [] # All accumulated rewards self.reward_policy = { ScorableAction.Kamikaze: -6, ScorableAction.TeamLost: -4, ScorableAction.Died: -1, ScorableAction.HitByLaser: -0.33, ScorableAction.FriendlyFire: -4, ScorableAction.LaseredEnemy: 2, ScorableAction.KilledEnemy: 1, ScorableAction.Survived: 4, ScorableAction.TeamWon: 4 } self.WIDTH = 35 self.HEIGHT = 48
def __init__(self, team, name, owner, position=Point(0, 0), bearing=0): self.team = team self.name = name self.owner = owner self.position = position self.bearing = bearing self.damage = 1000 self.dead = False
def process_laser(self, agent, command): agent.last_laser_world_tick = self.world_tick name = 'laser{0}'.format(len(self.lasers) + 1) start_pos = self.relative_position( agent, Point(agent.position.x, (agent.position.y - 20))) laser = Laser(agent.team, name, agent.name, start_pos, agent.bearing) self.lasers.append(laser) agent.command_finished()
def missile_relative_position(self, missile_point): x = missile_point.x y = missile_point.y angle = (self.bearing) * (math.pi / 180) # Convert to radians rotatedX = math.cos(angle) * (x - self.position.x) - math.sin( angle) * (y - self.position.y) + self.position.x rotatedY = math.sin(angle) * (x - self.position.x) + math.cos( angle) * (y - self.position.y) + self.position.y return Point(rotatedX, rotatedY)
def relative_position(self, ship, dst): x = dst.x y = dst.y angle = (ship.bearing) * (math.pi / 180) # Convert to radians rotatedX = math.cos(angle) * (x - ship.position.x) - math.sin( angle) * (y - ship.position.y) + ship.position.x rotatedY = math.sin(angle) * (x - ship.position.x) + math.cos( angle) * (y - ship.position.y) + ship.position.y return Point(rotatedX, rotatedY)
def __init__(self, team, name, position=Point(0, 0), bearing=0): super().__init__(team, name, position, bearing, True) self.num_rounds = 30000 # Number of random simulations so that we can find a good candidate move. self.temperature = 5 # Larger number means more exploration of unvisited nodes, while lower numbers will stick to the best nodes found thus far self.DEBUG = False self.DUMP = True
def right_missile_position(self): if not self.right_missile: return None return self.missile_relative_position( Point(self.position.x + 10, self.position.y + 5))
def left_missile_position(self): if not self.left_missile: return None return self.missile_relative_position( Point(self.position.x - 10, self.position.y + 5))
def get_center_point(self, row, col): x = (col * self.cell_size) - (self.cell_size / 2.0) y = (row * self.cell_size) - (self.cell_size / 2.0) return Point(x, y)
def __init__(self, team, name, position=Point(0, 0), bearing=0): super().__init__(team, name, position, bearing)