How to resolve the algorithm RPG attributes generator step by step in the uBasic/4tH programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm RPG attributes generator step by step in the uBasic/4tH programming language

Table of Contents

Problem Statement

RPG   =   Role Playing Game.

You're running a tabletop RPG, and your players are creating characters. 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: However, this can require a lot of manual dice rolling. A programatic solution would be much faster.

Write a program that:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm RPG attributes generator step by step in the uBasic/4tH programming language

Source code in the ubasic/4th programming language

dim @n(6)
@n(0) := "STR"
@n(1) := "CON"
@n(2) := "DEX"
@n(3) := "INT"
@n(4) := "WIS"
@n(5) := "CHA"
 
dim @s(6)
 
do
  s = 0 :  n = 0
  for i = 0 to 5
    @s(i) = FUNC(_rollstat)
    s = s + @s(i)
    if @s(i) > 14 then n = n + 1
  next
  until (s > 74) * (n > 1)
loop
 
for i = 0 to 5
  print show(@n(i)); ":"; using "__", @s(i) 
next

print "----" : Print "TOT: "; using "__", s
end
    ' simulates a marked regular hexahedron coming to rest on a plane
_d6 return (1 + rnd(6))

    ' rolls four dice, returns the sum of the three highest 
_rollstat
  local (4)
  a@ = FUNC(_d6) : b@ = FUNC(_d6) : c@ = FUNC(_d6) : d@ = FUNC(_d6)
return (a@ + b@ + c@ + d@ - Min(Min(a@, b@), Min(c@, d@)))


  

You may also check:How to resolve the algorithm Loops/Break step by step in the МК-61/52 programming language
You may also check:How to resolve the algorithm Count occurrences of a substring step by step in the Action! programming language
You may also check:How to resolve the algorithm Sort an array of composite structures step by step in the Lambdatalk programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the MATLAB programming language
You may also check:How to resolve the algorithm Intersecting number wheels step by step in the C programming language