Thread: Processor Fault

  1. #1
    Seņor Member
    Join Date
    Jan 2002

    Processor Fault

    This is my start of a blackjack game, I am tryin gto get the shuffle working, but i get an error that says "SHUFFLE(2) 0x2347:0x00EF Processor Fault". I am using Borland Turbo C++ 4.5. Here's my code with the error line in bold.



    void randomizecard (apvector<int>&, apvector<int>&, int &);
    void check(apvector<int>&, apvector<int>&, int &);

    void main ()
    apvector<int> card(54,0); //card value } SAME CARD, 1 ARRAY HOLDS
    apvector<int> cards(54,0); //card suit } VALUE, OTHER HOLDS SUIT


    for(int i = 1; i <=53; i++)
    randomizecard(card, cards, i);


    void randomizecard (apvector<int> &card, apvector<int> &cards, int &i)
    card[i]=random(13)+1; //randomizin

  2. #2
    geek SilentStrike's Avatar
    Join Date
    Aug 2001
    Remember, 0 based counting in C++... generally when iterating through a vector (say, named vec) you go from 0 to less than vec.length().

    The problem with your program is infinite recursion.

    randomizecard calls check, check calls randomize, randomize calls check, etc, forever. The allocated memory to store all the function calls (the stack) gets filled with those calls, and then the program crashes.

    Also, instead of using parrallel arrays of int, you might want to learn structs. IE,

    struct card {
         int suit;
         int case;
    And then declare the list of cards like this.

    apvector<card> cardList;

    Finally, that sorting version is just not gonna cut it. As a fairly simple solution, I recommend making a "copied deck", in order, with 1 of each card. Then pick a random card out of the copy list (remove it from the copied list), and put it into the real one. Repeat until the copied list is empty, and you will have a random deck, somewhat efficiently (no checks needed to see if you have duplicated a card)
    Prove you can code in C++ or C# at TopCoder, referrer rrenaud
    Read my livejournal

Popular pages Recent additions subscribe to a feed