Advertisement
DeepseaDarew

Darew's Ursarctic Deck Consistency

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