Jump to content

Remember playing cards helper


creeping
 Share

Recommended Posts

Bought some memory power thing off an Infomercial many years ago, had a chapter on remembering playing cards. Uses a system based on phonetics and mutilating the object that represents the card in order to remember what cards you have seen or not seen etc. Like Association etc... anyway its odd, but works. Wrote this a while ago so its not the greatest

;add include files
#include <Array.au3>
#include <GUIConstants.au3>

;GUI window height, width
Const $GUIheight = 300, $GUIwidth = 400     

;number of cards in deck
Const $numCardsInDeck = 52      
;number of cards in eqch suit
Const $numCardsInSuit = 13

;arrays to hold suit cards
Global $clubCards[$numCardsInSuit]
Global $spadeCards[$numCardsInSuit]
Global $heartCards[$numCardsInSuit]
Global $diamondCards[$numCardsInSuit]

;holds current deck being displayed
Global $workingDeck[1]
;holds peg word card names
Global $cardNames[1]

;determines number seconds card will be displayed for
$numSeconds = 3     
;determines weather card peg word will be shown
$showCardWord = 0       

;determines weather card peg word will be shown
$hideCards = 0  
;number of cards that will be hidden
$numCardsToHide = 0     

;array to hold card hidden file names
Dim $hiddenCards[1]             

;create main GUI window
GUICreate("", $GUIwidth, $GUIheight, (@DesktopWidth / 2) - ($GUIwidth / 2), @DesktopHeight / 4, -1)

$yCord = 20     ;Y cord of command buttons
$step  = 40     ;virtical distance between command buttons

;start command button
$butStart       = GUICtrlCreateButton("Start", 10, $yCord, 150) 
$yCord = $yCord + $step

;hide cards command button
$butHideCards   = GUICtrlCreateButton("Hide Cards", 10, $yCord, 150)    
$yCord = $yCord + $step

;display rate command button
$butDisplayRate = GUICtrlCreateButton("Change Display Rate", 10, $yCord, 150)   
$yCord = $yCord + $step

;show card peg word command button
$butShowWord    = GUICtrlCreateButton("Show Card Word = no", 10, $yCord, 150)   
$yCord = $yCord + $step

;exit command button
$butExit = GUICtrlCreateButton("Exit", 10, $yCord, 150) 

;path to icon files
$iconPath = @ScriptDir & "\" & "icons" & "\"

;create card icons
GUICtrlCreatePic($iconPath & "clubs.jpg",    20, 230, 20, 20)
GUICtrlCreatePic($iconPath & "spades.jpg",   20, 265, 20, 20)
GUICtrlCreatePic($iconPath & "hearts.jpg",   75, 230, 20, 20)
GUICtrlCreatePic($iconPath & "diamonds.jpg", 75, 265, 20, 23)

;create card icon check boxes
$chkClub    = GUICtrlCreateCheckbox ("", 50,  234, 15, 15)
$chkSpade   = GUICtrlCreateCheckbox ("", 50,  269, 15, 15)
$chkHeart   = GUICtrlCreateCheckbox("", 105, 234, 15, 15)
$chkDiamond = GUICtrlCreateCheckbox ("", 105, 269, 15, 15)

;check boxes
GUICtrlSetState($chkClub, $GUI_CHECKED)
GUICtrlSetState($chkSpade, $GUI_CHECKED)
GUICtrlSetState($chkHeart, $GUI_CHECKED)
GUICtrlSetState($chkDiamond, $GUI_CHECKED)

;ceate picture box
$picCard = GUICtrlCreatePic("", 207, 20, 142, 192, $SS_CENTERIMAGE)

;label control to show card peg word
$lblCardWord    = GUICtrlCreateLabel("", 203, 225, 150, 50, $SS_CENTER)     
GUICtrlSetFont($lblCardWord, 18 , 200)                                          
GUICtrlSetState($lblCardWord, $GUI_HIDE)                                        

GUISetState()

;start message loop
While 1
    ;get context window message
    $msg = GUIGetMsg() 
    
    Select
        ;if close event
        Case $msg = $GUI_EVENT_CLOSE 
            ;exit program
            ExitLoop
            
        ;if start button pressed 
        Case $msg = $butStart 
            Start()

        ;if hide cards button pressed 
        Case $msg = $butHideCards 
            HideCards() 

        ;if change display rate button pressed 
        Case $msg = $butDisplayRate 
            changeDisplayRate() 
            
        ;if show card word button pressed 
        Case $msg = $butShowWord    
            ShowCardWord()  
            
        ;if exit button pressed
        Case $msg = $butExit 
            ExitLoop    

    EndSelect
Wend

;delete GUI
GUIDelete()

Func Start()
    ;path of card picture files
    $cardPath = @ScriptDir & "\" & "cards" & "\"    
    
    ;card file extention    
    $ext = ".JPG"                                   
        
    ;assemble working deck
    AssembleDeck()
    
    $workingDeck[0] = UBound($workingDeck) - 1
    
    ;prompt user to shuffle cards
    $shuffle = MsgBox(4, "", "Shuffle Cards?")
    Select
        Case $shuffle = 6 ;Yes
            ;shuffle deck
            ShuffleCards()
    EndSelect
        
    ;set number of cards to show
    $numCardsToShow = $workingDeck[0] - $numCardsToHide
        
    ;start show card loop
    For $i = 1 to $numCardsToShow Step 1    
        ;hide card peg word
        GUICtrlSetState($lblCardWord, $GUI_HIDE)            
                
        ;ceate picture box
        GUICtrlSetImage($picCard, $cardPath & $workingDeck[$i] & $ext)   
    
        ;set label to card peg word
        GUICtrlSetData($lblCardWord, $cardNames[$i])                    
        
        ;wait display time
        Sleep($numSeconds * 1000)                                       
        
        ;if show card peg word is on, display word
        If $showCardWord = 1 Then
            GUICtrlSetState($lblCardWord, $GUI_SHOW)    

            ;wait 1 second
            Sleep(1000)
        EndIf
    Next
    
    ;hide card peg word
    GUICtrlSetState($lblCardWord, $GUI_HIDE)    
    
    If $numCardsToHide <> 0 Then
        ;prompt user to start seeing missing cards
        MsgBox(262144, "", "Press Enter to view missing cards")
                
        $numCardsToShow += 1
        
        ;display missing cards
        For $i = $numCardsToShow to $workingDeck[0] Step 1
            ;prompt user to move to next card
            MsgBox(262144, "", "Press Enter to view next card")
            
            ;ceate picture box
            GUICtrlSetImage($picCard, $cardPath & $workingDeck[$i] & $ext)
        Next
    EndIf
EndFunc

Func AssembleDeck()
    Const $delim = ","
    Const $boxChecked = 1
    
    ReDim $workingDeck[1]
    ReDim $cardNames[1]
    
    ;cards
    $clubStr    = "c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13"
    $spadeStr   = "s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13"
    $heartStr   = "h1,h2,h3,h4,h5,h6,h7,h8,h9,h10,h11,h12,h13"
    $diamondStr = "d1,d2,d3,d4,d5,d6,d7,d8,d9,d10,d11,d12,d13"
    
    ;peg words
    $clubWords    = "Cat,Can,Comb,Core,Coal,Cash,Coke,Cuff,Cap,Case,Club,Cream,King"
    $spadeWords   = "Suit,Sun,Sum,Sore,Sail,Sash,Sock,Safe,Soap,Suds,Spade,Steam,Sing" 
    $heartWords   = "Hat,Hen,Home,Hare,Hail,Hash,Hog,Hoof,Hub,Hose,Heart,Queen,Hinge"   
    $diamondWords = "Date,Dune,Dam,Door,Doll,Dash,Deck,Dive,Deb,Dose,Diamond,Dream,Drink" 
    
    ;assemble cards into suits
    $clubCards    = StringSplit($clubStr, $delim)
    $spadeCards   = StringSplit($spadeStr, $delim)
    $heartCards   = StringSplit($heartStr, $delim)
    $diamondCards = StringSplit($diamondStr, $delim)
    
    ;assemble cards into peg words
    $clubPegWords    = StringSplit($clubWords, $delim)
    $spadePegWords   = StringSplit($spadeWords, $delim)
    $heartPegWords   = StringSplit($heartWords, $delim)
    $diamondPegWords = StringSplit($diamondWords, $delim)
    
    ;check to see what suit checkboxes are checked, 1 = checked, 4 = un-checked
    $isCheckedClub    = GUICtrlRead($chkClub)
    $isCheckedSpade   = GUICtrlRead($chkSpade)
    $isCheckedHeart   = GUICtrlRead($chkHeart)
    $isCheckedDiamond = GUICtrlRead($chkDiamond)
    
    ;add cards to working deck based on checkboxes
    If $isCheckedClub = $boxChecked Then
        For $i = 1 to $numCardsInSuit Step 1    
            _ArrayAdd($workingDeck, $clubCards[$i])
            _ArrayAdd($cardNames, $clubPegWords[$i])
            
        Next
    EndIf
    
    If $isCheckedSpade = $boxChecked Then
        For $i = 1 to $numCardsInSuit Step 1
            _ArrayAdd($workingDeck, $spadeCards[$i])
            _ArrayAdd($cardNames, $spadePegWords[$i])
        Next
    EndIf
    
    If $isCheckedHeart = $boxChecked Then
        For $i = 1 to $numCardsInSuit Step 1
            _ArrayAdd($workingDeck, $heartCards[$i])
            _ArrayAdd($cardNames, $heartPegWords[$i])
        Next
    EndIf
    
    If $isCheckedDiamond = $boxChecked Then
        For $i = 1 to $numCardsInSuit Step 1
            _ArrayAdd($workingDeck, $diamondCards[$i])
            _ArrayAdd($cardNames, $diamondPegWords[$i])
        Next
    EndIf
EndFunc 

Func ShuffleCards()
    ;number to times to swap two cards
    $timesToMix  = 1000
    
    $workingDeck[0] = UBound($workingDeck) - 1
    
    ;swap two cards around in array
    For $i = 1 to $timesToMix Step 1
        $randomNum1 = Random(1, $workingDeck[0], 1)
        $randomNum2 = Random(1, $workingDeck[0], 1)
        
        _ArraySwap($workingDeck[$randomNum1], $workingDeck[$randomNum2])
        _ArraySwap($cardNames[$randomNum1], $cardNames[$randomNum2])
    Next
EndFunc

Func HideCards()
    ;set hide cards to true
    $hideCards = 1
    
    Do
        ;get number of cards to hide
        $numCardsToHide = InputBox("", "Enter number of cards to hide, must be less than 52!")      
        
    Until $numCardsToHide < 52
EndFunc

Func ChangeDisplayRate()
    $prompt = "Enter new flash rate"
    
    $numSeconds = InputBox("", $prompt)
EndFunc

Func ShowCardWord()
    If $showCardWord = 0 Then
        $showCardWord = 1
        GUICtrlSetData($butShowWord, "Show Card Word = " & "Yes")
    Else
        $showCardWord = 0
        GUICtrlSetData($butShowWord, "Show Card Word = " & "No")
    EndIf
EndFunc

memory_power_card_program.zip

Edited by creeping
Link to comment
Share on other sites

Other then that, I really like the way you comment most of your code.

I also like this, I must get in that habit myself.

[quote name='DaleHohm']You have a strange habit of posting error messages that don't match your code.[/quote][quote name='SmOke_N']Forget the learning... straight to the scripting :lol: (laugh.gif)[/quote]

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...