from constants import * # MiniYahtzee Example # Source code file: miniyahtzee.py import random class MiniYahtzee: def __init__(self): self._dice = [1, 1, 1] self.roll_type = UNCLASSIFIED def __str__(self): return "{:d} {:d} {:d}".format( \ self._dice[0], self._dice[1], self._dice[2]) def roll_dice(self): for i in range(0, 3): self._dice[i] = random.randrange(1, 7) def classify(self): self._dice.sort( ) if self._dice[0] == self._dice[1] and \ self._dice[1] == self._dice[2]: self.roll_type = TRIPLE elif self._dice[0] + 1 == self._dice[1] and \ self._dice[1] + 1 == self._dice[2]: self.roll_type = STRAIGHT elif self._dice[0] == self._dice[1] or \ self._dice[1] == self._dice[2]: self.roll_type = PAIR else: self.roll_type = NOTHING