botbowl icon indicating copy to clipboard operation
botbowl copied to clipboard

Fixed dice should be stored in Game object

Open mrbermell opened this issue 3 years ago • 1 comments

Currently the fixed dice are stored with a singleton pattern, namely the class itself (see code below). If fixed dice are used with multiple game objects at the same time there is a risk that a fixed dice for one game is consumed by another game. That behavior will not crash the execution and but can lead to very subtle bugs.

I propose we move information about the stored fixed rolls to the game object itself. I'm happy to write the PR if you agree.

class BBDie(Die, Immutable):
    value: BBDieResult
    FixedRolls = []

    @staticmethod
    def fix(value):
        if type(value) == BBDieResult:
            BBDie.FixedRolls.append(value)
        else:
            raise ValueError("Fixed result of BBDie must be a BBDieResult")

mrbermell avatar Jan 17 '22 08:01 mrbermell

Yeah, great idea.

Curious to see how you will implement it :)

njustesen avatar Jan 17 '22 10:01 njustesen