Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.26 KB | None | 0 0
  1. def set_pyramids(pyramid, hand):
  2.     ways_to_place = itertools.combinations(hand, 2)
  3.     empty_slots = [
  4.         5 - len(pyramid[0]),
  5.         5 - len(pyramid[1]),
  6.         3 - len(pyramid[2])
  7.     ]
  8.  
  9.     all_pyramids = []
  10.  
  11.     for card_pair in ways_to_place:
  12.         this_hand = list(card_pair)
  13.         # Create placeholder pyramid so we don't alter
  14.         placeholder_pyramid = copy.deepcopy(pyramid)
  15.  
  16.         first_hand_order = copy.deepcopy(this_hand)
  17.  
  18.         for idx, empty in enumerate(empty_slots):
  19.             if empty > 0:
  20.                 for _ in range(empty):
  21.                     placeholder_pyramid[idx].append(first_hand_order.pop())
  22.  
  23.         all_pyramids.append(copy.deepcopy(placeholder_pyramid))
  24.  
  25.         # Create placeholder pyramid so we don't alter
  26.         placeholder_pyramid = copy.deepcopy(pyramid)
  27.         second_hand_order = copy.deepcopy(this_hand)
  28.         # Reverse the list so we append the other possible order
  29.         second_hand_order.reverse()
  30.  
  31.         for idx, empty in enumerate(empty_slots):
  32.             if empty > 0:
  33.                 for _ in range(empty):
  34.                     placeholder_pyramid[idx].append(second_hand_order.pop())
  35.  
  36.         all_pyramids.append(copy.deepcopy(placeholder_pyramid))
  37.  
  38.     return all_pyramids
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement