main(int argc, char* argv[]) { int num_of_cards = 0; int rounds = 0; printf("The program started \n"); num_of_cards = atoi(argv[1]); printf("The number of cards in the initial deck is: %d\n", num_of_cards); if (num_of_cards == 0 || argc == 1) { printf ("Error: Enter the number of cards in the orig deck... \n"); return 0; } Deck_of_cards* orig_deck; orig_deck = init_deck_of_cards(num_of_cards); Deck_of_cards* deck_on_table = (Deck_of_cards*)calloc(sizeof(Deck_of_cards), 1); deck_on_table->head = NULL; deck_on_table->tail = NULL; printf("The Hand Deck is: \n"); print_deck(orig_deck); printf("The table Deck is: \n"); print_deck(deck_on_table); do { printf("Starting round:%d ..... \n",rounds); printf("===============================================\n"); while (move_top_card_to_table(&orig_deck, &deck_on_table)) { if (!move_card_back_of_deck(&orig_deck)) { break; } } printf("===============================================\n"); printf("Ending round:%d ..... \n",rounds); printf("The Hand Deck is: \n"); print_deck(orig_deck); printf("The table Deck is: \n"); print_deck(deck_on_table); move_deck_table_to_hand(&orig_deck, &deck_on_table); rounds++; } while (!comparator(&orig_deck)); char * output_to_stdio; sprintf(output_to_stdio, "The number of rounds to accomplish the orig state: %d", rounds); //print_deck(orig_deck); puts(output_to_stdio); }
void sort_by_defencePower(player_t *player) { if(player->mana<5) { printf(ANSI_COLOR_RED "Error! Not enough mana!\n" ANSI_COLOR_RESET); return; } player->mana-=5; int top = pre_random(player); int i,j; card_t card; for(i=0; i<player->deck.top-1; i++) { for(j=0; j<player->deck.top-i-1; j++) { if(player->deck.card[j].defencePower>player->deck.card[j+1].defencePower) { card=player->deck.card[j]; player->deck.card[j]=player->deck.card[j+1]; player->deck.card[j+1]=card; } } } print_deck(player->deck); player->hand.top=0; for(i=0; i<top; i++) { card_t card = pop(&player->deck); push(&player->hand, card); } }
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(int argc, char**argv) { // int a[NCARDS]; int i=0; a[0] = 6; a[1] = 7; a[2] = 1; a[3] = 9; printf("Initial deck: "); print_deck(a); // always a good idea at beginning INSERTSORT_reset(); INSERTSORT(); // set inputs by calling functions that Esterel generatesx // call Esterel program repeatedly until output is stable <=> is sorted finished = 0; while (!finished) { INSERTSORT_I_CARD1_IN(a[0]); INSERTSORT_I_CARD2_IN(a[1]); INSERTSORT_I_CARD3_IN(a[2]); INSERTSORT_I_CARD4_IN(a[3]); INSERTSORT_I_START(); // set inputs here INSERTSORT(); // call to proceed one tick // outputs are set by the kernel calling the functions INSERTSORT_O_* i = i + 1; printf("After %d rounds: ", i); print_deck(tmp); memcpy(a,tmp,4*sizeof(int)); INSERTSORT_reset(); INSERTSORT(); } return 0; }
int main(void) { t_deck *d; t_burned *b; b = malloc(sizeof(t_burned)); b->nb_card = 0; if (!(d = create_deck())) return (1); g_randfd = open("/dev/random", O_RDONLY); print_deck(d); get_random_card(d, b); get_random_card(d, b); get_random_card(d, b); print_deck(d); print_card(b->card[0]); print_card(b->card[1]); print_card(b->card[2]); recover_cards(d, b, NULL); print_deck(d); return (0); }
void print_game(GAME *game) { int i; printf("GAME(%x), %d players, current %d, owner %d, pile ", game, game->num_players, game->current_player, game->pile_owner); print_move(game->pile); printf("\n"); for (i = 0; i < game->num_players; i++) { printf(" rank %d, hand ", game->players[i].rank); print_deck(game->players[i].hand); printf("\n"); } }
int main (int argc, char *argv[]) { Card deck[DECK_SIZE]; Card starting_deck[DECK_SIZE]; char in_message[MAX_MESSAGE_LENGTH]; char out_message[MAX_MESSAGE_LENGTH]; int mode = 0; //encrypt = 0, decrypt = 1 if (argc != 1) { printf("usage: SolitareEncryption1\n"); printf("SEKEY environment variable must be set to the key value\n"); exit(1); } init_deck(starting_deck); while (1) { //set the deck to the key starting position memcpy(deck, starting_deck, sizeof(Card) * DECK_SIZE); print_deck(deck); if (!mode) { printf("Enter message to be encrypted (type '/help' for help):\n"); } else { printf("Enter message to be decrypted (type '/help' for help):\n"); } fflush(stdout); if (fgets(in_message, MAX_MESSAGE_LENGTH, stdin) == NULL) { printf("fgets failure\n"); exit(1); } //get rid of the newline from fgets int i; for (i = 0; in_message[i] != '\0'; i++) { if (in_message[i] == '\n') { in_message[i] = '\0'; break; } } if (!strcmp(in_message, "/quit")) { break; } else if (!strcmp(in_message, "/encrypt")) { mode = 0; printf("Encryption mode\n"); } else if (!strcmp(in_message, "/decrypt")) { mode = 1; printf("Decryption mode\n"); } else if (!strcmp(in_message, "/help")) { printf("/encrypt: switch to encryption mode\n" "/decrypt: switch to decryption mode\n" "/quit: quit program\n"); } else { if (!mode) { printf("Unencrypted: %s\n", in_message); printf("Encrypted: %s\n", encrypt(deck, in_message, out_message)); } else { printf("Encrypted: %s\n", in_message); printf("Decrypted: %s\n", decrypt(deck, in_message, out_message)); } } } return 0; }