How to resolve the algorithm RPG attributes generator step by step in the Common Lisp programming language

Published on 12 May 2024 09:40 PM

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

Source code in the common programming language

(defpackage :rpg-generator
  (:use :cl)
  (:export :generate))
(in-package :rpg-generator)
(defun sufficient-scores-p (scores)
  (and (>= (apply #'+ scores) 75)
       (>= (count-if #'(lambda (n) (>= n 15)) scores) 2)))

(defun gen-score ()
  (apply #'+ (rest (sort (loop repeat 4 collect (1+ (random 6))) #'<))))

(defun generate ()
  (loop for scores = (loop repeat 6 collect (gen-score))
        until (sufficient-scores-p scores)
        finally (format t "Scores: ~A~%" scores)
                (format t "Total: ~A~%" (apply #'+ scores))
                (format t ">= 15: ~A~%" (count-if (lambda (n) (>= n 15)) scores))
                (return scores)))


;; 22.11.07  Draft

(defun score-jet-des ()
  (loop :for resultat = (+ (random 6) 1)
        :repeat 4
        :sum resultat :into total
        :minimize resultat :into minimum
        :finally (return (- total minimum))))

(defun calcule-attributs-personnage ()
  (loop named a
        :do (loop :for score = (score-jet-des)
                  :repeat 6
                  :collect score :into scores
                  :sum score :into total
                  :count (>= score 15) :into frequence
                  :finally (when (and (>= total 75) (>= frequence 2))
                             (return-from a (values scores total))))))


  

You may also check:How to resolve the algorithm Respond to an unknown method call step by step in the Ruby programming language
You may also check:How to resolve the algorithm Program name step by step in the PowerShell programming language
You may also check:How to resolve the algorithm Factorial step by step in the FunL programming language
You may also check:How to resolve the algorithm Terminal control/Cursor movement step by step in the BASIC programming language
You may also check:How to resolve the algorithm Execute Brain step by step in the XBS programming language