Anonymous user
Playing cards: Difference between revisions
m
→version 2: added/changed comments and whitespace.
m (→version 2: added/changed comments and whitespace.) |
|||
Line 3,662:
===version 2===
<lang rexx>/*REXX
box = build(); say ' box of cards:' box /*a brand new standard box of
deck=shuffle(); say 'shuffled deck:' deck /*obtain a randomly shuffled deck. */
call deal 5, 4 /*
say; say; say right('[north]' hand.1,50)
say; say '[west]' hand.4 right('[east]' hand.2,60)
say; say right('[south]' hand.3,50)
say; say; say; say 'remainder of deck: ' deck
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
build: _=; ranks= "A 2 3 4 5 6 7 8 9 10 J Q K" /*ranks. */
if 5=='f5'x then suits= "h d c s" /*EBCDIC? */
else suits= "♥ ♦ ♣ ♠" /*ASCII. */
#ranks=words(ranks);
do r=1 for #ranks; _=_ word(ranks, r)@
end /*
return _
/*──────────────────────────────────────────────────────────────────────────────────────*/
shuffle: y=;
do shuffler=1 for #cards /*shuffle all the cards in deck. */
?=random(1, #cards + 1 - shuffler) /*each shuffle, random# decreases*/
y=y word(_, ?) /*shuffled deck, 1 card at─a─time*/
_=delword(_, ?, 1) /*delete the just─chosen card. */
end /*shuffler*/
return y
/*──────────────────────────────────────────────────────────────────────────────────────*/
deal:
do #cards /*deal the hand to the players. */
do player=1 for hands /*deal some cards to the players.*/
hand.player=hand.player word(deck, 1) /*deal the top card.*/
deck=subword(deck, 2) /*diminish deck, remove one card.*/
end /*player*/
end /*#cards*/
return
</lang>
'''output'''
<pre>
|