Playing cards: Difference between revisions
Content added Content deleted
m (→{{header|BASIC}}: Refine implementation: QuickBASIC.) |
(Playing cards in BASIC256) |
||
Line 1,116: | Line 1,116: | ||
2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC AD 2D 3D 4D 5D 6D 7D 8D 9D TD JD QD KD |
2C 3C 4C 5C 6C 7C 8C 9C TC JC QC KC AD 2D 3D 4D 5D 6D 7D 8D 9D TD JD QD KD |
||
</pre> |
</pre> |
||
=={{header|BASIC256}}== |
|||
{{trans|Run BASIC}} |
|||
<syntaxhighlight lang="vb">suite$ = "CDHS" #Club, Diamond, Heart, Spade |
|||
card$ = "A23456789TJQK" #Cards Ace to King |
|||
card = 0 |
|||
dim n(55) #make ordered deck |
|||
for i = 1 to 52 # of 52 cards |
|||
n[i] = i |
|||
next i |
|||
for i = 1 to 52 * 3 #shuffle deck 3 times |
|||
i1 = int(rand * 52) + 1 |
|||
i2 = int(rand * 52) + 1 |
|||
h2 = n[i1] |
|||
n[i1] = n[i2] |
|||
n[i2] = h2 |
|||
next i |
|||
for hand = 1 to 4 #4 hands |
|||
for deal = 1 to 13 #deal each 13 cards |
|||
card += 1 #next card in deck |
|||
s = (n[card] mod 4) + 1 #determine suite |
|||
c = (n[card] mod 13) + 1 #determine card |
|||
print mid(card$,c,1);mid(suite$,s,1);" "; #show the card |
|||
next deal |
|||
print |
|||
next hand |
|||
end |
|||
function word$(sr$, wn, delim$) |
|||
j = wn |
|||
if j = 0 then j += 1 |
|||
res$ = "" : s$ = sr$ : d$ = delim$ |
|||
if d$ = "" then d$ = " " |
|||
sd = length(d$) : sl = length(s$) |
|||
while true |
|||
n = instr(s$,d$) : j -= 1 |
|||
if j = 0 then |
|||
if n=0 then res$=s$ else res$=mid(s$,1,n-1) |
|||
return res$ |
|||
end if |
|||
if n = 0 then return res$ |
|||
if n = sl - sd then res$ = "" : return res$ |
|||
sl2 = sl-n : s$ = mid(s$,n+1,sl2) : sl = sl2 |
|||
end while |
|||
return res$ |
|||
end function</syntaxhighlight> |
|||
{{out}} |
|||
<pre>Same as Run BASIC entry.</pre> |
|||
=={{header|Batch File}}== |
=={{header|Batch File}}== |