Advertisement
Dessyreqt

Magic Combo Deck Tester

Feb 21st, 2013
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.78 KB | None | 0 0
  1. import numpy
  2. import random
  3. import itertools
  4. import math
  5. import sys
  6. import time
  7.  
  8.  
  9. #--------------------------------R, G, B, AnyColour, Colourless, LED----------------------#
  10. Handsize = 4
  11. Totalresults = numpy.array([0,0])
  12. #--------------------------------Defining Cards--------------------------------#
  13. class Blank():
  14.     DCC=0
  15.     CDDC=0
  16.     nColour=0
  17.     nCC=0
  18.    
  19. class ESG():
  20.     DCC=0
  21.     CDDC=0
  22.     nColour=1                                                           #Number of colours. Manamorphose is 2 colours for instance#
  23.     Colour = numpy.array([[0,1,0,0,0,0]])                               #Vector for colours. The numbers are R, G, B, AnyColour, Colourless, LED#
  24.     nCC=1                                                               #Number of casting costs. Pyretic has a lot of different ways to cast for instance#
  25.     CC = numpy.array([[0,0,0,0,0,0]])                                   #Casting costs themselves#
  26.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):#Resolving the card#
  27.         CardsOut = CardsIn[:]                                           #Copy the incoming cards#
  28.         CardsOut[x]= Blank()                                            #Replace the spot of the card that's being cast with a Blank#                          
  29.         ManapoolOut = numpy.add(ManapoolIn, ([0,1,0,0,0,0]))            #Calculate new manapool#                       
  30.         Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)          #Play rest of the hand#                                                        
  31.        
  32. class SSG():
  33.     DCC=0
  34.     CDDC=0
  35.     nColour=1
  36.     Colour= numpy.array([[1,0,0,0,0,0]])
  37.     nCC=1
  38.     CC = numpy.array([[0,0,0,0,0,0]])
  39.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  40.         CardsOut = CardsIn[:]
  41.         CardsOut[x]= Blank()                                                               
  42.         ManapoolOut = numpy.add(ManapoolIn, ([1,0,0,0,0,0]))                                   
  43.         Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn) 
  44.        
  45. class Petal():
  46.     DCC=0
  47.     CDDC=0
  48.     nColour=0
  49.     nCC=1
  50.     CC= numpy.array([[0,0,0,0,0,0]])
  51.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  52.         CardsOut = CardsIn[:]
  53.         CardsOut[x]= Blank()                                                               
  54.         ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,1,0,0]))                                   
  55.         Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)
  56.        
  57.  
  58. class CRit():
  59.     DCC=0
  60.     CDDC=0
  61.     nColour=1
  62.     Colour= numpy.array([[0,0,1,0,0,0]])
  63.     nCC=9
  64.     CC= numpy.array([[1,0,1,0,0,0], [0,1,1,0,0,0], [0,0,2,0,0,0], [0,0,1,1,0,0], [0,0,1,0,1,0], [1,0,0,1,0,0], [0,1,0,1,0,0], [0,0,0,1,1,0], [0,0,0,2,0,0]])
  65.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  66.         CardsOut = CardsIn[:]
  67.         CardsOut[x]= Blank()                                                               
  68.         ManapoolOut = numpy.add(ManapoolIn, ([0,0,3,0,0,0]))                                   
  69.         Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn) 
  70.        
  71. class DRit():
  72.     DCC=0
  73.     CDDC=0
  74.     nColour=1
  75.     Colour= numpy.array([[0,0,1,0,0,0]])
  76.     nCC=2
  77.     CC= numpy.array([[0,0,1,0,0,0], [0,0,0,1,0,0]])
  78.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  79.         CardsOut = CardsIn[:]
  80.         CardsOut[x]= Blank()                                                               
  81.         ManapoolOut = numpy.add(ManapoolIn, ([0,0,3,0,0,0]))                                   
  82.         Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)         
  83.        
  84. class LED():
  85.     DCC=0
  86.     CDDC=0
  87.     nColour=0
  88.     nCC=1
  89.     CC= numpy.array([[0,0,0,0,0,0]])
  90.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  91.         CardsOut = CardsIn[:]
  92.         CardsOut[x]= Blank()                                                               
  93.         ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,0,0,3]))                                   
  94.         Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)
  95.  
  96.  
  97. class Chrome():
  98.     DCC=0
  99.     CDDC=0
  100.     nColour=0
  101.     nCC=1
  102.     CC= numpy.array([[0,0,0,0,0,0]])
  103.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):  
  104.         for i in range (Handsize):
  105.             for j in range (CardsIn[i].nColour):
  106.                 CardsOut = CardsIn[:]
  107.                 CardsOut[x]= Blank()
  108.                 CardsOut[i]= Blank()
  109.                 ManapoolOut = numpy.add(ManapoolIn, CardsIn[i].Colour[j,:])                                
  110.                 Play(CardsOut, ManapoolOut, CantripsIn, DCCIn+CardsIn[i].DCC, CDDCIn+CardsIn[i].CDDC)
  111.        
  112.  
  113. class Pact(): #Approximation#
  114.     DCC=0
  115.     CDDC=0
  116.     nColour=1
  117.     Colour = numpy.array([[0,1,0,0,0,0]])
  118.     nCC=1
  119.     CC= numpy.array([[0,0,0,0,0,0]])
  120.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  121.         CardsOut = CardsIn[:]
  122.         ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,0,0,0]))
  123.         CardsOut[x]=ESG()
  124.         Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)
  125.         CardsOut[x]=Cantor()
  126.         Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)
  127.        
  128. class Probe():
  129.     nColour=0   #Approximation is made#
  130.     nCC=1
  131.     CC= numpy.array([[0,0,0,0,0,0]])
  132.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  133.         CardsOut = CardsIn[:]
  134.         CardsOut[x]= Selector(Shuffle[Handsize+CantripsIn])                                                            
  135.         ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,0,0,0]))                                   
  136.         Play(CardsOut, ManapoolOut, CantripsIn+1, DCCIn, CDDCIn)
  137.        
  138. class Manamorphose():
  139.     DCC=0
  140.     CDDC=0
  141.     nColour=2
  142.     Colour = numpy.array([[1,0,0,0,0,0], [0,1,0,0,0,0]])
  143.     nCC=12
  144.     CC= numpy.array([[2,0,0,0,0,0], [1,1,0,0,0,0], [1,0,1,0,0,0], [1,0,0,1,0,0], [1,0,0,0,1,0], [0,1,1,0,0,0], [0,1,0,1,0,0], [0,1,0,0,1,0], [0,2,0,0,0,0], [0,0,0,2,0,0], [0,0,0,1,1,0], [0,0,1,1,0,0]])
  145.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  146.         CardsOut = CardsIn[:]
  147.         CardsOut[x]= Selector(Shuffle[Handsize+CantripsIn])                                                            
  148.         ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,2,0,0]))                                   
  149.         Play(CardsOut, ManapoolOut, CantripsIn+1, DCCIn, CDDCIn)
  150.  
  151. class Cantor():
  152.     DCC=0
  153.     CDDC=0
  154.     nColour=2
  155.     Colour = numpy.array([[1,0,0,0,0,0], [0,1,0,0,0,0]])
  156.     nCC=3
  157.     CC= numpy.array([[1,0,0,0,0,0], [0,1,0,0,0,0], [0,0,0,1,0,0]])
  158.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  159.         CardsOut = CardsIn[:]
  160.         CardsOut[x]= Blank()                                                               
  161.         ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,1,0,0]))                                   
  162.         Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)
  163.        
  164. class Spy():
  165.     DCC=0
  166.     CDDC=0
  167.     nColour=1
  168.     Colour = numpy.array([[0,0,1,0,0,0]])
  169.     nCC=2
  170.     CC= numpy.array([[0,0,1,0,0,0], [0,0,0,1,0,0]])
  171.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  172.         global Results
  173.         if TotalMana(ManapoolIn)> 2:
  174.             if DCCIn<6:
  175.                 if CDDCIn<1:
  176.                     Results = numpy.add(Results, ([1,0]))
  177.            
  178.            
  179. class Informer():
  180.     DCC=0
  181.     CDDC=0
  182.     nColour=1
  183.     Colour = numpy.array([[0,0,1,0,0,0]])
  184.     nCC=2
  185.     CC= numpy.array([[0,0,1,0,0,0], [0,0,0,1,0,0]])
  186.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  187.         global Results
  188.         if TotalMana(ManapoolIn)> 2:
  189.             if DCCIn<6:
  190.                 if CDDCIn<1:
  191.                     Results = numpy.add(Results, ([1,0]))
  192.         elif TotalMana(ManapoolIn)> 1 and ManapoolIn[5]>0:
  193.             if DCCIn<6:
  194.                 if CDDCIn<1:
  195.                     Results = numpy.add(Results, ([1,0]))
  196. class Wish():
  197.     DCC=0
  198.     CDDC=0
  199.     nColour=1
  200.     Colour = numpy.array([[0,0,1,0,0,0]])
  201.     nCC=2
  202.     CC= numpy.array([[1,0,0,0,0,0], [0,0,0,1,0,0]])
  203.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  204.         global Results
  205.         if (TotalMana(ManapoolIn)+ManapoolIn[5])>4:
  206.             if TotalMana(ManapoolIn)>1:
  207.                 if ManapoolIn[2]>0 or ManapoolIn[3]>0 or ManapoolIn[5]>0:
  208.                     if DCCIn<6:
  209.                         if CDDCIn<1:
  210.                             Results = numpy.add(Results, ([1,0]))
  211.  
  212. class Belcher():   
  213.     DCC=0
  214.     CDDC=0
  215.     nColour=0
  216.     nCC=1
  217.     CC= numpy.array([[0,0,0,0,0,0]])
  218.     def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
  219.         global Results
  220.         if TotalMana(ManapoolIn)> 3:
  221.             Results = numpy.add(Results, ([0,1]))
  222.             if (TotalMana(ManapoolIn)+ManapoolIn[5])>6:
  223.                 Results = numpy.add(Results, ([1,0]))
  224.  
  225. class Moeba():
  226.     DCC=3
  227.     CDDC=0
  228.     nColour=1
  229.     Colour = numpy.array([[0,0,0,0,1,0]])
  230.     nCC=0
  231.  
  232. class DReturn():
  233.     DCC=2
  234.     CDDC=1
  235.     nColour=1
  236.     Colour = numpy.array([[0,0,1,0,0,0]])
  237.     nCC=0
  238.    
  239. class Bridge():
  240.     DCC=2
  241.     CDDC=0
  242.     nColour=1
  243.     Colour = numpy.array([[0,0,1,0,0,0]])
  244.     nCC=0
  245.    
  246. class Annex():
  247.     DCC=0
  248.     CDDC=0
  249.     nColour=1
  250.     Colour = numpy.array([[0,0,0,0,1,0]])
  251.     nCC=0  
  252.    
  253. class Creature():
  254.     DCC=2
  255.     CDDC=1
  256.     nColour=1
  257.     Colour = numpy.array([[0,0,0,0,1,0]])
  258.     nCC=0
  259.  
  260. class Therapy():
  261.     DCC=2
  262.     CDDC=0
  263.     nColour=1
  264.     Colour = numpy.array([[0,0,1,0,0,0]])
  265.     nCC=0
  266.        
  267. #------------------------------------------------------------------------------#
  268. def Selector(x):   #Decklist goes here. This function takes a number and returns a card class#
  269.     if x==0 or x==1 or x==2 or x==3:
  270.         return CRit()
  271.     elif x==4 or x==5 or x==6 or x==7:
  272.         return DRit()
  273.     elif x==8 or x==9 or x==10 or x==11:
  274.         return Chrome()
  275.     elif x==12 or x==13 or x==14 or x==15:
  276.         return Petal()
  277.     elif x==16 or x==17 or x==18 or x==19:
  278.         return SSG()
  279.     elif x==20 or x==21 or x==22 or x==23:
  280.         return Pact()
  281.     elif x==24 or x==25 or x==26 or x==27:
  282.         return Annex()
  283.     elif x==28 or x==29 or x==30 or x==31:
  284.         return Manamorphose()
  285.     elif x==32 or x==33 or x==34 or x==35:
  286.         return ESG()
  287.     elif x==36:
  288.         return Cantor()
  289.     elif x==37 or x==38 or x==39 or x==40:
  290.         return Spy()
  291.     elif x==41 or x==42 or x==43 or x==44:
  292.         return Informer()
  293.     elif x==45 or x==46 or x==47 or x==48:
  294.         return Probe()
  295.     elif x==49:
  296.         return Creature()
  297.     elif x==50 or x==51:
  298.         return Therapy()
  299.     elif x==52 or x==53 or x==54 or x==55:
  300.         return Moeba()
  301.     elif x==56 or x==57:
  302.         return Creature()
  303.     elif x==58:
  304.         return Bridge()
  305.     elif x==59:
  306.         return DReturn()
  307.     elif x==60:
  308.         return Blank()
  309.        
  310. def CompareCost(CastingCost, Manapool):                                 #Checks if we can pay a manacost of a card#
  311.     for i in range(6):     
  312.         if (Manapool[i]-CastingCost[i])<0:
  313.             return 0
  314.     return 1
  315.            
  316. def TotalMana(Manapool):                                            #Needs editing when Black is included. This function makes calculating if we can cast EtW/Belcher a little easier#
  317.     Totalmana = 0
  318.     for i in range (5):
  319.         Totalmana = Totalmana + Manapool[i]
  320.     return Totalmana
  321.        
  322.  
  323. def Play(Cards, Manapool, Cantrips, DCC, CDDC):
  324.     for i in range (Handsize):                                                              #Loop over cards in hand#              
  325.         for j in range (Cards[i].nCC):                                                      #Loop over possible mana costs#
  326.             if CompareCost(Cards[i].CC[j,:], Manapool)==1:                                  #Check if we can cast card i with manacost j#  
  327.                 Cards[i].resolve(numpy.subtract(Manapool, Cards[i].CC[j,:]), Cards, i, Cantrips, DCC, CDDC)     #Subtract manacost and resolve card#       
  328.                                                                                        
  329. #------------------------------------------------------------------------------#
  330. start_time = time.time()                                #This counts the time the whole scripts take#
  331. for i in range(10000):                                  #Amount of times we run a hand#
  332.     Results = numpy.array([0,0])                        #Vector that keeps count of the result of a goldfish. Numbers mean: BelcherWin, EtW 12+, EtW12-, DropBelcher#
  333.     Shuffle = numpy.random.permutation(60)
  334.     Hand=[None]*(Handsize)
  335.    
  336.  
  337.  
  338.     for j in range (Handsize):                          #Fill hand with shuffled cards#
  339.         Hand[j]=Selector(Shuffle[j])
  340.    
  341.     #print " ".join(x.__class__.__name__ for x in Hand)
  342.     #print Selector(Shuffle[7]).__class__.__name__
  343.     #print Selector(Shuffle[8]).__class__.__name__
  344.     #print Selector(Shuffle[9]).__class__.__name__
  345.     print i
  346.    
  347.     Play(Hand, numpy.array([0,0,0,0,0,0]),0,0,0)    #Here we start casting#
  348.  
  349.     for j in range (2):                             #Here we figure out if our hand won, and if it did, how#
  350.         if Results[j]>0:
  351.             Totalresults[j]=Totalresults[j]+1
  352.             break
  353.    
  354. print Totalresults
  355. elapsed_time = time.time() - start_time
  356. print "Elapsed time:", elapsed_time
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement