Showing posts with label simulation. Show all posts
Showing posts with label simulation. Show all posts

Sunday, March 17, 2024

Casio fx-9750GIII and fx-CG 50: Playing Games with the Probability Simulation Mode

Casio fx-9750GIII and fx-CG 50: Playing Games with the Probability Simulation Mode






The Probability Simulation add-in has six types of probability simulations:

* Coin Toss

* Dice Roll

* Spinner

* Marble Grab

* Card Draw

* Random Numbers


The add-in application is available for the following calculators:

* Casio fx-9750GIII and fx-9860GIII (and Graph 75/85/95 series, Graph 35+ E II)

* Casio fx-CG 10/20 and fx-CG 50 (and Graph 90+E)

* Casio fx-9860G


I believe on the fx-9750GIII and fx-9860GIII, the Probability Simulation Add-In is available out of the box. For others, the add-in can be downloaded through Casio’s Worldwide Education Website: https://edu.casio.com/download/index.php.


Let’s look at three ways we can use the Probability Simulation add-in in games of chance. This is a great app when you don’t have a pair of dice, playing cards, or a bag of marbles around.


In the Set Up menu, there is an option for seed from 1 to 99999.


Screen shots are from the fx-CG 50.


Interaction with Other Modes


* Data can be stored into global lists 1-26. Lists in these Casio calculators contain only numerical information. Numerical codes are used for card suits and face cards.


* There are no commands from the Add-In that can be used in programming. The simulation is mean to be a stand-alone app.




Drawing a Poker Hand






From the main screen, press F5 for Card Draw. To simulate poker, go into set up by pressing [SHIFT] {SET UP}. We can set either a 52 playing card deck, which is the standard deck without Jokers, or a reduced deck of 32 cards (sevens through Aces only). We don’t want Replacement, so turn that off. Press [ EXIT ] to go back to the simulation.


To draw a single card, press [ F1 ]. To draw multiple cards, press [ F2 ] for { +n }. At the prompt, press [AC/ON] and enter the number of cards.


We will have to memorize the cards or note the down on paper or another writing device.


To save the cards drawn, select [ F3 ] (STORE). There are three lists:


Draw: Draw number

Value: Card value. 1 = Ace, 11 = Jack, 12 = Queen, 13 = King

Suit: 1 = Heart, 2 = Club, 3 = Spade, 4 = Diamond


Lists can be allocated to the global list variables List 1 to List 26. Press [ F6 ] { EXE } to store the cards. Storing results works similarly in other applications.



Rolling Dice in Adventure Games





In adventure and fantasy games such as Dungeon and Dragons, sometimes dice beyond the standard six-sided die is needed. The Dice Roll (F2 from the Main Menu) has dice that are four-sided, six-sided, eight-sided, twelve-sided, and twenty-sided. Up to three dice can be thrown at once.


A Simple Lottery





Random integers from 0 to 99 can be drawn with the Random Numbers. Again, the set up menu is the key. For the lottery, turn the Repeat option off. Above are four draws from a simple lottery from 63 numbers.



This has been a look at Casio’s Probability Simulation Add-In. Until next time,


Eddie


All original content copyright, © 2011-2024. 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.


Sunday, April 9, 2023

Casio fx-9750GIII: Drawing the Unit Circle with an Angle

Casio fx-9750GIII:  Drawing the Unit Circle with an Angle


Introduction


The program TRIGCIRC draws a unit circle on the left side of the screen with any angle entered.  This program is an approximate simulation to the trigonometric circle application that is set to appear on future Casio non-graphing calculators in Europe, such as Belgium version of the fx-92.  Link:  https://tiplanet.org/forum/viewtopic.php?p=271049#p271049  


The program uses the full unit circle only.  



Casio fx-9750GIII Program: TRIGCIRC

(316 bytes)


Code:


Lbl 5

ClrText

Menu "ANGLE","DEG",1,"RAD",2,"GRAD",3

Lbl 1:Deg:Goto 4

Lbl 2:Rad:Goto 4

Lbl 3:Gra:Goto 4

Lbl 4

ClrGraph

ViewWindow -1.5,5,1,-1.5,1.5,1

"ANGLE"?→A

SketchThick Circle 0,0,1

SketchThick F-Line 0,0,cos A,sin A

Text 5,70,"sin θ:"

Text 12,70,sin A

Text 19,70,"cos θ:"

Text 26,70,cos A

If cos A≠0

Then

Text 33,70,"tan θ:"

Text 40,70,tan A

IfEnd

Text 47,70,"θ:"

Text 54,70,A◢

Menu "AGAIN?","YES",5,"NO",6

Lbl 6

"END - 2023 EWS"



Program Notes:


1.  Adding a display command, ◢, after a draw command like Text freezes the draw screen.  Program execution continues by pressing [ EXE ].


2.  The Text command works with pixels rather than Cartesian points.   Line numbers range from 0 to 63, top to down.  Column numbers range from 0 to 127, right to left.


3.  Syntax of Text:  Text line number, column number, text.   Text may have a string or a variable, but not both.


4.  I have a wrap-around label (Lbl 5) to let the user enter multiple angles.


5.  Due to the linear output of the programming mode, results are shown in floating point decimal approximations.  


6.  tan x = sin x / cos x.  If cos x = 0, then tan x is undefined.   This is why the If condition is present.  



Example Screenshots






I hope you find this useful and educational.  Have an excellent day,


Eddie 



All original content copyright, © 2011-2023.  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. 


Saturday, June 16, 2018

Casio fx-CG 50 and HP Prime: The Price is Right Wheel Simulation


Casio fx-CG 50 and HP Prime: The Price is Right Wheel Simulation

Introduction

On the very famous game show, The Price Is Right, currently enjoying its fifth decade in its current run on television (1972-present), the hour long game show is divided into three segments.  The first two segments are played this way:

* An item up for bid is presented to four contestants who directly called from the audience.  Whoever gets closest to the actual retail price without going over wins the prize and plays a pricing game. This cycle occurs three times.

* The three winners play in a Showcase Showdown, where they spin a wheel.  The goal is obtain a score closest to one dollar without going over.  The winner advances to the final Showcase round.

The third segment is the Showcase round played by the two winners of the Showcase Showdown, where prize packages worth thousands of dollars are at stake.

This blog will present a simulation of the Showcase Showdown.  Like the game show, the amounts are shown in cents, where 100 represents one dollar. 

Single Spin Simulation:  Casio fx-CG 50

This program simulates a single spin.  The spin starts on the dollar (100) space.  The space that the pointer is in red with arrows pointed at it.  You can use the program on monochrome screens if you wish, just not type the color commands (Black, Red).

Casio fx-CG50 Program TRIPWHL1

“EWS 2018-06-12”
{100,15,80,35,60,20,40,
75,55,95,50,85,30,65,10,
45,70,25,90,5}→List 1
1 → P
For 1 → K To RanInt#(20, 60)
ClrText
MOD(P, 20) → P
MOD(P+18, 20) → A
MOD(P+19, 20) → B
MOD(P, 20) → C
MOD(P+1, 20) → D
MOD(P+2 ,20) → E
A = 0 20 → A
B = 0 20 → B
C = 0 20 → C
D = 0 20 → D
E = 0 20 → E
Black Locate 5, 2, List 1[E]
Black Locate 5, 3, List 1[D]
Red Locate 5, 4, List 1[C]
Red Locate 10, 4 “
Black Locate 5, 5, List 1[B]
Black Locate 5, 6, List 1[A]
MOD(P+1, 20) → P
.1 + .4 K → T
For .1 → I To T Step .1
Next
Next

Note:  The lines .1+.4K and the second For loop that follows it is to simulate the wheel that slows down as it spins. 

Now, if you want a complete simulation, check out the HP Prime program TPIRWHEEL.

A Showcase Showdown Round Simulation:  HP Prime Program TPIRWHEEL

The program offers two modes:

2 Player Spinoff:  This is a one spin playoff between two players. 

3 Player Normal:  This is a normal game between three players.  Each player may have up to two spins.  If the score exceeds 1 dollar, the player is out, and given a final score of 0.

When entering the names, you do not need to worry about entering the quotes.

Bonus Spins

Should a player get 1 dollar in one spin or their score from two spins add up to 1 dollar, then the player gets a bonus spin and wins $1,000.  The bonus spin always starts from the 5 cent position.  Unlike the game show, all bonus spins are taken immediately.  Landing on the green 5 cents and 15 cents spaces wins $10,000, while landing on the red dollar space on the bonus spins wins $25,000.  The amount on the bonus spin does not affect the player’s final score.

End of the Game

The end of the game will lists the players and their final scores.

HP Prime Program TPIRWHEEL
The program is over 10,000 bytes in memory. 

sbr1(); // subroutine - wheel

EXPORT TPIRWHEEL()
BEGIN
// EWS 2018-06-09
// The Price Is Right Showcase Showdown
// Simulator - Official Version
// bonus spins starts immediately
// 2 player spinoff mode (manual)

// Setup
LOCAL n,k,j,t,str1,str2,str3;
LOCAL str4,m,b;
CHOOSE(n,"Number of Players",
{"2 Player Spinoff",
"3 Player Normal"});
n:=n+1;
LOCAL players:={};
LOCAL scores:=MAKELIST(0,X,1,n);
LOCAL bonuses:=MAKELIST(0,X,1,n);

// Names
FOR k FROM 1 TO n DO
str1:="Player "+STRING(k);
INPUT({{str2,[[2]]}},str1,"Name: ");
players:=CONCAT(players,{str2});
END;

// Spin the wheel
RECT(RGB(255,255,0));
IF n==3 THEN
TEXTOUT_P("The goal is to get close to",
10,10,7);
TEXTOUT_P("$1.00 without going over.",
10,40,7);
TEXTOUT_P("You can have up to two spins.",
10,70,7);
TEXTOUT_P("Good luck!",10,100,7);
ELSE
TEXTOUT_P("This is a spinoff.",10,10,7);
TEXTOUT_P("Highest number wins.",10,40,7);
END;
TEXTOUT_P("Press any key to
continue.",10,130,7);
WAIT(0);

// spinning the wheel
LOCAL t,w,w1,w2,ch; // pointer
t:=1;

FOR k FROM 1 TO n DO

MSGBOX(players(k)+"'s 1st spin");
m:=MAX(scores);

// Inital spin
w:=sbr1(t);
t:=w(1);
scores(k):=w(2);


// test for $1 and bonus spin
IF scores(k)==100 THEN
RECT();
TEXTOUT_P(players(k)+" has $1.00!",
10,10,7);
TEXTOUT_P("$1,000 bonus!",10,40,7,
RGB(0,128,0));
bonuses(k):=1000;
WAIT(0);
// bonus spin
MSGBOX("Bonus Spin");
w:=sbr1(1);
t:=w(1); b:=0;
IF w(2)==5 OR w(2)==15 THEN b:=10000 END;
IF w(2)==100 THEN b:=25000 END;
IF b>0 THEN
str4:=players(k)+" has won $"+
STRING(b)+"!";
bonuses(k):=bonuses(k)+b;
ELSE
str4:="No bonus money.";
END;
TEXTOUT_P(str4,10,180,7);
WAIT(0);
CONTINUE; END;

IF n==3 THEN
// second spin?
str4:=players(k)+" has "+
scores(k)+" cents.";
TEXTOUT_P(str4,10,180,7);
WAIT(0);

CHOOSE(ch,
"Score to beat: "+STRING(m)+
" Spin Again?",{"SPIN","STAY"});
IF ch==1 THEN

MSGBOX(players(k)+"'s 2nd spin");

w:=sbr1(t);
t:=w(1);
scores(k):=w(2)+scores(k);

// did the player go over?
IF scores(k)>100 THEN
str4:=players(k)+" has gone over.";
TEXTOUT_P(str4,10,200,7,RGB(255,0,0));
WAIT(0);
scores(k):=0;
END;

// test for $1.00 and bonus spin
IF scores(k)==100 THEN
RECT();
TEXTOUT_P(players(k)+" has $1.00!",
10,10,7);
TEXTOUT_P("$1,000 bonus!",10,40,7,
RGB(0,128,0));
bonuses(k):=1000;
// bonus spin
MSGBOX("Bonus Spin");
w:=sbr1(1);
t:=w(1); b:=0;
IF w(2)==5 OR w(2)==15 THEN b:=10000 END;
IF w(2)==100 THEN b:=25000 END;
IF b>0 THEN
str4:=players(k)+" has won $"+
STRING(b)+"!";
bonuses(k):=bonuses(k)+b;
ELSE
str4:="No bonus money.";
END;
TEXTOUT_P(str4,10,180,7);
WAIT(0);
CONTINUE;
END;

END;

END;

// total score
str4:=players(k)+" has "+
scores(k)+" cents.";
TEXTOUT_P(str4,10,180,7);
WAIT(0);

END;


// end of the game
RECT();
TEXTOUT_P("Final Scores",10,10,7);
FOR k FROM 1 TO n DO
TEXTOUT_P(players(k)+":",10,
10+25*k,7);
TEXTOUT_P(STRING(scores(k)/100,2,2),170,
10+25*k,7);
IF bonuses(k)>0 THEN
TEXTOUT_P("$"+STRING(bonuses(k),2,0),
225,10+25*k,7,RGB(0,128,0)); END;
END;
WAIT(0);

END;


// subroutine spin the wheel
sbr1(x)
BEGIN
LOCAL wheel;

// colors
LOCAL b:=RGB(255,240,240); // snow white
LOCAL r:=RGB(255,0,0); // red
LOCAL dg:=RGB(0,255,0); // lime green
LOCAL tn:=RGB(255,208,0); // tangerine

// the wheel {{amount, color}}
wheel:=
{{100,r},{15,dg},{80,b},
{35,b},{60,b},{20,b},{40,b},
{75,b},{55,b},{95,b},{50,b},
{85,b},{30,b},{65,b},{10,b},
{45,b},{70,b},{25,b},{90,b},
{5,dg}};

// pointer
LOCAL pt,k,pm2,pm1,pc,pp1,pp2;
pt:=x;


// wheel display
FOR k FROM 1 TO RANDINT(20,60) DO
RECT();
pt:=pt MOD 20;

// display
pm2:=(pt+18) MOD 20;
pm1:=(pt+19) MOD 20;
pc:=pt MOD 20;
pp1:=(pt+1) MOD 20;
pp2:=(pt+2) MOD 20;


// box the numbers
RECT_P(74,44,164,144,0);
// borders
LINE_P(74,44,164,44,tn);
LINE_P(74,64,164,64,tn);
LINE_P(74,84,164,84,tn);
LINE_P(74,104,164,104,tn);
LINE_P(74,124,164,124,tn);
LINE_P(74,144,164,144,tn);
LINE_P(74,44,74,144,tn);
LINE_P(164,44,164,144,tn);
// side decoration - left with $
FILLPOLY_P([(28,44),(43,24),(58,24),
(73,44),(73,144),(28,144)],
RGB(255,128,0));
TEXTOUT_P("$",44,74,7,RGB(224,224,224));
// side decoration - right
FILLPOLY_P([(165,44),(180,24),(195,24),
(210,44),(210,144),(165,144)],
RGB(255,128,0));
// draw the pointer
TEXTOUT_P("<<",165,80,7,RGB(255,0,0));
// draw the numbers
TEXTOUT_P(wheel(pp2,1),95,40,7,
wheel(pp2,2));
TEXTOUT_P(wheel(pp1,1),95,60,7,
wheel(pp1,2));
TEXTOUT_P(wheel(pc,1),95,80,7,
wheel(pc,2));
TEXTOUT_P(wheel(pm1,1),95,100,7,
wheel(pm1,2));
TEXTOUT_P(wheel(pm2,1),95,120,7,
wheel(pm2,2));

// slow down the wheel
WAIT(0.08+0.01*k);
// next pointer
pt:=pt+1 MOD 20;

END;

// store results
LOCAL x1:=(pt-1) MOD 20;
IF x1==0 THEN x1:=20; END;
LOCAL x2:=wheel(x1,1);
RETURN {x1,x2};

END;

Source:

“Showcase Showdown” The Price Is Right Wiki.  Retrieved June 8, 2018.  http://priceisright.wikia.com/wiki/Showcase_Showdown

Eddie

All original content copyright, © 2011-2018.  Edward Shore.  

HP 20S: Acoustics Programs

HP 20S: Acoustics Programs Program A: Speed of Sound in Dry Air cs = 20.05 × √(273.15 + T°C) Code: 01: 61, 41, A: LBL A 02: ...