Dessyreqt icon

Magic Combo Deck Tester

Dessyreqt | PRO | 02/21/13 08:57:46 PM UTC | 0 ⭐ | 386 👁️ | Never ⏰ | []
Python |

10.78 KB

|

None

|

0 👍

/

0 👎

import numpy
import random
import itertools
import math
import sys
import time
 
 
#--------------------------------R, G, B, AnyColour, Colourless, LED----------------------#
Handsize = 4
Totalresults = numpy.array([0,0])
#--------------------------------Defining Cards--------------------------------#
class Blank():
    DCC=0
    CDDC=0
    nColour=0
    nCC=0
    
class ESG():
    DCC=0
    CDDC=0
    nColour=1                                                           #Number of colours. Manamorphose is 2 colours for instance#
    Colour = numpy.array([[0,1,0,0,0,0]])                               #Vector for colours. The numbers are R, G, B, AnyColour, Colourless, LED#
    nCC=1                                                               #Number of casting costs. Pyretic has a lot of different ways to cast for instance#
    CC = numpy.array([[0,0,0,0,0,0]])                                   #Casting costs themselves#
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):#Resolving the card#
        CardsOut = CardsIn[:]                                           #Copy the incoming cards#
        CardsOut[x]= Blank()                                            #Replace the spot of the card that's being cast with a Blank#                           
        ManapoolOut = numpy.add(ManapoolIn, ([0,1,0,0,0,0]))            #Calculate new manapool#                        
        Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)          #Play rest of the hand#                                                         
        
class SSG():
    DCC=0
    CDDC=0
    nColour=1
    Colour= numpy.array([[1,0,0,0,0,0]])
    nCC=1
    CC = numpy.array([[0,0,0,0,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        CardsOut = CardsIn[:]
        CardsOut[x]= Blank()                                                                
        ManapoolOut = numpy.add(ManapoolIn, ([1,0,0,0,0,0]))                                    
        Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)  
        
class Petal():
    DCC=0
    CDDC=0
    nColour=0
    nCC=1
    CC= numpy.array([[0,0,0,0,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        CardsOut = CardsIn[:]
        CardsOut[x]= Blank()                                                                
        ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,1,0,0]))                                    
        Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)
        
 
class CRit():
    DCC=0
    CDDC=0
    nColour=1
    Colour= numpy.array([[0,0,1,0,0,0]])
    nCC=9
    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]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        CardsOut = CardsIn[:]
        CardsOut[x]= Blank()                                                                
        ManapoolOut = numpy.add(ManapoolIn, ([0,0,3,0,0,0]))                                    
        Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)  
        
class DRit():
    DCC=0
    CDDC=0
    nColour=1
    Colour= numpy.array([[0,0,1,0,0,0]])
    nCC=2
    CC= numpy.array([[0,0,1,0,0,0], [0,0,0,1,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        CardsOut = CardsIn[:]
        CardsOut[x]= Blank()                                                                
        ManapoolOut = numpy.add(ManapoolIn, ([0,0,3,0,0,0]))                                    
        Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)          
        
class LED():
    DCC=0
    CDDC=0
    nColour=0
    nCC=1
    CC= numpy.array([[0,0,0,0,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        CardsOut = CardsIn[:]
        CardsOut[x]= Blank()                                                                
        ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,0,0,3]))                                    
        Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)
 
 
class Chrome():
    DCC=0
    CDDC=0
    nColour=0
    nCC=1
    CC= numpy.array([[0,0,0,0,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):   
        for i in range (Handsize):
            for j in range (CardsIn[i].nColour):
                CardsOut = CardsIn[:]
                CardsOut[x]= Blank()
                CardsOut[i]= Blank()
                ManapoolOut = numpy.add(ManapoolIn, CardsIn[i].Colour[j,:])                                 
                Play(CardsOut, ManapoolOut, CantripsIn, DCCIn+CardsIn[i].DCC, CDDCIn+CardsIn[i].CDDC)
        
 
class Pact(): #Approximation#
    DCC=0
    CDDC=0
    nColour=1
    Colour = numpy.array([[0,1,0,0,0,0]])
    nCC=1
    CC= numpy.array([[0,0,0,0,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        CardsOut = CardsIn[:]
        ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,0,0,0]))
        CardsOut[x]=ESG()
        Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)
        CardsOut[x]=Cantor()
        Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)
        
class Probe():
    nColour=0   #Approximation is made#
    nCC=1
    CC= numpy.array([[0,0,0,0,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        CardsOut = CardsIn[:]
        CardsOut[x]= Selector(Shuffle[Handsize+CantripsIn])                                                             
        ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,0,0,0]))                                    
        Play(CardsOut, ManapoolOut, CantripsIn+1, DCCIn, CDDCIn)
        
class Manamorphose():
    DCC=0
    CDDC=0
    nColour=2
    Colour = numpy.array([[1,0,0,0,0,0], [0,1,0,0,0,0]])
    nCC=12
    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]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        CardsOut = CardsIn[:]
        CardsOut[x]= Selector(Shuffle[Handsize+CantripsIn])                                                             
        ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,2,0,0]))                                    
        Play(CardsOut, ManapoolOut, CantripsIn+1, DCCIn, CDDCIn)
 
class Cantor():
    DCC=0
    CDDC=0
    nColour=2
    Colour = numpy.array([[1,0,0,0,0,0], [0,1,0,0,0,0]])
    nCC=3
    CC= numpy.array([[1,0,0,0,0,0], [0,1,0,0,0,0], [0,0,0,1,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        CardsOut = CardsIn[:]
        CardsOut[x]= Blank()                                                                
        ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,1,0,0]))                                    
        Play(CardsOut, ManapoolOut, CantripsIn, DCCIn, CDDCIn)
        
class Spy():
    DCC=0
    CDDC=0
    nColour=1
    Colour = numpy.array([[0,0,1,0,0,0]])
    nCC=2
    CC= numpy.array([[0,0,1,0,0,0], [0,0,0,1,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        global Results
        if TotalMana(ManapoolIn)> 2:
            if DCCIn<6:
                if CDDCIn<1:
                    Results = numpy.add(Results, ([1,0]))
            
            
class Informer():
    DCC=0
    CDDC=0
    nColour=1
    Colour = numpy.array([[0,0,1,0,0,0]])
    nCC=2
    CC= numpy.array([[0,0,1,0,0,0], [0,0,0,1,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        global Results
        if TotalMana(ManapoolIn)> 2:
            if DCCIn<6:
                if CDDCIn<1:
                    Results = numpy.add(Results, ([1,0]))
        elif TotalMana(ManapoolIn)> 1 and ManapoolIn[5]>0:
            if DCCIn<6:
                if CDDCIn<1:
                    Results = numpy.add(Results, ([1,0]))
class Wish():
    DCC=0
    CDDC=0
    nColour=1
    Colour = numpy.array([[0,0,1,0,0,0]])
    nCC=2
    CC= numpy.array([[1,0,0,0,0,0], [0,0,0,1,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        global Results
        if (TotalMana(ManapoolIn)+ManapoolIn[5])>4:
            if TotalMana(ManapoolIn)>1:
                if ManapoolIn[2]>0 or ManapoolIn[3]>0 or ManapoolIn[5]>0:
                    if DCCIn<6:
                        if CDDCIn<1:
                            Results = numpy.add(Results, ([1,0]))
 
class Belcher():    
    DCC=0
    CDDC=0
    nColour=0
    nCC=1
    CC= numpy.array([[0,0,0,0,0,0]])
    def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, DCCIn, CDDCIn):
        global Results
        if TotalMana(ManapoolIn)> 3:
            Results = numpy.add(Results, ([0,1]))
            if (TotalMana(ManapoolIn)+ManapoolIn[5])>6:
                Results = numpy.add(Results, ([1,0]))
 
class Moeba():
    DCC=3
    CDDC=0
    nColour=1
    Colour = numpy.array([[0,0,0,0,1,0]])
    nCC=0
 
class DReturn():
    DCC=2
    CDDC=1
    nColour=1
    Colour = numpy.array([[0,0,1,0,0,0]])
    nCC=0
    
class Bridge():
    DCC=2
    CDDC=0
    nColour=1
    Colour = numpy.array([[0,0,1,0,0,0]])
    nCC=0
    
class Annex():
    DCC=0
    CDDC=0
    nColour=1
    Colour = numpy.array([[0,0,0,0,1,0]])
    nCC=0   
    
class Creature():
    DCC=2
    CDDC=1
    nColour=1
    Colour = numpy.array([[0,0,0,0,1,0]])
    nCC=0
 
class Therapy():
    DCC=2
    CDDC=0
    nColour=1
    Colour = numpy.array([[0,0,1,0,0,0]])
    nCC=0
        
#------------------------------------------------------------------------------#
def Selector(x):   #Decklist goes here. This function takes a number and returns a card class#
    if x==0 or x==1 or x==2 or x==3:
        return CRit()
    elif x==4 or x==5 or x==6 or x==7:
        return DRit()
    elif x==8 or x==9 or x==10 or x==11:
        return Chrome()
    elif x==12 or x==13 or x==14 or x==15:
        return Petal()
    elif x==16 or x==17 or x==18 or x==19:
        return SSG()
    elif x==20 or x==21 or x==22 or x==23:
        return Pact()
    elif x==24 or x==25 or x==26 or x==27:
        return Annex()
    elif x==28 or x==29 or x==30 or x==31:
        return Manamorphose()
    elif x==32 or x==33 or x==34 or x==35:
        return ESG()
    elif x==36:
        return Cantor()
    elif x==37 or x==38 or x==39 or x==40:
        return Spy()
    elif x==41 or x==42 or x==43 or x==44:
        return Informer()
    elif x==45 or x==46 or x==47 or x==48:
        return Probe()
    elif x==49:
        return Creature()
    elif x==50 or x==51:
        return Therapy()
    elif x==52 or x==53 or x==54 or x==55:
        return Moeba()
    elif x==56 or x==57:
        return Creature()
    elif x==58:
        return Bridge()
    elif x==59:
        return DReturn()
    elif x==60:
        return Blank()
        
def CompareCost(CastingCost, Manapool):                                 #Checks if we can pay a manacost of a card#
    for i in range(6):      
        if (Manapool[i]-CastingCost[i])<0:
            return 0
    return 1
            
def TotalMana(Manapool):                                            #Needs editing when Black is included. This function makes calculating if we can cast EtW/Belcher a little easier#
    Totalmana = 0
    for i in range (5):
        Totalmana = Totalmana + Manapool[i]
    return Totalmana
        
 
def Play(Cards, Manapool, Cantrips, DCC, CDDC):
    for i in range (Handsize):                                                              #Loop over cards in hand#               
        for j in range (Cards[i].nCC):                                                      #Loop over possible mana costs# 
            if CompareCost(Cards[i].CC[j,:], Manapool)==1:                                  #Check if we can cast card i with manacost j#   
                Cards[i].resolve(numpy.subtract(Manapool, Cards[i].CC[j,:]), Cards, i, Cantrips, DCC, CDDC)     #Subtract manacost and resolve card#        
                                                                                        
#------------------------------------------------------------------------------#
start_time = time.time()                                #This counts the time the whole scripts take#
for i in range(10000):                                  #Amount of times we run a hand#
    Results = numpy.array([0,0])                        #Vector that keeps count of the result of a goldfish. Numbers mean: BelcherWin, EtW 12+, EtW12-, DropBelcher#
    Shuffle = numpy.random.permutation(60)
    Hand=[None]*(Handsize)
    
 
 
    for j in range (Handsize):                          #Fill hand with shuffled cards#
        Hand[j]=Selector(Shuffle[j])
    
    #print " ".join(x.__class__.__name__ for x in Hand)
    #print Selector(Shuffle[7]).__class__.__name__
    #print Selector(Shuffle[8]).__class__.__name__
    #print Selector(Shuffle[9]).__class__.__name__
    print i
    
    Play(Hand, numpy.array([0,0,0,0,0,0]),0,0,0)    #Here we start casting#
 
    for j in range (2):                             #Here we figure out if our hand won, and if it did, how#
        if Results[j]>0:
            Totalresults[j]=Totalresults[j]+1
            break
    
print Totalresults
elapsed_time = time.time() - start_time
print "Elapsed time:", elapsed_time

Comments

  •  icon
    01/01/70 12:00:00 AM UTC
    Plain Text |

    0 B

    |

    👍

    /

    👎