Jump to content

BlackJack


themax90
 Share

Recommended Posts

I just finished a blackjack game! YAY! using my card functions. :evil:

Below is the attached zip files, one is sectioned for study and editing, another is just the whole script for those who are more single filed.

Anyways here is my card systems:

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
Func CardAce($card, $gui, $bot)
    If $bot = 1 Then
        If $card = 1 Then
            $total = Random(1, 2, 1)
            If $total = 1 Then
                $total = 11
            ElseIf $total = 2 Then
                $total = 1
            EndIf
        Else
            $total = $card
        EndIf
        Return $total
    ElseIf $bot = 0 Then
        If $card = 1 Then
            $acewin = GUICreate("Ace", 137, 102, (@DesktopWidth - 137) / 2, (@DesktopHeight - 102) / 2)
            $label = GUICtrlCreateLabel("A ace has been drawn, would you like it to be worth 11 or 1?", 10, 10, 120, 30, 0x1000 + 1)
            $1 = GUICtrlCreateCheckbox("One", 10, 50, 50, 20)
            $11 = GUICtrlCreateCheckbox("Eleven", 10, 80, 50, 20)
            $ok = GUICtrlCreateButton("Ok", 80, 60, 50, 30)
            GUISetState()
            While 1
                $msg = GUIGetMsg()
                If $msg = $ok Then
                    If GUICtrlRead($1) = 1 And GUICtrlRead($11) <>1 Then
                        $total = 1
                        GUIDelete($acewin)
                        GUISetState($gui, @SW_SHOW)
                        Return $total
                        ExitLoop
                    ElseIf GUICtrlRead($11) = 1 And GUICtrlRead($1) <> 1 Then
                        $total = 11
                        GUIDelete($acewin)
                        GUISetState($gui, @SW_SHOW)
                        Return $total
                        ExitLoop
                    Else
                        MsgBox(0, "Error", "Either both are selected or none, please choose one.")
                    EndIf
                EndIf
            WEnd
        Else
            $total = $card
            Return $total
        EndIf
    EndIf
EndFunc;==>CardAce
Func TwentyOneTest($total)
    If $total = 21 Then
        Return 1
    Else
        Return $total
    EndIf
EndFunc;==>TwentyOneTest

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"

You can get cards.au3 and errors.au3 from the sectioned blackjack zip

.

I hope u all like, took me a week or so. Just for fun! :)

Edited by AutoIt Smith
Link to comment
Share on other sites

This is great, AutoIt Smith! :)

Just one small thing I noticed -- I'm pretty sure that the dealer is obliged to hit until he has a higher score than the player. (I won 17 to 16 just then.)

Link to comment
Share on other sites

  • Moderators

@Valik - Most Casino's make the dealer hit on 16 but not all. Found this out the hard way once.

@AutoIt Smith - Nice Job: I'm currently working on a Heads Up Texas Hold'em game.

P.S. Misspelled word "Duce" = "Deuce".

Edit: Had to fix my own misspelled word! :)

Edited by ronsrules

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

@Valik - Most Casino's make the dealer hit on 16 but not all.  Found this out the hard way once.

@AutoIt Smith - Nice Job:  I'm currently working on a Heads Up Texas Hold'em game.

P.S. Misspelled word "Duce" = "Deuce".

Edit:  Had to fix my own misspelled word! :evil:

<{POST_SNAPBACK}>

headsup holdem eh!

will you be including a random shuffle generator

as seen in online cardrooms?

If so would you please remove the code which guarantees your opponent a 2 outer on the river.

TYVM

Hardcopy :)

Contributions: UDF _DateYearFirstChildren are like Farts, you can just about stand your own.Why am I not a Vegetarian?...Well...my ancestors didn't fight & evolve to the Top of the food chain for me to survive on Salad

Link to comment
Share on other sites

I noticed that you write to an INI. You could use my _INITable() functions to improve your script speed by writing to a string and not a file. If you wanted to save the information to a file all you would have to use is _INITableSave() and _INITableLoad().

I really like your game! Great work! :whistle:

Link to comment
Share on other sites

@kabalarian

I have no idea whats wrong with your processor but it works on everywhere i've tried. I've been gone for a week or so and havn't been able to read feedback. Also I rewrote the payout becauseti tripled incom, just change the all $win's to $betamount's and you'll be safe, o and Kaba, could u be betting like 1000 or NOT EVENC REATING a bank roll.

I just hope my card functions and and server emulations(to come) will help you all

@erifash

Dang you I was working on that also!!! but you beat me to it, hehe

Yah thisprogram was just a quick boredom fix, afew misspellings and a output error, and AI was sloopy to get the job done. Thanks all!

AutoIt Smith

Be on the lookout for moreprograms

Link to comment
Share on other sites

Blackjack 1.2 is here, Fixed!

Duce is renamed to Deuce and all payout, subductive glitches are fixed.

Blackjack normal(playing w/ source)

Blackjack sectioned to be fixed soon....

If anyone wants to give feed back it's cool.

AutoIt Smith

Edited by AutoIt Smith
Link to comment
Share on other sites

  • 1 month later...

Can I play you in blackjack, you be the dealer, for a thousand a hand ;)

In blackjack advantage the house has over the player is very minimal, like 49 to 51 if the player plays correctly.

If a player knows both of the dealer cards, the odds flip around enough that you could never lose playing black jack - just a gues, but I would say the odds would now be 75-80 percent in the players advantage.

(You need to hide one of the dealers cards)

Link to comment
Share on other sites

  • 3 weeks later...
  • 4 weeks later...

Yes i know, I never wanted to rework on it. It's open to who ever as long as you put my name on it somewhere. The projects been closed for, ummm.... 3 months, so yah B) But thanks :o

New Link...

Edited by AutoIt Smith
Link to comment
Share on other sites

  • 9 months later...

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...