#!/usr/bin/env python3 import typing import random class Pip: def __init__(self, visible: bool = False): self.visible = visible def __str__(self): return '*' if self.visible else ' ' def __int__(self): return int(self.visible) def __bool__(self): return self.visible class Face: def __init__(self, value: int): positions = list(range(9)) self.pips = [Pip() for _ in range(9)] for _ in range(value): position = random.choice(positions) positions.remove(position) self.pips[position].visible = True def __str__(self): face_display = '' for pip in self.pips: face_display += f'|{pip}' if (self.pips.index(pip) + 1) % 3 == 0: face_display += '|\n' return face_display def __int__(self): return sum(int(pip) for pip in self.pips) class Dice: def __init__(self, values: typing.List[int]): self.faces = [] for value in values: face = Face(value) self.faces.append(face) # there should be some address/location system iterating though the axes: # - +x, +y, +z, -z, -y, -x # - for the faces in those directions from the origin # would also like a convention of pip orientation/placement def roll(self): face = random.choice(self.faces) print(face) return int(face) if __name__ == '__main__': alpha = [1, 2, 3, 3, 5, 7] beta = [0, 2, 4, 4, 5, 6] dice_a = Dice(alpha) dice_b = Dice(beta) a = dice_a.roll() b = dice_b.roll() print(a, b, a + b)