Saturday, June 9, 2018

HP 32SII and HP Prime: Throwing Dice


HP 32SII and HP Prime: Throwing Dice

Note: Symbols that are produced by Unicode should, but may not show up on all browsers. Please make sure your browsers are updated to the latest version.  
⚀ ⚁ ⚂ ⚃ ⚄ ⚅

Let Em’ Roll

One way to simulate a pair of dice being thrown is to generate two random integers between 1 through 6.  The integers are either shown as a pair or vector of integers.  For calculators that do not have a list capacity or want a more compact representation, the program for the HP 32S II (which can easily apply almost to any other programming calculator), in the format A.0B, where A is one die and B is the other.   For example, 3.06 represents a 3 and a 6 being thrown.

The formula would be:   RandInt(1,6) + RandInt(1,6)/100

On certain Sharp calculators, such as the Sharp EL-W516T, the R.DICE function generates a single digit between 1 and 6.

HP 32 SII Program: Dice Generator

D01 LBL D
D02 RANDOM
D03 6
D04 *
D05 1
D06 +
D07 IP
D08 1
D09 %
D10 RANDOM
D11 6
D12 *
D13 1
D14 +
D15 IP
D16 +
D17 RTN

HP Prime:  Graphical Representation of Dice

We can also use the Unicode representation of dice.

Unicode Character
Decimal
Hexadecimal
⚀
9856
2680
⚁
9857
2681
⚂
9858
2682
⚃
9859
2683
⚄
9860
2684
⚅
9861
2685

Unicode characters need to be in strings.  The HP Prime program RDICE returns a list, the roll in compact format, along with the Unicode representation.  This is only one of many ways to do it.

An example output of RDICE is {4.02, “⚃”, “⚁”}

HP Prime Program: RDICE

EXPORT RDICE()
BEGIN
// rolling dice A.0B
LOCAL A, B, C, D;
A≔RANDINT(1,6); C≔9855+A;
B≔RANDINT(1,6); D≔9855+B;
RETURN {A+B/100, CHAR(C), CHAR(D)};
END;

Have fun and roll those dice,

Eddie


All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Sunday, June 3, 2018

Sharp EL-5500 III: Slots: Triples and Cherries Pay


Sharp EL-5500 III:  Slots:  Triples and Cherries Pay

BAR | BAR | BAR
   7    |   7    |   7
   🍒  |   🍒   |  🍒

Note: Symbols that are produced by Unicode should, but may not show up on all browsers. Please make sure your browsers are updated to the latest version.  

Take a Spin

This program is a three reel slot simulator, each with ten symbols:

0:  BAR
1:  Cherry (🍒)
2:  Orange
3:  Plum
4:  Bell (🔔)
5:  Lemon (🍋)
6:  Watermelon (🍉)
7:  Seven
8:  Apple (🍎)
9:  Shamrock (☘)

To see the version for the HP 32SII, please click here:  https://edspi31415.blogspot.com/2018/06/hp-32s-ii-two-versions-of-slots.html

🍒 | 🍒 | 🍒

Each spin has an ante of 25¢.  The results appear in the form 0.###  (ignore the left most 0.)  See the Take a Spin section above for the symbols used in the game.

The payouts are these:

A cherry in any one slot (0.1xy, 0.x1y, or 0.xy1):  $1.00
Any two cherries (0.11x, 0.1x1, 0.x11):  $10.00
Three BARS (0.000):  $35.00  ($15 + $20)
Three Sevens (0.777):  $70.00  ($50 + $20)
Any other triple (0.xxx, x≠0 and x≠7):  $20.00

Note: You can use any line numbering system, I used the line numbers 1400-1499 for this program. The first “D” on line 1400 is optional, but is there to make the program a defined program for the EL-5500 III, running it by pressing [DEF] [ D ].  If you are using another calculator, this may not be an option, so ignore the “D” in that case.

Sharp EL-5500 III Program Slots: Triples and Cherries Pay

1400: “D”: PAUSE “Slots”   
1402: CLEAR
1404: INPUT “Bankroll: $”; J
1406: P = 0
1408: J = J - .25
1410: N = .1*(RND 10-1)+.01*(RND 10-1)+.001*(RND 10 – 1)
1412: PRINT USING “########”; 1000*N
1414: S = N/.111
1416: IF (S-INT(S)) = 0 THEN 1450
1418: X = N: GOSUB 1430
1420: X = S: GOSUB 1430
1422: X = S: GOSUB 1430
1424: J = J + INT(TEN (P – 1))  // TEN: 10^x
1426: GOTO 1470

1430: I = INT(X*10)
1432: S = 10*X – I
1434: IF I = 1 THEN LET P = P + 1
1436: RETURN

1450: IF S = 0 THEN LET J = J + 35
1452: IF S = 7 THEN LET J = J + 50
1454: IF S<>0 AND S<>7 THEN LET J = J + 20
1456: GOTO 1470

1470: PRINT “Bank $”; USING “##########.##”; J
1472: INPUT “1 = Again ? :”, C
1474: IF C = 1 THEN 1406
1476: END

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

HP 32S II: Two Versions of Slots


HP 32S II: Two Versions of Slots

BAR | BAR | BAR
   7    |   7    |   7
   🍒  |   🍒   |  🍒

Note: Symbols that are produced by Unicode should, but may not show up on all browsers. Please make sure your browsers are updated to the latest version.  

Take a Spin

The two programs are three reel slot simulators, each with ten symbols:

0:  BAR
1:  Cherry (🍒)
2:  Orange
3:  Plum
4:  Bell (🔔)
5:  Lemon (🍋)
6:  Watermelon (🍉)
7:  Seven
8:  Apple (🍎)
9:  Shamrock (☘)

Slots Version 1:  Classic Adapted Version

This version is adapted from the HP-19C/HP-29C Games Solutions: Games book, which in turn, the original program was adapted from HP-65 user program by Craig A. Pearce.

Each spin has an ante of 10¢.  The results appear in the form 0.###  (ignore the left most 0.)

The payouts are these:

Cherry on the first slot, 0.1xy ( 🍒 | any | any ):  20¢
Cherry on the first two slots 0.11x ( 🍒 | 🍒 | any ):  30¢
Three of a kind other than cherries, 0.xxx where x≥2:  $1.00
Non-cherry symbol on the first two slots, BAR on the third, 0.xx0 where x≥2:  $1.00
Three BARS, 0.000:  $10.00

To operate:

1.  Initialize:  XEQ S
2.  Spin:  XEQ J
3.  Check your winnings or losses:  XEQ K

HP 32S II Program Classic Slots
(115.5 bytes)

// initialize (4.5 bytes)
S01 LBL S
S02 CLVARS
S03 STOP (R/S)

// spin (40.5 bytes)
J01 LBL J
J02 FIX 3
J03 RANDOM
J04 STO N
J05 XEQ T
J06 STO K
J07 –
J08 XEQ T
J09 STO L
J10 –
J11 XEQ T
J12 STO M
J13 1
J14 RCL K   // check for cherries
J15 x=y?
J16 GTO O
J17 RCL L
J18 x≠y?
J19 GTO P
J20 RCL M
J21 x≠y?
J22 GTO Q
J23 1
J24 XEQ U
J25 1
J26 STO U
J27 R↓

// three of kind check (7.5 bytes)
Q01 LBL Q
Q02 x≠0?
Q03 GTO P
Q04 9
Q05 DSE U

// pay the ante of 10 cents (12.5 bytes)
P01 LBL P
P02 RCL N
P03 -0.1

// accounting of the pot (6.0 bytes)
U01 LBL U
U02 STO+ J
U03 R↓
U04 RTN

// cherry routine (29.5 bytes)
O01 LBL O
O02 0.2
O03 XEQ U
O04 RCL L
O05 x≠y?
O06 GTO P
O07 0.3
O08 XEQ U
O09 GTO P

// peel digits from the spin (9.0 bytes)
T01 LBL T
T02 10
T03 *
T04 ENTER
T05 IP
T06 RTN

// recall pot (6.0 bytes)
K01 LBL K
K02 RCL J
K03 FIX 2
K04 STOP (R/S)

Source: HP-19C/29-C Solutions: Games. Hewlett Packard.  1977


Slots Version 2:  Cherries and Triples Pay 

🍒 | 🍒 | 🍒

Each spin has an ante of 25¢.  The results appear in the form 0.###  (ignore the left most 0.)  See the Take a Spin section above for the symbols used in the game.

The payouts are these:

A cherry in any one slot (0.1xy, 0.x1y, or 0.xy1):  $1.00
Any two cherries (0.11x, 0.1x1, 0.x11):  $10.00
Three BARS (0.000):  $35.00  ($15 + $20)
Three Sevens (0.777):  $70.00  ($50 + $20)
Any other triple (0.xxx, x≠0 and x≠7):  $20.00

To operate:

1.  Initialize and store your bank roll:  XEQ S
2.  Spin:  XEQ J.  The results of the slot and the resulting bank roll will automatically be displayed.

HP 32S II Program Cherries and Triples Pay
(124.0 bytes)

// initialization (6.0 bytes)
S01 LBL S
S02 CLRVARS
S03 STO J
S04 STOP (R/S)

// spin (62.5 bytes)
J01 LBL J
J02 0
J03 STO P // store in P
J04 0.25  // ante
J05 STO- J
J06 FIX 3
J07 RANDOM
J08 RND  // round to display settings
J09 PSE
J10 PSE
J11 PSE
J12 STO N
J13 0.111  // check for triple
J14 ÷
J15 STO S
J16 FP
J17 x=0?
J18 GTO T
J19 RCL N  // count for cherries
J20 XEQ P
J21 RCL S
J22 XEQ P
J23 RCL S
J24 XEQ P
J25 RCL P
J26 1
J27 –
J28 10^x 
J29 IP
J30 STO+ J
J31 GTO U

// count cherries (21.0 bytes)
P01 LBL P
P02 10
P03 *
P04 ENTER
P05 IP
P06 –
P07 STO O
P08 LASTx
P09 1
P10 x≠y?
P11 RTN
P12 1
P13 STO+ P
P14 RTN

// check the triple (16.5 bytes)
T01 LBL T
T02 RCL S
T03 x=0? // 3 bars
T04 XEQ K
T05 RCL S
T06 7
T07 x=y? // 3 sevens
T08 XEQ L
T09 20
T10 STO+ J
T11 GTO U

// add bonus for 3 bars (6.0 bytes)
K01 LBL K
K02 15
K03 STO+ J
K04 RTN

// add bonus for 3 sevens (6.0 bytes)
L01 LBL L
L02 50
L03 STO+ J
L04 RTN

/// show balance (6.0 bytes)
U01 LBL U
U02 RCL J
U03 FIX 2
U04 STOP (R/S)

Good luck!

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

HP Prime: At the Races


HP Prime:  At the Races

I am planning to do lots of gaming this month of June 2018.

Note: Symbols that are produced by Unicode should, but may not show up on all browsers. Please make sure your browsers are updated to the latest version.  

🐎 (Trumpet Sounds)  🐎

The program GAME_RACE simulates a race between seven racers:

Apple ѽ  (Decimal Unicode: 1149, Hexadecimal Unicode: 47D)
Knight ♞ (Decimal Unicode: 9822, Hexadecimal Unicode: 265E)
Spade ♠ (Decimal Unicode: 9824, Hexadecimal Unicode: 2660)
Club ♣ (Decimal Unicode: 9827, Hexadecimal Unicode: 2663)
Heart ♥ (Decimal Unicode: 9289, Hexadecimal Unicode: 2665)
Diamond ♦ (Decimal Unicode: 9830, Hexadecimal Unicode: 2666)
Spike ✥ (Decimal Unicode: 10021, Hexadecimal Unicode: 2725)

To watch a race in action, all you have to do is to run GAME_RACE.  Betting not included. 



🐎  HP Prime Program GAME_RACE 🐎

EXPORT GAME_RACE()
BEGIN
// 2018-04-15 EWS

// initialize racers
// apple
LOCAL l1:={1149,#FF0000h,300,30};
// knight
LOCAL l2:={9822,#C0C0C0h,300,45};
// spade
LOCAL l3:={9824,#400080h,300,60};
// club
LOCAL l4:={9827,#000080h,300,75};
// heart
LOCAL l5:={9829,#FF0000h,300,90};
// diamond
LOCAL l6:={9830,#F0E090h,300,105};
// spike
LOCAL l7:={10021,#808080h,300,120};

// the race
LOCAL h,k,j,q;

FOR h FROM 1 TO 3 DO
RECT(#00FF00h);
TEXTOUT_P(CHAR(1149)+CHAR(9822)+
CHAR(9824)+CHAR(9827)+CHAR(9829)+
CHAR(9830)+CHAR(10021),125,100,5);
TEXTOUT_P(STRING(3-h+1),125,120,5);
WAIT(1);
END;
TEXTOUT_P(" ",125,120,5,0,25,#00FF00h);
TEXTOUT_P("And they're off!",125,
120,5);
WAIT(0.5);

REPEAT

// background
RECT();

// background
FILLPOLY_P({(20,0),(20,150),
(330,150),(330,0)},#00FF00h);
FILLPOLY_P({(0,0),(0,150),
(20,150),(20,0)},#E0E0E0h);
LINE_P(0,25,330,25);
// crowd
FOR h FROM 20 TO 300 STEP 10 DO
TEXTOUT_P(CHAR(9823),h,0,5);
END;
TEXTOUT_P(CHAR(9818),140,0,5,#000080h);
TEXTOUT_P(CHAR(9819),150,0,5,#FF0000h);
// racers
FOR h FROM 1 TO 7 DO
TEXTOUT_P(CHAR(1149),l1(3),l1(4),5,l1(2));
TEXTOUT_P(CHAR(9822),l2(3),l2(4),5,l2(2));
TEXTOUT_P(CHAR(9824),l3(3),l3(4),5,l3(2));
TEXTOUT_P(CHAR(9827),l4(3),l4(4),5,l4(2));
TEXTOUT_P(CHAR(9829),l5(3),l5(4),5,l5(2));
TEXTOUT_P(CHAR(9830),l6(3),l6(4),5,l6(2));
TEXTOUT_P(CHAR(10021),l7(3),l7(4),5,l7(2));
END;

WAIT(0.5);
// move the racers
l1(3):=l1(3)-RANDINT(1,3)*5;
l2(3):=l2(3)-RANDINT(1,3)*5;
l3(3):=l3(3)-RANDINT(1,3)*5;
l4(3):=l4(3)-RANDINT(1,3)*5;
l5(3):=l5(3)-RANDINT(1,3)*5;
l6(3):=l6(3)-RANDINT(1,3)*5;
l7(3):=l7(3)-RANDINT(1,3)*5;


q:={l1(3),l2(3),l3(3),
l4(3),l5(3),l6(3),l7(3)};
q:=q<5;
q:=ΣLIST(q);
UNTIL q>0;

TEXTOUT_P("The race is over!",
0,160,5,#008000h);

WAIT(0);
END;

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

HP Prime: Treasure Hunt


HP Prime:  Treasure Hunt

Background

The game show Treasure Hunt had three series on TV:  1956 – 1959, 1973 – 1977, and 1981 – 1982.  Generally, two contestants (three in the 1973 – 1977 series) play a mini-game where the winner earned the right to hunt for treasure. 

On the treasure hunt, the contestant selected from 1 of 30 (66 in 1981 – 1982) boxes.  Each box had a cash envelope that was offered as a sure thing.  Either the contestant took the sure thing or took the box.  The boxes contained various prizes, from cars and trips to “klunks” (prank prizes not worth very much).  One box always had a cash jackpot.  In the 1973 – 1977 series, the jackpot box had $25,000.

In the 1973 -1977 and 1981 – 1982 series, the contestants were always female.

Can you find the treasure?

The program GAME_TREASURE presents you with 12 boxes, one has $50,000.  Select a box by just tapping the screen.  You will then be presented with a sure thing.  A choose box will be presented where you make your choice to take the sure thing or take a risk and open the box.  Good luck.  Below is an example game in progress.





HP Prime Program GAME_TREASURE

EXPORT GAME_TREASURE()
BEGIN
// EWS 2018-04-14

// Intro screen
// Dark green screen (fir green)
RECT(#003000h);

// Intro screen
TEXTOUT_P("Are you ready to make money?",
0,0,4,#FFFF00h);
TEXTOUT_P("Welcome to your treasure",
0,20,4,#FFFF00h);
TEXTOUT_P("hunt! Choose your box and",
0,40,4,#FFFF00h);
TEXTOUT_P("GOOD LUCK!",
0,60,4,#FFFF00h);
WAIT(1.5);

// select money boxes
LOCAL tlst,sure,tar;
tlst:=RANDINT(12,1,15000);
tar:=RANDINT(1,12);
tlst(tar):=50000;
sure:=RANDINT(1000,6000);

// draw boxes
LOCAL tx,ty,I,J,L:=1;
tx:={10,70,80,140,150,210,220,280};
ty:={10,60,70,120,130,180};

LOCAL c,m,m1,mx,my;

WHILE MOUSE(1)≥0 DO END;

// draw the boxes
RECT();
FOR J FROM 0 TO 2 DO
FOR I FROM 0 TO 3 DO

FILLPOLY_P({
(tx(2*I+1),ty(2*J+1)),
(tx(2*I+2),ty(2*J+1)),
(tx(2*I+2),ty(2*J+2)),
(tx(2*I+1),ty(2*J+2))},#0000FFh);
// text
TEXTOUT_P(L,tx(2*I+1)+10,
ty(2*J+1)+15,7,#FFFFFFh);
L:=1+L;
END;
END;

// get user choice
REPEAT
m:=MOUSE(); m1:=m(1);
UNTIL SIZE(m1)>0;
mx:=m1(1); my:=m1(2);

IF (mx≥10 AND mx≤70) AND
(my≥10 AND my≤60) THEN
c:=1;
END;

IF (mx≥80 AND mx≤140) AND
(my≥10 AND my≤60) THEN
c:=2;
END;

IF (mx≥150 AND mx≤210) AND
(my≥10 AND my≤60) THEN
c:=3;
END;

IF (mx≥220 AND mx≤280) AND
(my≥10 AND my≤60) THEN
c:=4;
END;

IF (mx≥10 AND mx≤70) AND
(my≥70 AND my≤120) THEN
c:=5;
END;

IF (mx≥80 AND mx≤140) AND
(my≥70 AND my≤120) THEN
c:=6;
END;

IF (mx≥150 AND mx≤210) AND
(my≥70 AND my≤120) THEN
c:=7;
END;

IF (mx≥220 AND mx≤280) AND
(my≥70 AND my≤120) THEN
c:=8;
END;

IF (mx≥10 AND mx≤70) AND
(my≥130 AND my≤180) THEN
c:=9;
END;

IF (mx≥80 AND mx≤140) AND
(my≥130 AND my≤180) THEN
c:=10;
END;

IF (mx≥150 AND mx≤210) AND
(my≥130 AND my≤180) THEN
c:=11;
END;

IF (mx≥220 AND mx≤280) AND
(my≥130 AND my≤180) THEN
c:=12;
END;

// analysis
RECT();
TEXTOUT_P("BOX "+c,10,10,6);
TEXTOUT_P("Today's sure thing is $"+
sure,10,30,6,#0000FFh);
WAIT(2.5);
LOCAL h;
CHOOSE(h,"$"+sure+"?",
"Take it!","The box!");

RECT();
TEXTOUT_P("BOX "+c,10,10,6);
IF h==1 THEN
TEXTOUT_P("Today's sure thing is $"+
sure,10,30,6,#0000FFh);
TEXTOUT_P("Your box had $"+
tlst(c),10,50,6);
ELSE
TEXTOUT_P("You turned down $"+sure,
10,30,6);
WAIT(0.75);
TEXTOUT_P("Your box has.... ",
10,50,6);
WAIT(0.75);
TEXTOUT_P("$"+tlst(c)+"!",
10,70,6,#00A060h);
END;

IF tlst(c)≠50000 THEN
LOCAL w;
w:=POS(tlst,50000);
TEXTOUT_P("Box "+w+" had the $50000.",
10,110,6);
END;

WAIT(0);
END;

Source:
“Treasure Hunt (U.S. Game Show)” Wikipedia.  April 12, 2018.  Retrieved June 3, 2018.  Link:  https://en.wikipedia.org/wiki/Treasure_Hunt_(U.S._game_show)

Eddie

All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

Classic RPN Stack Operations

  Classic RPN Stack Operations Starting Stack: T:  d Z:  c Y:  b X:  a OVER :   Copies b to the Z and X stacks, while leaving ...