""" skunk.py Simulate the 'skunk' dice game. Players take turns rolling two dice. They can continue rolling or stop. If a 1 comes up, that's "skunk", 0 for that turn. If a 1-1 comes up, "double skunk", entire total is reset to 0. Each has a total score so far, the sum of their rolls. First to 100 wins. """ import random class ScoreSheet: def __init__(self, players): self.scores = {} # { 'you':0, 'computer':0 } self.players = players for player in players: self.scores[player.name] = 0 def summary(self): """ return string summarizing the state of the game """ result = '' for player in self.players: score = self.scores[player.name] result = result + f" {player.name} has {score}" result = result + '\n' return result class Dice: def roll(self): """ return (x,y) two random ints from 1 to 6 """ return (random.randint(1, 6), random.randint(1, 6)) class HumanPlayer: def __init__(self): self.name = 'you' class ComputerPlayer: def __init__(self): self.name = 'computer' class Skunk: def __init__(self): self.players = [ HumanPlayer(), ComputerPlayer() ] self.scores = ScoreSheet(self.players) self.dice = Dice() def play(self): print(" Let's play *** SKUNK *** !! ") while True: print(self.scores.summary()) for player in self.players: dice = self.dice.roll() print(f" {player.name} rolls {dice}") # check if 1 or (1,1) ; stop and/or reset total score # tell the user the current score for this turn # ask if they want to keep going # # check to see if someone has won (over 100) return def main(): skunk = Skunk() skunk.play() if __name__ == '__main__': main()