blackjack

This is a discussion on blackjack within the C Programming forums, part of the General Programming Boards category; i have programed blackjack it works but i know there is a better way of doing it. Does anybody know ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    41

    blackjack

    i have programed blackjack it works but i know there is a better way of doing it. Does anybody know where i can find source code for a simple game of blackjack.

    i was once told that the best way to learn is to try it yourself, then find out how to do it right. then do it right yourself

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    Rewrite it yourself - several times.

    Look at your current version, and think about things you had difficulty with, and things you might like to improve upon.

    > then find out how to do it right
    Staring at someone else's code won't teach you half as much.
    Plus there is no "right" answer.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,304
    Sounds like you're wanting to turn in someone else's work.
    Why don't you try posting some of your own code instead, so we can tell you how to improve it.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Mar 2010
    Posts
    41
    Quote Originally Posted by iMalc View Post
    Sounds like you're wanting to turn in someone else's work.
    Why don't you try posting some of your own code instead, so we can tell you how to improve it.
    Code:
    #include<stdio.h>
    #include<string.h>
    #include<stdlib.h>
    #include<time.h>
    #define DECKSIZE 52
    #define VALUE 9
    #define FACE 4
    
    typedef struct {
            int value;
            char* suit;
            char* name;
    }Card;
    
    Card cards[DECKSIZE];
    char *faceName[]={"two","three","four","five","six","seven","eight","nine",
                      "ten","jack","queen","king","ace"};
    char *suitName[]={"spades","diamonds","hearts","clubs"};
    void printDeck(){
    int i;
    for (i=0;i<6000;i++){
    int j = i+ rand()%(6000-i);
            this=rand()%DECKSIZE;
            that=rand()%DECKSIZE;
    while(this==that)that=rand()%(52+1);
    //printf("shuffle  card%d with card %d\n", this, that);
    temp=cards[this];
    cards[this]=cards[that];
    cards[that]=temp;
    }
    }
    int main(){
            int suitCount=0;
            int faceCount=0;
            int i;
            for(i=0;i<DECKSIZE;i++){
                    if(faceCount<9){
                            cards[i].value=faceCount+2;
                    }else{
                            cards[i].value=10;
                    }
                    cards[i].suit=suitName[suitCount];
                    cards[i].name=faceName[faceCount++];
                    if(faceCount==13){
                            cards[i].value=11;
                            suitCount++;
                            faceCount=0;
                    }
            }
    {
    
    //printDeck();
    //shuffleDeck();
    //printDeck();
            }
    int P_hand, D_hand;
    P_hand=rand() %52+1;
    D_hand=rand() %52+1;
    shuffleDeck();
    printf("%s of %s,----%s of %s\n ",cards[1].name,cards[3].suit,cards[4].name,cards[2].suit );
    shuffleDeck();
    printf("%s of %s,----%s of %s\n",cards[1].name,cards[3].suit,cards[4].name,cards[2].suit  );
    shuffleDeck();
            return 0;
    }
    there now how can you help me with finishing this? and for the record i would never alter someone elses work and make it my own. you dont learn anything that way. i just need some help like i said.
    no what i need help with is making sure that the values of the cards is being stored in the last printf statement and having that total stored so that i can start on my math function part of this blackjack program im trying out so any help will be greatly appreciated

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,540
    One thread at a time please
    my blackjack prog
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. blackjack
    By gloworm in forum C Programming
    Replies: 6
    Last Post: 04-05-2010, 02:39 AM
  2. Simple Blackjack Program
    By saber1357 in forum C Programming
    Replies: 1
    Last Post: 03-28-2009, 03:19 PM
  3. Help with Blackjack program
    By sugie in forum C++ Programming
    Replies: 1
    Last Post: 04-30-2005, 12:30 AM
  4. Blackjack!
    By Dr. Bebop in forum Game Programming
    Replies: 1
    Last Post: 10-03-2002, 08:58 PM
  5. Blackjack
    By the_head in forum C Programming
    Replies: 1
    Last Post: 08-03-2002, 08:57 AM

Tags for this Thread


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