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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
#!/usr/bin/env python3
#*******************************************************************************
# This file is a part of the Cursed Dice Model Generator
# Copyright (C) 2024 Christian Hodgden
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#*******************************************************************************
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]
gamma = [1, 2, 3, 4, 5, 6]
sigma = [random.randint(1, 6) for _ in range(6)]
delta = [abs(g - s) for g, s in zip(gamma, sigma)]
delta = [abs(7 - s) for g, s in zip(gamma, sigma)]
# What I really want is to init the dice with a total pip count and then choose the distribution
# We probably need a batch dice class
dice_a = Dice(alpha)
dice_b = Dice(beta)
dice_g = Dice(gamma)
dice_s = Dice(sigma)
dice_d = Dice(delta)
a = dice_a.roll()
b = dice_b.roll()
g = dice_g.roll()
s = dice_s.roll()
d = dice_d.roll()
print(a, b, a + b)
|