def test_can_add_round(self): """ Test that: 1. We have not exceeded the total rounds for this battle 2. All combatants are alive 3. No combatant can attack the same target twice in a row """ with LogCapture(): logger = logging.getLogger() battle = Battle(log=logger, total_rounds=1) battlemaster = Battlemaster() unit_charlie = self._make_unit(is_player=True, level=99) unit_omega = self._make_unit(is_player=True, level=13) battle.add_combatant(combatant=unit_charlie) battle.add_combatant(combatant=unit_omega) # Make sure battle was added battlemaster.add_battle(battle=battle) # Target's Scissors cut Attacker's Paper attacker_weapon = self._make_item(item_type="lizard") target_weapon = self._make_item(item_type="spock") unit_charlie.equip_item(item=attacker_weapon) unit_omega.equip_item(item=target_weapon) """ Sunny day scenario """ can_add_round = battle.can_add_round(attacker=unit_charlie, target=unit_omega) self.assertTrue(can_add_round) """ Test that we cannot exceed total rounds """ dungeon = self._make_dungeon() battle.start_round(battle=battle, ircutils="quux", ircmsgs="quux", irc="quux", dungeon=dungeon) self.assertEqual(len(battle.rounds), 1) # Swap combatant order so it is someone else's turn battle.combatants = list(reversed(battle.combatants)) cannot_exceed_rounds_error = battle.can_add_round(attacker=unit_charlie, target=unit_omega) self.assertEqual(cannot_exceed_rounds_error, "Cannot add round: maximum rounds reached.")
def test_add_battle_with_rounds(self): combatant_1 = self._make_unit(level=13, is_player=False) combatant_2 = self._make_unit(level=13, is_player=False) with LogCapture(): logger = logging.getLogger() battle = Battle(log=logger) battle.add_combatant(combatant_1) battle.add_combatant(combatant_2) self.assertEqual(len(battle.combatants), 2) battlemaster = Battlemaster() battlemaster.add_battle(battle=battle) self.assertEqual(len(battlemaster.battles), 1) actual_1 = battlemaster.get_battle_by_combatant(combatant=combatant_1) self.assertIsNotNone(actual_1) self.assertEqual(battle, actual_1) actual_2 = battlemaster.get_battle_by_combatant(combatant=combatant_2) self.assertIsNotNone(actual_2) self.assertEqual(battle, actual_2) self.assertTrue(combatant_1.is_alive()) self.assertTrue(combatant_2.is_alive()) """ Round 1 """ attacker_weapon = self._make_item(item_type="rock") target_weapon = self._make_item(item_type="scissors") combatant_1.equip_item(item=attacker_weapon) combatant_2.equip_item(item=target_weapon) dungeon = self._make_dungeon() battle.start_round(battle=battle, irc="quux", ircutils="quux", ircmsgs="quux", dungeon=dungeon) self.assertEqual(len(battle.rounds), 1) rounds_won_for_combatant_1 = battle.get_rounds_won( combatant=combatant_1) rounds_won_for_combatant_2 = battle.get_rounds_won( combatant=combatant_2) self.assertEqual(rounds_won_for_combatant_1, 1) self.assertEqual(rounds_won_for_combatant_2, 0) """ Round 2 """ round_2_attacker_weapon = self._make_item(item_type="paper") round_2_target_weapon = self._make_item(item_type="rock") combatant_2.equip_item(item=round_2_attacker_weapon) combatant_1.equip_item(item=round_2_target_weapon) battle.combatants = list(reversed(battle.combatants)) battle.start_round(battle=battle, irc="quux", ircutils="quux", ircmsgs="quux", dungeon=dungeon) self.assertEqual(len(battle.rounds), 2) rounds_won_for_combatant_1 = battle.get_rounds_won( combatant=combatant_1) rounds_won_for_combatant_2 = battle.get_rounds_won( combatant=combatant_2) self.assertEqual(rounds_won_for_combatant_1, 1) self.assertEqual(rounds_won_for_combatant_2, 1) """ Round 3 """ round_3_attacker_weapon = self._make_item(item_type="lizard") round_3_target_weapon = self._make_item(item_type="spock") combatant_1.equip_item(item=round_3_attacker_weapon) combatant_2.equip_item(item=round_3_target_weapon) battle.combatants = list(reversed(battle.combatants)) battle.start_round(battle=battle, irc="quux", ircutils="quux", ircmsgs="quux", dungeon=dungeon) self.assertEqual(len(battle.rounds), 3) rounds_won_for_combatant_1 = battle.get_rounds_won( combatant=combatant_1) rounds_won_for_combatant_2 = battle.get_rounds_won( combatant=combatant_2) self.assertEqual(rounds_won_for_combatant_1, 2) self.assertEqual(rounds_won_for_combatant_2, 1) """ Make sure we can't exceed max rounds """ cannot_add_round_reason = battle.can_add_round(attacker=combatant_1, target=combatant_2) self.assertEqual(cannot_add_round_reason, "Cannot add round: maximum rounds reached.") self.assertEqual(len(battle.rounds), 3)