def test_init(): ai0 = aifighter.AIFighter() assert ai0.critters == [] crits = ['crit0', 'crit1', 'crit2'] ai1 = aifighter.AIFighter(crits) assert ai1.critters == ['crit0', 'crit1', 'crit2'] crits.remove('crit2') # make sure it keeps a copy, not the original assert ai1.critters == ['crit0', 'crit1', 'crit2']
def __init__(self, screen, screenDims, ioManager, fighter): self.screen = screen self.screenDims = screenDims self.battleOver = False self.ioManager = ioManager self.battleImgs = ioManager.get_data('battles', 'images') self.battleImgs = self.create_images(self.battleImgs) self.critterImgs = self.create_images(ioManager.get_data('critters', 'images')) aiFighter = aifighter.AIFighter(self.generate_ai_critters()) self.battle = battle.BattleHandler(fighter, aiFighter) self.buttons = [] self.displayOutcome = False self.quit = False self.print_colors() self.step = ('move', 0) self.buttons = self.get_buttons() self.stepFuncs = {'move' : self.select_move, 'target' : self.select_target, 'turn' : self.run_turn, 'end' : self.run_end, 'switch' : self.try_switch, 'enter' : self.try_enter, 'win' : self.back_to_map, 'lose' : self.quit_game} # TODO: make keyMapping global self.keyMapping = {pygame.K_1 : 1, pygame.K_2 : 2, pygame.K_3 : 3, pygame.K_4 : 4, pygame.K_5 : 5, pygame.K_6 : 6}
def create_fighter(className): if className == 'ai': with patch('madness.critter.Critter'): return aifighter.AIFighter() else: with patch('madness.critter.Critter'): return fighter.Fighter('ioManager')
def test_get_actions(rangeMock, choiceMock): ai = aifighter.AIFighter() crits = [mock.Mock() for i in range(4)] crits[2].get_move_list.return_value = ['move0', 'move1', 'move2', 'move3'] crits[3].get_move_list.return_value = ['move0', 'move1', 'move2'] choiceMock.return_value = 0 rangeMock.return_value = 1 actions = ai.get_actions(crits) assert actions[0] == (2, 0, 1) assert actions[1] == (3, 0, 1) choiceMock.assert_called_with([0, 1]) rangeMock.assert_any_call(4) rangeMock.assert_any_call(3)
def test_do_switch(rangeMock): ai = aifighter.AIFighter() crit0Mock = mock.Mock() crit0Mock.dead = False crit1Mock = mock.Mock() crit1Mock.dead = False crit2Mock = mock.Mock() crit2Mock.dead = True crit3Mock = mock.Mock() crit3Mock.dead = False ai.critters = [crit0Mock, crit1Mock, crit2Mock, crit3Mock] battleCrits = ['crit0', 'crit1', None, crit1Mock] rangeMock.return_value = 1 assert ai.do_switch(battleCrits) == [crit3Mock] rangeMock.assert_called_with(2) battleCrits = ['crit0', 'crit1', None, None] rangeMock.return_value = 0 assert ai.do_switch(battleCrits) == [crit0Mock, crit1Mock] battleCrits = [None, None, 'crit2', 'crit3'] assert ai.do_switch(battleCrits) == []