int go(int row, int col){ if (mark[row][col]){ return mark[row][col]; } int cnt = 0; if (wrong(row + 1, col)>0 && map[row][col] < map[row + 1][col]){ cnt += go(row + 1, col); } if (wrong(row - 1, col)> 0 && map[row][col] < map[row - 1][col]){ cnt += go(row - 1, col); } if (wrong(row, col + 1) >0 && map[row][col] < map[row][col + 1]){ cnt += go(row, col + 1); } if (wrong(row, col - 1) > 0 && map[row][col] < map[row][col - 1]){ cnt += go(row, col - 1); } mark[row][col] = cnt; return mark[row][col]; }
void umain(int argc, char **argv) { char c1, c2; int r, rfd, wfd, kfd, n1, n2, off, nloff; int pfds[2]; close(0); close(1); opencons(); opencons(); if ((rfd = open("testshell.sh", O_RDONLY)) < 0) panic("open testshell.sh: %e", rfd); if ((wfd = pipe(pfds)) < 0) panic("pipe: %e", wfd); wfd = pfds[1]; cprintf("running sh -x < testshell.sh | cat\n"); if ((r = fork()) < 0) panic("fork: %e", r); if (r == 0) { dup(rfd, 0); dup(wfd, 1); close(rfd); close(wfd); if ((r = spawnl("/bin/sh", "sh", "-x", 0)) < 0) panic("spawn: %e", r); close(0); close(1); wait(r); exit(); } close(rfd); close(wfd); rfd = pfds[0]; if ((kfd = open("testshell.key", O_RDONLY)) < 0) panic("open testshell.key for reading: %e", kfd); nloff = 0; for (off=0;; off++) { n1 = read(rfd, &c1, 1); n2 = read(kfd, &c2, 1); if (n1 < 0) panic("reading testshell.out: %e", n1); if (n2 < 0) panic("reading testshell.key: %e", n2); if (n1 == 0 && n2 == 0) break; if (n1 != 1 || n2 != 1 || c1 != c2) cprintf("Umesh: n1 = [%d],n2 = [%d],c1 = [%c], c2 = [%c]",n1,n2,c1,c2); wrong(rfd, kfd, nloff); if (c1 == '\n') nloff = off+1; } cprintf("shell ran correctly\n"); breakpoint(); }
static int list(const mklib_session *sr, const char *vhost, const char *url, const char *get, unsigned long getlen, const char *post, unsigned long postlen, unsigned int *status, const char **content, unsigned long *content_len, char *header) { if (strcmp(url, "/image.png") == 0) { *content = (char *) monkey_head_png; *content_len = sizeof(monkey_head_png); sprintf(header, "Content-type: image/png"); return MKLIB_TRUE; } if (!post) { front(); } else { if (strstr(post, "q1=who") || strstr(post, "q1=yes")) points(); else wrong(); } *content = buf; *content_len = strlen(buf); sprintf(header, "Content-type: text/html"); // TRUE here means we handled this request. return MKLIB_TRUE; }
void umain(int argc, char **argv) { char c1, c2; int r, rfd, wfd, kfd, n1, n2, off, nloff; close(0); close(1); opencons(); opencons(); if ((rfd = open("testshell.sh", O_RDONLY)) < 0) panic("open testshell.sh: %e", rfd); if ((wfd = open("testshell.out", O_WRONLY|O_CREAT|O_TRUNC)) < 0) panic("open testshell.out: %e", wfd); cprintf("running sh -x < testshell.sh > testshell.out\n"); if ((r = fork()) < 0) panic("fork: %e", r); if (r == 0) { dup(rfd, 0); dup(wfd, 1); close(rfd); close(wfd); if ((r = spawnl("/sh", "sh", "-x", 0)) < 0) panic("spawn: %e", r); close(0); close(1); wait(r); exit(); } close(rfd); close(wfd); wait(r); if ((rfd = open("testshell.out", O_RDONLY)) < 0) panic("open testshell.out for reading: %e", rfd); if ((kfd = open("testshell.key", O_RDONLY)) < 0) panic("open testshell.key for reading: %e", kfd); nloff = 0; for (off=0;; off++) { n1 = read(rfd, &c1, 1); n2 = read(kfd, &c2, 1); if (n1 < 0) panic("reading testshell.out: %e", n1); if (n2 < 0) panic("reading testshell.key: %e", n2); if (n1 == 0 && n2 == 0) break; if (n1 != 1 || n2 != 1 || c1 != c2) wrong(rfd, kfd, nloff); if (c1 == '\n') nloff = off+1; } cprintf("shell ran correctly\n"); breakpoint(); }
int search(int y, int x) { if(dp[y][x]) return dp[y][x]; int cnt = 0; if(!wrong(y-1, x) && map[y-1][x] > map[y][x]) cnt += search(y-1, x); if(!wrong(y+1, x) && map[y+1][x] > map[y][x]) cnt += search(y+1, x); if(!wrong(y, x-1) && map[y][x-1] > map[y][x]) cnt += search(y, x-1); if(!wrong(y, x+1) && map[y][x+1] > map[y][x]) cnt += search(y, x+1); dp[y][x] = cnt; return dp[y][x]; }
ustring* Mode_eng_jap::next(ustring lword) { ustring* return_string = new ustring[4]; switch (equals(lword)) { case 0: return_string[1] = last->get_wd2_alt(); return_string[3] = "c"; break; case 1: return_string[1] = last->get_wd2(); return_string[3] = "c"; break; case 2: wrong(last); return_string[1] = last->get_wd2_alt(); return_string[3] = "nc"; break; case 3: wrong(last); return_string[1] = last->get_wd2(); return_string[3] = "nc"; break; default: std::cerr << "something is wrong in the equals function" << std::endl; return_string[1] = ""; return_string[3] = "nc"; break; } delete last; Word *next; if (session->size()) { next = session->pop(); last = next; return_string[0] = next->get_wd1(); } else { last = NULL; return_string[0] = "End of Session"; } return_string[2] = lword; return return_string; }
int main() { shared_ptr_example(); test_c_deleter(); wrong(); right(); cast(); }
/* Evaluates f'(x) */ double fPrime(const char* funname, double x) { if(strcmp(funname, "poly1") == 0) return (2*x); else if(strcmp(funname, "sin") == 0) return (cos(x)); else if(strcmp(funname, "xsin") == 0) return (sin(x)+x*cos(x)); else if(strcmp(funname, "poly2") == 0) return (3*x*x+6*x+4); else if(strcmp(funname, "imaginary") == 0) return (3*x*x+6*x+4); else { printf("Error: %s is not a valid function name\n", funname); wrong(); } }
/* Evaluates f(x) */ double f(const char* funname, double x) { if(strcmp(funname, "poly1") == 0) return (x*x - 4); else if(strcmp(funname, "sin") == 0) return (sin(x)-.5); else if(strcmp(funname, "xsin") == 0) return (x*sin(x)-10); else if(strcmp(funname, "poly2") == 0) return (x*x*x+3*x*x+4*x-1); else if(strcmp(funname, "imaginary") == 0) return (x*x+1); else { printf("Error: %s is not a valid function name\n", funname); wrong(); } }
/* Prints the function in readable form */ void printFunction(const char * funname) { char * func; if(strcmp(funname, "poly1") == 0) func = "y = x^2 - 4 = 0"; else if(strcmp(funname, "sin") == 0) func = "y = sin(x)-.5 = 0"; else if(strcmp(funname, "xsin") == 0) func = "y = x*sin(x)-10 = 0"; else if(strcmp(funname, "poly2") == 0) func = "y = x^3+3*x^2+4*x-1 = 0"; else if(strcmp(funname, "imaginary") == 0) func = "y = x^2+1 = 0"; else { printf("Error: %s is not a valid function name\n", funname); wrong(); } printf("Function: %s\n", func); }
int main() { scanf("%d", &n); for(int i = 0; i < n; i++) scanf("%s", s[i]); memset(ans, 'x', sizeof(ans)); ans[n-1][n-1] = 'o'; for(int i = 0; i < 2 * n - 1; i++) for(int j = 0; j < 2 * n - 1; j++) { if(i == n - 1 && j == n - 1) continue; if(!check(i - (n - 1), j - (n - 1))) ans[i][j] = '.'; } if(wrong()) puts("NO"); else { puts("YES"); for(int i = 0; i < 2 * n - 1; i++) { for(int j = 0; j < 2 * n - 1; j++) putchar(ans[i][j]); puts(""); } } return 0; }
int Read_tRNA_File (char *filename) { int i, j; FILE *file_handle; char curr_char; char aa_list[] = { 'A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'Z', 'S', 'T', 'V', 'W', 'Y', 'X' }; //'X' represents the 'stop' amino acid, 'Z' represents the smaller set of serine codons: AGT and AGC. The other ser codons are TCT, TCC, TCG, and TCA. //Note program expects 'X' to be at end of list so 'Z' is put in internally. int num_codons; int aa_processed; int max_aa = 22; //20 AA but serine may get split and we may have stop codons int fscanf_check; j = 0; //initialize AA structures for (i = 0; i < max_aa; i++) { AA[i].aa = aa_list[i]; AA[i].num_codons = 0; } file_handle = fopen (filename, "r"); if (!file_handle) { if(R_or_C == 1){ printf ("\ntRNA File: %s Doesn't Exist\ntRNA", filename); wrong (); }else{ Rprintf("\ntRNA File: %s Doesn't Exist\ntRNA", filename); exit(EXIT_FAILURE); } } //get aa index curr_char = fgetc(file_handle); while (curr_char != EOF) { i = 0; //set AA index to 0 //flip through AA until you get a match while (curr_char != AA[i].aa && i < max_aa) { i++; } if (i == max_aa) { if (curr_char == '"') { while (curr_char != '\n'){ curr_char = fgetc (file_handle); } //Get AA index for next line curr_char = fgetc (file_handle); }else { if(R_or_C == 1){ printf ("\nAA index '%c' in file did not match any known AA. Exiting...\n",curr_char); }else{ Rprintf ("\nAA index '%c' in file did not match any known AA. Exiting...\n",curr_char); } exit (1); } } else { //get current codon count num_codons = AA[i].num_codons; if (num_codons >= 6) //check num_codons value { printf ("\nCodon count for AA is greater than maximum possible value of 6. Exiting...\n"); exit (1); } curr_char = fgetc (file_handle); //get next character. Should be a \t //read in codon for (j = 0; j < 3; j++) //load codon sequence and put in codon_index codon index { AA[i].codon[num_codons][j] = fgetc (file_handle); } AA[i].codon[num_codons][j] = '\0'; curr_char = fgetc (file_handle); //get next char. Should be a \t //read in elongation rate fscanf_check = fscanf (file_handle, "%lf", &AA[i].elong_rate[num_codons]); if (fscanf_check != 1) { fprintf(stderr, "Reading in elongation file failed\n"); exit(1); } //elong_rate = AA[i].elong_rate[num_codons]; //increment codon count for the aa AA[i].num_codons++; num_codons++; //read until end of line or EOF while ((curr_char != '\n') && (curr_char != EOF)) curr_char = fgetc (file_handle); //get aa index for next codon if not at EOF if (curr_char != EOF) curr_char = fgetc (file_handle); } } fclose (file_handle); //check to make sure the correct # of AA and codons are defined aa_processed = 0; for (i = 0; i < max_aa; i++) { if (AA[i].num_codons > 0) { aa_processed++; } } return aa_processed; //return # of }
int main(){ init(); fence(); wrong(); return 0; }
int main(int argc, char** argv) { if (!(argc == 3)) { printf("Usage: newton <poly1|sin|xsin|poly2|imaginary> <initial guess>\n"); wrong(); } int valid = 0; //Check if the argument is valid or not if (strcmp(argv[1], "poly1") == 0) //Compare the argument valid = 1; else if (strcmp(argv[1], "sin") == 0) //Compare the argument valid = 1; else if (strcmp(argv[1], "xsin") == 0) //Compare the argument valid = 1; else if (strcmp(argv[1], "poly2") == 0) //Compare the argument valid = 1; else if (strcmp(argv[1], "imaginary") == 0) //Compare the argument valid = 1; else valid = 0; //Sets the check variable to 0 if it's not equal to any of the strings mentioned above if (valid == 0) { printf("Error: %s is not a valid function name\n", argv[1]); //Prints out this error if the entered argument is invalid exit(1); } printFunction(argv[1]); double start = atof(argv[2]); int i = 0; double y = f(argv[1], start); double yPrime = fPrime(argv[1], start); double yIteration12 = y; double startIteration12 = start; //Following snippet based on the algorithm provided on the handout which goes like - /*x = starting point y = f(x) dy = f'(x) iterations = 0; while (abs(y) > TOLERANCE and iterations < MAX_ITERATIONS) x = x - f(x)/f'(x) y = f(x) iterations++ }*/ while (fabs(y) > TOLERANCE && i <= MAX_ITER) { printf("At iteration %d, x=%f, y=%f, y'=%f\n", i, start, y, yPrime); if (yPrime == 0.000000) { printf("Error: at x=%f, f'(x)=%d\n", start, (int) yPrime); wrong(); } startIteration12 = start; start = start - y/yPrime; yIteration12 = y; y = f(argv[1], start); yPrime = fPrime(argv[1], start); i++; } //END OF SNIPPET if (!(y < 0.000001 && y > -0.000001)) printf("Error: after 12 iterations, x=%f and f(x)=%f\n", startIteration12, yIteration12); else { printf("At iteration %d, x=%f, y=%f, and y'=%f\n", i, start, y, yPrime); printf("Solution: iteration=%d x=%f y=%f\n", i, start, y); } return 0; }
void parseMasterList(void) { char *tok=inM(); numLibs=numProgs=0; /*Parse LIBS section*/ if (tokNot("LIBS")) wrong("Expected LIBS, got ",tok); nextTok(); if (tokNot("{")) wrong("Expected {, got",tok); nextTokN(); while (tokNot("}")) { lib *l=(lib *)malloc(sizeof(lib)); strcpy(l->path,codeLoc); strcpy(l->name,tok); libs[numLibs++]=l; nextTokN(); } nextTok(); /*Parse PROGRAMS section*/ if (tokNot("PROGRAMS")) wrong("Expected PROGRAMS, got ",tok); nextTok(); if (tokNot("{")) wrong("Expected {, got ",tok); nextTokN(); while (tokNot("}")) { prog *p=(prog *)malloc(sizeof(prog)); strcpy(p->path,codeLoc); strcpy(p->name,tok); p->numLibs=p->numProgs=p->isOnlyBinary=p->isCat=p->isDoc=0; progs[numProgs++]=p; nextTok(); if (tokNot("{")) wrong("Expected {, got ",tok); nextTok(); if (tokIs("PROGRAMS")) { /*We have a program list-- parse it.*/ nextTokN(); while (tokNot("}")&&tokNot("BINS")) { int progNo,oldNumProgs=p->numProgs; for (progNo=0;progNo<numProgs;progNo++) if (0==strcmp(tok,progs[progNo]->name)) p->progs[p->numProgs++]=(PROG *)progs[progNo]; if (oldNumProgs==p->numProgs) /*We couldn't find the referenced program.*/ printf("SEVERE WARNING: couldn't find program '%s',\n" " part of program '%s'! Ignoring...\n\n",tok,p->name); nextTokN(); } } if (tokIs("BINS")) { /*We have a "directory-less binaries" list-- parse it.*/ nextTokN(); while (tokNot("}")) { prog *q; /*q will be a directory-less binary for program p*/ q=(prog *)malloc(sizeof(prog)); p->progs[p->numProgs++]=(PROG *)q; strcpy(q->path,codeLoc);/*Same path.*/ strcpy(q->name,tok);/*New name.*/ q->numLibs=q->numProgs=0;/*No subprograms.*/ q->isOnlyBinary=1; nextTokN(); } } if (tokIs("}")) nextTokN() else wrong("Expected } to close PROGRAM, got ",tok); } nextTok(); /*Parse DOCUMENTATION section*/ if (tokNot("DOCUMENTATION")) wrong("Expected DOCUMENTATION, got ",tok); nextTok(); if (tokNot("{")) wrong("Expected {, got",tok); nextTokN(); while (tokNot("}")) { prog *p=(prog *)malloc(sizeof(prog)); strcpy(p->path,codeLoc); strcpy(p->name,tok); p->numLibs=p->numProgs=p->isOnlyBinary=p->isCat=0; p->isDoc=1; progs[numProgs++]=p; nextTokN(); } nextTok(); /*Parse CATEGORIES section*/ if (tokNot("CATEGORIES")) wrong("Expected CATEGORIES, got ",tok); nextTok(); if (tokNot("{")) wrong("Expected {, got ",tok); nextTokN(); while (tokNot("}")) { prog *p=(prog *)malloc(sizeof(prog)); strcpy(p->path,"CATEGORY/"); strcpy(p->name,tok); p->numProgs=p->numLibs=p->isOnlyBinary=p->isDoc=0; p->isCat=1; progs[numProgs++]=p; nextTok(); if (tokNot("{")) wrong("Expected {, got ",tok); nextTok(); while (tokNot("}")) { int progNo,oldNumProgs=p->numProgs; for (progNo=0;progNo<numProgs;progNo++) if (0==strcmp(tok,progs[progNo]->name)) p->progs[p->numProgs++]=(PROG *)progs[progNo]; if (oldNumProgs==p->numProgs) /*We couldn't find the referenced program.*/ printf("WARNING: couldn't find '%s',\n" " a part of the '%s' package! Ignoring...\n\n",tok,p->name); nextTokN(); } if (tokIs("}")) nextTokN() else wrong("Expected } to close CATEGORIES, got ",tok); } }
void play() { char str[256],str2[256],log[81],done,doub,dh,split_card,suggestion ,*YouWereDealt="\1n\1k\0015 You \1n\1m were dealt: %s\r\n" ,*UserWasDealt="\1n\1m\1h%s\1n\1m was dealt: %s\r\n" ,*YourHand="\1n\1k\0015 You \1n\1m (%2d) %s" ,*UserHand="\1n\1m\1h%-25s \1n\1m(%2d) %s" ,*DealerHand="\1n\1hDealer \1n\1m(%2d) " ,*Bust="\1n\1r\1hBust\1n\r\n" ,*Natural="\1g\1h\1iNatural " ,*Three7s="\1r\1h\1iThree 7's " ,*Blackjack="\1n\0011\1k Blackjack! \1n\r\n" ,*TwentyOne="\1n\0012\1k Twenty-one \1n\r\n"; int h,i,j,file; uint max; long val; time_t start,now; struct tm* tm; sprintf(str,"MESSAGE.%d",node_num); /* remove message if waiting */ if(fexist(str)) remove(str); getgamedat(0); if(node[node_num-1]) { getgamedat(1); node[node_num-1]=0; putgamedat(); getgamedat(0); } if(total_players && misc&INPLAY) { bputs("\r\n\1hWaiting for end of hand (^A to abort)...\1n"); start=now=time(NULL); getgamedat(0); while(total_players && misc&INPLAY) { if((i=inkey(0))!=0) { /* if key was hit */ if(i==1) { /* if ctrl-a */ bputs("\r\n"); return; } } /* return */ mswait(100); getgamedat(0); now=time(NULL); if(now-start>300) { /* only wait up to 5 minutes */ bputs("\r\ntimeout\r\n"); return; } } bputs("\r\n"); } getgamedat(1); node[node_num-1]=user_number; putgamedat(); if(!total_players) shuffle(); else listplayers(); sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,joined()); putallnodemsg(str); while(1) { aborted=0; #if DEBUG debugline("top of loop"); #endif if(autoplay) lncntr=0; bprintf(ShoeStatus,cur_card,total_decks*52); if(cur_card>(total_decks*52)-(total_players*10)-10 && lastplayer()) shuffle(); getgamedat(1); misc&=~INPLAY; status[node_num-1]=BET; node[node_num-1]=user_number; putgamedat(); bprintf("\r\n\1n\1cYou have \1h%s\1n\1ck credits\r\n" ,ultoac(credits/1024L,str)); if(credits<min_bet/1024) { bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet); bputs("\1n\1r\1hCome back when you have more credits.\r\n"); break; } if(credits/1024L>(ulong)max_bet) max=max_bet; else max=credits/1024L; sprintf(str,"\r\nBet amount (in kilobytes) or ~Quit [%u]: " ,ibet<credits/1024L ? ibet : credits/1024L); chat(); mnemonics(str); if(autoplay && keyhit()) autoplay=0; if(autoplay) i=ibet; else i=getnum(max); if(i==-1) /* if user hit ^C or 'Q' */ break; bputs("\r\n"); if(i) /* if user entered a value */ bet[0]=i; else /* if user hit enter */ bet[0]=ibet<credits/1024L ? ibet : credits/1024L; if(bet[0]<min_bet) { bprintf("\1n\1cMinimum bet: \1h%uk\r\n",min_bet); bputs("\1n\1r\1hCome back when you're ready to bet more.\r\n"); break; } ibet=bet[0]; getgamedat(0); /* to get all new arrivals */ sprintf(str,"\1m\1h%s\1n\1m bet \1n\1h%u\1n\1mk\r\n",user_name,bet[0]); putallnodemsg(str); pc[0]=2; /* init player's 1st hand to 2 cards */ for(i=1;i<MAX_HANDS;i++) /* init player's other hands to 0 cards */ pc[i]=0; hands=1; /* init total player's hands to 1 */ getgamedat(1); /* first come first serve to be the */ for(i=0;i<total_nodes;i++) /* dealer in control of sync */ if(node[i] && status[i]==SYNC_D) break; if(i==total_nodes) { #if DEBUG debugline("syncdealer"); #endif syncdealer(); } /* all players meet here */ else { /* first player is current after here */ #if DEBUG debugline("syncplayer"); #endif syncplayer(); } /* game is closed (INPLAY) at this point */ #if DEBUG debugline("waitturn 1"); #endif waitturn(); getnodemsg(); /* Initial deal card #1 */ getcarddat(); player[0][0]=card[cur_card++]; putcarddat(); sprintf(str,YouWereDealt,cardstr(card[cur_card-1])); if(!symbols) strip_symbols(str); bputs(str); sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1])); putallnodemsg(str); if(lastplayer()) { getcarddat(); dealer[0]=card[cur_card++]; dc=1; putcarddat(); } nextplayer(); #if DEBUG debugline("waitturn 2"); #endif waitturn(); getnodemsg(); getcarddat(); /* Initial deal card #2 */ player[0][1]=card[cur_card++]; putcarddat(); sprintf(str,YouWereDealt,cardstr(card[cur_card-1])); if(!symbols) strip_symbols(str); bputs(str); sprintf(str,UserWasDealt,user_name,cardstr(card[cur_card-1])); putallnodemsg(str); if(lastplayer()) { getcarddat(); dealer[1]=card[cur_card++]; dc=2; putcarddat(); } nextplayer(); #if DEBUG debugline("waitturn 3"); #endif waitturn(); getnodemsg(); getcarddat(); for(i=0;i<hands;i++) { if(autoplay) lncntr=0; done=doub=0; while(!done && pc[i]<MAX_CARDS && cur_card<total_decks*52) { h=hand(player[i],pc[i]); str[0]=0; for(j=0;j<pc[i];j++) { strcat(str,cardstr(player[i][j])); strcat(str," "); } j=bstrlen(str); while(j++<19) strcat(str," "); if(h>21) { strcat(str,Bust); sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); break; } if(h==21) { if(pc[i]==2) { /* blackjack */ if(player[i][0].suit==player[i][1].suit) strcat(str,Natural); strcat(str,Blackjack); } else { if(player[i][0].value==7 && player[i][1].value==7 && player[i][2].value==7) strcat(str,Three7s); strcat(str,TwentyOne); } sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); // fdelay(500); break; } strcat(str,"\r\n"); sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); if(doub) break; sprintf(str,"\1n\1hDealer\1n\1m card up: %s\r\n" ,cardstr(dealer[1])); if(!symbols) strip_symbols(str); bputs(str); if(tutor) { if(pc[i]==2) split_card=pair(player[i],pc[i]); else split_card=0; if(split_card==A || (split_card==9 && (dealer[1].value<7 || (dealer[1].value>7 && dealer[1].value<10))) || split_card==8 || (split_card==7 && dealer[1].value<9) || (split_card==6 && dealer[1].value<7) || (split_card==4 && dealer[1].value==5) || (split_card && split_card<4 && dealer[1].value<8)) suggestion='P'; else if(soft(player[i],pc[i])) { if(h>18) suggestion='S'; else if(pc[i]==2 && ((h==18 && dealer[1].value>3 && dealer[1].value<7) || (h==17 && dealer[1].value>2 && dealer[1].value<7) || (h>13 && dealer[1].value>3 && dealer[1].value<7) || (h==12 && dealer[1].value>4 && dealer[1].value<7))) suggestion='D'; else suggestion='H'; } else { /* hard */ if(h>16 || (h>13 && dealer[1].value<7) || (h==12 && dealer[1].value>3 && dealer[1].value<7)) suggestion='S'; else if(pc[i]==2 && (h==11 || (h==10 && dealer[1].value<10) || (h==9 && dealer[1].value<7))) suggestion='D'; else suggestion='H'; } } if(tutor==1) suggest(suggestion); strcpy(str,"\r\n~Hit"); strcpy(tmp,"H\r"); if(bet[i]+ibet<=credits/1024L && pc[i]==2) { strcat(str,", ~Double"); strcat(tmp,"D"); } if(bet[i]+ibet<=credits/1024L && pc[i]==2 && hands<MAX_HANDS && player[i][0].value==player[i][1].value) { strcat(str,", ~Split"); strcat(tmp,"S"); } strcat(str,", or [Stand]: "); chat(); mnemonics(str); if(autoplay && keyhit()) autoplay=0; if(autoplay) { lncntr=0; bputs("\r\n"); strcpy(str,stand()); bputs(str); putallnodemsg(str); done=1; } else switch(getkeys(tmp,0)) { case 'H': /* hit */ if(tutor==2 && suggestion!='H') wrong(suggestion); strcpy(str,hit()); bputs(str); putallnodemsg(str); getcarddat(); player[i][pc[i]++]=card[cur_card++]; putcarddat(); break; case 'D': /* double down */ if(tutor==2 && suggestion!='D') wrong(suggestion); strcpy(str,doubit()); bputs(str); putallnodemsg(str); getcarddat(); player[i][pc[i]++]=card[cur_card++]; putcarddat(); doub=1; bet[i]+=ibet; break; case 'S': /* split */ if(tutor==2 && suggestion!='P') wrong(suggestion); strcpy(str,split()); bputs(str); putallnodemsg(str); player[hands][0]=player[i][1]; getcarddat(); player[i][1]=card[cur_card++]; player[hands][1]=card[cur_card++]; putcarddat(); pc[hands]=2; bet[hands]=ibet; hands++; break; case CR: if(tutor==2 && suggestion!='S') wrong(suggestion); strcpy(str,stand()); bputs(str); putallnodemsg(str); done=1; break; } } } if(lastplayer()) { /* last player plays the dealer's hand */ getcarddat(); while(hand(dealer,dc)<17 && dc<MAX_CARDS && cur_card<total_decks*52) dealer[dc++]=card[cur_card++]; putcarddat(); } nextplayer(); #if DEBUG debugline("waitturn 4"); #endif waitturn(); getnodemsg(); if(firstplayer()==node_num) { strcpy(str,"\1n\0014\1h Final \1n\r\n"); bputs(str); putallnodemsg(str); } getcarddat(); dh=hand(dealer,dc); /* display dealer's hand */ sprintf(str,DealerHand,dh); for(i=0;i<dc;i++) { strcat(str,cardstr(dealer[i])); strcat(str," "); } i=bstrlen(str); while(i++<50) /* was 50 */ strcat(str," "); if(dh>21) { strcat(str,Bust); if(!symbols) strip_symbols(str); bputs(str); } else if(dh==21) { if(dc==2) { /* blackjack */ if(dealer[0].suit==dealer[1].suit) strcat(str,Natural); strcat(str,Blackjack); } else { /* twenty-one */ if(dc==3 && dealer[0].value==7 && dealer[1].value==7 && dealer[2].value==7) strcat(str,Three7s); strcat(str,TwentyOne); } if(!symbols) strip_symbols(str); bputs(str); } else { if(!symbols) strip_symbols(str); bprintf("%s\r\n",str); } for(i=0;i<hands;i++) { /* display player's hand(s) */ h=hand(player[i],pc[i]); str[0]=0; for(j=0;j<pc[i];j++) { strcat(str,cardstr(player[i][j])); strcat(str," "); } j=bstrlen(str); while(j++<19) strcat(str," "); if(logit) { now=time(NULL); tm=localtime(&now); sprintf(log,"%02d%02d%02d.log" /* log winnings */ ,tm->tm_mon+1,tm->tm_mday,tm->tm_year%100); if((file=nopen(log,O_RDONLY))!=-1) { read(file,tmp,filelength(file)); tmp[filelength(file)]=0; val=atol(tmp); close(file); } else val=0L; if((file=nopen(log,O_WRONLY|O_CREAT|O_TRUNC))==-1) { bprintf("error opening %s\r\n",log); return; } } if(h<22 && (h>dh || dh>21 /* player won */ || (h==21 && pc[i]==2 && dh==21 && dh>2))) { /* blackjack */ j=bet[i]; /* and dealer got 21 */ if(h==21 && /* natural blackjack or three 7's */ ((player[i][0].value==7 && player[i][1].value==7 && player[i][2].value==7) || (pc[i]==2 && player[i][0].suit==player[i][1].suit))) j*=2; else if(h==21 && pc[i]==2) /* regular blackjack */ j*=1.5; /* blackjack pays 1 1/2 to 1 */ sprintf(tmp,"\1n\1h\1m\1iWon!\1n\1h %u\1n\1mk",j); strcat(str,tmp); credits+=j*1024L; val-=j*1024L; moduserdat(); } else if(h<22 && h==dh) strcat(str,"\1n\1hPush"); else { strcat(str,"\1nLost"); credits-=bet[i]*1024L; val+=bet[i]*1024L; moduserdat(); } if(logit) { sprintf(tmp,"%ld",val); write(file,tmp,strlen(tmp)); close(file); } /* close winning log */ strcat(str,"\1n\r\n"); sprintf(str2,YourHand,h,str); if(!symbols) strip_symbols(str2); bputs(str2); sprintf(str2,UserHand,user_name,h,str); putallnodemsg(str2); } nextplayer(); if(!lastplayer()) { #if DEBUG debugline("lastplayer waitturn"); #endif waitturn(); nextplayer(); } #if DEBUG debugline("end of loop"); #endif getnodemsg(); } getgamedat(1); node[node_num-1]=0; putgamedat(); sprintf(str,"\1n\1m\1h%s \1n\1m%s\r\n",user_name,left()); putallnodemsg(str); }
int main() { if ( init() == 0 ) { printf("aRobot init success !\n"); } else { printf("aRobot init failed , and exit\n"); return 0; } char raw[25]; int lebal = 0; fgets(raw, 20, stdin); raw[strlen(raw)-1]='\0'; while ( raw[0] == '\0' || strstr(AROBOT_EXIT, raw) == NULL) { lebal = 0; if (strcmp(raw, AROBOT_ACTION) == 0 ) { lebal = 1; action(); } if (strcmp(raw, STAT_ACTION_SIT) == 0 ) { lebal = 1; actionType = STAT_ACTION_SIT; sit(); } if (strcmp(raw, STAT_ACTION_SLEEP) == 0 ) { lebal = 1; actionType = STAT_ACTION_SLEEP; sleep(); } if (strcmp(raw, STAT_ACTION_WALK) == 0 ) { lebal = 1; actionType = STAT_ACTION_WALK; walk(); } if (strcmp(raw, STAT_ACTION_RUN) == 0 ) { lebal = 1; actionType = STAT_ACTION_RUN; run(); } if (strncmp(raw, STAT_ACTION_EAT, strlen(STAT_ACTION_EAT)) == 0 ) { lebal = 1; actionType = STAT_ACTION_EAT; eat(raw+strlen(STAT_ACTION_EAT)); } if (strcmp(raw, STAT_ACTION_HEAR_AND_SAY) == 0 ) { lebal = 1; actionType = STAT_ACTION_HEAR_AND_SAY; char word[255]; dyf->hear(word, 255); dyf->say(word); //hearf(word, 255); //sayf(word); } if (strncmp(raw, STAT_ACTION_DRINK, strlen(STAT_ACTION_DRINK)) == 0 ) { lebal = 1; actionType = STAT_ACTION_DRINK; drink(raw + strlen(STAT_ACTION_DRINK) ); } if ( ! lebal ) { wrong(); } fgets(raw, 20, stdin); raw[strlen(raw)-1]='\0'; } printf("Bye bye !\n"); if (dlhandler) dlclose(dlhandler); return 0; }
void Fixture::wrong(Parse *cell, const QString &actual) { wrong(cell); cell->addToBody(label("expected") + "<hr>" + escape(actual) + label("actual")); }