Sponsored Content
Top Forums Programming Need help with Card Dealing Program Post 302508619 by Corona688 on Monday 28th of March 2011 02:18:11 PM
Old 03-28-2011
Why not have each card as a unique number, and decide from that number what suit it is? The suit defines the color, so that solves both problems.

Code:
#include <stdio.h>

enum suit_t
{
        // Arranged in this order to get black/red/black/red.
        SUIT_CLUB=0,    // 0 & 1 == 0.  Black.
        SUIT_HEART=1,   // 1 & 1 == 1.  Red.
        SUIT_SPADE=2,   // 2 & 1 == 0.  Black.
        SUIT_DIAMOND=3  // 3 & 1 == 1.  Red.
};

enum card_t
{
        CARD_MIN=0, CARD_MAX=52,

        // Cards are numbered as 0, 4, 8, 12, etc.  The first 2 bits decide the suit.
        CARD_ACE=(0<<2),      CARD_2=(1<<2),
        CARD_3=(2<<2),          CARD_4=(3<<2),
        CARD_5=(4<<2),          CARD_6=(5<<2),
        CARD_7=(6<<2),          CARD_8=(7<<2),
        CARD_9=(8<<2),          CARD_10=(9<<2),
        CARD_JACK=(10<<2),      CARD_QUEEN=(11<<2),
        CARD_KING=(12<<2)
};

const char const *cardnames[]={
        "Ace", "Two", "Three", "Four", "Five", "Six", "Seven",
        "Eight", "Nine", "Ten", "Jack", "Queen", "King", NULL };

const char const *colornames[]={ "Black", "Red", NULL };
const char const *suitnames[]={"Clubs", "Hearts", "Spades", "Diamonds", NULL };

#define CARD_NAMESTR(X)         (cardnames[(X)>>2])
#define CARD_SUITSTR(X)         (suitnames[(X)&SUIT_DIAMOND])
#define CARD_COLORSTR(X)        (colornames[((X)&1)])

int main(void)
{
        int card;

        for(card=CARD_MIN; card < CARD_MAX; card++)
        {
                printf("card %d is the %s of %s, and is %s\n", card,
                        CARD_NAMESTR(card), CARD_SUITSTR(card),
                        CARD_COLORSTR(card));
        }
}

Code:
card 0 is the Ace of Clubs, and is Black
card 1 is the Ace of Hearts, and is Red
card 2 is the Ace of Spades, and is Black
card 3 is the Ace of Diamonds, and is Red
card 4 is the Two of Clubs, and is Black
card 5 is the Two of Hearts, and is Red
card 6 is the Two of Spades, and is Black
card 7 is the Two of Diamonds, and is Red
...
card 44 is the Queen of Clubs, and is Black
card 45 is the Queen of Hearts, and is Red
card 46 is the Queen of Spades, and is Black
card 47 is the Queen of Diamonds, and is Red
card 48 is the King of Clubs, and is Black
card 49 is the King of Hearts, and is Red
card 50 is the King of Spades, and is Black
card 51 is the King of Diamonds, and is Red


Last edited by Corona688; 03-28-2011 at 03:36 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Help in dealing with arra

I am readinga file lin by line and based craeting a arry of unique elemenst from the second column of the line. However when i coem out of the while loop my array becomes empty , can eny one tell me what I would be doing wrong #!/bin/bash logfile="./mylog.dat" begin=100 end="$(( $begin +... (5 Replies)
Discussion started by: jojan
5 Replies

2. UNIX Desktop Questions & Answers

Does Red Hat Fedora support Nvidia card 8800GTX and 260 card?

Does Red Hat Fedora support Nvidia card 8800GTX and 260 card? Does any Linux OS support Nvidia card? (1 Reply)
Discussion started by: sito
1 Replies

3. UNIX and Linux Applications

webinject - dealing with popups

Hello We have a webapp that launches a link in a popup. We need to use webinject to check the content of that popup but have been so far unsuccessful. We use webinject as a nagios plugin. Does anyone have any experience of using/configuring webinject and know if this is possible or not? ... (1 Reply)
Discussion started by: skewbie
1 Replies

4. Shell Programming and Scripting

Dealing with files with spaces in the name

Hello, I'm a computer science major and I'm having problems dealing with file names with spaces in them. Particularly I'm saving a file name in a variable and then using the variable in a compare function i.e. a='te xt.txt' b='file2.txt' cmp $a $b If anyone could help me with this particular... (10 Replies)
Discussion started by: jakethegreycat
10 Replies

5. Shell Programming and Scripting

cp not dealing with variable properly? please help

I am having trouble with a script that is supposed to : a)take all the jpg pictures in a given directory/parameter and create thumbnails of it in a directory on the desktop. e.g from /here/are/the/files.jpg to ~/Desktop/parser-the/files.png this is my script: all the individual parts... (2 Replies)
Discussion started by: orochinagi
2 Replies

6. UNIX and Linux Applications

Dealing with geany core

Geany : Home Page, the text editor, sometimes crashes and leaves a geany.core file. This is a binary file and supposedly contains all unsaved work and possibly some other information. Does anyone know how to deal with this file? (2 Replies)
Discussion started by: figaro
2 Replies

7. Shell Programming and Scripting

Dealing with multiple files

Korn Shell I have hundreds of small files like below created every day. A midnight cron job moves them to the location /u04/temp/logs But sometimes I have to manually move these files based a certain dates or time. I have two basic requirements 1.Using mv command I want to move all .dat... (2 Replies)
Discussion started by: kraljic
2 Replies

8. UNIX for Dummies Questions & Answers

Dealing with sum

I have file input 1/1/2013 1AS030A 0 1083 CHINA 1/1/2013 1AS030B 0 675 KOREA 1/1/2013 1AS035A 162 662 CHINA 1/1/2013 1AS035B 51 799 INDIA 1/1/2013 1AS035C 0 731 CHINA 1/2/2013 1AS073A 10 1375 KOREA... (5 Replies)
Discussion started by: radius
5 Replies

9. Shell Programming and Scripting

Dealing with edge-list

I have an edge-list with nodes, edge.txt A B B J J H C A G H G A A C K G I have another file which tells me which of these nodes are important, input.txt G C A (3 Replies)
Discussion started by: Sanchari
3 Replies

10. Programming

Dealing with XML comments

I'm writing my own simple XML parser as an experiment. It's a lot more complicated than it's supposed to be. Things supposedly forbidden in XML comments happen all the time in the wild. You're never, ever supposed to find -- inside <!-- xml comments --> but in practice, you don't just find... (2 Replies)
Discussion started by: Corona688
2 Replies
secolor.conf(5) 						File Formats Manual						   secolor.conf(5)

NAME
secolor.conf - The SELinux color configuration file. DESCRIPTION
This optional file controls the color to be associated to the context components associated to the raw context passed by selinux_raw_con- text_to_color(3), when context related information is to be displayed in color by an SELinux-aware application. selinux_raw_context_to_color(3) obtains this color information from the active policy secolor.conf file as returned by selinux_col- ors_path(3). FILE FORMAT
The file format is as follows: color color_name = #color_mask [...] context_component string = fg_color_name bg_color_name [...] Where: color The color keyword. Each color entry is on a new line. color_name A single word name for the color (e.g. red). color_mask A color mask starting with a hash (#) that describes the hexadecimal RGB colors with black being #000000 and white being #ffffff. context_component The context component name that must be one of the following: user, role, type or range Each context_component string ... entry is on a new line. string This is the context_component string that will be matched with the raw context component passed by selinux_raw_context_to_color(3). A wildcard '*' may be used to match any undefined string for the user, role and type context_component entries only. fg_color_name The color_name string that will be used as the foreground color. A color_mask may also be used. bg_color_name The color_name string that will be used as the background color. A color_mask may also be used. EXAMPLES
Example 1 entries are: color black = #000000 color green = #008000 color yellow = #ffff00 color blue = #0000ff color white = #ffffff color red = #ff0000 color orange = #ffa500 color tan = #D2B48C user * = black white role * = white black type * = tan orange range s0-s0:c0.c1023 = black green range s1-s1:c0.c1023 = white green range s3-s3:c0.c1023 = black tan range s5-s5:c0.c1023 = white blue range s7-s7:c0.c1023 = black red range s9-s9:c0.c1023 = black orange range s15:c0.c1023 = black yellow Example 2 entries are: color black = #000000 color green = #008000 color yellow = #ffff00 color blue = #0000ff color white = #ffffff color red = #ff0000 color orange = #ffa500 color tan = #d2b48c user unconfined_u = #ff0000 green role unconfined_r = red #ffffff type unconfined_t = red orange user user_u = black green role user_r = white black type user_t = tan red user xguest_u = black yellow role xguest_r = black red type xguest_t = black green user sysadm_u = white black range s0:c0.c1023 = black white user * = black white role * = black white type * = black white SEE ALSO
selinux(8), selinux_raw_context_to_color(3), selinux_colors_path(3) SELinux API documentation 08 April 2011 secolor.conf(5)
All times are GMT -4. The time now is 09:43 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy