Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include <string.h>
- #include <stdbool.h>
- const char *cards[52] = { "AC","AD","AH","AS","2C","2D","2H","2S","3C","3D","3H","3S","4C","4D","4H","4S","5C","5D","5H","5S","6C","6D","6H","6S","7C","7D","7H","7S"
- ,"8C","8D","8H","8S","9C","9D","9H","9S","10C","10D","10H","10S","JC","JD","JH","JS","QC","QD","QH","QS","KC","KD","KH","KS" };
- bool win;
- bool fold;
- int P1Chips = 100;
- int CPUChips = 100;
- char P1handType[100];
- char CPUhandType[100];
- int main()
- {
- printf("**Welcome to 5-card stud poker!**\n");
- printf(" \n");
- printf("Note: the cards have as suffix the initial of their suit\n");
- printf("Eg:AC(Ace of Clubs)\n");
- printf(" KH(King of Hearts)\n");
- printf(" \n");
- printf("1. Start new game (Player 1 vs cpu)(Press Enter)");
- while (getchar() != '\n');
- TheGame();
- getchar();
- return 0;
- }
- int TheGame()
- {
- char PayAnte;
- printf(" \n");
- printf("You have %d", P1Chips);
- printf(" chips ");
- printf("CPU has %d", CPUChips);
- printf(" chips \n\n");
- printf("To play you must pay 2 chips as ante, do you wish to pay?(Y/N) \n");
- scanf("%c", &PayAnte);
- if (PayAnte == 'N' || PayAnte == 'n')
- {
- printf("You must be broke, CPU wins");
- getchar();
- return 0;
- }
- else if (PayAnte == 'Y' || PayAnte == 'y')
- {
- P1Chips = P1Chips - 2;
- CPUChips = CPUChips - 2;
- printf("\nYou have %d", P1Chips);
- printf(" chips ");
- printf("CPU has %d", CPUChips);
- printf(" chips \n\n");
- srand(time(NULL));
- int P1RandomCard = rand() % 52;
- //printf("%s\n", cards[P1RandomCard]);
- int P1RandomCard2 = rand() % 52;
- //printf("%s\n", cards[P1RandomCard2]);
- int P1RandomCard3 = rand() % 52;
- // printf("%s\n", cards[P1RandomCard3]);
- int P1RandomCard4 = rand() % 52;
- //printf("%s\n", cards[P1RandomCard4]);
- int P1RandomCard5 = rand() % 52;
- //printf("%s\n", cards[P1RandomCard5]);
- //Player 1 set of 5 random cards
- char *P1cards[5] = { cards[P1RandomCard],cards[P1RandomCard2],cards[P1RandomCard3], cards[P1RandomCard4],cards[P1RandomCard5] };
- char P1Cardslastchar1 = cards[P1RandomCard][strlen(cards[P1RandomCard]) - 1];
- char P1Cardslastchar2 = cards[P1RandomCard2][strlen(cards[P1RandomCard2]) - 1];
- char P1Cardslastchar3 = cards[P1RandomCard3][strlen(cards[P1RandomCard3]) - 1];
- char P1Cardslastchar4 = cards[P1RandomCard4][strlen(cards[P1RandomCard4]) - 1];
- char P1Cardslastchar5 = cards[P1RandomCard5][strlen(cards[P1RandomCard5]) - 1];
- printf("\n Your random selected cards are: ");
- int elements = sizeof(P1cards) / sizeof(P1cards[0]);
- for (int i = 0; i < elements; i++) {
- char *p = P1cards[i];
- while (*p)
- putchar(*p++);
- putchar(' ');
- }
- srand(time(NULL) - 1);
- int CPURandomCard = rand() % 52;
- // printf("%s\n", cards[CPURandomCard]);
- int CPURandomCard2 = rand() % 52;
- // printf("%s\n", cards[CPURandomCard2]);
- int CPURandomCard3 = rand() % 52;
- // printf("%s\n", cards[CPURandomCard3]);
- int CPURandomCard4 = rand() % 52;
- // printf("%s\n", cards[CPURandomCard4]);
- int CPURandomCard5 = rand() % 52;
- // printf("%s\n", cards[CPURandomCard5]);
- //CPU's set of 5 random cards
- char *CPUcards[5] = { cards[CPURandomCard],cards[CPURandomCard2],cards[CPURandomCard3], cards[CPURandomCard4],cards[CPURandomCard5] };
- char CPUCardslastchar1 = cards[CPURandomCard][strlen(cards[CPURandomCard]) - 1];
- char CPUCardslastchar2 = cards[CPURandomCard2][strlen(cards[CPURandomCard2]) - 1];
- char CPUCardslastchar3 = cards[CPURandomCard3][strlen(cards[CPURandomCard3]) - 1];
- char CPUCardslastchar4 = cards[CPURandomCard4][strlen(cards[CPURandomCard4]) - 1];
- char CPUCardslastchar5 = cards[CPURandomCard5][strlen(cards[CPURandomCard5]) - 1];
- //Determining hand types
- if (P1Cardslastchar1 == P1Cardslastchar2 && P1Cardslastchar2 == P1Cardslastchar3 && P1Cardslastchar3 == P1Cardslastchar4 && P1Cardslastchar4 == P1Cardslastchar5)
- P1handType[5] = "Flush";
- if (CPUCardslastchar1 == CPUCardslastchar2 && CPUCardslastchar2 == CPUCardslastchar3 && CPUCardslastchar3 == CPUCardslastchar4 && CPUCardslastchar4 == CPUCardslastchar5)
- CPUhandType[5] = "Flush";
- getchar();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement