Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from random import shuffle
- LIFE_TOTAL = 20
- LAND_COUNT = 18
- FETCH_LAND = 0
- def playAGame():
- deck = ["land"] * LAND_COUNT + ["bolt"] * (60 - LAND_COUNT-FETCH_LAND)+ ["fetch land"]*FETCH_LAND
- hand = []
- landCounter = 0
- damageDealt = 0
- turnCounter = 0
- draw = 7
- mulligan(draw,hand,deck)
- # Opening hand 7 cards
- while damageDealt < LIFE_TOTAL:
- turnCounter += 1
- #print "Turn", turnCounter
- #print "My hand", hand
- drawPhase(deck, hand)
- landCounter = landPhase(hand, landCounter, deck)
- damageDealt = boltPhase(hand, landCounter, damageDealt)
- # print "I win on turn", turnCounter
- return turnCounter
- def drawPhase(deck, hand):
- myDraw = random.choice(deck)
- #print "I drew", myDraw
- deck.remove(myDraw)
- hand.append(myDraw)
- def mulligan(draw,hand,deck):
- if draw != 0:
- for a in range(draw):
- drawPhase(deck, hand)
- if (hand.count("land") + hand.count("fetch land")) < 1 or (hand.count("land") + hand.count("fetch land")) > 5:
- #print hand
- #print "I mulligan"
- hand = []
- mulligan(draw-1,hand,deck)
- else:
- pass
- def landPhase(hand, landCounter, deck):
- if "fetch land" in hand:
- #print "I play a fetch land"
- hand.remove("fetch land")
- #print "I crack my fetch land"
- try:
- deck.remove("land")
- except ValueError:
- #print "No more lands in library"
- pass
- #print "I shuffle my library"
- shuffle(deck)
- return landCounter + 1
- if "land" in hand:
- #print "I play a land"
- hand.remove("land")
- return landCounter + 1
- else:
- return landCounter
- def boltPhase(hand, landCounter, damageDealt):
- damageDealtThisPhase = 0
- for a in range(landCounter):
- if "bolt" in hand:
- # print "I play a bolt"
- hand.remove("bolt")
- damageDealtThisPhase += 3
- return damageDealt + damageDealtThisPhase
- totalTurns = 0;
- #playAGame()
- for a in range(100000):
- totalTurns += playAGame();
- print totalTurns / 100000.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement