void check_hu(char* cards) { static std::set<int> tested; for(int i=0;i<18;++i) { if(cards[i] > 4) return; } int num = 0; for(int i=0;i<9;++i) { num = num * 10 + cards[i]; } if(tested.find(num) != tested.end()) { return; } tested.insert(num); if(!HuLib::get_hu_info(cards, NULL, 0, 0)) { printf("测试失败 \n"); print_cards(cards); } }
// This is the Find the Ace game. // It returns -1 if the player has 0 credits. int find_the_ace() { int i, ace, total_wager; int invalid_choice, pick = -1, wager_one = -1, wager_two = -1; char choice_two, cards[3] = {'X', 'X', 'X'}; ace = rand()%3; // Place the ace randomly. printf("******* Find the Ace *******\n"); printf("In this game, you can wager up to all of your credits.\n"); printf("Three cards will be dealt out, two queens and one ace.\n"); printf("If you find the ace, you will win your wager.\n"); printf("After choosing a card, one of the queens will be revealed.\n"); printf("At this point, you may either select a different card or\n"); printf("increase your wager.\n\n"); if(player.credits == 0) { printf("You don't have any credits to wager!\n\n"); return -1; } while(wager_one == -1) // Loop until valid wager is made. wager_one = take_wager(player.credits, 0); print_cards("Dealing cards", cards, -1); pick = -1; while((pick < 1) || (pick > 3)) { // Loop until valid pick is made. printf("Select a card: 1, 2, or 3 "); scanf("%d", &pick); } pick--; // Adjust the pick since card numbering starts at 0. i=0; while(i == ace || i == pick) // Keep looping until i++; // we find a valid queen to reveal. cards[i] = 'Q'; print_cards("Revealing a queen", cards, pick); invalid_choice = 1; while(invalid_choice) { // Loop until valid choice is made. printf("Would you like to:\n[c]hange your pick\tor\t[i]ncrease your wager?\n"); printf("Select c or i: "); choice_two = '\n'; while(choice_two == '\n') // Flush extra newlines. scanf("%c", &choice_two); if(choice_two == 'i') { // Increase wager. invalid_choice=0; // This is a valid choice. while(wager_two == -1) // Loop until valid second wager is made. wager_two = take_wager(player.credits, wager_one); } if(choice_two == 'c') { // Change pick. i = invalid_choice = 0; // Valid choice while(i == pick || cards[i] == 'Q') // Loop until the other card i++; // is found, pick = i; // and then swap pick. printf("Your card pick has been changed to card %d\n", pick+1); } } for(i=0; i < 3; i++) { // Reveal all of the cards. if(ace == i) cards[i] = 'A'; else cards[i] = 'Q'; } print_cards("End result", cards, pick); if(pick == ace) { // Handle win. printf("You have won %d credits from your first wager\n", wager_one); player.credits += wager_one; if(wager_two != -1) { printf("and an additional %d credits from your second wager!\n", wager_two); player.credits += wager_two; } } else { // Handle loss. printf("You have lost %d credits from your first wager\n", wager_one); player.credits -= wager_one; if(wager_two != -1) { printf("and an additional %d credits from your second wager!\n", wager_two); player.credits -= wager_two; } } return 0; }
//This is the find the ace game int find_the_ace() { int i, ace, total_wager; int invalid_choice, pick = -1, wager_one = -1, wager_two = -1; char choice_two, cards[3] = {'X', 'X', 'X'}; ace = rand()%3; printf("****** Find the ACE ******\n"); printf("In this game you can wager up to all of your credits\n"); printf("three cards will be dealt out, two queens and one ace\n"); printf("if you find the ace, you will win your wager\n"); printf("after choosing a card, one of the queens will be revealed\n"); printf("at this point, you may either select a different card or increase your wager\n\n"); if(player.credits == 0) { printf("you dont have enough credits\n\n"); return -1; } while(wager_one == -1) wager_one = take_wager(player.credits, 0); print_cards("dealing cards", cards, -1); pick = -1; while((pick < 1) || (pick > 3)) { printf("select a card: 1, 2, or 3 "); scanf("%d", &pick); } pick--; i = 0; while(i == ace || i == pick) { i++; } cards[i] = 'Q'; print_cards("Revealing a queen", cards, pick); invalid_choice = 1; while(invalid_choice) { printf("would you like to:\n[c]hange your pick\tor\t[i]ncrese your wager?\n"); printf("Select c or i; "); choice_two = '\n'; while(choice_two == '\n') scanf("%c", &choice_two); if(choice_two == 'i') { invalid_choice = 0; while(wager_two == -1) wager_two = take_wager(player.credits, wager_one); } if(choice_two == 'c') { i = invalid_choice = 0; while(i == pick || cards[i] == 'Q') i ++; pick = i; printf("Your card pick has been changed to card %d\n", pick + 1); } } for(i = 0; i < 3; i++) { if(ace == i) cards[i] = 'A'; else cards[i] = 'Q'; } print_cards("End Result", cards, pick); if(pick == ace) { printf("You have won %d credits from your first wager\n", wager_one); player.credits += wager_one; if(wager_two != -1) { printf("and an additional %d credits from your second wager\n", wager_two); player.credits += wager_two; } } else { printf("you have lost %d credits from your first wager\n", wager_one); player.credits -= wager_one; if(wager_two != -1) { printf("and an additional %d credits from your second wager\n", wager_two); player.credits -= wager_two; } } return 0; }
void* run_low(void *arg){ char **argv=(char**)arg; char line[500]; int lowfd; int ret; const int inlen=100; int ilen; int inarr[inlen]; FILE *outf=stdout; int ioff; int *iptr; int ind; struct sockaddr_un address; lowfd = socket(AF_UNIX, SOCK_STREAM, 0); address.sun_family = AF_UNIX; strcpy(address.sun_path, SERVER_SOCKET_NAME); ilen = sizeof(address); ret = connect(lowfd, (struct sockaddr *)&address, ilen); if(ret == -1) { perror("Unable to connect to server"); exit(1); } sprintf(line,"t%s\n%s",argv[1],argv[2]); write(lowfd, line, strlen(line)); read(lowfd, &ret, sizeof(ret)); printf("result from server = %d\n", ret); print_server_error(ret); read(lowfd, &ind, sizeof(ind)); printf("my index = %d\n", ind); if(ret==SRV_OK){ while((ilen=read(lowfd,inarr,sizeof(*inarr)*inlen))>0){ iptr=inarr; ilen/=sizeof(*inarr); while(ilen>0){ switch(iptr[1]){ case -MTG_ACT_TAP: fprintf(outf,"%d taps cards:\n",iptr[2]); ioff=3; break; case -MTG_ACT_VIS: fprintf(outf,"%d shows cards:\n",iptr[2]); ioff=3; break; case -MTG_ACT_MOVE: fprintf(outf,"%d moves (to [%c]) cards :\n",iptr[2],zone_letter[iptr[3]]); ioff=4; break; case -MTG_ACT_TRANS: fprintf(outf,"%d gives control (to [%d]) cards :\n",iptr[2],iptr[3]); ioff=4; break; case -MTG_ACT_DRAW: fprintf(outf,"%d draws %d cards\n",iptr[2],iptr[3]); ioff=4; break; default: ioff=2; break; } if(iptr[0]-ioff>0){ print_cards(outf,iptr+ioff,iptr[0]-ioff); } ilen-=iptr[0]; iptr+=iptr[0]; } } } return (void*)0; }
int find_the_ace(int credits) { int i = 0; int ace = rand() % 3; int total_wager; int invalid_choice = 1; int pick = -1; int wager_one = -1; int wager_two = -1; char choice_two = '\n'; char cards[3] = { 'X','X','X' }; printf("***FIND-THE-ACE***\n"); if (credits <= 0) { printf("You do not have any credits to wager!"); return -1; } while (wager_one == -1) wager_one = take_wager(credits, 0); print_cards("Dealing cards", cards, -1); while (pick < 1 || pick > 3) { printf("Select a card: 1, 2 or 3 "); scanf_s("%d", &pick); } --pick; while (i == ace || i == pick) ++i; cards[i] = 'Q'; print_cards("Revealing a queen", cards, pick); while (invalid_choice) { printf("would you like to:\n[c]hange your pick\tot\t[i]ncrease your wager?\n"); printf("Select c or i :"); while (choice_two == '\n') scanf_s("%c", &choice_two); if (choice_two == 'i') { invalid_choice = 0; while (wager_two < 0) wager_two = take_wager(credits, wager_one); } if (choice_two == 'c') { invalid_choice = 0; i = 0; while (i == pick || cards[i] == 'Q')++i; pick = i; printf("Your card pick was changed to card %d\n", pick + 1); } choice_two = '\n'; } for (i = 0; i < 3; ++i) { if (ace == i) cards[i] = 'A'; else cards[i] = 'Q'; } print_cards("End Result", cards, pick); if (pick == ace) { printf("You have won %d credits from your first wager\n", wager_one); credits += wager_one; if (wager_two > 0) { printf("and additional %d credits from your second wager!\n", wager_two); credits += wager_two; } } else { printf("You have lost %d credits from your first wager\n", wager_one); credits -= wager_one; if (wager_two > 0) { printf("and additional %d credits from your second wager!\n", wager_two); credits -= wager_two; } } return credits; }