class CrazyEightsSimulation(object): def __init__(self): # Create a couple players. self.the_doctor = Player("The Doctor") self.the_master = Player("The Master") self.game = CrazyEights([self.the_doctor, self.the_master]) def play(self): print ("*" * 45) print ("Starting Crazy Eights") self.game.start() while not self.game.have_a_winner(): for player in self.game.players: self.lay_down_card_or_pickup(player) for report in self.printable_hand_for_all_players(): print report print "Last 5 discarded cards ", "".join([str(c) for c in self.game.discard_pile][0:5]) print ("*" * 45) def printable_hand_for_all_players(self): """ A list of all players' hands. """ return ["{0}\t{1}".format(p.name, p.printable_hand()) for p in self.game.players] def lay_down_card_or_pickup(self, player): """Bot to play crazyeights for the players.""" for card in player.hand: try: suit = None if card.value == "8": # Since this is a PoC, just pick a suit we have randomly. choice([c.suit for c in player.hand]) self.game.lay_down(card, suit) player.hand.remove(card) return except: pass # if we make it out here, we need to pick up and try again. self.game.pickup(player) self.lay_down_card_or_pickup(player)
def __init__(self): # Create a couple players. self.the_doctor = Player("The Doctor") self.the_master = Player("The Master") self.game = CrazyEights([self.the_doctor, self.the_master])