Skip to content

Instantly share code, notes, and snippets.

@tomkel5
Created August 4, 2016 21:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomkel5/432c94ac7a4d03251bf99fd280d051dc to your computer and use it in GitHub Desktop.
Save tomkel5/432c94ac7a4d03251bf99fd280d051dc to your computer and use it in GitHub Desktop.
Greedy Dice Effectiveness
from random import shuffle
class Card:
POKEMON = "P"
GREEDY_DICE = "G"
UNKNOWN = "U"
class Game:
def __init__(self):
self.deck = self.generate_deck()
self.hand = []
self.prizes = []
def play(self):
self.generate_deck()
self.draw_opening_hand()
self.deal_prizes()
def generate_deck(self):
pass
def draw_opening_hand(self):
pass
def deal_prizes(self):
self.prizes = self.deck[:6]
self.deck = self.deck[6:]
def num_greedy_dice_prized(self):
return self.prizes.count(Card.GREEDY_DICE)
class GameThatRequiresBasicPokemon(Game):
"""This Game requires that the opening hand contain a Pokemon to be a valid opening draw"""
def generate_deck(self):
cards = [Card.POKEMON]
cards += [Card.GREEDY_DICE for i in range(4)]
cards += [Card.UNKNOWN for i in range(55)]
return cards
def draw_opening_hand(self):
hand = []
while Card.POKEMON not in hand:
shuffle(self.deck)
hand = self.deck[:7]
self.hand = hand
self.deck = self.deck[7:]
class GameThatDoesNotRequireBasicPokemon(Game):
"""This Game does not consider Pokemon cards"""
def generate_deck(self):
cards = [Card.GREEDY_DICE for i in range(4)]
cards += [Card.UNKNOWN for i in range(56)]
return cards
def draw_opening_hand(self):
shuffle(self.deck)
self.hand = self.deck[:7]
self.deck = self.deck[7:]
required_pokemon_total = 0
no_required_pokemon_total = 0
iterations = 1000000
for i in range(iterations):
required_pokemon_game = GameThatRequiresBasicPokemon()
required_pokemon_game.play()
required_pokemon_total += required_pokemon_game.num_greedy_dice_prized()
no_required_pokemon_game = GameThatDoesNotRequireBasicPokemon()
no_required_pokemon_game.play()
no_required_pokemon_total += no_required_pokemon_game.num_greedy_dice_prized()
print "Average Greedy Dice prized in %s iterations" % (iterations)
print ""
print " Opening hand requires one basic Pokemon: %.4f" % (required_pokemon_total / float(iterations))
print " Opening hand does not require one basic Pokemon: %.4f" % (no_required_pokemon_total / float(iterations))
> python emulator.py
Average Greedy Dice prized in 1000000 iterations
Opening hand requires one basic Pokemon: 0.4070
Opening hand does not require one basic Pokemon: 0.4008
> python emulator.py
Average Greedy Dice prized in 1000000 iterations
Opening hand requires one basic Pokemon: 0.4063
Opening hand does not require one basic Pokemon: 0.3996
> python emulator.py
Average Greedy Dice prized in 1000000 iterations
Opening hand requires one basic Pokemon: 0.4071
Opening hand does not require one basic Pokemon: 0.3992
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment