Facebook
From voiceless math, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 217
  1. https://www.online-python.com/online_python_compiler
  2.  
  3. #Yugioh probability estimator that takes Prosperity, Desires, Upstart, Extravagance, Duality into account
  4. #Can copy all this into https://www.online-python.com/online_python_compiler or another online compiler if you don't want to learn how to download python.
  5.  
  6.  
  7. #In input_cards_here: Enter card name *space* quantity, then hit enter. Leave no spaces in card names
  8. #After the quantity, you can write other names the card can by. For instance, things it directly/indirectly searches...
  9. #or something like Monster or TriBrigadeMonster etc if you have some combos that can use any card of that type.
  10. #Certain draw/excavation cards have their effects built in. Write Desires, Prosperity, Extravagance, Upstart, Duality as the names for those cards
  11.  
  12. #For input_possibilities_heare, list the acceptable combinations of cards in hand. Follow the syntax in the example
  13. #For example 2 + A AND 1 - B AND 0 = C means "2 or more of A, 1 or fewer of B, exactly 0 of C
  14. #Instead of 1 + A, you can just write A. So the first line means "1 or more Fluffal and 1 or more Edge and 1 or more poly"
  15. #Each line represents a different acceptable combination of cards in hand
  16.  
  17. #Final line is the number of trials
  18.  
  19. #outputs the estimated probability you get one of these desired combinations
  20.  
  21. deck_size = 43
  22. hand_size = 5
  23. input_cards_here="""
  24. Lo 3
  25. Diviner 3
  26. Saffira 3
  27. Skull 2
  28. Saur 2
  29. BranFu 3
  30. Barrier 3
  31. Preprep 3
  32. Trias 1
  33. """
  34. input_possibilities_here="""
  35. Lo
  36. Diviner
  37. Saffira AND Skull
  38. Skull AND Barrier
  39. Preprep AND Skull
  40. Preprep AND Saffira
  41. Barrier AND Preprep
  42. Barrier AND Saffira
  43. Saffira AND Saur
  44. Preprep AND Saur
  45. Preprep AND Trias
  46. Saffira AND Trias
  47. Barrier AND Trias
  48. Lo AND Trias
  49. Preprep AND Diviner
  50. BranFu AND Preprep
  51. BranFu AND Saffira
  52. BranFu AND Skull
  53. BranFu AND Barrier
  54. """
  55. num_trials=10000
  56.  
  57. #Below is the actual code; can ignore
  58.  
  59.  
  60. from itertools import product
  61. import random
  62. import sys
  63.  
  64. def empty_deck(n):
  65.  deck=[]
  66.  for i in range(0, n):
  67.   deck.append("blank")
  68.  return deck
  69.  
  70.  
  71. def add_card(deck, name, quantity):
  72.  for i in range(0, quantity):
  73.   del deck[0]
  74.   deck.append(name)
  75.  return deck
  76.  
  77. def get_hand(deck, k, num_extras):
  78.  for i in range(0,k+num_extras):
  79.   rand=random.randint(i,len(deck)-1)
  80.   temp=deck[rand]
  81.   deck[rand]=deck[i]
  82.   deck[i]=temp
  83.  hand=[]
  84.  extras=[]
  85.  for i in range(0,k):
  86.   hand.append(deck[i])
  87.  for i in range(k,k+num_extras):
  88.   extras.append(deck[i])
  89.  return([hand,extras])
  90.  
  91. def hand_comb(hand):
  92.  cats=[]
  93.  for c in hand:
  94.   if c!="blank":
  95.    cats.append(card_hash[c])
  96.  return product(*cats)
  97.  
  98.  
  99. def is_valid(hand, condition):
  100.  for cond in condition:
  101.   card=cond[0]
  102.   sign=cond[2]
  103.   num=0
  104.   for c in hand:
  105.    if c==card:
  106.     num+=1
  107.   if num<cond[1] and sign!="-":
  108.    return False
  109.   if num>cond[1] and sign!="+":
  110.    return False
  111.  return True
  112.  
  113. def is_one_valid(hand,possibilities):
  114.  combs = hand_comb(hand)
  115.  for comb in combs:
  116.   for p in possibilities:
  117.    if is_valid(comb,p):
  118.     return True
  119.  return False
  120.  
  121. def is_one_valid_draw(hand,extras,possibilities,can_extrav,can_desires,can_upstart,can_prosperity,can_duality):
  122.  if is_one_valid(hand,possibilities):
  123.   return True
  124.  if can_desires and "Desires" in hand:
  125.   temp_hand=hand.copy()
  126.   temp_extras=extras.copy()
  127.   temp_hand.append(temp_extras.pop())
  128.   temp_hand.append(temp_extras.pop())
  129.   if is_one_valid_draw(temp_hand,temp_extras,possibilities,False,False,can_upstart,False,can_duality):
  130.    return True
  131.  if can_extrav and "Extravagance" in hand:
  132.   temp_hand=hand.copy()
  133.   temp_extras=extras.copy()
  134.   temp_hand.append(temp_extras.pop())
  135.   temp_hand.append(temp_extras.pop())
  136.   if is_one_valid_draw(temp_hand,temp_extras,possibilities,False,False,False,False,can_duality):
  137.    return True
  138.  if can_prosperity and "Prosperity" in hand:
  139.   for i in range(0,6):
  140.    temp_hand=hand.copy()
  141.    temp_extras=extras.copy()
  142.    temp_hand.append(temp_extras[i])
  143.    del temp_extras[0:6]
  144.    if is_one_valid_draw(temp_hand,temp_extras,possibilities,False,False,False,False,can_duality):
  145.     return True
  146.  if can_upstart and "Upstart" in hand:
  147.   temp_hand=hand.copy()
  148.   temp_extras=extras.copy()
  149.   temp_hand.append(temp_extras.pop())
  150.   temp_hand.remove("Upstart")
  151.   if is_one_valid_draw(temp_hand,temp_extras,possibilities,False,can_desires,can_upstart,False,can_duality):
  152.    return True
  153.  if can_duality and "Duality" in hand:
  154.   for i in range(0,3):
  155.    temp_hand=hand.copy()
  156.    temp_extras=extras.copy()
  157.    temp_hand.append(temp_extras[i])
  158.    del temp_extras[0:3]
  159.    if is_one_valid_draw(temp_hand,temp_extras,possibilities,False,can_desires,can_upstart,can_prosperity,False):
  160.     return True
  161.  return False
  162.  
  163. card_hash = dict()
  164. deck=empty_deck(deck_size)
  165. all_cats=[]
  166. deck_count=0
  167. num_extras=0
  168. cardlines=input_cards_here.splitlines()
  169. cardlines.pop(0)
  170. for cardline in cardlines:
  171.  s=cardline.split(" ")
  172.  #catch int error here
  173.  try:
  174.   deck=add_card(deck,s[0],int(s[1]))
  175.  except:
  176.   print("Error in input_cards_here, check line "+cardline)
  177.   sys.exit(0)
  178.  deck_count+=int(s[1])
  179.  all_cats.append(s[0])
  180.  if s[0]=="Upstart":
  181.      num_extras+=int(s[1])
  182.  card_cats=[]
  183.  card_cats.append(s[0])
  184.  for i in range(2, len(s)):
  185.   card_cats.append(s[i])
  186.   if s[i] not in all_cats:
  187.    all_cats.append(s[i])
  188.  card_hash[s[0]]=card_cats
  189. if "Prosperity" in deck or "Extravagance" in deck:
  190.     num_extras+=6
  191. if "Duality" in deck:
  192.     num_extras+=3
  193. if "Desires" in deck:
  194.     num_extras+=2
  195. if deck_count>deck_size:
  196.  print("Inputted cards: "+str(deck_count)+". Exceeds deck size: "+str(deck_size))
  197.  sys.exit(0)
  198.  
  199. possibilities=[]
  200. text_possibilities=input_possibilities_here.splitlines()
  201. text_possibilities.pop(0)
  202. for possibility in text_possibilities:
  203.  if len(possibility)==0:
  204.   continue
  205.  conditions=[]
  206.  text_conditions=possibility.split("AND")
  207.  for condition in text_conditions:
  208.   parts=condition.split()
  209.   if len(parts)==3:
  210.    if parts[2] not in all_cats:
  211.     print("Possibility: " +possibility+ " contains unlisted card or category "+ parts[2])
  212.     sys.exit(0)
  213.    if parts[1] not in ['-','+','='] or not parts[0].isdigit():
  214.     print("Check formatting of line: "+possibility)
  215.     sys.exit(0)
  216.    conditions.append([parts[2],int(parts[0]),parts[1]])
  217.   elif len(parts)==1:
  218.    if parts[0] not in all_cats:
  219.     print("Possibility: " +possibility+ " contains unlisted card or category "+ parts[0])
  220.     sys.exit(0)  
  221.    conditions.append([parts[0], 1, '+'])
  222.   else:
  223.    print("Check formatting of input_possibilities_here, line: "+possibility)
  224.  possibilities.append(conditions)
  225.  
  226. counter=0
  227. for i in range(0,num_trials):
  228.  hand=get_hand(deck,hand_size, num_extras)
  229.  if is_one_valid_draw(hand[0],hand[1],possibilities,True,True,True,True,True):
  230.   counter+=1
  231. print("probability of success: "+ str(counter/num_trials*100)+"%")