def test_serialization(self):
     """Test repr and from_string methods together."""
     for s in self.SERIALIZATION_FIXTURES:
         self.assertEqual(repr(BattlegroundState.from_string(s)), s,
                          'Invalid deserialize & serialize transformation')
     for _ in range(10):
         state = BattlegroundStateFactory.build_with_creatures(9)
         s = repr(state)
         self.assertEqual(repr(BattlegroundState.from_string(s)), s,
                          'Invalid deserialize & serialize transformation')
Exemple #2
0
 def test_serialization(self):
     """Test repr and from_string methods together."""
     for s in self.SERIALIZATION_FIXTURES:
         self.assertEqual(repr(BattlegroundState.from_string(s)), s,
                          'Invalid deserialize & serialize transformation')
     for _ in range(10):
         state = BattlegroundStateFactory.build_with_creatures(9)
         s = repr(state)
         self.assertEqual(repr(BattlegroundState.from_string(s)), s,
                          'Invalid deserialize & serialize transformation')
    def test_equality_when_different_uids(self):
        """Test equality when creature uids differ."""
        bg1 = BattlegroundState()
        bg2 = BattlegroundState()

        uid1 = bg1.add_creature(CreatureStateFactory())
        bg1.remove_creature(uid1)

        creature_state = CreatureStateFactory()
        bg1.add_creature(creature_state)
        bg2.add_creature(creature_state)

        self.assertEqual(bg1, bg2)
Exemple #4
0
    def test_normalize(self):
        bg = BattlegroundState()
        h1 = bg.normalize()

        uid = bg.add_creature(CreatureStateFactory())
        h2 = bg.normalize()
        self.assertNotEqual(h1, h2)

        bg.remove_creature(uid)
        self.assertEqual(h1, bg.normalize())
Exemple #5
0
    def __init__(self, battleground=None):
        if battleground is None:
            battleground = BattlegroundState()

        self._life1 = 20
        self._life2 = 20
        self.active_player = 0
        self.phase = TurnPhase.DeclareAttackers
        self.battleground = battleground
    def test_get_combat_assignment(self):
        bg = BattlegroundState()

        cr1 = bg.add_creature(CreatureStateFactory())
        cr2 = bg.add_creature(CreatureStateFactory())
        cr3 = bg.add_creature(CreatureStateFactory())
        cr4 = bg.add_creature(CreatureStateFactory())

        bg[cr1].attack()
        bg[cr2].attack()
        bg[cr3].block(cr1)
        bg[cr4].block(cr1)

        combat_assignment = bg.get_combat_assignment()
        self.assertIsInstance(combat_assignment, CombatAssignment)
        self.assertEqual(len(combat_assignment), 2)

        expected_ca = CombatAssignment({cr1: [cr3, cr4], cr2: []})
        self.assertTrue(combat_assignment.is_reorder_of(expected_ca))

        self.assertIsInstance(combat_assignment[cr1], tuple)
    def test_normalize(self):
        bg = BattlegroundState()
        h1 = bg.normalize()

        uid = bg.add_creature(CreatureStateFactory())
        h2 = bg.normalize()
        self.assertNotEqual(h1, h2)

        bg.remove_creature(uid)
        self.assertEqual(h1, bg.normalize())
Exemple #8
0
    def test_get_combat_assignment(self):
        bg = BattlegroundState()

        cr1 = bg.add_creature(CreatureStateFactory())
        cr2 = bg.add_creature(CreatureStateFactory())
        cr3 = bg.add_creature(CreatureStateFactory())
        cr4 = bg.add_creature(CreatureStateFactory())

        bg[cr1].attack()
        bg[cr2].attack()
        bg[cr3].block(cr1)
        bg[cr4].block(cr1)

        combat_assignment = bg.get_combat_assignment()
        self.assertIsInstance(combat_assignment, CombatAssignment)
        self.assertEqual(len(combat_assignment), 2)

        expected_ca = CombatAssignment({cr1: [cr3, cr4], cr2: []})
        self.assertTrue(combat_assignment.is_reorder_of(expected_ca))

        self.assertIsInstance(combat_assignment[cr1], tuple)
Exemple #9
0
    def test_equality_when_different_creature_order(self):
        """Test equality when creatures have been added in different orders."""
        bg1 = BattlegroundState()
        bg2 = BattlegroundState()

        creature_state1 = CreatureStateFactory()
        creature_state2 = CreatureStateFactory()

        bg1.add_creature(creature_state1)
        bg1.add_creature(creature_state2)

        bg2.add_creature(creature_state2)
        bg2.add_creature(creature_state1)

        self.assertEqual(bg1, bg2)
Exemple #10
0
    def from_string(cls, string):
        match = re.match(cls._FROM_STRING_PATTERN, string)
        if not match:
            raise ValueError('Invalid string: %r' % string)
        params = match.groupdict()

        game_state = GameState()
        game_state._life1 = int(params['life1'])
        game_state._life2 = int(params['life2'])
        game_state.active_player = int(params['active_player'])
        game_state.phase = int(params['phase'])
        game_state.battleground = \
            BattlegroundState.from_string(params['battleground'])
        return game_state
Exemple #11
0
    def from_string(cls, string):
        match = re.match(cls._FROM_STRING_PATTERN, string)
        if not match:
            raise ValueError('Invalid string: %r' % string)
        params = match.groupdict()

        game_state = GameState()
        game_state._life1 = int(params['life1'])
        game_state._life2 = int(params['life2'])
        game_state.active_player = int(params['active_player'])
        game_state.phase = int(params['phase'])
        game_state.battleground = \
            BattlegroundState.from_string(params['battleground'])
        return game_state
    def test_equality_when_different_creature_order(self):
        """Test equality when creatures have been added in different orders."""
        bg1 = BattlegroundState()
        bg2 = BattlegroundState()

        creature_state1 = CreatureStateFactory()
        creature_state2 = CreatureStateFactory()

        bg1.add_creature(creature_state1)
        bg1.add_creature(creature_state2)

        bg2.add_creature(creature_state2)
        bg2.add_creature(creature_state1)

        self.assertEqual(bg1, bg2)
Exemple #13
0
    def test_equality_when_different_uids(self):
        """Test equality when creature uids differ."""
        bg1 = BattlegroundState()
        bg2 = BattlegroundState()

        uid1 = bg1.add_creature(CreatureStateFactory())
        bg1.remove_creature(uid1)

        creature_state = CreatureStateFactory()
        bg1.add_creature(creature_state)
        bg2.add_creature(creature_state)

        self.assertEqual(bg1, bg2)