Results 1 to 11 of 11

Thread: BlackJack (counting the score/points)

  1. #1

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802

    BlackJack (counting the score/points)

    Hi,
    I'm working on a BlackJack game but I can't figure out a good way to add the points on the cards. I have more then 100 lines of code for just the three first cards - there has to be a better way of doing this... The biggest problem is the aces... I want the label with the points to say "Points: 6 Or 16" if you have an ace and a five.
    I have all the cards in an array, intDeck(51) and the points for all the cards in another, intPoints(51) so intDeck(0) is worth intPoints(0), intDeck(1) is worth intPoints(1) and so on. All the aces are set as 11 in the intPoints(51) array.
    Any ideas how I can keep track of the scores?

    Thanks in advance
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  2. #2
    Hyperactive Member Ambivalentiowa's Avatar
    Join Date
    Apr 2002
    Location
    Coming soon to a store near you!
    Posts
    375
    You could use two variables P1score and p2score to keep a runnning tally. Whenever a new card comes just say p1score=p1score+intPoints(2) or whatever. Whenever an ace is drawn, ask the player if they want it worth 1 or 11. Or have a button that lets them change it between 1 and 11 and just set it's value to 1.
    -Show me on the doll where the music touched you.

  3. #3

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    Thanks for the reply
    That's what I've been trying to do but it's really hard...
    If I ask them when they get the card and they set it to 11 what if they need it to be 1 later? Or if I make it so they can change it all the time, what if they bust while the ace is 11 and could prevent that by changing it to 1, I would need some kind of system that checked if they had an ace somewhere set to 11 and the score is less or = to 31, and if I manage to write that code I wouldn't nedd the user to select weather they want the ace to be 1 or 11 as my program could figure it out by it self and we are back at square one...
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  4. #4
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    Cant you just detect whether making it work 11 would make the player bust, if so set it to 1, else set it to 11??
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  5. #5

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    Yeah, if the user only could have one ace it would be easy, but what if the user has two or three or even four aces?
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  6. #6
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    When it's their turn (or you have to get the value of the aces), make them all = 11, then if they would be bust 1 by 1 make them worth only 1 point. If they are still over the limit, then the player has lost.
    Quotes:
    "I am getting better then you guys.." NoteMe, on his leet english skills.
    "And I am going to meat her again later on tonight." NoteMe
    "I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
    "my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
    Have I helped you? Please Rate my posts.


  7. #7

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    That's a good idea, I'll try it as soon as I get home from school, thanks

    It worked!!! Thank you so much!
    Last edited by McCain; Apr 29th, 2002 at 07:17 PM.
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  8. #8

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    I just realized that I don't know all the rules of blackjack...
    When do the dealer get his cards? Before the player get his? After the player is done? Every second one?
    I've looked everywhere but it never says anything about the dealer, only what you are supposed to do and what your rules are...

    Solved it, I played the java BJ over at http://www.blackjackinfo.com and saw that the dealer gets his cards after the player is finnished with his hand
    Last edited by McCain; Apr 30th, 2002 at 09:55 PM.
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  9. #9
    Hyperactive Member Ambivalentiowa's Avatar
    Join Date
    Apr 2002
    Location
    Coming soon to a store near you!
    Posts
    375
    Don't forget that if there's a tie, the dealer always wins!
    -Show me on the doll where the music touched you.

  10. #10

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    No he doesn't... If it's a tie or a "push" as it's called in BJ you get your bet back - you don't win anything you dont lose anything...
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

  11. #11

    Thread Starter
    Fanatic Member McCain's Avatar
    Join Date
    Jan 2002
    Location
    Sweden/Denmark
    Posts
    802
    For some reason my BJ program thinks the score is two points less then it actuallly is, and sometimes it keeps taking more/new cards even though the total score is more then 17. Any ideas why this happens anyone?

    Here's the score keeping code:
    VB Code:
    1. Private Sub CalcCpoints()
    2.     If intCcards = 2 Then
    3.         intCpoints = intValues(1) + intValues(3) 'The dealer`s score is the value of the first card (1) and the second card (3)
    4.         If intCpoints = 21 Then lblCpoints.Caption = "BlackJack!!!"
    5.         If intCpoints = 22 Then intCpoints = 12 'If the dealer gets two aces the score is 12 (or 2...)
    6.         If intCpoints <> 21 Then lblCpoints.Caption = "Points: " & intCpoints
    7.        
    8.     ElseIf intCcards = 3 Then
    9.         intCpoints = intValues(1) + intValues(3) 'the first two cards...
    10.         intCpoints = intCpoints + intValues(intCcards + 2) '... plus the third card
    11.        
    12.         If intCpoints > 21 And intValues(intCcards + 2) = 11 Then 'If the score is higher then 21 and the third card is an ace...
    13.             intValues(intCcards + 2) = 1 '...the ace has to be counted as 1 point
    14.             Call CalcCpoints 're-calculate the points
    15.         End If
    16.         If intCpoints > 21 And intValues(3) = 11 Then
    17.             intValues(3) = 1
    18.             Call CalcCpoints
    19.         End If
    20.         If intCpoints > 21 And intValues(1) = 11 Then
    21.             intValues(1) = 1
    22.             Call CalcCpoints
    23.         End If
    24.        
    25.         If intCpoints <= 21 Then
    26.             lblCpoints.Caption = "Points: " & intCpoints
    27.         ElseIf intCpoints > 21 Then
    28.             lblCpoints.ForeColor = vbRed
    29.             lblCpoints.Caption = "Busted! " & intCpoints & " points"
    30.         End If
    31.        
    32.     ElseIf intCcards = 4 Then
    33.         intCpoints = intValues(1) + intValues(3)
    34.         intCpoints = intCpoints + intValues(intCcards + 2)
    35.         intCpoints = intCpoints + intValues(intCcards + 3)
    36.        
    37.         If intCpoints > 21 And intValues(intCcards + 3) = 11 Then
    38.             intValues(intCcards + 3) = 1
    39.             Call CalcCpoints
    40.         End If
    41.         If intCpoints > 21 And intValues(intCcards + 2) = 11 Then
    42.             intValues(intCcards + 2) = 1
    43.             Call CalcCpoints
    44.         End If
    45.         If intCpoints > 21 And intValues(3) = 11 Then
    46.             intValues(3) = 1
    47.             Call CalcCpoints
    48.         End If
    49.         If intCpoints > 21 And intValues(1) = 11 Then
    50.             intValues(1) = 1
    51.             Call CalcCpoints
    52.         End If
    53.        
    54.         If intCpoints <= 21 Then
    55.             lblCpoints.Caption = "Points: " & intCpoints
    56.         ElseIf intCpoints > 21 Then
    57.             lblCpoints.ForeColor = vbRed
    58.             lblCpoints.Caption = "Busted! " & intCpoints & " points"
    59.         End If
    60.        
    61.     ElseIf intCcards = 5 Then
    62.         intCpoints = intValues(1) + intValues(3)
    63.         intCpoints = intCpoints + intValues(intCcards + 2)
    64.         intCpoints = intCpoints + intValues(intCcards + 3)
    65.         intCpoints = intCpoints + intValues(intCcards + 4)
    66.        
    67.         If intCpoints > 21 And intValues(intCcards + 4) = 11 Then
    68.             intValues(intCcards + 4) = 1
    69.             Call CalcCpoints
    70.         End If
    71.         If intCpoints > 21 And intValues(intCcards + 3) = 11 Then
    72.             intValues(intCcards + 3) = 1
    73.             Call CalcCpoints
    74.         End If
    75.         If intCpoints > 21 And intValues(intCcards + 2) = 11 Then
    76.             intValues(intCcards + 2) = 1
    77.             Call CalcCpoints
    78.         End If
    79.         If intCpoints > 21 And intValues(3) = 11 Then
    80.             intValues(3) = 1
    81.             Call CalcCpoints
    82.         End If
    83.         If intCpoints > 21 And intValues(1) = 11 Then
    84.             intValues(1) = 1
    85.             Call CalcCpoints
    86.         End If
    87.         If intCpoints <= 21 Then
    88.             lblCpoints.Caption = "Points: " & intCpoints
    89.         ElseIf intCpoints > 21 Then
    90.             lblCpoints.ForeColor = vbRed
    91.             lblCpoints.Caption = "Busted! " & intCpoints & " points"
    92.         End If
    93.     End If
    94. End Sub
    Never argue with fools, they will only drag you down to their level, and beat you with experience.

    Q: How do you tell an experienced hacker from a novice?
    A: The latter thinks there's 1000 bytes in a kilobyte, while the former is sure there's 1024 meters in a kilometer

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width