(11C) (15C) Simple configurable dice
04-06-2018, 12:53 PM (This post was last modified: 04-06-2018 09:51 PM by Michael Zinn.)
Post: #1
 Michael Zinn Member Posts: 56 Joined: Mar 2018
(11C) (15C) Simple configurable dice
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
04-06-2018, 01:17 PM
Post: #2
 David Hayden Senior Member Posts: 336 Joined: Dec 2013
RE: (11C) (15C) Simple configurable dice
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
04-06-2018, 01:29 PM
Post: #3
 Michael Zinn Member Posts: 56 Joined: Mar 2018
RE: (11C) (15C) Simple configurable dice
(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)
04-06-2018, 06:53 PM
Post: #4
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: (11C) (15C) Simple configurable dice
(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
04-06-2018, 07:40 PM
Post: #5
 Michael Zinn Member Posts: 56 Joined: Mar 2018
RE: (11C) (15C) Simple configurable dice
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.
04-06-2018, 09:40 PM
Post: #6
 rprosperi Senior Member Posts: 4,324 Joined: Dec 2013
RE: (11C) (15C) Simple configurable dice
(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...

--Bob Prosperi
04-06-2018, 09:53 PM
Post: #7
 Michael Zinn Member Posts: 56 Joined: Mar 2018
RE: (11C) (15C) Simple configurable dice
Good idea! I added comments to the code to make it clear for 11C users.
04-06-2018, 09:57 PM
Post: #8
 rprosperi Senior Member Posts: 4,324 Joined: Dec 2013
RE: (11C) (15C) Simple configurable dice
(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.

--Bob Prosperi
05-02-2018, 08:03 PM
Post: #9
 Dieter Senior Member Posts: 2,397 Joined: Dec 2013
RE: (11C) (15C) Simple configurable dice
(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
05-04-2018, 06:44 PM
Post: #10
 Michael Zinn Member Posts: 56 Joined: Mar 2018
RE: (11C) (15C) Simple configurable dice
(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).
 « Next Oldest | Next Newest »

User(s) browsing this thread: 1 Guest(s)