Thread: How would a programme know to stop before 21?

  1. #1
    Registered User
    Join Date
    Feb 2003

    Smile How would a programme know to stop before 21?


    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.


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

    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:

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


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