_TITLE "27 Cards Trick" ' B+ started 2019-11-06 ' Saw this on Internet after Steve's Flip It link [youtube]https://www.youtube.com/watch?v=l7lP9y7Bb5g[/youtube]
' Cool! I wonder if it works half as well as computer program? Let's see!
' So I barrowed Steve's Cards and some code for the presentation.
' 2019-11-08 some changes in wording per jack's suggestion and added do again option.
' 2019-11-10 27 Cards Trick mod 2 attempt a more elegant stacking sub, good success!
' eliminated several variables and arrays.
CONST cardW
= 72, cardH
= 96, marg
= 50, mint
= &HFF88DDAA
DIM SHARED table
(0 TO 8, 0 TO 2) ' store card indexes as layed out each time DIM fav
, cardsAbove
, col
, row
, i
, p$
, pick$
, f$
xSpace
= (_WIDTH - 2 * marg
) / 9 favAgain:
yCP 160, "* * * The 27 Cards Trick * * *"
yCP 200, "I present to you a 27 cards trick I learned from the Internet."
yCP 220, "I will shuffle the deck, and lay out 27 cards in 3 rows."
yCP 240, "You just need to pick a card and tell me which row the card is in."
yCP 260, "I will deal cards 2 more times and ask for the row the card is in now."
yCP 280, "I will then show you your card."
inputG 132, 320, "But first, enter your favorite number between 1 and 27 (inclusive)", f$, 4
cardsAbove = fav - 1
pass
(3) = INT(cardsAbove
/ 9) pass
(2) = INT((cardsAbove
- 9 * pass
(3)) / 3) pass(1) = (cardsAbove - 9 * pass(3)) - pass(2) * 3
yCP 340, "Number needs to be > 0 and < 28. Try again."
Shuffle
p$ = "Choose any card then enter the row: 1, 2 or 3 that card is on >"
p$ = "Again, enter the row: 1, 2 or 3 that the card is on now >"
p$ = "One last time, enter the row: 1, 2 or 3 that the card is now on >"
tryAgain:
deal27
stacks2deck pass(i), pick$
'go back and get a proper row
DisplayCard col * xSpace + marg, row * ySpace + marg, Deck(i)
i = i + 1
quiz:
p$
= "Isn't that your card at your favorite number," + STR$(fav
) + ", on the end?" p$ = "Want to see the trick again? enter y for yes, any other for no >"
DisplayCard col * xSpace + marg, row * ySpace + marg, Deck(i)
table(col, row) = Deck(i)
i = i + 1
' I am sure there is a less awkward way to do this but I am eager to share, mod 2 YES! there is!
SUB stacks2deck
(place
, pick$
) Deck(i + place * 9) = table(i, nPick)
Deck
(i
+ ((place
+ 1) MOD 3) * 9) = table
(i
, ((nPick
+ 1) MOD 3)) Deck
(i
+ ((place
+ 2) MOD 3) * 9) = table
(i
, ((nPick
+ 2) MOD 3))
SUB DisplayCard
(x
, y
, index
) suit
= index \
13: value
= index
MOD 13 _PUTIMAGE (x
, y
)-STEP(cardW
, cardH
), CardImage
, 0, (value
* cardW
, suit
* cardH
)-STEP(cardW
, cardH
)
SUB yCP
(y
, s$
) 'for xmax pixel wide graphics screen Center Print at pixel y row
FOR i
= 0 TO 51: Deck
(i
) = i:
NEXT 'put the cards in the deck
'INPUT for Graphics screen
SUB inputG
(x
, y
, prmpt$
, var$
, expectedLenVar%
) 'input for a graphics screen x, y is where the prompt will start , returns through var$ _PRINTSTRING (x
, y
), prmpt$
+ " {" + tmp$
+ "}" + SPACE$(expectedLenVar%
- LEN(tmp$
)) 'spaces needed at end to clear backspace chars
'screen snapshot
mult = textHeight / 16
xlen
= LEN(txt$
) * 8 * mult