class PlayerDamage(unittest.TestCase): def setUp(self): self.player = Player('hero') self.enemy = Enemy('wolf') def test_player_attack(self): self.player.attack_enemy(self.enemy) # call the method after that => # (if all steps of this sequence work as expected means test passed successfully) # game -> return enemy.receive_damage(self.attack) -> # -> self.lives=1 - self.attack(damage)=1 => self.lives = 0 -> return self.notify_is_dead() -> # -> (if not self.is_alive()) -> return self.lives>0 -> False => True -> # return f'{self.name} lost' self.assertEqual(self.enemy.lives, 0) # True self.assertEqual(self.enemy.is_alive(), False) # False self.assertEqual(self.enemy.notify_if_dead(), 'wolf lost!') # True
def load_enemies(file): Enemy.query.delete() stat_schema = { "str": 0, "dex": 0, "arm": 0, "weap": 0, "hp": 0, "hp_max": 0, } for row in open(file): if "#" not in row: name, level, exp, strength, dex, arm, weap, hp, hp_max, sprite_pos, desc = row.rstrip( ).split("|") stat_schema["str"], stat_schema["dex"], stat_schema[ "arm"], stat_schema["weap"], stat_schema["hp"], stat_schema[ "hp_max"] = int(strength), int(dex), int(arm), int( weap), int(hp), int(hp_max) new_enemy = Enemy(name=name, level=level, exp=exp, stats=stat_schema.copy(), sprite_pos=sprite_pos, description=desc) db.session.add(new_enemy) db.session.commit() print("ENEMIES!! =============ADDED!")
class TestPlayerDamage(): def setup(self): self.player = Player('hero') self.enemy = Enemy('wolf') @pytest.mark.enemySuite @pytest.mark.playerSuite def test_player_attack(self): self.player.attack_enemy(self.enemy) # call the method after that => # (if all steps of this sequence work as expected means test passed successfully) # game -> return enemy.receive_damage(self.attack) -> # -> self.lives=1 - self.attack(damage)=1 => self.lives = 0 -> return self.notify_is_dead() -> # -> (if not self.is_alive()) -> return self.lives>0 -> False => True -> # return f'{self.name} lost' assert self.enemy.lives == 0 # True assert self.enemy.is_alive() is False # False assert self.enemy.notify_if_dead() == 'wolf lost!' # True
def step(self, action): '''step on action :param action (int): action chosen by the agent :return state (1d array): current state after taking action :return reward (float): constant reward of 1 :return done (bool): if the episode is finished :return info (dict): empty dict ''' if self.done: raise TypeError( 'Unable to step on action since episode is done.. Call reset() to start new episode' ) for event in pygame.event.get(): # Should we add a new enemy? if event.type == self.ADDENEMY: # Create the new enemy, and add it to our sprite groups if len(self.enemies) < self.max_num_enemies: new_enemy = Enemy() self.enemies.add(new_enemy) self.all_sprites.add(new_enemy) # adding a new cloud if event.type == self.ADDCLOUD: if len(self.clouds) < self.max_clouds: new_cloud = Cloud() self.clouds.add(new_cloud) self.all_sprites.add(new_cloud) # Update position of rocket player with action taken self.player.update(action) # Update the position of our enemies and clouds self.enemies.update() self.clouds.update() # background colour self.screen.fill((135, 206, 235)) # Draw all our sprites for entity in self.all_sprites: self.screen.blit(entity.surf, entity.rect) # Check if any enemies have collided with the player if pygame.sprite.spritecollideany(self.player, self.enemies): # If so, remove the player self.player.kill() self.done = True # Ensure we maintain a 30 frames pe second rate #self.clock.tick(1000) curr_state = self.__get_curr_state() reward = 1 info = {} return curr_state, reward, self.done, info
class PlayerDamage(unittest.TestCase): def setUp(self): self.player = Player("Mario") self.enemy = Enemy("Bowser") def test_player_attack(self): result = self.player.attack_enemy(self.enemy) self.assertEqual(self.enemy.lives, 0) self.assertFalse(self.enemy.is_alive()) self.assertEqual(result, "Bowser lost!")
def test_enemy_init(self): e = Enemy("orc") self.assertEqual(e.name, "orc") self.assertEqual(e.lives, 1)
def test_enemy_takes_damage(self): e = Enemy("goblin") e.receive_damage(1) self.assertEqual(e.lives, 0)
def test_enemy_init(self): e = Enemy('orc') assert e.name == 'orc' assert e.lives == 1
def setup(self): self.player = Player('hero') self.enemy = Enemy('wolf')
def test_enemy_takes_damage(self): e = Enemy('goblin') e.receive_damage(1) assert e.lives == 0
def setUp(self): self.player = Player("Mario") self.enemy = Enemy("Bowser")
def test_enemy_init(self): e = Enemy('orc') self.assertEqual(e.name, 'orc') self.assertEqual(e.lives, 1)