Sign in to follow this  
Followers 0
themax90

Card Deck Creation

2 posts in this topic

I just noticed since the outburst of my Blackjack game atleast 4 or 5 people are working on card games or asking about them, and now would be the time to further show may card deck emulation. (Soon to be revamped with other methods if avialible)

Here is cards.au3(for in example script, thisis the emulation and generation)

Func DeckCreate($ref)
    IniWrite($deck, "Deck" & $ref, "CS", "52")
    $i = 52
    While $i <> 0
        IniWrite($deck, "Deck" & $ref, $i, "0")
        $i = $i - 1
    WEnd
    While IniRead($deck, "Deck" & $ref, "CS", -1) <> 0
        $a = Random(1, 13, 1)
        $b = Random(1, 4, 1)
        $card = $a & ":" & $b
        $cardcheck = CardCheck($card, $ref)
        If $cardcheck = 1 Then
            $spot = IniRead($deck, "Deck" & $ref, "CS", -1)
            If $spot = -1 Then
                Error(0)
            Else
                IniWrite($deck, "Deck" & $ref, "CS", ($spot - 1))
                IniWrite($deck, "Deck" & $ref, $spot, $card)
            EndIf
        ElseIf $cardcheck = 0 Then
            Sleep(1)
        EndIf
    WEnd
    IniWrite($deck, "Deck" & $ref, "CS", "52")
EndFunc ;==>DeckCreate
Func DeckDelete()
    FileDelete($deck)
EndFunc ;==>DeckDelete
Func CardCheck($card, $ref)
    $i = 52
    While 1
        $check = IniRead($deck, "Deck" & $ref, $i, -1)
        If $check = -1 Then
            Error(0)
        ElseIf $check = $card Then
            Return 0
            ExitLoop
        ElseIf $check = 0 Then
            Return 1
            ExitLoop
        ElseIf $check <> $card And $check <> 0 And $check <> - 1 Then
            $i = $i - 1
        EndIf
    WEnd
EndFunc ;==>CardCheck
Func CardDraw($ref)
    $cardspot = IniRead($deck, "Deck" & $ref, "CS", -1)
    If $cardspot = -1 Then
        Error(1)
    ElseIf $cardspot = 0 Then
        Return 0
    Else[attachmentid=3499]
        IniWrite($deck, "Deck" & $ref, "CS", ($cardspot - 1))
        $drawcard = IniRead($deck, "Deck" & $ref, $cardspot, -1)
        IniWrite($deck, "Deck" & $ref, $cardspot, "0")
        If $drawcard = -1 Then
            Error(1)
        Else
            Return $drawcard
            IniWrite("Deck.ini", "Deck" & $ref, $cardspot, "0")
        EndIf
    EndIf
EndFunc ;==>CardDraw
Func CardInterpret($card)
    $card = StringSplit($card, ":")
    $card[1] = StringReplace($card[1], "4", "Four")
    $card[1] = StringReplace($card[1], "5", "Five")
    $card[1] = StringReplace($card[1], "6", "Six")
    $card[1] = StringReplace($card[1], "7", "Seven")
    $card[1] = StringReplace($card[1], "8", "Eight")
    $card[1] = StringReplace($card[1], "9", "Nine")
    $card[1] = StringReplace($card[1], "10", "Ten")
    $card[1] = StringReplace($card[1], "11", "Jack")
    $card[1] = StringReplace($card[1], "12", "Queen")
    $card[1] = StringReplace($card[1], "13", "King")
    $card[1] = StringReplace($card[1], "3", "Three")
    $card[1] = StringReplace($card[1], "2", "Duce")
    $card[1] = StringReplace($card[1], "1", "Ace")
    $card[2] = StringReplace($card[2], "1", " of Hearts")
    $card[2] = StringReplace($card[2], "2", " of Diamonds")
    $card[2] = StringReplace($card[2], "3", " of Spades")
    $card[2] = StringReplace($card[2], "4", " of Clubs")
    $card = $card[1] & $card[2]
    Return $card
EndFunc ;==>CardInterpret
Func CardNum($card)
    $card = StringSplit($card, ":")
    If $card[1] = "13" Or $card[1] = "12" Or $card[1] = "11" Or $card[1] = "10" Then
        $newcard = 10
    ElseIf $card[1] = "1" Then
        $newcard = 1
    ElseIf $card[1] = "2" Then
        $newcard = 2
    ElseIf $card[1] = "3" Then
        $newcard = 3
    ElseIf $card[1] = "4" Then
        $newcard = 4
    ElseIf $card[1] = "5" Then
        $newcard = 5
    ElseIf $card[1] = "6" Then
        $newcard = 6
    ElseIf $card[1] = "7" Then
        $newcard = 7
    ElseIf $card[1] = "8" Then
        $newcard = 8
    ElseIf $card[1] = "9" Then
        $newcard = 9
    EndIf
    Return $newcard
EndFunc ;==>CardNum

Now for a demonstration use this script

; Deck INI Location
$deck = @tempdir & "\Deck.ini"
; Reference Password
$ref = 1
SplashTextOn("", "Creating Deck........", "150", "20", "-1", "-1", 1, "", "", "")
DeckCreate($ref)
SplashOff()
While 1
    $card = CardDraw($ref)
    If $card = 0 Then
        MsgBox(0, "Deck Empty", "Deck Depleted.")
        Exit
    Else
    MsgBox(0, "Card Draw", "Your card is : " & CardInterpret($card))
    EndIf
WEnd
; Include card functions and errors in reference to card functions
#include "Include\cards.au3"
#include "Include\errors.au3"

The errors.au3 can be found in the sectioned version of my blackjack game,hereis a link:

http://www.autoitscript.com/forum/index.ph...pe=post&id=3499

I hope this helps all making card games. People who wish to revamp this method could you please atleast note that I made this as a base. If you dont wish to do that work(in revamping) you can email me and I can test out the script and see if it works, in the future I hope several versions are avialible for all mindsets of scripters.

My email is king.of.all@comcast.net

Much love,

AutoIt Smith

Share this post


Link to post
Share on other sites



I already have a carddraw($ref) function to return the card cipher and thenu can you card analyze and cardnum to retreive more data.

Thank you for the suggestion!

Share this post


Link to post
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
Sign in to follow this  
Followers 0