RPG attributes generator

Revision as of 12:57, 19 July 2018 by rosettacode>Lonney (Added to category:simple & altered language)

You're running a tabletop RPG, and your players are creating characters.

RPG attributes generator is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Each character has six core attributes: strength, dexterity, constitution, intelligence, wisdom, and charisma.

One way of generating values for these attributes is to roll four, 6-sided dice (d6) and sum the three highest rolls, discarding the lowest roll.

Some players like to assign values to their attributes in the order they're rolled.

To ensure generated characters don't put players at a disadvantage, the following requirements must be satisfied:

  • The total of all character attributes must be at least 75.
  • At least two of the attributes must be at least 15.

However, this can require a lot of manual dice rolling. A programatic solution would be much faster.

Task

Write a program that:

  1. Generates 4 random integer values between 1 and 6.
  2. Saves the sum of the 3 largest values.
  3. Generates a total of 6 values this way.
  4. Displays the 6 values once finished.

  • The order in which each value was generated must be preserved.
  • The total of all 6 values must be at least 75.
  • At least 2 of the values must be 15 or more.

Python

Python: Simple

<lang python>import random random.seed()

attributes_total = 0 count = 0

while attributes_total < 75 and count < 2:

   attributes = []
   for attribute in range(0, 6):
       rolls = []
       
       for roll in range(0, 4):
           rolls.append(random.randint(1, 6))
       
       sorted_rolls = sorted(rolls)
       largest_3 = sorted_rolls[1:]
       rolls_total = sum(largest_3)
       
       if rolls_total >= 15:
           count += 1
       
       attributes.append(rolls_total)
   attributes_total = sum(attributes)
   

print(attributes)</lang>