def test_get_all_subsets(self): S = [1, 2, 3] subsets = list(combinatorics.get_all_subsets(S)) self.assertEqual(len(subsets), 8) hashable_subsets = [tuple(subset) for subset in subsets] self.assertNoDuplicates(hashable_subsets)
def _get_next_states_when_attacking(self, state): # What creatures can attack? attacking_creature_uids = [] for uid, creature in state.battleground.creatures_with_uids: if (creature.controlling_player == state.attacking_player and not creature.tapped): attacking_creature_uids.append(uid) # Generate all possible attack assignments. subset_generator = \ combinatorics.get_all_subsets(attacking_creature_uids) for attacker_uids in subset_generator: next_state = state.copy() next_state.declare_attackers(attacker_uids) yield next_state