Deal cards for FreeCell: Difference between revisions
Content added Content deleted
m (added whitespace before the TOC, added other whitespace in the task's preamble.) |
(added FreeBASIC) |
||
Line 1,123: | Line 1,123: | ||
4C QS 9C 9H 7C 6H 2C 2S |
4C QS 9C 9H 7C 6H 2C 2S |
||
4S TS 2H 5D JC 6C JH QH |
4S TS 2H 5D JC 6C JH QH |
||
JD KS KC 4H</pre> |
|||
=={{header|FreeBASIC}}== |
|||
<lang freebasic>' version 04-11-2016 |
|||
' compile with: fbc -s console |
|||
' to seed ms_lcg(seed > -1) |
|||
' to get random number ms_lcg(-1) or ms_lcg() or just ms_lcg |
|||
Function ms_lcg(seed As Integer = -1) As UInteger |
|||
Static As UInteger ms_state |
|||
If seed <> -1 Then |
|||
ms_state = seed Mod 2 ^ 31 |
|||
Else |
|||
ms_state = (214013 * ms_state + 2531011) Mod 2 ^ 31 |
|||
End If |
|||
Return ms_state Shr 16 |
|||
End Function |
|||
' ------=< MAIN >=------ |
|||
Dim As UByte card(51) |
|||
Dim As String suit = "CDHS", value = "A23456789TJQK" |
|||
Dim As Long i, c, s, v, game = 1 |
|||
Dim As ULong game_nr(1 To 2) = { 1, 617} |
|||
Do |
|||
ms_lcg(game_nr(game)) ' seed generator |
|||
Print "game #"; game_nr(game) |
|||
game = game + 1 |
|||
For i = 0 To 51 ' set up the cards |
|||
card(i) = i |
|||
Next |
|||
For i = 51 To 0 Step -1 ' shuffle |
|||
c = ms_lcg Mod (i +1) |
|||
Swap card(i), card(c) |
|||
Next |
|||
c = 0 |
|||
Do |
|||
For i = 0 To 7 |
|||
s = card(51 - c) Mod 4 |
|||
v = card(51 - c) \ 4 |
|||
Print Chr(value[v]); Chr(suit[s]); " "; |
|||
c = c +1 |
|||
If c > 51 Then Exit Do |
|||
Next |
|||
Print |
|||
Loop |
|||
Print : Print |
|||
Loop Until game > UBound(game_nr) |
|||
' empty keyboard buffer |
|||
While Inkey <> "" : Wend |
|||
Print : Print "hit any key to end program" |
|||
Sleep |
|||
End</lang> |
|||
{{out}} |
|||
<pre>game #1 |
|||
JD 2D 9H JC 5D 7H 7C 5H |
|||
KD KC 9S 5S AD QC KH 3H |
|||
2S KS 9D QD JS AS AH 3C |
|||
4C 5C TS QH 4H AC 4D 7S |
|||
3S TD 4S TH 8H 2C JH 7D |
|||
6D 8S 8D QS 6C 3D 8C TC |
|||
6S 9C 2H 6H |
|||
game #617 |
|||
7D AD 5C 3S 5S 8C 2D AH |
|||
TD 7S QD AC 6D 8H AS KH |
|||
TH QC 3H 9D 6S 8D 3D TC |
|||
KD 5H 9S 3C 8S 7H 4D JS |
|||
4C QS 9C 9H 7C 6H 2C 2S |
|||
4S TS 2H 5D JC 6C JH QH |
|||
JD KS KC 4H</pre> |
JD KS KC 4H</pre> |
||