#!/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 . #******************************************************************************* 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)