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 = 10
- FETCH_LAND = 8
- def playAGame():
- deck = ["land"] * LAND_COUNT + ["bolt"] * (60 - LAND_COUNT-FETCH_LAND)+ ["fetch land"]*FETCH_LAND
- hand = []
- landCounter = 0
- damageDealt = 0
- turnCounter = 0
- # Opening hand 7 cards
- for a in range(7):
- drawPhase(deck, hand)
- 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 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