Challenge just for fun

This is a discussion on Challenge just for fun within the C Programming forums, part of the General Programming Boards category; BACKGROUND INFORMATION: A deck of 52 cards consists of 4 suits: Spades (S), Clubs (C), Diamonds (D), and Hearts (H), ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    1

    Challenge just for fun

    BACKGROUND INFORMATION:
    A deck of 52 cards consists of 4 suits: Spades (S),
    Clubs (C), Diamonds (D), and Hearts (H), with each
    suit made up of 13 different card ranks:
    2, 3, 4, 5, 6, 7, 8, 9, 10, J, Q, K, and A
    (where J=Jack, Q=Queen, K=King and A=Ace).
    In the game of "POKER", each player is RANDOMLY
    dealt a series of 5 cards which constitues a player's
    "HAND". The cards are then evaluated to determine
    the "hand's" strength by looking for special
    combinations or sequences in the 5 card set.

    Poker Hand strengths in ascending order
    (weakest to strongest)are ranked as follows:

    1. High Card only (any one: A, K, J, 10, etc.).
    2. One Pair (any 2 cards of the same rank).
    3. Two Pairs.
    4. Three Of A Kind (any 3 cards of the same rank).
    5. Straight (any consequtive sequence of 5 cards)
    (see below for an example).
    6. Flush (any 5 cards of the same suit).
    7. Full House (any Three Of A Kind AND any 1 Pair).
    8. Four Of A Kind (4 cards of the same rank).
    9. Straight Flush
    (any consequtive sequence of 5 cards of the
    same suit).
    10. Royal Flush (A, K, Q, J, 10) of all the same
    suit.

    Examples of 5 randomly dealt "poker hands" are:

    hand1: AC-2D-7H-JS-AD (One Pair: "2 Aces").
    hand2: 10S-9S-8D-6C-7D (Straight: "6-7-8-9-10").
    hand3: 2S-3S-6S-QS-5S (Flush: "5 Spades").
    hand4: KD-KH-4H-KS-QH (3 Of A Kind: "3 Kings").
    hand5: JC-4D-JD-JH-4S (Full House:
    "3 Jacks AND 2 4's").

    where the first piece of data represents the card's
    rank followed by the card's suit.
    (eg.) AC = Ace of Clubs
    2D = 2 of Diamonds
    7H = 7 of Hearts
    JS = Jack of Spades
    AD = Ace of Diamonds

    NOTE:
    The cards that are dealt may appear in any numerical
    value "rank" and in any suit, but no single card may
    appear more than once (no repeats).

    To generate a random number in C, you must use the
    function: (prototyped in the C <stdlib.h> library)
    int rand( );
    that returns a random number between 0 and the
    symbolic constant RAND_MAX inclusive.

    You must also use the function:
    void srand(unsigned int seed);
    to create a unique set of random values each time
    the program is executed. You will also have to include
    the <time.h> library for this function to work
    correctly (see the program below for an example)

    #include <stdio.h>
    #include <stdlib.h>
    #include <time.h>

    int main( ) {
    int i, number;

    srand(time(NULL));
    for(i=0; i<5; i++) {
    number = rand( );
    printf("random number is: %d\n", number);
    }
    return 0;
    }

    SPECIFICATIONS:
    You are to write a C program that simulates the
    dealing of a "poker hand" for a single (1) player,
    displays that hand on the screen, and determines
    if the player has been dealt a "Flush" or a
    "Straight Flush" ONLY.
    The program will NOT accept any user input (data),
    but must display 100 hands (each on a single line).
    Your program must then continue to execute
    (starting once again from 0) until a Flush AND a
    Straight Flush are found. Those hands should then be
    displayed as well as the number of hands that were
    required to be dealt in order to achieve those hands
    (see sample runs below).

    NOTE: You must find the Flush & Straight Flush
    even if they were already found in your
    100 hand deal!

    You will need to use ARRAYS to complete this
    assignment. As well, it is highly recommended
    that you use functions to modularize your program
    into several smaller parts!
    Programs without functions which are overly
    cumbersome or inefficient may result in your
    instructor deducting marks.


    Sample runs of the program are:

    a.out
    AC-2D-7H-JS-AD
    10S-9S-8D-6C-7D
    KD-KH-4H-KS-QH
    JC-4D-JD-JH-4S
    ...
    (assume 100 such hands have been dealt).

    Finding Flush & Straight Flush...
    2S-3S-6S-QS-5S (Flush)
    after 198 hands!

    8C-9C-5C-7C-6C (Straight Flush)
    after 70578 hands!

    a.out
    5H-4S-KD-JS-2D
    10S-4D-2C-3H-JD
    2S-6D-QS-5H-4C
    3D-6H-8C-JH-5C
    ...
    (assume 100 such hands have been dealt).

    Finding Flush & Straight Flush...
    5S-7S-9S-10S-QS (Flush)
    after 290 hands!

    5D-6D-7D-8D-9D (Straight Flush)
    after 73997 hands!

  2. #2
    Mayor of Awesometown Govtcheez's Avatar
    Join Date
    Aug 2001
    Location
    MI
    Posts
    8,825
    I see... So, what's the problem?

    > Challenge just for fun

    Sniff, sniff, smells like homework...

  3. #3
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    Okay, I've done it! Hey, that was fun!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. AI Challenge
    By unknown_111 in forum General AI Programming
    Replies: 0
    Last Post: 10-02-2007, 12:18 AM
  2. A Challenge in C++
    By Brad0407 in forum C++ Programming
    Replies: 38
    Last Post: 07-18-2007, 12:56 PM
  3. Programming Challenge (for my school)
    By Ezerhorden in forum C++ Programming
    Replies: 2
    Last Post: 01-04-2006, 05:56 AM
  4. Challenge?
    By Mackology101 in forum C Programming
    Replies: 5
    Last Post: 11-23-2004, 01:30 PM
  5. Requesting a challenge
    By RealityFusion in forum C++ Programming
    Replies: 8
    Last Post: 08-18-2003, 08:24 PM

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