import numpy
import random
import itertools
import math
import sys
import time
#--------------------------------R, G, AnyColour, LED----------------------#
Handsize = 4
Totalresults = numpy.array([0,0,0,0])
#--------------------------------Defining Cards--------------------------------#
class Blank():
nColour=0
nCC=0
class ESG():
nColour=1 #Number of colours. Manamorphose is 2 colours for instance#
Colour = numpy.array([[0,1,0,0]]) #Vector for colours. The numbers are R, G, AnyColour, 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]]) #Casting costs themselves#
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):#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])) #Calculate new manapool#
Play(CardsOut, ManapoolOut, CantripsIn, RiteIn, StormIn, GrantIn)#Play rest of the hand#
class SSG():
nColour=1
Colour= numpy.array([[1,0,0,0]])
nCC=1
CC = numpy.array([[0,0,0,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
CardsOut = CardsIn[:]
CardsOut[x]= Blank()
ManapoolOut = numpy.add(ManapoolIn, ([1,0,0,0]))
Play(CardsOut, ManapoolOut, CantripsIn, RiteIn, StormIn, GrantIn)
class Petal():
nColour=0
nCC=1
CC= numpy.array([[0,0,0,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
CardsOut = CardsIn[:]
CardsOut[x]= Blank()
ManapoolOut = numpy.add(ManapoolIn, ([0,0,1,0]))
Play(CardsOut, ManapoolOut, CantripsIn, RiteIn, StormIn+1, GrantIn)
class Pyretic():
nColour=1
Colour= numpy.array([[1,0,0,0]])
nCC=5
CC= numpy.array([[2,0,0,0], [1,1,0,0], [1,0,1,0], [0,1,1,0], [0,0,2,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
CardsOut = CardsIn[:]
CardsOut[x]= Blank()
ManapoolOut = numpy.add(ManapoolIn, ([3,0,0,0]))
Play(CardsOut, ManapoolOut, CantripsIn, RiteIn, StormIn+1, GrantIn)
class LED():
nColour=0
nCC=1
CC= numpy.array([[0,0,0,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
CardsOut = CardsIn[:]
CardsOut[x]= Blank()
ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,3]))
Play(CardsOut, ManapoolOut, CantripsIn, RiteIn, StormIn+1, GrantIn)
class Tinder():
nColour=1
Colour = numpy.array([[0,1,0,0]])
nCC=2
CC= numpy.array([[0,1,0,0], [0,0,1,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
CardsOut = CardsIn[:]
CardsOut[x]= Blank()
ManapoolOut = numpy.add(ManapoolIn, ([2,0,0,0]))
Play(CardsOut, ManapoolOut, CantripsIn, RiteIn, StormIn+1, GrantIn)
class Rite():
nColour=1
Colour = numpy.array([[1,0,0,0]])
nCC=2
CC= numpy.array([[1,0,0,0], [0,0,1,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
CardsOut = CardsIn[:]
CardsOut[x]= Blank()
ManapoolOut = numpy.add(ManapoolIn, ([2+RiteIn,0,0,0]))
Play(CardsOut, ManapoolOut, CantripsIn, RiteIn+1, StormIn+1, GrantIn)
class Chrome():
nColour=0
nCC=1
CC= numpy.array([[0,0,0,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
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, RiteIn, StormIn+1, GrantIn)
class Grant():
nColour=1
Colour = numpy.array([[0,1,0,0]])
nCC=1
CC= numpy.array([[0,0,0,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
CardsOut = CardsIn[:]
ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,0]))
Check=0
for i in range(Handsize+CantripsIn):
if Shuffle[i]==36:
Check=1
if GrantIn>0:
Check=1
if Check==1:
CardsOut[x]=Blank()
Play(CardsOut, ManapoolOut, CantripsIn, RiteIn, StormIn+1, GrantIn+1)
elif Check==0:
CardsOut[x]= Taiga()
Play(CardsOut, ManapoolOut, CantripsIn, RiteIn, StormIn+1, GrantIn+1)
class Taiga():
nColour=0
nCC=1
CC= numpy.array([[0,0,0,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
CardsOut = CardsIn[:]
CardsOut[x]= Blank()
ManapoolOut1 = numpy.add(ManapoolIn, ([1,0,0,0]))
ManapoolOut2 = numpy.add(ManapoolIn, ([0,1,0,0]))
Play(CardsOut, ManapoolOut1, CantripsIn, RiteIn, StormIn, GrantIn)
Play(CardsOut, ManapoolOut2, CantripsIn, RiteIn, StormIn, GrantIn)
class Manamorphose():
nColour=2
Colour = numpy.array([[1,0,0,0], [0,1,0,0]])
nCC=6
CC= numpy.array([[2,0,0,0], [1,1,0,0], [1,0,1,0], [0,2,0,0], [0,1,1,0], [0,0,2,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
CardsOut = CardsIn[:]
CardsOut[x]= Selector(Shuffle[Handsize+CantripsIn])
ManapoolOut = numpy.add(ManapoolIn, ([1,1,0,0]))
Play(CardsOut, ManapoolOut, CantripsIn+1, RiteIn, StormIn+1, GrantIn)
class Probe():
nColour=0 #Approximation is made#
nCC=1
CC= numpy.array([[0,0,0,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
CardsOut = CardsIn[:]
CardsOut[x]= Selector(Shuffle[Handsize+CantripsIn])
ManapoolOut = numpy.add(ManapoolIn, ([0,0,0,0]))
Play(CardsOut, ManapoolOut, CantripsIn+1, RiteIn, StormIn+1, GrantIn)
class Wish():
nColour=1
Colour = numpy.array([[1,0,0,0]])
nCC=3
CC= numpy.array([[2,0,0,0], [1,0,1,0], [0,0,2,0]]) #Approximation is made#
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
global Results
if (TotalMana(ManapoolIn)+ManapoolIn[3])>3: #Needs Editing when Black is included#
if StormIn>3:
Results = numpy.add(Results, ([0,0,1,0]))
else:
Results = numpy.add(Results, ([0,1,0,0]))
class EtW():
nColour=1
Colour = numpy.array([[1,0,0,0]])
nCC=2
CC= numpy.array([[1,0,0,0], [0,0,1,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
global Results
if TotalMana(ManapoolIn)> 2:
if StormIn>4:
Results = numpy.add(Results, ([0,1,0,0]))
else:
Results = numpy.add(Results, ([0,0,1,0]))
class Belcher(): #Needs Editing when Black is included#
nColour=0
nCC=1
CC= numpy.array([[0,0,0,0]])
def resolve(self, ManapoolIn, CardsIn, x, CantripsIn, RiteIn, StormIn, GrantIn):
global Results
if TotalMana(ManapoolIn)> 3:
Results = numpy.add(Results, ([0,0,0,1]))
if (TotalMana(ManapoolIn)+ManapoolIn[3])>6:
Results = numpy.add(Results, ([1,0,0,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 or x==4 or x==5 or x==6 or x==7:
return Pyretic()
elif x==8 or x==9 or x==10 or x==11:
return Rite()
elif x==12 or x==13 or x==14 or x==15:
return Tinder()
elif x==16 or x==17 or x==18 or x==19:
return Petal()
elif x==20 or x==21 or x==22 or x==23:
return Chrome()
elif x==24 or x==25 or x==26 or x==27:
return ESG()
elif x==28 or x==29 or x==30 or x==31:
return SSG()
elif x==32 or x==33 or x==34 or x==35:
return Grant()
elif x==36:
return Taiga()
elif x==37 or x==38 or x==39 or x==40:
return LED()
elif x==41 or x==42 or x==43 or x==44:
return Manamorphose()
elif x==45 or x==46 or x==47 or x==48:
return Probe()
elif x==49 or x==50 or x==51 or x==52:
return Wish()
elif x==53 or x==54 or x==55 or x==56:
return Belcher()
elif x==57 or x==58 or x==59:
return EtW()
elif x==60:
return Blank()
def CompareCost(CastingCost, Manapool): #Checks if we can pay a manacost of a card#
for i in range(4): #Needs editing when Black is included#
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 (3):
Totalmana = Totalmana + Manapool[i]
return Totalmana
def Play(Cards, Manapool, Cantrips, Rite, Storm, Grant):
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, Rite, Storm, Grant) #Subtract manacost and resolve card#
#------------------------------------------------------------------------------#
start_time = time.time() #This counts the time the whole scripts take#
for i in range(5000): #Amount of times we run a hand#
Results = numpy.array([0,0,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__#
Play(Hand, numpy.array([0,0,0,0]),0, 0, 0, 0) #Here we start casting#
for j in range (4): #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