• Advertisement
Sign in to follow this  

5 card dd card recegnition

This topic is 4882 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

int game::rank() { //starts the loop, it may go throurh it a few usless times but it is the inly accurate way for(loop[1] = 0; loop[1]<5; loop[1]++) { for(loopa = 0; loopa<5; loopa++) { //2 pair if(mycard[loop[1]] == mycard[loop[1]+1] && mycard[loop[1]+2] == mycard[loop[1]+3]) { if(loop[1]+3 <=4) { card_rank[1] = 27 + mycard[loop[1]] + mycard[loop[1]+2]; return 0; } } //basic pair if(mycard[loop[1]] == mycard[loop[1]+1]) { card_rank[1] = mycard[loop[1]]+13; } //3 of a kind else if(mycard[loop[1]] == mycard[loop[1]+1] && mycard[loop[1]] == mycard[loop[1]+2]) { card_rank[1] = mycard[loop[1]] + 120; } //-------------------------- if(pccard[loop[1]] == pccard[loop[1]+1] && pccard[loop[1]+2] == pccard[loop[1]+3]) { if(loop[1]+3 <=4) { card_rank[2] = 27 + pccard[loop[1]] + pccard[loop[1]+2]; return 0; } } //basic pair if(pccard[loop[1]] == pccard[loop[1]+1]) { card_rank[2] = pccard[loop[1]]+13; } //3 of a kind else if(pccard[loop[1]] == pccard[loop[1]+1] && pccard[loop[1]] == pccard[loop[1]+2]) { card_rank[2] = pccard[loop[1]] + 120; } } } } that was only part of it, I am currently finishing it. please post any comments.

Share this post

Link to post
Share on other sites
What is this loop[1] that shows up all over the place???

No wait, don't tell me you have an *array of global loop counter variables*???

Also, you're not using loopa anywhere.

Also, it looks like you think array indices start at 1. No no no. They start at 0.

Also, I have absolutely no idea what your card_rank values are supposed to mean. Use some symbolic names, at the very least. And don't worry about packing them in tightly. As long as they're ordered.

Also, assuming a 5-card hand, what do you expect to happen when you try to check mycard[loop[1]+3] on the last loop[1] iteration?

Also, don't try to repeat the check with mycard and pccard all jumbled together like that. You're going to be doing all the same things. So write your function so it takes a 'hand' as input, and then call it with mycard[], then with pccard[] and have it return the rank() of each (instead of trying to store it in some other array).

Oh, here's a hint that will probably make things much easier: Instead of trying to look for matched values, try making a tally of how many of each value there are:

int values[13] = {0};
// Each element counts the number of cards in the hand whose
// value equals the array index.
for (int i = 0; i < 5; i++) {

Then, you can go through and check if there are any 2s, 3s or 4s in the array:

int paircount = 0, triplecount = 0, quadcount = 0;
for (int i = 0; i < 13; i++) {
if (values == 2) paircount++;
// similarly for the others
// Going from that information to the hand type is left as an
// exercise, as is "remembering" the value that was
// paired/tripled/quadrupled. Although, there wouldn't be
// anything really wrong with just looking it up again.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement