How to resolve the algorithm RPG attributes generator step by step in the Racket programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm RPG attributes generator step by step in the Racket 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 Racket programming language
Source code in the racket programming language
#lang racket
(define (d6 . _)
(+ (random 6) 1))
(define (best-3-of-4d6 . _)
(apply + (rest (sort (build-list 4 d6) <))))
(define (generate-character)
(let* ((rolls (build-list 6 best-3-of-4d6))
(total (apply + rolls)))
(if (or (< total 75) (< (length (filter (curryr >= 15) rolls)) 2))
(generate-character)
(values rolls total))))
(module+ main
(define-values (rolled-stats total) (generate-character))
(printf "Rolls:\t~a~%Total:\t~a" rolled-stats total))
You may also check:How to resolve the algorithm N'th step by step in the PL/I programming language
You may also check:How to resolve the algorithm Unix/ls step by step in the Furor programming language
You may also check:How to resolve the algorithm Palindrome detection step by step in the Cowgol programming language
You may also check:How to resolve the algorithm Inverted index step by step in the Java programming language
You may also check:How to resolve the algorithm Keyboard input/Flush the keyboard buffer step by step in the XPL0 programming language