static void /* convert columns to power series */ cols(projUV **c, projUV **d, int nu, int nv) { projUV *sv, **dd; int j, k; dd = (projUV **)vector2(nu, nv, sizeof(projUV)); sv = (projUV *)vector1(nv, sizeof(projUV)); bclear(d, nu, nv); bclear(dd, nu, nv); bmove(d[0], c[nu-1], nv); for (j = nu-2; j >= 1; --j) { for (k = nu-j; k >= 1; --k) { bmove(sv, d[k], nv); submop(d[k], 2., d[k-1], dd[k], nv); bmove(dd[k], sv, nv); } bmove(sv, d[0], nv); subop(d[0], c[j], dd[0], nv); bmove(dd[0], sv, nv); } for (j = nu-1; j >= 1; --j) subop(d[j], d[j-1], dd[j], nv); submop(d[0], .5, c[0], dd[0], nv); freev2((void **) dd, nu); pj_dalloc(sv); }
void postfix(char *input){ int i,valid=TRUE; for(i=0;input[i]!='\0'&&valid;i++){ //printf("%c\n",input[i]); //if(input[i]=='0'||input[i]=='1'||input[i]=='2'||input[i]=='3'||input[i]=='4'||input[i]=='5'||input[i]=='6'||input[i]=='7'||input[i]=='8'||input[i]=='9'){ ////push(start,(int)input[i]); //printf("%d",input[i]); //debug //} //else if(input[i]=='+'||input[i]=='-'||input[i]=='*'||input[i]=='/'||input[i]=='$'){ //printf("%c",input[i]); //debug //} //else{ //printf("\nInvalid String !\n"); //} switch(input[i]){ case '0': push(&(start->top),0); break; case '1': push(&(start->top),1); break; case '2': push(&(start->top),2); break; case '3': push(&(start->top),3); break; case '4': push(&(start->top),4); break; case '5': push(&(start->top),5); break; case '6': push(&(start->top),6); break; case '7': push(&(start->top),7); break; case '8': push(&(start->top),8); break; case '9': push(&(start->top),9); break; /* case '0': push(start,0); break; case '1': push(start,1); break; case '2': push(start,2); break; case '3': push(start,3); break; case '4': push(start,4); break; case '5': push(start,5); break; case '6': push(start,6); break; case '7': push(start,7); break; case '8': push(start,8); break; case '9': push(start,9); break; */ case '+': addop(); break; case '-': subop(); break; case '*': mulop(); break; case '/': divop(); break; case '$': expop(); break; default: printf("\nInvalid String !\n"); valid=FALSE; break; }//end switch }//end for }
//*********Main Function************** int main(){ int i,valid=TRUE; start=getNode(); start->info=0; start->next=NULL; printf("\nEnter Postfix String: "); gets(input); for(i=0;input[i]!='\0'&&valid;i++){ //printf("%c\n",input[i]); //if(input[i]=='0'||input[i]=='1'||input[i]=='2'||input[i]=='3'||input[i]=='4'||input[i]=='5'||input[i]=='6'||input[i]=='7'||input[i]=='8'||input[i]=='9'){ ////push(start,(int)input[i]); //printf("%d",input[i]); //debug //} //else if(input[i]=='+'||input[i]=='-'||input[i]=='*'||input[i]=='/'||input[i]=='$'){ //printf("%c",input[i]); //debug //} //else{ //printf("\nInvalid String !\n"); //} switch(input[i]){ case '0': push(start,0); break; case '1': push(start,1); break; case '2': push(start,2); break; case '3': push(start,3); break; case '4': push(start,4); break; case '5': push(start,5); break; case '6': push(start,6); break; case '7': push(start,7); break; case '8': push(start,8); break; case '9': push(start,9); break; case '+': addop(); break; case '-': subop(); break; case '*': mulop(); break; case '/': divop(); break; case '$': expop(); break; default: printf("\nInvalid String !\n"); valid=FALSE; break; }//end switch }//end for printf("\nValue of expression %s\t=",input); display(start->next); printf("\n"); }//end main
void takeDamage(int dam) { // we've been hit with `dam' units of energy. int s = GET_SHIELD_ENERGY; uchar i, j, m; for (i = 1; i < 11; ++i) { // shake the ship for (j = 0; j < 200; ++j) setWide(i & 1); } // absorption of shields dam -= s; if (dam <= 0) { // if some left, give back to shields SET_SHIELD_ENERGY(-dam); messageCode(MSG_CODE_SHIELDS_OK); } else { // residual damage goes to operations int di[L_COUNT-2]; int dv; int dm; if (s > 0) { SET_SHIELD_ENERGY(0); messageCode(MSG_CODE_SHIELDS_GONE); alertsound(); } /* allocate the damage randomly to each operation (not shields). * generate n-1 random numbers (mod dam+1). * take the smallest and allocate this damage (will be <= dam) * then take the next smallest and allocate this much minus previous * give any remaining amount to the last */ dm = dam + 1; // generate n-1 partitions of the damage value for (i = 0; i < L_COUNT-2; ++i) { uint r = rand16(); uint q = r/(uint)dm; di[i] = r - q*dm; } dm = 0; for (i = 1; i < L_COUNT-1; ++i) { // find min partition m = 0; for (j = 1; j < L_COUNT-2; ++j) if (di[j] < di[m]) m = j; // take damage to operations i dv = (di[m] - dm) >> 3; // amount of operational units dm = di[m]; subop(i, dv); di[m] = 0x7fff; } // remainder of total damage and last partition to last operation subop(L_COUNT-1, dam - dm); } }