![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: May 2005
Posts: 6
Rep Power: 0
![]() |
can som1 help?
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM_FACES 13
void shuffle( int wDeck[][ 13 ] );
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] );
int getSuit( int Card );
int getFace( int Card );
int main()
{
const char *suit[ 4 ] = { "Hearts", "Diamonds", "Clubs", "Spades" };
const char *face[ 13 ] =
{ "Ace", "Deuce", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King" };
int deck[ 4 ][ 13 ] = { 0 };
shuffle( deck );
deal( deck, face, suit );
return 0;
}
void shuffle( int wDeck[][ 13 ] )
{
int row;
int column;
int card;
for ( card = 1; card <= 5; card++ ) {
do {
row = rand() % 4;
column = rand() % 13;
} while( wDeck[ row ][ column ] != 0 );
wDeck[ row ][ column ] = card;
}
}
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] )
{
int card;
int row;
int column;
for ( card = 1; card <= 5; card++ ) {
for ( row = 0; row <= 3; row++ ) {
for ( column = 0; column <= 12; column++ ) {
if ( wDeck[ row ][ column ] == card ) {
printf( "%5s of %-8s%c", wFace[ column ], wSuit[ row ],
card % 2 == 0 ? '\n' : '\t' );
}
}
}
}
}how can you check to see if the five cards that were deal does it contain a pair of the same numbers ex) 3 of spades, 4 of cloves, 5 of diamond, 3 of diamonds, king of spades, this should say it has a pairs of 3s |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Loop through and check one against the other. It works kinda like a bubble sort, really.
|
|
|
|
|
|
#3 |
|
Programming Guru
![]() |
just lots of comparison to be done i think.
Or you could just have a 3 digit code for each card (first digit is suit and the next 2 are number of card and the comparison would be faster) |
|
|
|
|
|
#4 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
Hell, use hex and make it two digits.
![]() |
|
|
|
|
|
#5 |
|
Newbie
Join Date: May 2005
Posts: 6
Rep Power: 0
![]() |
revised prog
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define NUM_FACES 13
void shuffle( int wDeck[][ 13 ] );
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] );
int getSuit( int Card );
int getFace( int Card );
int main()
{
const char *suit[ 4 ] = { "Hearts", "Diamonds", "Clubs", "Spades" };
const char *face[ 13 ] =
{ "Ace", "Deuce", "Three", "Four",
"Five", "Six", "Seven", "Eight",
"Nine", "Ten", "Jack", "Queen", "King" };
int deck[ 4 ][ 13 ] = { 0 };
shuffle( deck );
deal( deck, face, suit );
return 0;
}
void shuffle( int wDeck[][ 13 ] )
{
int row;
int column;
int card;
for ( card = 1; card <= 5; card++ ) {
do {
row = rand() % 4;
column = rand() % 13;
} while( wDeck[ row ][ column ] != 0 );
wDeck[ row ][ column ] = card;
}
}
void deal( const int wDeck[][ 13 ], const char *wFace[],
const char *wSuit[] )
{
int card;
int row;
int column;
for ( card = 1; card <= 5; card++ ) {
for ( row = 0; row <= 3; row++ ) {
for ( column = 0; column <= 12; column++ ) {
if ( wDeck[ row ][ column ] == card ) {
printf( "%5s of %-8s%c", wFace[ column ], wSuit[ row ],
card % 2 == 0 ? '\n' : '\t' );
}
}
}
}
}
void deal(int pokerHand[][2], const char *suit1[], const char *face1[])
{
int a , b;
for ( a = 0 ; a <= 4; a++ ){
b = 0;
printf("%s", suit1[pokerHand[a][b]]);
b = 1;
printf("%s ", face1[pokerHand[a][b]]);
}
printf("\n");
}
void cardQuality( int playerHand [][2] ) {
int y,z;
int positFace[5], positSuit[5];
int *fPtr = positFace, *sPtr = positSuit ;
int Facepass = 0;
int swap;
int Suitpass = 0 ;
int straight = 0;
for ( y = 0 ; y <= 4 ; y++ ){
z = 1 ;
*fPtr = playerHand[y][z];
fPtr++ ;
}
for ( y = 0 ; y <= 4 ; y++ ){
z = 0 ;
*sPtr = playerHand[y][z];
sPtr++ ;
}
for ( y = 0 ; y <= 3 ; y++ ) {
for ( z = (y + 1); z <= 4 ; z++ ){
if ( *(positFace + y ) == *(positFace + z ) ) {
Facepass++;
}
}
}
for ( z = 0 ; z <= 3 ; z++ ){
for (y = 0 ; y <= 3 ; y++ ){
if ( positFace[y] > positFace[y+1] ) {
Swap(&positFace[y],&positFace[y+1]);
}
}
}
for ( z = 0; z <= 3 ; z++ ){
if ( positFace[z] == positFace[z + 1] - 1 ){
straight++;
}
}
for ( z = 1; z <= 4 ; z++ ){
if ( *positSuit == *(positSuit + z ) ) {
Suitpass++;
}
}
switch ( Facepass ){
case 1 :
printf("The poker hand contains a pair\n" );
break ;
case 2 :
printf("The poker hand contains two pair\n" );
break;
case 3 :
printf("The poker hand contains three of a kind\n");
break ;
case 4:
printf("The poker hand contains full house\n");
break ;
case 6:
printf("The poker hand contains four fo a kind\n");
break ;
default :
if ( Suitpass == 4 && straight != 4) {
printf("The poker hand contains flush\n");
}
if ( straight == 4 && Suitpass != 4) {
printf("The poker hand contains straight\n");
}
if ( straight == 4 && Suitpass == 4) {
printf("The poker hand contains straight flush\n");
}
break;
}
} |
|
|
|
|
|
#6 |
|
Newbie
Join Date: May 2005
Posts: 6
Rep Power: 0
![]() |
error C2084: function 'void deal(const int (*)[13],const char ** ,const char ** )' already has a body
warning C4028: formal parameter 1 different from declaration these are the 2 errors i got |
|
|
|
|
|
#7 |
|
Professional Programmer
|
What are you using to compile? I don't get those errors. The only error I get involves the use of swap() under void cardQuality(). I changed from upper to lower case 's', and that eliminated one problem. But it appears it's not being used properly in this case. I'm looking it up and I'll post anymore info I find. I'm using Dev C++, btw.
__________________
Amateurs built the ark Professionals built the Titanic |
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: Nov 2004
Location: 1691 miles East of L.A.
Posts: 159
Rep Power: 5
![]() |
You have 2 deal functions.
void deal( const int wDeck[][ 13 ], const char *wFace[], const char *wSuit[] ) void deal(int pokerHand[][2], const char *suit1[], const char *face1[])
__________________
-- lostcauz Stepped in what?... Behind whose barn?... I didn't even know they had a cow! |
|
|
|
|
|
#9 |
|
Newbie
Join Date: May 2005
Posts: 6
Rep Power: 0
![]() |
to peace_of_mind: the compiler im using is microsoft visual studio.net 2003
|
|
|
|
|
|
#10 |
|
Programming Guru
![]() |
You can have 2 functions of the same name as long as the parameters to pass are different .....
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|