How would a programme know to stop before 21?

This is a discussion on How would a programme know to stop before 21? within the C++ Programming forums, part of the General Programming Boards category; Hi As a off again on again novice, I am trying to work out if I made a black Jack ...

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    62

    Smile How would a programme know to stop before 21?

    Hi

    As a off again on again novice, I am trying to work out if I made a black Jack game, how would I get the computer to decide to stop between 16 and 21 without it always going over 21 even if it had 21? What would be the most basic way? I'm no student but if people still think I should work this out for myself where is the best place on the net? It's probally in one of my 6 C++ programming books but I can't see it.

    Chris

  2. #2
    Registered User
    Join Date
    Jan 2006
    Location
    Washington D.C.
    Posts
    25
    I've coded a console blackjack game for fun a few months back, you can get the source here:

    http://70.86.55.186/~guyonasm/coding/blackjack.tar.gz

    Simply use WinRAR to extract it.

    As for your question, You could keep track of the total hand value of the computer in lets say cValueCount. And we also kept the players hand value in pValueCount. Then you'd run a conditional statement on it as such:

    Code:
    while (valueCount < 16 && pValueCount <= 21)
    {
    // keep picking cards
    }
    Its a slight adaption to my code, but basically if the player's hand is already over 21, then there's no need to get anymore cards, because we've already won regardless. But if we're below the value of 16, we're going to pluck again.

  3. #3
    Registered User
    Join Date
    Feb 2003
    Posts
    62
    Just wanted to say thanks very much

    I was trying to think too complicated Artificail Intelagence instructions (which I got no training on) and your right that's a lot more simple.

    Chris

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. How to view the programme before it disappears
    By yousuf in forum C Programming
    Replies: 2
    Last Post: 03-22-2008, 08:12 AM
  2. Replies: 3
    Last Post: 05-13-2007, 08:55 AM
  3. HUGE fps jump
    By DavidP in forum Game Programming
    Replies: 23
    Last Post: 07-01-2004, 10:36 AM
  4. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM
  5. Gui Programme does'nt Compiles from DOS
    By Shadowhunt in forum C++ Programming
    Replies: 1
    Last Post: 06-06-2003, 08:05 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21