Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 BlackJack Help
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
KONjbnj




PostPosted: Thu May 11, 2006 1:54 pm   Post subject: BlackJack Help

So far, it is running smoothly, but the only problem I have is the ace being counted as 11 or 1. If you have an ace and the total is under 21, it automatically sets to 11. The problem I have is that around the third card, the numbers stop adding up. But when it gets to the fifth or so card, it goes again. How do I get around that?

code:
var pos_x_player : int := 0
var pos_x_dealer : int := 0
var player, dealer : int
var c1, c2, c3 : int
var d1, d2, d3 : int
var acecount : int := 0
var doneace, doneace2 : int := 0
%Dealer Cards
proc dealercards
    d1 := Rand.Int (1, 52)
    d2 := Rand.Int (1, 52)
    if d2 = d1 then
        d2 := Rand.Int (1, 52)
    end if
    dealer := cardtotal (d1)
    locate (4, 30)
    colorback (120)
    color (40)
    put dealer ..
    Pic.Draw (cards (d1), 250, 320, picCopy)
    Pic.Draw (cards (53), 300, 320, picCopy)
end dealercards
%Player Cards
proc playercards
    c1 := Rand.Int (1, 52)
    c2 := Rand.Int (1, 1)
    if c2 = c1 then
        c2 := Rand.Int (1, 52)
    end if
    player := cardtotal (c1) + cardtotal (c2)
    locate (15, 37)
    colorback (120)
    color (40)
    put player ..
    Pic.Draw (cards (c1), 250, 120, picCopy)
    Pic.Draw (cards (c2), 300, 120, picCopy)
end playercards
%Player Hit Cards
proc playerhit
    c3 := Rand.Int (1, 52)
    pos_x_player := pos_x_player + 50
    player := player + cardtotal (c3)
    locate (15, 37)
    colorback (120)
    color (40)
    put player ..
    Pic.Draw (cards (c3), 300 + pos_x_player, 120, picCopy)
end playerhit
%Dealer Hit Cards
proc dealerhit
    var d1 : int
    d1 := Rand.Int (1, 52)
    pos_x_dealer := pos_x_dealer + 50
    dealer := dealer + cardtotal (d1)
    locate (4, 30)
    colorback (120)
    color (40)
    put dealer ..
    Pic.Draw (cards (d1), 300 + pos_x_dealer, 320, picCopy)
end dealerhit
%Setting the Ace value at 1 and 11
proc oneor11c1
    if c1 = 1 or c1 = 14 or c1 = 27 or c1 = 40 then
        acecount := 1
        player := 11 + cardtotal (c2)
    end if
    locate (15, 37)
    colorback (120)
    color (40)
    put player ..
end oneor11c1
proc oneor11c2
    if c2 = 1 or c2 = 14 or c2 = 27 or c2 = 40 and acecount not= 1 then
        player := cardtotal (c1) + 11
    end if
    locate (15, 37)
    colorback (120)
    color (40)
    put player ..
end oneor11c2
%Turning 11 to 1 if total > 21
proc acecheck1
    if player > 21 and c1 = 1 or c1 = 14 or c1 = 27 or c1 = 40 and doneace = 1then
        player := player - 10
        doneace := 0
    end if
    locate (15, 37)
    colorback (120)
    color (40)
    put player ..
end acecheck1
proc acecheck2
    if player > 21 and c2 = 1 or c2 = 14 or c2 = 27 or c2 = 40 and doneace2 = 1 then
        player := player - 10
        doneace2 := 0
    end if
    locate (15, 37)
    colorback (120)
    color (40)
    put player ..
end acecheck2

%Main Program
proc main
    var x, y, button : int
    loop
        mousewhere (x, y, button)
        if x >= 400 and x <= 449 and y >= 10 and y <= 55 and button = 1 then
            pos_x_player := 0
            pos_x_dealer := 0
            Pic.Draw (table, 0, 0, picCopy)
            Pic.Draw (buttons (1), 400, 10, picCopy)
            Pic.Draw (buttons (2), 450, 10, picCopy)
            Pic.Draw (buttons (3), 500, 10, picCopy)
            Pic.Draw (buttons (4), 550, 10, picCopy)
            playercards
            oneor11c1
            oneor11c2
            acecheck1
            acecheck2
            dealercards
            acecount := 0
            delay (200)
        elsif x >= 450 and x <= 499 and y >= 10 and y <= 55 and button = 1 then
            playerhit
            acecheck1
            acecheck2
            delay (200)
        elsif x >= 500 and x <= 549 and y >= 10 and y <= 55 and button = 1 then
        end if
        exit when x >= 550 and x <= 599 and y >= 10 and y <= 55 and button = 1
    end loop
    cls
end main


Everything else so far works except that.
Sponsor
Sponsor
Sponsor
sponsor
KONjbnj




PostPosted: Thu May 11, 2006 1:57 pm   Post subject: (No subject)

I figured it might've been better to give you the entire program.


BlackJack.zip
 Description:

Download
 Filename:  BlackJack.zip
 Filesize:  161.3 KB
 Downloaded:  58 Time(s)

do_pete




PostPosted: Thu May 11, 2006 2:41 pm   Post subject: (No subject)

Shouldn't it be counted as 11 if the total is smaller or equal to 10?
Clayton




PostPosted: Thu May 11, 2006 3:07 pm   Post subject: (No subject)

instead of doing a complex checking thing you have going on, just have a boolean variable to check the card total each time something happens to it, if its 10 or less, set the boolean to false, 11 or more, set it to true (or whatever way you want to do it)
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 4 Posts ]
Jump to:   


Style:  
Search: