TheCDC

MTG Tron land probability

Jul 15th, 2017
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.24 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. """What is the probability of assembling Tron on the play?
  3. Given: deck contains the max of 4 copies of each land.
  4. We get a total of 3 turns, drawing two cards in the process.
  5. That means we see exactly 9 cards naturally.
  6. """
  7. import random
  8.  
  9. TRON_LANDS = set("abc")  # one letter per tron land
  10.  
  11.  
  12. def deck():
  13.     d = []
  14.     for l in TRON_LANDS:
  15.         d.extend([l for i in range(4)])
  16.     d.extend([0 for i in range(60 - len(d))])
  17.  
  18.     assert len(d) == 60, "Deck size sanity check"
  19.     return d
  20.  
  21.  
  22. def main():
  23.     d = deck()
  24.     trials = 1000000
  25.     num_successful_games = 0
  26.     # d = ["a", "b", "c"]
  27.     for i in range(trials):
  28.         random.shuffle(d)
  29.  
  30.         hand = d[:9]  # 9 cards because that's how many we get in 3 turns on the play
  31.         overlap = len(TRON_LANDS.intersection(set(hand)))
  32.         if overlap == len(TRON_LANDS):
  33.             num_successful_games += 1
  34.             # print(hand)
  35.     print("Ratio of successful games = {}/{} = {}".format(num_successful_games,
  36.                                                           trials, num_successful_games / trials))
  37.     """Example output:
  38.    Ratio of successful games = 96095/1000000 = 0.096095
  39.     """
  40.  
  41. if __name__ == '__main__':
  42.     main()
Add Comment
Please, Sign In to add comment