_TITLE "256 Cards Trick" ' B+ started 2019-11-06 from 27 Cards Trick ' 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.
' 2019-11-10 OK try 256 Cards Trick! This ought to be good! ;-))
CONST xmax
= 1284, ymax
= 500, cardW
= 18, cardH
= 40, marg
= 2, xSpace
= 20, ySpace
= 50, mint
= &HFF88DDAA, deepblue
= &HFF000044
DIM SHARED table
(0 TO 63, 0 TO 3) ' store card indexes as layed out each time DIM fav
, cardsAbove
, col
, row
, i
, p$
, pick$
, f$
, remains
favAgain:
yCP 160, "* * * The 256 Cards Trick * * *"
yCP 200, "I present to you a 256 cards trick a modified 27 Cards Trick I learned from the Internet."
yCP 220, "I will shuffle the deck, and lay out 256 cards in 4 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 3 more times and ask for the row the card is in now."
yCP 280, "I will then show you your card."
p$ = "But first, enter your favorite number between 1 and 256 (inclusive)"
inputG
(_WIDTH - (LEN(p$
) + 6) * 8) / 2, 320, p$
, f$
, 4 cardsAbove = fav - 1
pass
(4) = INT(cardsAbove
/ 64) remains = cardsAbove - 64 * pass(4)
pass
(3) = INT(remains
/ 16) remains = remains - 16 * pass(3)
pass
(2) = INT(remains
/ 4) pass(1) = remains - 4 * pass(2)
yCP 340, "Number needs to be > 0 and < 257. Try again."
Shuffle
p$ = "Choose any card then enter the row: 1, 2, 3 or 4 that card is on >"
p$ = "Again, enter the row: 1, 2, 3 or 4 that the card is on now >"
p$ = "One last time, enter the row: 1, 2, 3 or 4 that the card is now on >"
tryAgain:
deal256
stacks2deck pass(i), pick$
'go back and get a proper row
drawCard 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 >"
drawCard 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 * 64) = table(i, nPick)
Deck
(i
+ ((place
+ 1) MOD 4) * 64) = table
(i
, ((nPick
+ 1) MOD 4)) Deck
(i
+ ((place
+ 2) MOD 4) * 64) = table
(i
, ((nPick
+ 2) MOD 4)) Deck
(i
+ ((place
+ 3) MOD 4) * 64) = table
(i
, ((nPick
+ 3) MOD 4))
SUB yCP
(y
, s$
) 'for xmax pixel wide graphics screen Center Print at pixel y row
FOR i
= 0 TO 255: 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
DIM s4$
, clr
, c~&
, shape
, n$
, op
s4$ = DecBase4$(i)
LINE (x
, y
)-STEP(cardW
, cardH
), &HFFFFFFFF, BF
polygon x
+ 9, y
+ 30, 8, shape
+ 3, _PI(1.5) PAINT (x
+ 9, y
+ 30), c~&
, &HFF000000 COLOR &HFFFFFFFF, deepblue
n = nDec 'copy this because or nDec gets changed effecting main code
n = n - d * 4 ^ pow
b$ = b$ + "0"
DecBase4$ = b$
SUB polygon
(xOrigin
, yOrigin
, radius
, nVertex
, RadianAngleOffset!
) DIM polyAngle!
, x1!
, y1!
, i
, x2!
, y2!
polyAngle!
= _PI(2) / nVertex
x1!
= xOrigin
+ radius
* COS(polyAngle!
+ RadianAngleOffset!
) y1!
= yOrigin
+ radius
* SIN(polyAngle!
+ RadianAngleOffset!
) x2!
= xOrigin
+ radius
* COS(i
* polyAngle!
+ RadianAngleOffset!
) y2!
= yOrigin
+ radius
* SIN(i
* polyAngle!
+ RadianAngleOffset!
) LINE (x1!
, y1!
)-(x2!
, y2!
) x1! = x2!: y1! = y2!