def _get_next_states_when_ordering_blockers(self, state): unordered_combat_assignment = state.battleground.get_combat_assignment() mappings_generator = \ combinatorics.get_all_shuffled_mappings(unordered_combat_assignment) for mapping in mappings_generator: combat_assignment = CombatAssignment(mapping) next_state = state.copy() next_state.resolve_combat(combat_assignment) yield next_state
def test_get_all_shuffled_mappings(self): mapping = { 1: (4, ), 2: (5, 6), 3: (7, 8, 9), 4: () } shuffled_mappings = list( combinatorics.get_all_shuffled_mappings(mapping)) self.assertEqual(len(shuffled_mappings), 12) hashable_mappings = [] # Are all mappings unique and valid? for m in shuffled_mappings: self.assertEqual(set(mapping.keys()), set(m.keys())) for key in mapping: self.assertEqual(set(mapping[key]), set(m[key])) items = sorted(m.items()) # Convert each item to something hashable. items = [ (i[0], tuple(i[1])) for i in items ] hashable_mappings.append(tuple(items)) self.assertNoDuplicates(hashable_mappings)