def get_score(self): shot = self._get_attr('enemi').shot game = self._get_attr('game') exploded = int(game.exploded) level_cleared = int(not game.levels) SURVIVAL = (self.total_steps - exploded) * float(get_val(os.environ, 'SURVIVAL', '0.00')) score = shot * 0.1 + exploded * -1. + level_cleared * 1. + SURVIVAL return score
def get_action(self, curr_state, valid_actions): if self.method == "eps-greedy": epsilon = get_val(self.kwargs, "epsilon", 0.05) action = self.dqn.get_action(curr_state, valid_actions=valid_actions, method="eps-greedy", epsilon=epsilon) elif self.method == "softmax-entropy": entropy = get_val(self.kwargs, "entropy", 0.2) temperature = estimate_temperature(self.dqn, [curr_state], [valid_actions], entropy=entropy, tol=1e-2) action = self.dqn.get_action( curr_state, valid_actions=valid_actions, method="softmax", temperature=temperature ) elif self.method == "softmax-l2": av = self.dqn.av(curr_state) temperature = get_val(self.kwargs, "temperature", 1.0) temperature *= npla.norm(av) action = self.dqn.get_action( curr_state, valid_actions=valid_actions, method="softmax", temperature=temperature ) return action
def __init__(self, data, pos, aimAt): pygame.sprite.Sprite.__init__(self) self.add(data.bullets) self.add(data.destroyableEntities) # explode bombs it comes into contact with self.image = Bullet.image self.baseImageSize = self.image.get_size() bullet_size = float(get_val(os.environ, "BULLET", 1.0)) self.image = pygame.transform.scale( self.image, (int(self.baseImageSize[0] * bullet_size), int(self.baseImageSize[1] * bullet_size)) ) self.rect = self.image.get_rect(center=pos) self.coords = [float(self.rect.centerx), float(self.rect.centery)] self.angle = self.get_angle(pos, aimAt) sound.play("shoot%s" % (random.randint(1, 2)), 0.4)
def __init__(self, data, topleft, velocity=(0, fallSpeed)): pygame.sprite.Sprite.__init__(self) self.add(data.bombs) self.baseImage = Bomb.baseImage self.baseImageSize = self.baseImage.get_size() bomb_size = int(get_val(os.environ, "BOMB", 1.0)) self.baseImage = pygame.transform.scale( self.baseImage, (self.baseImageSize[0] * bomb_size, self.baseImageSize[1] * bomb_size) ) self.rotation = 0.0 self.rect = self.baseImage.get_rect(topleft=topleft) self.yCoord = topleft[1] # float for accuracy self.fallSpeed = Bomb.fallSpeed self.smoke = SmokeSpawner(data, self.rect.midtop, 2)