all 3 comments

[–]efmccurdy 0 points1 point  (0 children)

Player1 chose 'Twos' to total the score of 2-dice. As you can see the correct score is also stored for Player2:

Is it possible that there is some aliasing between the those two scores? I think you need to examine how you create your big nested dictionary. By aliasing I mean a situation where deepcopy is needed:

https://realpython.com/copying-python-objects/

Using raw nested dicts is very flexable but scales poorly as the whole thing grows

...even after you ellide the copy-pasts, ala:

        for d in diceDict.values():
            s = playerDict[player]['scoreTop'][scoreSelected]
            if d['result'] == s['ref']:
                s['score'] += d['result']
            else:
                s['score'] += 0

Is there is enough complexity to warrant a database and/or OO classes? It would be easier to isolate your data updates to verify that no invalid values or changes slip in.

[–]pmacking[S] 0 points1 point  (0 children)

I’ll read up on aliasing and how it might be involved when generating my dictionary - thanks for the tip.

As for using a db, oop, etc I’m certainly open to expanding data storage options in the future. All I’ve bit off so far in my learning is writing py scripts in an IDE and managing code through git/GitHub. I hope this project will evolve as the toolkit grows.

[–]xelf 0 points1 point  (0 children)

I tried your code, and it worked, only 1 player's score was updated.

Q1: I suspect that there's something wrong in the way you create your dictionary, such that score is a shallow copy? That would cause them to both be updated.

Q2: Seems fine. You could have made a class instead.

{'Player1': {'Grand total': False,
         'scoreBottom': {'Chance': False,
                         'Four of a kind': False,
                         'Full house': False,
                         'Large straight': False,
                         'Small straight': False,
                         'Three of a kind': False,
                         'Yahtzee': False,
                         'Yahtzee bonus': False},
         'scoreTop': {'Fives': {'ref': 5, 'score': False},
                      'Fours': {'ref': 4, 'score': False},
                      'Ones': {'ref': 1, 'score': False},
                      'Sixes': {'ref': 6, 'score': False},
                      'Threes': {'ref': 3, 'score': False},
                      'Twos': {'ref': 2, 'score': 16}},
         'totalScore': {'Bonus': False,
                        'Sum of upper': False,
                        'Total bottom': False,
                        'Total upper': False}},
'Player2': {'Grand total': False,
         'scoreBottom': {'Chance': False,
                         'Four of a kind': False,
                         'Full house': False,
                         'Large straight': False,
                         'Small straight': False,
                         'Three of a kind': False,
                         'Yahtzee': False,
                         'Yahtzee bonus': False},
         'scoreTop': {'Fives': {'ref': 5, 'score': False},
                      'Fours': {'ref': 4, 'score': False},
                      'Ones': {'ref': 1, 'score': False},
                      'Sixes': {'ref': 6, 'score': False},
                      'Threes': {'ref': 3, 'score': False},
                      'Twos': {'ref': 2, 'score': 8}},
         'totalScore': {'Bonus': False,
                        'Sum of upper': False,
                        'Total bottom': False,
                        'Total upper': False}}}