How to resolve the algorithm RPG attributes generator step by step in the ALGOL 68 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm RPG attributes generator step by step in the ALGOL 68 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 ALGOL 68 programming language

Source code in the algol programming language

BEGIN # RPG attributes generator #

    INT attrib count = 6;
    MODE RESULT = STRUCT( BOOL success, INT sum, high count, [ 1 : attrib count ]INT a );

    PROC generate attrib = INT:
    BEGIN
        INT min := 255, sum := 0;
        FOR i FROM 0 TO 3 DO
            INT v = ENTIER( next random * 6 ) + 1;
            IF v < min THEN
                min := v
            FI;
            sum +:= v
        OD;
        sum - min
    END # generate attrib #;

    PROC generate = ( REF RESULT res )VOID:
    BEGIN
        high count OF res := 0;
        sum OF res        := 0;
        FOR i FROM LWB a OF res TO UPB a OF res DO
            INT v = generate attrib;
            IF v >= 15 THEN
               high count OF res +:= 1
            FI;
            sum OF res +:= v;
            ( a OF res )[ i ] := v
        OD;
        success OF res := ( high count OF res >= 2 AND sum OF res >= 75 )
    END # generate # ;

    RESULT res;
    success OF res := FALSE;
    WHILE NOT success OF res DO
        generate( res );
        print( ( "attribs: " ) );
        FOR i FROM LWB a OF res TO UPB a OF res DO
            print( ( whole( ( a OF res )[ i ], 0 ) ) );
            IF i < UPB a OF res THEN
                print( ( " " ) )
            FI
        OD;
        print( ( " sum=", whole( sum OF res, 0 )
               , " highCount=", whole( high count OF res, 0 )
               , " ", IF success OF res THEN "success" ELSE "failed" FI
               , newline
               )
             )
    OD

END

  

You may also check:How to resolve the algorithm Multiplication tables step by step in the MUMPS programming language
You may also check:How to resolve the algorithm Draw a pixel step by step in the Raku programming language
You may also check:How to resolve the algorithm Nonoblock step by step in the Lua programming language
You may also check:How to resolve the algorithm Draw a pixel step by step in the M2000 Interpreter programming language
You may also check:How to resolve the algorithm Queue/Usage step by step in the Prolog programming language