CardTrick01

A Simple Card Trick
In this simple card trick, you choose a card from one of the 21 displayed. The computer will guess your chosen card simply by asking you in which column your card lies.

code Dim Deck(52) Dim DisplayCard(3, 7)

[CardMagic] Call ShuffleDeck Print "Choose a card. Don't tell me.  Keep it a secret." Print " " Call DealColumns For i = 1 to 3 Print " " Input "In which column is your card now";col Print" ": Print " " Call ScoopColumns col Call DealColumns Next i   Print " ": Print " " Print "Your secret card is the ";CardDesc$(DisplayCard(2, 4));"!" Print " ": Print " " Input "Play again";yn$ If Instr(Upper$(yn$), "Y") Then [CardMagic] Cls Print " ": Print " " Print "Thank you for playing. Maybe you'll stump me next time.  :)" End

Sub ShuffleDeck For i = 1 to 52 Deck(i) = i   Next i    For i = 52 to 2 Step -1 c = Int(Rnd(1) * i) + 1 temp = Deck(i) Deck(i) = Deck(c) Deck(c) = temp Next i End Sub

Sub ScoopColumns nCol Select Case nCol Case 1 c1 = 2 c2 = 1 c3 = 3 Case 2 c1 = 3 c2 = 2 c3 = 1 Case 3 c1 = 2 c2 = 3 c3 = 1 End Select n = 0 For row = 1 to 7 n = n + 1 Deck(n) = DisplayCard(c1, row) Next row For row = 1 to 7 n = n + 1 Deck(n) = DisplayCard(c2, row) Next row For row = 1 to 7 n = n + 1 Deck(n) = DisplayCard(c3, row) Next row End Sub

Sub DealColumns cls Print "Magic Card Trick" Print " " col = 1 row = 1 For i = 1 to 21 DisplayCard(col, row) = Deck(i) card$ = CardDesc$(DisplayCard(col, row)) Print Space$(25 - Len(card$));card$; col = col + 1 If col = 4 Then Print col = 1 row = row + 1 End If   Next i End Sub

Function CardDesc$(card) pip$ = "Ace Deuce Three Four Five Six Seven " + _ "Eight Nine Ten Jack Queen King" n = card mod 13 If n = 0 Then n = 13 End If   n$ = Word$(pip$, n)    suit$ = "Spades Hearts Clubs Diamonds " s = Int(card / 13) + 1 If card / 13 = Int(card / 13) Then s = s - 1 End If   s$ = Word$(suit$, s)    CardDesc$ = n$;" of ";s$ End Function code