Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def set_pyramids(pyramid, hand):
- ways_to_place = itertools.combinations(hand, 2)
- empty_slots = [
- 5 - len(pyramid[0]),
- 5 - len(pyramid[1]),
- 3 - len(pyramid[2])
- ]
- all_pyramids = []
- for card_pair in ways_to_place:
- this_hand = list(card_pair)
- # Create placeholder pyramid so we don't alter
- placeholder_pyramid = copy.deepcopy(pyramid)
- first_hand_order = copy.deepcopy(this_hand)
- for idx, empty in enumerate(empty_slots):
- if empty > 0:
- for _ in range(empty):
- placeholder_pyramid[idx].append(first_hand_order.pop())
- all_pyramids.append(copy.deepcopy(placeholder_pyramid))
- # Create placeholder pyramid so we don't alter
- placeholder_pyramid = copy.deepcopy(pyramid)
- second_hand_order = copy.deepcopy(this_hand)
- # Reverse the list so we append the other possible order
- second_hand_order.reverse()
- for idx, empty in enumerate(empty_slots):
- if empty > 0:
- for _ in range(empty):
- placeholder_pyramid[idx].append(second_hand_order.pop())
- all_pyramids.append(copy.deepcopy(placeholder_pyramid))
- return all_pyramids
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement