blib/lib/VANAMBURG/Magic.pm

filter: Statementstmt 100% 8 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 2 / 2 Podpod n/a totaltotal 100% 10 / 10 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« lib/VANAMBURG/FaceValueSingleton.pm ↑ Summary lib/VANAMBURG/StackCard.pm »
1 package VANAMBURG::Magic;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 =head1 NAME
7  
8 VANAMBURG::Magic - A resource for the discriminating card magician.
9  
10 =head1 VERSION
11  
12 Version 0.03
13  
14 =cut
15  
16 2 our $VERSION = '0.04';
17  
18  
19 =head1 SYNOPSIS
20  
21 This package is meant for use by magicians. Specifically, it intends to make working with rosary stacks and memorized decks easier to learn.
22 Scripts, such as those included, make it easier to drill memory of stacks. It is easier to practice tricks that use complicated stacks,
23 or mathematical principles, in a virtual environment. By writing simple scripts, such as thouse include in this distribution,
24 a lot of time can be saved during the initial period of learning. Restacking a complex stack with real cards is very time consuming.
25  
26 The modules contained in this package are object oriented and very easy to include in simple scripts or web applications.If you are not familiar with Perl
27 programming but would like to write simple scripts, I recommend a good starting point is "Learn Perl in about 2 hours 30 minutes"
28 By Sam Hughes at his site: http://qntm.org/files/perl/perl.html
29  
30 =head2 CREATE DECKS, PACKETS OR STACKS
31  
32 =head3 Built in Stacks
33
34 # Create stack in Aronson order
35 my $aronson_dec = VANAMBURG::PacketFactory->create_stack_aronson;
36  
37 $my $joyal_chased_deck = VANAMBURG::PacketFactory->create_stack_joyal_chased;
38
39 my $joyal_shocked_deck = VANAMBURG::PacketFactory->create_stack_joyal_shocked;
40
41 my $tamariz_deck = VANAMBURG::PacketFactory->create_stack_mnemonical;
42
43 my $bcs = VANAMBURG::PacketFactory->create_stack_breakthrough_card_system;
44
45 my $si_stebbins = VANAMBURG::PacketFactory->create_si_stebbins_chased_3step;
46  
47 my $si_stebbins_4 = VANAMBURG::PacketFactory->create_si_stebbins_chased_4step;
48
49 my $si_stebbins_shocked = VANAMBURG::PacketFactory->create_si_stebbins_shocked_3step;
50
51 my $si_stebbins_shocked_4 = VANAMBURG::PacketFactory->create_si_stebbins_shocked_4step;
52  
53  
54 =head3 Create arbitrary stacks or packets
55  
56 # Create any arbitrary packet, or deck of cards.
57 my $forcing_deck = VANAMBURG::PacketFactory->create_packet("5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D,5D");
58
59 # Create a stack, where each card has, and retains, a stack number, even when shuffled.
60 my $stack = VANAMBURG::PacketFactory->create_stack("AD,2D,3D,4D,5D,6D,7D,8D,9D,10D,JD,QD,KD");
61
62
63 =head2 DO STUFF WITH PACKETS
64
65 See docuentation for L<VANAMBURG::Packet> for all the operations available for the stacks shown above.
66
67 =head1 A FEW OF THE IMPORTANT MODULES INCLUDED
68  
69 =over
70  
71 =item L<VANAMBURG::Packet>
72  
73 =item L<VANAMBURG::PacketFactory>
74  
75 =item L<VANAMBURG::Card>
76  
77 =item L<VANAMBURG::StackCard>
78  
79 =item L<VANAMBURG::Suit>
80  
81 =item L<VANAMBURG::FaceValue>
82  
83 =back
84  
85 and more ...
86  
87  
88 =head1 INCLUDED SCRIPTS
89  
90 Three training scripts are installed on your system when this module is installed.
91  
92 =head2 memdeckrandom
93  
94 The memdeckrandom script helps train in memory work by offering 10 random cards. The user can choose
95 from 9 stacks and can be trained by either entering the stack number for a card, or entering the
96 card for a given stack number.
97  
98 Example session 1:
99  
100 $ memdeckrandom
101
102 Deck Menu
103 ======================
104 Enter 1 for Breakthrough Card System
105 Enter 2 for Aronson Stack
106 Enter 3 for Tamariz Mnemonica
107 Enter 4 for Joyal SHoCked
108 Enter 5 for Joyal CHaSeD
109 Enter 6 for Si Stebbins CHaSed (step = 3)
110 Enter 7 for Si Stebbins CHaSed (step = 4)
111 Enter 8 for Si Stebbins SHoCkeD (step = 3)
112 Enter 9 for Si Stebbins SHoCkeD (step = 4)
113
114
115 Enter choice: 1
116
117 Menu
118 ======================
119 Enter 1 for Card to Number
120 Enter 2 for Number to Card
121 Enter q to quit
122
123 Enter choice: 1
124
125 When presented with a card, enter the stack number and press enter.
126
127 10 random cards will be presented.
128
129
130 Eight of Diamonds: 19
131 Correct
132 Two of Clubs: 46
133 Correct
134 Two of Hearts: 15
135 Correct
136 Two of Diamonds: 11
137 Correct
138 Queen of Clubs: 5
139 Correct
140 Seven of Diamonds: 4
141 Wrong - stack number = 3
142 Four of Spades: 21
143 Correct
144 Ten of Diamonds: 41
145 Correct
146 Seven of Hearts: 47
147 Correct
148 Nine of Hearts: 34
149 Correct
150
151 bye
152  
153  
154 Example session 2:
155  
156 $ memdeckrandom
157
158 Deck Menu
159 ======================
160 Enter 1 for Breakthrough Card System
161 Enter 2 for Aronson Stack
162 Enter 3 for Tamariz Mnemonica
163 Enter 4 for Joyal SHoCked
164 Enter 5 for Joyal CHaSeD
165 Enter 6 for Si Stebbins CHaSed (step = 3)
166 Enter 7 for Si Stebbins CHaSed (step = 4)
167 Enter 8 for Si Stebbins SHoCkeD (step = 3)
168 Enter 9 for Si Stebbins SHoCkeD (step = 4)
169
170
171 Enter choice: 1
172
173 Menu
174 ======================
175 Enter 1 for Card to Number
176 Enter 2 for Number to Card
177 Enter q to quit
178
179 Enter choice: 2
180 Enter the abbreviation for the card (AS,JD, 2H, etc)
181 when prompted with a stack number.
182
183 10 random stack numbers will be used.
184
185 Card at 1: as
186 Correct
187 Card at 42: js
188 Correct
189 Card at 27: 6h
190 Correct
191 Card at 34: 9h
192 Correct
193 Card at 26: ad
194 Correct
195 Card at 28: ah
196 Correct
197 Card at 43: 10h
198 Correct
199 Card at 44: 9s
200 Correct
201 Card at 49: 8s
202 Correct
203 Card at 14: kh
204 Correct
205
206 bye
207
208  
209  
210 Immediately below I show the source code for this script. If you have computer programming experience, you will easily be able to use it as a guide
211 to creating your own scripts. Teaching Perl is beyond my scope, but if you are interested in learning and need help getting a new script working, please contact
212 me at the email address you will find on this page.
213  
214 =head2 memdecksequence
215  
216 The memdecksequence script is useful in training for either proficiency in using common rosary stacks, or
217 in working sequentially through a mem deck.
218  
219 Example session1:
220  
221 $ memdecksequence
222
223 Rosary Trainer Menu
224 ======================
225 Enter 1 for Breakthrough Card System
226 Enter 2 for Si Stebbins CHaSed (step = 3)
227 Enter 3 for Si Stebbins CHaSed (step = 4)
228 Enter 4 for Si Stebbins SHoCkeD (step = 3)
229 Enter 5 for Si Stebbins SHoCkeD (step = 4)
230
231 Enter q to quit
232
233 Enter choice: 5
234 Direction Menu
235 ======================
236 Enter 1 for Top to Bottom
237 Enter 2 for Bottom to Top
238
239 Enter choice: 1
240 What comes after AS? 5H
241 Correct
242 What comes after 5H? 9C
243 Correct
244 What comes after 9C? KD
245 Correct
246 What comes after KD? 4S
247 Correct
248 What comes after 4S? 8H
249 Correct
250 What comes after 8H?
251  
252 Example session2:
253  
254 $ memdecksequence
255
256 Rosary Trainer Menu
257 ======================
258 Enter 1 for Breakthrough Card System
259 Enter 2 for Si Stebbins CHaSed (step = 3)
260 Enter 3 for Si Stebbins CHaSed (step = 4)
261 Enter 4 for Si Stebbins SHoCkeD (step = 3)
262 Enter 5 for Si Stebbins SHoCkeD (step = 4)
263
264 Enter q to quit
265
266 Enter choice: 2
267
268 Direction Menu
269 ======================
270 Enter 1 for Top to Bottom
271 Enter 2 for Bottom to Top
272
273 Enter choice: 2
274 What comes before JD? 8S
275 Correct
276 What comes before 8S? 5H
277 Correct
278 What comes before 5H? 2C
279 Correct
280 What comes before 2C? KD
281 Wrong - correct answer is QD
282 What comes before QD?
283  
284 =head2 PRACTICING TRICKS WITH SCRIPTS
285  
286 Mem deck magic can be very difficult, especially when math with cards is involved. Also resetting the deck
287 can be time consuming. Using scripts can accelerate improving capability with these skills.
288  
289 =head3 Simon Aronson's "Everybody's Lazy"
290  
291 Get a copy of "Simply Simon" by Simon Aronson, study "Everybody's Lazy" and this will make sense. For now,
292 let it suffice as an example of how you can make practicing math with cards a lot easier and save
293 time resetting.
294  
295 Example sessions:
296  
297 gordon@gordon-LX6810-01$ eblazytrainer
298
299
300 Card C: Ten of Hearts
301
302
303 Enter location for card a: 10
304
305
306 Card A: Eight of Clubs
307
308
309 Enter location for card b: 12
310
311
312 Card B: Six of Hearts
313
314
315 Enter low for range: 15
316 Enter High for range: 31
317 What is card for spectator guess of 27: 4h
318
319
320 Nice job! How did you do that?!
321  
322  
323
324  
325 =head1 SOURCE CODE EXAMPLES
326  
327 While the source is included with this module, it might be helpful to see some example code here.
328  
329 =head2 rosarytrainer source
330  
331 #!/usr/bin/perl
332 use v5.10;
333 use strict;
334 use warnings;
335 use FindBin;
336 use Term::ReadLine;
337 use English;
338 use lib "$FindBin::Bin/../lib";
339 use VANAMBURG::BCS;
340 use VANAMBURG::SiStebbins;
341
342 my $menu = <<END;
343
344 Rosary Trainer Menu
345 ======================
346 Enter 1 for Breakthrough Card System
347 Enter 2 for Si Stebbins CHaSed (step = 3)
348 Enter 3 for Si Stebbins CHaSed (step = 4)
349 Enter 4 for Si Stebbins SHoCkeD (step = 3)
350 Enter 5 for Si Stebbins SHoCkeD (step = 4)
351
352 Enter q to quit
353 END
354 say $menu;
355 my $term = Term::ReadLine->new("BCS Test");
356 my $test = $term->readline("Enter choice: ");
357 exit if ( $test =~ /q/i );
358 exit if !( $test ~~ [ 1, 2, 3, 4, 5 ] );
359
360 my $deck;
361 given ($test) {
362 when (/1/) { $deck = VANAMBURG::BCS->new; }
363 when (/2/) { $deck = VANAMBURG::SiStebbins->new; }
364 when (/3/) { $deck = VANAMBURG::SiStebbins->new( step => 4 ); }
365 when (/4/) {
366 $deck = VANAMBURG::SiStebbins->new( suit_order => 'SHoCkeD' );
367 }
368 when (/5/) {
369 $deck =
370 VANAMBURG::SiStebbins->new( suit_order => 'SHoCkeD', step => 4 );
371 }
372 default { say "unknown option $test. quitting"; exit; }
373 }
374
375 my $sub_menu = <<END;
376
377 Direction Menu
378 ======================
379 Enter 1 for Top to Bottom
380 Enter 2 for Bottom to Top
381 END
382 say $sub_menu;
383 my $direction = $term->readline("Enter choice: ");
384 if ( !( $direction ~~ [ 1, 2 ] ) ) {
385 say "invalid option";
386 exit;
387 }
388
389 my @locations = ( 1 .. 52 );
390 @locations = reverse @locations if ( $direction == 2 );
391 my $first_location = shift @locations;
392
393 my $current_card = $deck->card_at_location($first_location);
394 my $before_after = $direction == 2? 'before':'after';
395 for my $location (@locations) {
396 my $next_card = $deck->card_at_location($location);
397 my $answer = uc $term->readline(
398 "What comes $before_after " . $current_card->abbreviation . '? ' );
399 if ( $answer eq $next_card->abbreviation ) {
400 say "Correct";
401 }
402 else {
403 say "Wrong - correct answer is " . $next_card->abbreviation;
404 }
405 $current_card = $next_card;
406 }
407  
408  
409  
410 =head2 eblazytrainer
411  
412 #!/usr/bin/perl
413 use v5.10;
414 use strict;
415 use warnings;
416 use Term::ReadLine;
417 use FindBin;
418 use lib "$FindBin::Bin/../lib";
419 use VANAMBURG::BCS;
420 use VANAMBURG::RandomNumbers;
421
422 my $bcs = VANAMBURG::BCS->new;
423 my $term = Term::ReadLine->new("Everybody's Lazy");
424
425 my $location_a = VANAMBURG::RandomNumbers->number_between( 10, 17 );
426 my $carda = $bcs->cut_take_bury($location_a);
427
428 my $location_b = VANAMBURG::RandomNumbers->number_between( 10, 17 );
429 my $cardb = $bcs->cut_take_bury($location_b);
430
431 my $location_c = VANAMBURG::RandomNumbers->number_between( 13, 18 );
432 my $cardc = $bcs->cut_take_bury($location_c);
433
434 say( "\nCard C: " . $cardc->display_name . "\n" );
435
436 #
437 # -------- CARD A
438 #
439
440 my $resp = -1;
441 my $card_a_loc = 53 - $cardc->stack_number;
442 while ( $resp != $card_a_loc ) {
443 $resp = $term->readline("Enter location for card a: ");
444 say $card_a_loc if ($resp eq 'help');
445 }
446 say "\nCard A: " . $carda->display_name . "\n";
447 $bcs->cut_and_take($card_a_loc);
448
449 #
450 # -------- CARD B
451 #
452
453 $resp = -1;
454 while ( $resp != $carda->stack_number ) {
455 $resp = $term->readline("Enter location for card b: ");
456 say $carda->stack_number if ($resp eq 'help');
457 }
458 say "\nCard B: " . $cardb->display_name . "\n";
459 $bcs->cut_and_take( $carda->stack_number );
460
461 #
462 # -------- LOW RANGE
463 #
464
465 $resp = -1;
466 my $low_range = $cardb->stack_number - $carda->stack_number;
467 while ( $resp != $low_range ) {
468 $resp = $term->readline("Enter low for range: ");
469 say $low_range if ($resp eq 'help');
470 }
471
472 #
473 # -------- HIGH RANGE
474 #
475
476 $resp = -1;
477 my $high_range = $cardc->stack_number - $carda->stack_number;
478 while ( $resp != $high_range ) {
479 $resp = $term->readline("Enter High for range: ");
480 say $high_range if ($resp eq 'help');
481 }
482
483
484 #
485 # -------- MAGICIAN CARD
486 #
487
488 $resp = -1;
489 my $spectator_guess = generate_card_between( $low_range, $high_range );
490 my $magician_card = $bcs->card_at_location($spectator_guess);
491 while ( uc $resp ne uc $magician_card->abbreviation ) {
492 $resp =
493 $term->readline("What is card for spectator guess of $spectator_guess: ");
494 say $magician_card->abbreviation if ($resp eq 'help');
495 }
496 say "\nNice job! How did you do that?!\n";
497
498 sub generate_card_between {
499 my ( $low, $high ) = @_;
500 while (1) {
501 my $deck_num = int( rand( $high + 1 ) );
502 return $deck_num if ( $deck_num >= $low );
503 }
504 }
505  
506 =cut
507  
508  
509  
510  
511 =head1 AUTHOR
512  
513 "Gordon Van Amburg", C<< <"vanamburg at cpan.org"> >>
514  
515 =head1 BUGS
516  
517 Please report any bugs or feature requests to C<bug-vanamburg-magic at rt.cpan.org>, or through
518 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=VANAMBURG-Magic>. I will be notified, and then you'll
519 automatically be notified of progress on your bug as I make changes.
520  
521  
522  
523  
524 =head1 SUPPORT
525  
526 You can find documentation for this module with the perldoc command.
527  
528 perldoc VANAMBURG::Magic
529  
530  
531 You can also look for information at:
532  
533 =over 4
534  
535 =item * RT: CPAN's request tracker
536  
537 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=VANAMBURG-Magic>
538  
539 =item * AnnoCPAN: Annotated CPAN documentation
540  
541 L<http://annocpan.org/dist/VANAMBURG-Magic>
542  
543 =item * CPAN Ratings
544  
545 L<http://cpanratings.perl.org/d/VANAMBURG-Magic>
546  
547 =item * Search CPAN
548  
549 L<http://search.cpan.org/dist/VANAMBURG-Magic/>
550  
551 =back
552  
553  
554 =head1 ACKNOWLEDGEMENTS
555  
556  
557 =head1 LICENSE AND COPYRIGHT
558  
559 Copyright 2011 "Gordon Van Amburg".
560  
561 This program is free software; you can redistribute it and/or modify it
562 under the terms of either: the GNU General Public License as published
563 by the Free Software Foundation; or the Artistic License.
564  
565 See http://dev.perl.org/licenses/ for more information.
566  
567  
568 =cut
569  
570 2 1; # End of VANAMBURG::Magic
« lib/VANAMBURG/FaceValueSingleton.pm ↑ Summary lib/VANAMBURG/StackCard.pm »