Drawing Cards and Video Poker
04-02-2020, 02:33 PM (This post was last modified: 04-02-2020 02:36 PM by Eddie W. Shore.)
Post: #1
 Eddie W. Shore Senior Member Posts: 1,122 Joined: Dec 2013
Drawing Cards and Video Poker
The Function drawcardfx

The function drawcardfx draws a set number of cards from a deck of 52 standard playing cards.

To achieve this effect, I made four lists:

List 1: A list of all integers 0 to 51.

List 2: The suits. I took each of the elements of List 1 MOD 4, giving the answers of 0, 1, 2, 3, respectively. Each of the modulo are assigned to a suit:

0: Clubs. This is character 9827 for the HP Prime. ♣
1: Diamonds. This is character 9826. (9827 - 1) ♢
2: Hearts. This is character 9825. (9827 - 2) ♡
3: Spades. This is character 9824. (9827 - 3) ♠

List 3: The ranks. I divided each element of List 1 by 4, take the integer part, then add 1. For example: for card number 17: IP(17/4) + 1 = IP(4.25) + 1 = 4 + 1 = 5. This is why I let List 1 range for 0 to 51 instead of 1 to 52, since IP(52/4) + 1 = 14 while IP(0/4) + 1 = 1, and I want four 1s, four 2s, four 3s, up to four 13s. There are 13 ranks in a standard deck of cards.

List 4: This list starts empty and will hold all the cards drawn in the hand. Empty lists are allowed in the HP Prime.

I then turned List 2 and List 3 into appropriate strings. For List 3, I turned each 1 into an Ace (A), 11 into a Jack (J), 12 into a Queen (Q), and 13 into a King (K).

The While loop allows me to pull to generate a sample with no repeats. If there is an easier way for me to do this on the HP Prime, please let us in the comments.

The function returns a list of strings in the format "(rank) (suit)".

Example: drawcardfx(5) might return
{"K ♠", "9 ♡", "A ♠", "4 ♢", "K ♣"}

HP Prime Program: drawcardfx

Code:
 EXPORT drawcardfx(n) BEGIN // 2020-04-01 EWS // Draws n cards // single draw // no print out LOCAL x,k,t,s; LOCAL L1,L2,L3,L4; RANDSEED(); // list of cards L1:=MAKELIST(x,x,0,51); L2:=9827-(L1 MOD 4); L3:=IP(L1/4)+1; FOR k FROM 1 TO 52 DO L2(k):=CHAR(L2(k)); L3(k):=STRING(L3(k)); IF L3(k)=="1" THEN L3(k):="A"; END; IF L3(k)=="11" THEN L3(k):="J"; END; IF L3(k)=="12" THEN L3(k):="Q"; END; IF L3(k)=="13" THEN L3(k):="K"; END; END; L4:={}; k:=1; WHILE k≤n DO t:=RANDINT(1,52); // if statement IF L1(t)≠0 THEN s:=L3(t)+" "+L2(t); L1(t):=0; L4:=CONCAT(L4,{s}); k:=k+1; END; END; // end the program RETURN L4; END;

A Simple Video Poker Program

The program VIDEOPOKER is simple video poker program. You are dealt a hand of 5 cards from a standard 52 card deck. You are then asked to hold every card that you want to keep. Once you decide which cards to keep, that card is held. Executing the DRAW option redraws the cards and you are shown your final hand.

This is a very simple program because there is no better or ranking of hands. This just has the play of the cards.

The game is achieved by having the game draw 10 cards in advance, separating them into groups of 5.

This program will require the function drawcardfx above.

Example Game:
Run VIDEOPOKER - no arguments needed.

6 ♢
5 ♢
10 ♠
Q ♠
6 ♡

A choose box appears after I press [ Enter ]. Let's say I want to hold the pair of sixes. So I highlight each of the sixes and press [ Enter ]. After doing this the choose box now reads:

HOLD?
HELD
5 ♢
10 ♠
Q ♠
HELD
DRAW

I now choose draw and I get:
------------------
Final hand:
6 ♢
A ♠
4 ♢
6 ♣
6 ♡

I improved my hand to a set of sixes (three sixes).

HP Prime Program VIDEOPOKER

Code:
 EXPORT VIDEOPOKER() BEGIN // just for fun // 2020-04-01 EWS // drawcardfx required LOCAL c,k,s,t; LOCAL cardz,L01,L02,Lhand,Lrep,L03; cardz:=drawcardfx(10); L01:=SUB(cardz,1,5); L02:=SUB(cardz,6,10); Lhand:=L01; Lrep:={1,2,3,4,5,6}; PRINT(); PRINT("Your first hand:"); FOR k FROM 1 TO 5 DO PRINT(Lhand(k)); END; WAIT(0); L03:=CONCAT(Lhand,{"DRAW"}); WHILE c≠6 DO CHOOSE(c,"HOLD?",L03); Lrep(c):=0; L03(c):="HELD"; END; FOR k FROM 1 TO 5 DO IF Lrep(k)≠0 THEN Lhand(k):=L02(k); END; END; PRINT("-----------"); PRINT("Final hand:"); FOR k FROM 1 TO 5 DO PRINT(Lhand(k)); END; END;
 « Next Oldest | Next Newest »

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