2D Dice Grid Scoring Algorithm

This challenge is based on a 4×4 grid of dice (16 dice in total). Each game starts by shaking the grid to generate a new grid of 16 values.
2D-dice-grid

All dice are 6-sided dice, generating random values between 1 and 6 when the grid is shaken. The grid can be simplified by showing the actual dice values:
2D-dice-grid-values

Once the new grid is set, its score can be calculated by identifying specific patterns as follows:

  1. Start with a score of 0,
  2. If all four corners are even numbers, add 20 pts to the score,
  3. If all four corners are odd numbers, add 20 pts to the score,
  4. If all four dice on a diagonal are even numbers, add 20 pts to the score,
  5. If all four dice on a diagonal are odd numbers, add 20 pts to the score,
  6. If all four dice on on any row are even numbers, add 20 pts to the score,
  7. If all four dice on on any row are odd numbers, add 20 pts to the score,
  8. If all four dice on on any column are even numbers, add 20 pts to the score,
  9. If all four dice on on any column are odd numbers, add 20 pts to the score,
  10. Add to the score the total value (sum) of all 16 dice.

So for example, with the above grid, we can calculate the score of the grid as follows:
2D-dice-grid-score

Python Implementation

To help you with this challenge we have started the code for you by creating 4 functions to:

  • Generate/shake the grid of 16 dice.
  • Display the 4×4 grid on screen.
  • Check if a number is even.
  • Check if a number is odd.

We have also implemented the first section of the scoring algorithm, by initialising the grid score to 0 and by checking if all four corners are even. If so the score is increased by 20pts.

Your task is to complete the following code to implement the full scoring algorithm using the 10 rules mentioned above.

unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 4.2 / 5. Vote count: 27

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!

Tagged with: