Problem with dealing hands of poker cards


 
Thread Tools Search this Thread
Top Forums Programming Problem with dealing hands of poker cards
# 1  
Old 03-29-2011
Problem with dealing hands of poker cards

Hi I'm making a poker game program and I need to deal 5 hands of cards(each hand has 5 cards each) in the program, each hand needs to contain different cards and we need to then display the number of pairs in each hands. I'm currently stuck in the dealing part.
This is what I have so far for dealing card:
Code:
void deal(card cards[52], card hands[5][5]) {
  int i, j, cd, hd;
  int value, hi, med, lo;
  card shuff;
  
for(cd=0, i=0; cd<5; cd++) {
    for(hd=0;hd<5;hd++) {
      hands[hd][cd] = cards[i];
      ++i;
    }
  }
for(i=0;i<5;i++) {  
    med = 5;
    lo = 1;
for(; lo < med; lo++)  {
      shuff = hands[i][lo];    
      hi = lo - 1;
      while(hands[i][hi].face > shuff.face)  {
        hands[i][hi + 1] = hands[i][hi];
        --hi;
        if(hi < 0) break;
      } 
      hands[i][hi+1] = shuff;
    }
  }
  for(i = 0; i < 5; i++) {
    printf("\nHand #%d:\n\n", i+1);
    for(j = 0; j < 5; j++) {
      printf("\t%s of %s, is %s \n ",cards[j%13].face,cards[j%13].suit,cards[j%26].color);
    }  
  }
}

however, the compiled result shows all the hands has the exactly same cards. I'm not sure what Ive done wrong, can anyone help pls?
# 2  
Old 03-29-2011
This code is incomplete. could you post the complete code?

Also, it would be a lot simpler to make the cards integers.

---------- Post updated at 08:58 AM ---------- Previous update was at 08:51 AM ----------

Code:
printf("\t%s of %s, is %s \n ",cards[j%13].face,cards[j%13].suit,cards[j%26].color);

There's no references to i here, so naturally it'd print the same cards every loop -- there's nothing to make it print a different hand.
Login or Register to Ask a Question

Previous Thread | Next Thread

7 More Discussions You Might Find Interesting

1. Red Hat

Is here anyone hands on in Linux Bare Metal Restore..??

Hi all, I am working on Linux Bare Metal Restore in which i have few things to be discussed with a person who has his/her hands on in that process. If anyone kindly give a reply post in this thread.. :) :) Thanks Selva (3 Replies)
Discussion started by: selvarajvs
3 Replies

2. UNIX for Dummies Questions & Answers

Unix hands on

Hi, I am new to UNIX system, i have theoritical knowledge but never gotta chance to work on UNIX system. I dont have the environment to practice, is there anything which i can download or any online website to work over and get better in UNIX? Please help me.. Thanks & Regard's Span'rd (2 Replies)
Discussion started by: spaniard
2 Replies

3. Linux

problem of wild cards matching..$ls t[A-Z] output

hi all, i have created a file by name tt and while listing the file ,i used the command $ls t from which i was expecting not to list tt file output coz of uppercase range, But it listed that file tt file and am not able understand the reason. kindly help. NOTE OS :Red Hat Enterprise... (0 Replies)
Discussion started by: rajp_8007
0 Replies

4. AIX

New to AIX and got my hands on a RS6000 v.need help getting it on the network

So im fairly new to AIX and my knowledge is very, very limited but i got my hands on an RS6000 43P model and im trying to get it on the network so i can access it from work. I have pretty much tried everything i can/know how to do by reading up as much as i can but im still lost. I have the 43P... (2 Replies)
Discussion started by: IIIII
2 Replies

5. UNIX for Dummies Questions & Answers

I need hands-on skill.

Can someone help me get into a UNIX server so I can get some hands-on skills? (3 Replies)
Discussion started by: FernandesE74
3 Replies

6. AIX

Hands On Learning - AIX

Hi all, I am interested in your opinions of the best way to get hands-on security experience with AIX. I am proficient with most linux flavors on intel, but need to get familiar with AIX. Any ideas on how to get some hands-on without lumping out $4Gs for a used RS/6000? Thanks EW (4 Replies)
Discussion started by: ewelsh
4 Replies

7. News, Links, Events and Announcements

Hands on Support

Check this link. Its Sun Solaris Docs link that place all sorts of Materials in it. From Hands on Support materials Etc. Quite intresting. Sun OS Hands on Docs. :cool: (1 Reply)
Discussion started by: killerserv
1 Replies
Login or Register to Ask a Question