HP Forums
(11C) (15C) Simple configurable dice - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (11C) (15C) Simple configurable dice (/thread-10451.html)



(11C) (15C) Simple configurable dice - Michael Zinn - 04-06-2018 12:53 PM

A simple dice role program that rolls R1 many R2 sided dice and adds them together. The idea is that you don't change the configuration often, but can roll dice easily with just one button press. E.g. if you want to play Monopoly you would put 2 in R1 and 6 in R2 at the start of the game, set your calculator to USER mode and then role the dice with just one button press.

Example Configurations
Code:
R1 R2  Result
-- --- ------
 1   2 Coin toss
 1   6 dice roll
 2   6 Monopoly / Settlers of Catan
 3  20 Roll 3d20 (Dungeons & Dragons)
 1 100 Cthulhu RPG

Code
Code:
LBL 3  ; You could use label D for Dice here
  FIX 0
  RCL 1
  STO I
  CLx
  LBL 4
    RAN#
    RCL * 2   ; On 11C: RCL 2 * (two lines of code)
    INT
    +
    DSE I
      GTO 4
  RCL + 1  ; On 11C: RCL 1 + (two lines of code)
  RTN



RE: (11C) (15C) Simple configurable dice - David Hayden - 04-06-2018 01:17 PM

Nice routine.

You can save some runtime and one program step by adding R1 after the loop rather than adding 1, R1 times:
Code:
LBL 3  ; You could use label D for Dice here
  FIX 0
  RCL 1
  STO I
  CLx
  LBL 4
    RAN#
    RCL * 2
    INT
    +
    DSE I
      GTO 4
  RCL + 1
  RTN



RE: (11C) (15C) Simple configurable dice - Michael Zinn - 04-06-2018 01:29 PM

(04-06-2018 01:17 PM)David Hayden Wrote:  [...]
You can save some runtime and one program step by adding R1 after the loop rather than adding 1, R1 times:[...]

Hah, of course! Clever idea.
Must have missed that because I wrote it for one dice roll first and added the loop later. :o)


RE: (11C) (15C) Simple configurable dice - Dieter - 04-06-2018 06:53 PM

(04-06-2018 12:53 PM)michaelzinn Wrote:  A simple dice role program that rolls R1 many R2 sided dice and adds them together.

Yes, but it only works on the 15C, not on the 11C (as suggested by the thread subject).
The 11C does not feature RCL arithmetic, so you have to use RCL 2 * and RCL 1 + instead.

Dieter


RE: (11C) (15C) Simple configurable dice - Michael Zinn - 04-06-2018 07:40 PM

Yes, but that's a trivial change that you can do when typing in the program. I would only omit the "(11C)" for programs that use more complex hard to port features like matrices or complex numbers.

The point is, if I were interested in finding programs to use on my 11C I would want this dice program to have "(11C)" in the title so that I can find it easily.


RE: (11C) (15C) Simple configurable dice - rprosperi - 04-06-2018 09:40 PM

(04-06-2018 07:40 PM)michaelzinn Wrote:  Yes, but that's a trivial change that you can do when typing in the program. I would only omit the "(11C)" for programs that use more complex hard to port features like matrices or complex numbers.

The point is, if I were interested in finding programs to use on my 11C I would want this dice program to have "(11C)" in the title so that I can find it easily.

Suggestion: It's probably a good idea to edit the OP (only the author can edit his own messages) to note that comments on how to adapt it for the 11C (which are easy) can be found in the thread below, so an 11C enthusiast that finds this thread and tries it, isn't confused since it won't work as listed in the beginning. One would think folks read a whole thread before keying in a program... one would think lots of logical things...


RE: (11C) (15C) Simple configurable dice - Michael Zinn - 04-06-2018 09:53 PM

Good idea! I added comments to the code to make it clear for 11C users.


RE: (11C) (15C) Simple configurable dice - rprosperi - 04-06-2018 09:57 PM

(04-06-2018 09:53 PM)michaelzinn Wrote:  Good idea! I added comments to the code to make it clear for 11C users.

Even better idea, that can't be missed, excellent, thx.


RE: (11C) (15C) Simple configurable dice - Dieter - 05-02-2018 08:03 PM

(04-06-2018 01:17 PM)David Hayden Wrote:  You can save some runtime and one program step by adding R1 after the loop rather than adding 1, R1 times:
Code:
LBL 3  ; You could use label D for Dice here
  FIX 0
  RCL 1
  STO I
  CLx
  LBL 4
    RAN#
    RCL * 2
    INT
    +
    DSE I
      GTO 4
  RCL + 1
  RTN

I just noticed you can save even two more steps if you remove both the CLX and the RCL+1. ;-)

Dieter


RE: (11C) (15C) Simple configurable dice - Michael Zinn - 05-04-2018 06:44 PM

(05-02-2018 08:03 PM)Dieter Wrote:  
(04-06-2018 01:17 PM)David Hayden Wrote:  You can save some runtime and one program step by adding R1 after the loop rather than adding 1, R1 times:
Code:
LBL 3  ; You could use label D for Dice here
  FIX 0
  RCL 1
  STO I
  CLx
  LBL 4
    RAN#
    RCL * 2
    INT
    +
    DSE I
      GTO 4
  RCL + 1
  RTN

I just noticed you can save even two more steps if you remove both the CLX and the RCL+1. ;-)

Dieter

Even better! It seems that writing "composable" code just leads to wasted performance. Maybe instead of extending existing programs, everything should be rewritten from scratch every time you want to add a feature (at least when programming a calculator).