int test_queue(){ int i,j; Card card; Deck * deck = malloc(sizeof(Deck)); Deck * deck2 = malloc(sizeof(Deck)); Hand * hand = malloc(sizeof(Hand)); build_deck(deck); shuffle_deck(deck); build_deck(deck2); shuffle_deck(deck2); i = 0; for (;;){ printf("Initialized Deck and Hand\n"); print(deck->card, DECK_SIZE); print(hand->card, HAND_SIZE); for (j = 0; j < HAND_SIZE; ++j){ card = deal_card(deck); hand->card[j] = card; } printf("\nAdded cards to hand\n"); print(deck->card, DECK_SIZE); print(hand->card, HAND_SIZE); for (j = 0; j < HAND_SIZE; ++j){ add_card(deck, hand->card[j]); hand->card[j].suite = -1; hand->card[j].value = -1; } printf("\nPut cards back into deck\n"); print(deck->card, DECK_SIZE); print(hand->card, HAND_SIZE); printf("\n\n"); i++; if (i == 100) break; } sort_cards(deck->card, DECK_SIZE); sort_cards(deck2->card, DECK_SIZE); for (i = 0; i < DECK_SIZE; ++i) if (deck->card[i].value != deck2->card[i].value) printf("Bad Shuffle\n"); printf("Good Shuffle\n"); return 0; }
void check_good_shuffle(){ int i; Deck * deck1 = malloc(sizeof(Deck)); Deck * deck2 = malloc(sizeof(Deck)); build_deck(deck1); build_deck(deck2); shuffle_deck(deck2); sort_cards(deck1->card, DECK_SIZE); sort_cards(deck2->card, DECK_SIZE); print(deck1->card, DECK_SIZE); print(deck2->card, DECK_SIZE); for (i = 0; i < DECK_SIZE; ++i) if (deck1->card[i].value != deck2->card[i].value) { printf("Bad Shuffle\n"); return; } printf("Good Shuffle\n"); return; }
int main(void) { Deck deck; initialise_deck(deck); printf("A brand new deck of cards, whose seal has just been broken:\n"); display_deck(deck); srand(time(NULL)); for(int i = 0; i < 3; ++i) { shuffle_deck(deck, 1); printf("\nAfter shuffling the deck "); i == 0 ? printf("once:\n") : i == 1 ? printf("twice:\n") : printf("thrice:\n"); display_deck(deck); } shuffle_deck(deck, 5); printf("\nAfter shuffling the deck 5 more times:\n"); display_deck(deck); return EXIT_SUCCESS; }
int main(int argc,char **argv) { int n; int curr_arg; bool bDebug; bool bRankOnly; bool bInteger; int seed; struct pile deck; struct pile piles[NUM_PILES]; int retval; if ((argc < 2) || (argc > 5)) { printf(usage); return 1; } bDebug = false; bRankOnly = false; bInteger = false; for (curr_arg = 1; curr_arg < argc; curr_arg++) { if (!strcmp(argv[curr_arg],"-debug")) bDebug = true; else if (!strcmp(argv[curr_arg],"-rank_only")) bRankOnly = true; else if (!strcmp(argv[curr_arg],"-integer")) bInteger = true; else break; } if (argc - curr_arg != 1) { printf(usage); return 2; } sscanf(argv[curr_arg],"%d",&seed); srand(seed); initialize_deck(&deck); if (bDebug) { printf("print_pile(&deck,bRankOnly,bInteger);\n"); print_pile(&deck,bRankOnly,bInteger); } shuffle_deck(&deck); deal_to_piles(&deck,piles); print_piles(piles,false,bRankOnly,bInteger); return 0; }
int main() { double start_time[10]; int i, j; int sorted_players[10]; testgame = new_game(10); for (i = 0; i < 10; i++) { testgame->players[i].active = 1; } print_deck(); puts("*** AFTER SHUFFLING ***"); shuffle_deck(testgame); print_deck(); puts("*** COMMUNITY CARDS ***"); deal_community(testgame); print_community(); puts("*** DEALING CARDS ***"); deal_cards(); print_hands(); puts("*** SORTING PLAYERS ***"); get_player_ranks(testgame, sorted_players); puts("In order of card ranking (low to high):"); for (i = 0; i < 10; i++) printf("Player %d\n", sorted_players[i]); /* puts("*** BENCHMARKING ***"); start_time[0] = get_time(); for (i = 0; i < 5000; i++) shuffle_deck(); printf("Shuffled deck 5,000 times in %f\n", get_time() - start_time[0]); for (i = 0; i < 10; i++) { start_time[i] = get_time(); for (j = 0; j < 100000; j++) get_best_player_hand(i); printf("Calculated best hand for Player %d 100,000 times in %f\n", i, get_time() - start_time[i]); } */ return 0; }
int main() { struct Card unused_cards[TOTAL_DECK]; struct Card working_deck[TOTAL_DECK]; generate_deck(unused_cards); shuffle_deck(unused_cards); format_deck(unused_cards); int playing = TRUE; while (playing == TRUE) { playing = game_round(unused_cards, working_deck); format_deck(working_deck); } printf("Final count: %d\n", count_deck(working_deck)); return 1; }
int main(int argc, char *argv[]) { double dealt; char* endptr1; if(argc == 2) { dealt = strtod(argv[1], &endptr1); } else if(argc == 1) { dealt = 5; } printf("Welcome to the Poker Table\n"); struct deck *deck = make_deck(); shuffle_deck(deck); if(!deck) { fprintf(stderr, "Could not create deck"); return 1; } if(dealt > 52 || dealt < 0) { printf("%.2f was not a correct number of cards.\n", dealt); dealt = 5; printf("You were dealt %.2f cards.\n", dealt); print_card_new(deck, dealt); //print_card_abbrev(deck); } else if(dealt <= 52) { print_card_new(deck, dealt); //passes the variable 'deck' because it expects a pointer to a deck structure //print_card_abbrev(deck); } free_deck(deck); }
int *draw_n_cards_for_n_players_n_times(int nSuits, int nCardsOfSuit, int nCards, int nPlayers, int nTimes){ int index, i, j; int *sumOfCards; player **players; deck *cardinal; sumOfCards = (int *)calloc(nCards*11, sizeof(int)); players = malloc(sizeof(player *)*nPlayers); cardinal = create_deck(nSuits, nCardsOfSuit); while(nTimes){ index = 0; shuffle_deck(cardinal); for(i = 0; i < nPlayers; i++){ players[i] = get_new_player(); for(j = 0; j < nCards - 2; j++, index++) give_card(players[i]->hand, cardinal, index); calculate_score(players[i]); sumOfCards[players[i]->score] += 1; } for(i = 0; i < nPlayers; i++) trash_participant(players[i]); nTimes--; } trash_deck(cardinal); return sumOfCards; }
int main() { for (size_t n = 0; n <= 100; ++n) { for (int i = 0; i < 1000; ++i) { std::vector< size_t > deck; /* the deck is initially sorted */ for (size_t i = 0; i < n; ++i) { deck.push_back(i); } shuffle_deck(deck); assert(is_valid_deck(deck) == true); } std::cout << "passed random tests for decks of size " << n << std::endl; } return 0; }
int main(int ac, char **av) { int i; i = 0; printf("Hello\n"); if (ac == 1) { t_game *game; game = init_game(22); display_deck(&game->deck); printf("=================================================================\n"); // printf("Name: %s\n", av[0]); while (i < 1) { game->deck = *shuffle_deck(&game->deck); display_deck(&game->deck); printf("=================================================================\n"); i++; } game = serve_card(game); // display_deck(&game->deck); printf("=================================================================\n"); i = 0; while (i < game->np) { display_player(&game->players[i]); i++; } game = serve_flop(game); // display_deck(&game->deck); printf("=================================================================\n"); i = 0; while (i < game->np) { display_player(&game->players[i]); i++; } printf("=================================================================\n"); game = serve_turn(game); // display_deck(&game->deck); printf("=================================================================\n"); i = 0; while (i < game->np) { display_player(&game->players[i]); i++; } printf("=================================================================\n"); game = serve_river(game); // display_deck(&game->deck); printf("=================================================================\n"); i = 0; while (i < game->np) { display_player(&game->players[i]); i++; } printf("=================================================================\n"); printf("Name: %s\n", av[0]); } return (0); }
// from UDP made simple at https://www.abc.se/~m6695/udp.html int main(int argc, char *argv[]) { struct sockaddr_in si_me, si_oth,si_other[4]; int s, sockFd[4]; socklen_t slen=sizeof(struct sockaddr_in); ssize_t len; FILE *fd; fd = fopen("/var/tmp/serve_client","w"); char buf[BUFLEN]={"start"}; char *trick[4]; FF_trick(trick); //Game initiation, shuffling and dealing. Card sorted_deck[52]; Card shuffled_deck[52]; char *deck[52]; new_deck(sorted_deck); shuffle_deck(sorted_deck,shuffled_deck); convert_card_struct(shuffled_deck,deck,buf); Game *game = malloc(sizeof(Game)); memcpy(game->deck,deck,sizeof(deck)); for (int k = 0; k < 4; k++) memcpy(game->buffer[k],buf, sizeof(buf)); for (int k = 0; k < 4; k++) printf("Shuffled deck: \n%s\n\n",game->buffer[k]); //get communication going if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP))==-1) diep("socket"); printf("socket open\n"); memset((char *) &si_me, 0, sizeof(si_me)); si_me.sin_family = AF_INET; si_me.sin_port = htons(GAMEPORT); si_me.sin_addr.s_addr = htonl(INADDR_ANY); if (bind(s, (struct sockaddr *) &si_me, sizeof(si_me))==-1) diep("bind"); printf("bound\n"); //Player initiation int counter[4]; for(int i=0;i<4;i++){ counter[i] = i; } pthread_t players[4]; for(int i=0;i<4;i++){ pthread_t tmp=0; players[i] = tmp; } //Player thread arguments are initiated Player player[4]; for(int i=0;i<4;i++){ memset((char *) &si_other[i], 0, sizeof(si_other[i])); Player tmp={i,&s,game,&si_me,&si_other[i]}; memcpy(&player[i], (void *) &tmp, sizeof(tmp)); } //deal cards into each player's game buffer for (int k = 0; k < 4; k++) { sprintf(player[k].game->buffer[k],"%s;",game->deck[k]); for(int j=4;j<52;j+=4) { strcat(player[k].game->buffer[k], game->deck[(j+k)]); strcat(player[k].game->buffer[k],";"); } printf("Player %d game buffer: %s\n",k,player[k].game->buffer[k]); } for (int k = 0; k < 4; k++)printf("Player %d game buffer: %s\n",k,player[k].game->buffer[k]); //deal cards into player hands for (int k = 0; k < 4; k++) { for(int j=0;j<52;j+=4) { player[k].game->hands[k][j/4] = malloc(3); strcpy(player[k].game->hands[k][j/4], game->deck[(j+k)]); } } /* print hands for (int k = 0; k < 4; k++) { printf("Player %d game hand: ", k); for (int l = 0; l < 13; l++) { printf("%s ", player[k].game->hands[k][l]); } printf("\n"); }*/ int j=0,connected=0; void *buffer = (void *) strdup(buf); bool connections[]={false,false,false,false}; char *this_is_my_pos[4]; do{ printf("inet: %s\tsocket descriptor: %d\n\n", inet_ntoa(player[j].si_other->sin_addr), player[j].sockfd); if((len = recvfrom(s, buffer, BUFLEN, 0, &si_oth, &slen)) == -1) diep("recvfrom()"); //check given position separate_strings(buffer,";",this_is_my_pos,4); if((j=find_DD(this_is_my_pos,4))== -1) printf("not a new connection\n"); if(j < 4 && j >= 0 && !connections[j]){ //In preparation for threads sockFd[j]= s; player[j].sockfd = &sockFd[j]; strcpy(si_other[j].sin_zero,si_oth.sin_zero); si_other[j].sin_addr.s_addr=si_oth.sin_addr.s_addr; si_other[j].sin_port=si_oth.sin_port; si_other[j].sin_family=si_oth.sin_family; player[j].si_other = &si_other[j]; printf("pthread to addr: %d\n",si_oth.sin_addr.s_addr); //pthread_create(&players[j],NULL,&player_waits_or_plays,(void *) &player[j]); //Signal that four clients are connected connections[j]=true; connected += 1; } else perror("not a new connection\n"); printf("Received packet from IP-address: %s: Port: %d\nPosition: %d\nData: %s\nLength: %d\n", inet_ntoa(si_oth.sin_addr), ntohs(si_oth.sin_port), j, (char *) buffer,(int) len); //strängen delas upp i fyra separate_strings(buffer,";",trick,4); printf("received split into: %s",trick[0]); for(int i=1;i<4;i++) printf(" %s",trick[i]); //skicka första handen printf("\nSending packet: \n%s\nto player %d\n", game->buffer[j],j); if (sendto(s, game->buffer[j], 200, 0, (struct sockaddr *) &si_oth, slen)==-1) diep("sendto()"); } while (connected<4); int starter=0; // Här börjar spelet, första handen har skickats till klienterna. Vem börjar? starter=who_starts(game->hands); int winner=-1; printf("player %d starts\n", starter); EE_trick(trick,starter); printf("Winner: %d\n", winner=check_winner(trick,starter)); EE_trick(trick,starter); EE_trick(game->trick,starter); // Lägg nu sticket i fyra buffertar, en till varje spelare (overkill!) for (int m = 0; m < 4; m++) { for (int k = 0; k < 4; k++) { if (!k) sprintf(player[m].game->buffer[m], "%s;", trick[0]); else { strcat(game->buffer[m], trick[k]); strcat(game->buffer[m], ";"); } printf("Game buffer: %s\n", game->buffer[m]); } } for (int k = 0; k < 4; k++)printf("Player %d game buffer: %s\n",k,player[k].game->buffer[k]); for (int l = 0; l < 4; l++) { if ((len = recvfrom(s, buffer, BUFLEN, 0, (struct sockaddr *) &si_oth, &slen)) == -1) diep("recvfrom()"); if (si_other[l].sin_addr.s_addr == si_oth.sin_addr.s_addr) { if (sendto(s, game->buffer[l], sizeof(game->buffer[l]), 0, (struct sockaddr *) &si_other[l], slen) == -1) diep("sendto()"); printf("Skickar %s till spelare %d\n",game->buffer[l], player[l].pos); } } /*for (int l = 0; l < 4; l) { if((len = recvfrom(s, buffer, BUFLEN, 0, (struct sockaddr *) &si_oth, &slen)) == -1) diep("recvfrom()"); }*/ int o=0; do{ if((len = recvfrom(s, buffer, BUFLEN, 0, (struct sockaddr *) &si_oth, &slen)) == -1) diep("recvfrom()"); printf("from addr: %d\n",si_oth.sin_addr.s_addr); if ((strstr(buffer,"00"))) { for (int m = 0; m < 4; m++) { sprintf(player[m].game->buffer[m], "%s;", buffer); printf("Buffer written: %s\n", buffer); } for (int l = 0; l < 4; l++) { if (si_other[l].sin_addr.s_addr == si_oth.sin_addr.s_addr) { if (sendto(s, game->buffer[l], sizeof(game->buffer[l]), 0, (struct sockaddr *) &si_other[l], slen) == -1) diep("sendto()"); printf("Skickar %s till spelare %d\n", buffer, player[l].pos); //pthread_create(&players[l], NULL, &player_waits_or_plays, (void *) &player[l]); } } } } while (!(strstr(buffer,"00"))); void *new_buffer; void *best_buffer; new_buffer = malloc(40); best_buffer = malloc(40); int FFs=0, best_count=4; // så länge första handen spelas vill vi jämföra skickade händer med mottagna händer while(strstr(buffer, "00") && strstr(buffer,"FF")){ if((len = recvfrom(s, new_buffer, BUFLEN, 0, (struct sockaddr *) &si_oth, &slen)) == -1) diep("recvfrom()"); //Vill du ha hela din hand igen? if(strstr((char*) new_buffer, "DD")){ for (int i = 0; i < 4; i++) { if(si_oth.sin_addr.s_addr==player[i].si_other->sin_addr.s_addr){ if (sendto(s, game->hands[i], sizeof(game->hands[i]), 0, (struct sockaddr *) &si_other[i], slen) == -1) diep("sendto()"); // inga onödiga loopar! break; } } //tillbaka till att ta emot igen! continue; } else if((strcmp((char *) buffer, (char *) new_buffer)) && !(strstr(new_buffer, "EE"))) { printf("Gammalt stick: %s\nUppdaterat stick: %s",(char*) buffer, (char*) new_buffer); char *tmp = strdup(new_buffer); if((FFs= count_FF(tmp)) < best_count) best_count = FFs; else continue; // skriv inte över sticket om det inte nästa kort spelats strcpy((char*)buffer, new_buffer); split((char*) buffer,';',game->trick); //bufferten måste återställas efter split() strcpy((char*)buffer, new_buffer); printf("\nkontroll av pekare: : \n"); for (int i = 0; i < 4; i++) printf("trick %d: %s\n",i,game->trick[i]); for (int i = 0; i < 4; i++) printf("trick %d: %s\n",i,game->trick[i]); for (int l = 0; l < 4; l++){ strcpy(game->buffer[l],new_buffer); if (sendto(s, game->buffer[l], sizeof(game->buffer[l]), 0, (struct sockaddr *) &si_other[l], slen) == -1) diep("sendto()"); else printf("Precis skickat %s till spelare %d\n",game->buffer[l], player[l].pos); } } } assert(!strstr(game->buffer[0],"FF")); split(game->buffer[0],';',trick); //Ta reda på vem som vann sticket //int winner=-1; printf("Winner: %d\n", winner=check_winner(trick,starter)); // Jag räknar med att klienten ställer frågor om sticket EE_trick(trick,winner); EE_trick(game->trick,winner); // Förmodligen börjar en do-while-loop här som kör så länge // Switch-sats beroende på /*while(strcmp(buffer,"quit")){ printf("buffer: %s \n",player[j].game->buffer); if ((len = recvfrom(s, buffer, BUFLEN, 0, &si_oth, &slen)) == -1) diep("recvfrom()"); printf("Received packet from %s:%d\nData: %s\nLength: %d\n", inet_ntoa(si_oth.sin_addr), ntohs(si_oth.sin_port), (char *) buffer,len); */ //counter[j] = pthread_create(&players[j], NULL, &player_waits_or_plays, (void *) &player[j]); //pthread_join((players[j]),NULL); printf("\nclient data: %s \n",buffer); separate_strings(buffer,";",trick,4); printf("received split into: %s",trick[0]); for(int i=1;i<4;i++) printf(" %s",trick[i]); printf("\n"); /* //Receive data and start game threads for each client for(int j=0;j<4;j++) { if ((len = recvfrom(player[j].sockfd, player[j].game->buffer, BUFLEN, 0, &si_other[i], &slen)) == -1) diep("recvfrom()"); counter[j++] = pthread_create(&players[j], NULL, &player_waits_or_plays, (void *) &player[j]); printf("Received packet from %s:%d\nData: %s\nLength: %d\n", inet_ntoa(si_other[i].sin_addr), ntohs(si_other[i].sin_port), (char *) buffer,len); } // Jag försöker föra över detta till trådarna--------------------// char cards_to_send[40]; i=0; sprintf(cards_to_send,"%s;",player[i].game->deck[player[i].pos]); for(int j=4;j<52;j+=4) { strcat(cards_to_send, player[i].game->deck[player[i].pos+j]); strcat(cards_to_send,";"); } printf("Sending packet2: \n%s\n", cards_to_send); if (sendto(s, cards_to_send, 40, 0, (struct sockaddr *) &si_other[i], slen)==-1) diep("sendto()"); int k=0; */ close(s); return 0; }
/* * Description: The main driver function for this program. * Input: Command line arguments * Result: EXIT_SUCCESS or EXIT_FAILURE * PRE: None. * POST: The appropriate encryption/decryption function will be called. */ int main( int argc, char** argv ) { if( argc == 1 ) // Program was executed with no arguments, so show usage. { show_usage( argv[ 0 ] ); } else if( strcasecmp( argv[ 1 ], "-e" ) == 0 ) // Encrypt { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } //pontifex -e deck.txt plaintext.txt ciphertext.txt printf( "Reading in deck...\n" ); card_ptr deck = read_deck_from_file( argv[ 2 ] ); printf( "Reading in plaintext...\n" ); char* plaintext = read_filetext( argv[ 3 ] ); printf( "Encrypting...\n" ); char* ciphertext = encode_message( plaintext, deck ); write_filetext( ciphertext, argv[ 4 ] ); } else if( strcasecmp( argv[ 1 ], "-d" ) == 0 ) // Decrypt { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } //pontifex -d deck.txt ciphertext.txt decrypted.txt printf( "Reading in deck...\n" ); card_ptr deck = read_deck_from_file( argv[ 2 ] ); printf( "Reading in ciphertext...\n" ); char* ciphertext = read_filetext( argv[ 3 ] ); printf( "Decrypting...\n" ); char* plaintext = decode_message( ciphertext, deck ); write_filetext( plaintext, argv[ 4 ] ); } else if( strcasecmp( argv[ 1 ], "-a" ) == 0 ) // Create a new deck with all cards in ascending order { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } printf( "Creating a new deck with cards in ascending order...\n" ); fflush( stdout ); //pontifex -a deck.txt card_ptr deck = new_deck(); write_deck_to_file( deck, argv[ 2 ] ); } else if( strcasecmp( argv[ 1 ], "-r" ) == 0 ) // Create a new, randomly shuffled deck { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } printf( "Creating a new, randomly shuffled deck...\n" ); //pontifex -r deck.txt card_ptr deck = new_deck(); deck = shuffle_deck( deck ); write_deck_to_file( deck, argv[ 2 ] ); } else if( strcasecmp( argv[ 1 ], "-k" ) == 0 ) // Show key sequence { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } printf( "Showing key sequence generated by deck in given file...\n" ); //pontifex -k deck.txt printf( "Reading in deck...\n" ); card_ptr deck = read_deck_from_file( argv[ 2 ] ); char* keystream = generate_keystream( deck, 8 ); int i; for( i = 0; i < 8; i++ ) { int key = keystream[ i ] - 64; printf( "%d ", key ); } printf( "\n" ); } else if( strcasecmp( argv[ 1 ], "-f" ) == 0 ) // Test reading a deck from a file { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } printf( "Testing reading deck from a file...\n" ); //pontifex -f deck.txt printf( "Reading in deck...\n" ); card_ptr deck = read_deck_from_file( argv[ 2 ] ); show_deck( deck ); } else if( strcasecmp( argv[ 1 ], "-m" ) == 0 ) // Test move joker steps { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } printf( "Testing move joker steps with deck in given file...\n" ); //pontifex -m deck.txt printf( "Reading in deck...\n" ); card_ptr deck = read_deck_from_file( argv[ 2 ] ); card_ptr currentCard = deck; while( currentCard->number != JOKER_A ) { currentCard = currentCard->next; } deck = swap_joker1( deck, currentCard ); currentCard = deck; while( currentCard->number != JOKER_B ) { currentCard = currentCard->next; } deck = swap_joker2( deck, currentCard ); show_deck( deck ); } else if( strcasecmp( argv[ 1 ], "-t" ) == 0 ) // Test triple cut step { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } printf( "Testing triple cut step with deck in given file...\n" ); //pontifex -t deck.txt printf( "Reading in deck...\n" ); card_ptr deck = read_deck_from_file( argv[ 2 ] ); deck = triple_cut( deck ); show_deck( deck ); } else if( strcasecmp( argv[ 1 ], "-c" ) == 0 ) // Test count cut step { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } printf( "Testing count cut step with deck in given file...\n" ); //pontifex -c deck.txt printf( "Reading in deck...\n" ); card_ptr deck = read_deck_from_file( argv[ 2 ] ); deck = count_cut( deck ); show_deck( deck ); } else if( strcasecmp( argv[ 1 ], "-p" ) == 0 ) // Test entire pontifex algorithm { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } printf( "Testing all pontifex steps with deck in given file...\n" ); //pontifex -p deck.txt printf( "Reading in deck...\n" ); card_ptr deck = read_deck_from_file( argv[ 2 ] ); // Step 1, find joker A card_ptr currentCard = deck; while( currentCard->number != JOKER_A ) { currentCard = currentCard->next; } deck = swap_joker1( deck, currentCard ); printf( "Step 1:\n" ); show_deck( deck ); // Step 2, find joker B currentCard = deck; while( currentCard->number != JOKER_B ) { currentCard = currentCard->next; } deck = swap_joker2( deck, currentCard ); printf( "Step 2:\n" ); show_deck( deck ); // Step 3, do triple cut deck = triple_cut( deck ); printf( "Step 3:\n" ); show_deck( deck ); // Step 4, do count cut deck = count_cut( deck ); printf( "Step 4:\n" ); show_deck( deck ); // Step 5, find output card int streamval = get_output_card( deck ); printf( "Step 5:\n" ); printf( "%i\n", streamval ); } else if( strcasecmp( argv[ 1 ], "-o" ) == 0 ) // Test output card step { if( argv[ 2 ] == NULL ) { show_usage( argv[ 0 ] ); return EXIT_FAILURE; } printf( "Testing find output card step with deck in given file...\n" ); //pontifex -o deck.txt printf( "Reading in deck...\n" ); card_ptr deck = read_deck_from_file( argv[ 2 ] ); printf( "Output card: %i\n", get_output_card( deck ) ); } else { printf( "Invalid flag: %s\n", argv[ 1 ] ); show_usage( argv[ 0 ] ); return EXIT_FAILURE; } printf( "Done\n" ); return EXIT_SUCCESS; }
int main() { Game *game = init_game(); char username[50]; Deck *deck = init_deck(); Strategy *strategy; int exchange[] = {1,2,4,5,0}; int i; Player *playerptr; strategy = init_strategy(4, &exchange[0]); printf("\n\nWelcome to Five-Card Draw!\n\n\nPlease enter your name: "); scanf("%s",username); /*add players to game*/ /*add live user first*/ game_insert_player(game, NULL, username, HUMAN); /*add three CPU players*/ game_insert_player(game, game->head->prev, "Dennis Ritchie", CPU); game_insert_player(game, game->head->prev, "Brian Kernighan", CPU); game_insert_player(game, game->head->prev, "Kyle Loudon", CPU); printf("\n\nWelcome, %s. You will begin with $%.2f in chips.\n\n",game->human->name, game->human->chips); /*human player is dealer in the first game. dealer designation rotates afterward*/ set_dealer(game, game->human); while (game->continue_game) { /* player may quit by pressing CTRL+C at any time and will be given the option to continue after the game has been settled. if the player does not have enough in chips remaining to pay the ante, s/he will be removed from the table. */ /*announce dealer*/ if(game->dealer->type == HUMAN) printf("You are the dealer.\n\n"); else printf("%s is the dealer.\n\n", game->dealer->name); /*players ante*/ playerptr = game->dealer->next; for (i = 0; i < NUMPLAYERS; ++i) { make_bet(game, playerptr, (float) ANTE); playerptr = playerptr->next; } /*deal cards*/ shuffle_deck(deck, NUMCARDS, NULL, 0); printf("Dealing...\n\n"); deal_game(deck, game); /*bet_round(game);*/ /*if (game->folded < 4) {*/ exchange_round(game, deck); /*} else { printf("Just one player remains.\n"); settle_game(game); } bet_round(game); */ settle_game(game); } printf("Thanks for playing!\n\n\n"); return 0; }
struct deck *get_shuffled_deck(uint8_t seed) { struct deck *d; d = create_deck(); shuffle_deck(d, seed); return d; }