1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
#!/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)
|