void ch_att::getMap() // Get all infos about the map and the players. { for (int i=1;i<=MAX_PLAYER;i++) if (i!=myID) { p[i].status=DEAD; p[i].lastx=p[i].x; p[i].lasty=p[i].y; p[i].x=0; p[i].y=0; p[i].hp=askHP(i); } for (int i=1,dis,id;i<=N;i++) for (int j=1;j<=M;j++) { g[i][j]=askWhat(i,j); if (g[i][j]>EMPTY && g[i][j]!=myID) { id=g[i][j]; p[id].x=i; p[id].y=j; p[id].status=ALIVE; if (p[id].lastx>0) { dis=abs1(p[id].lastx-p[id].x)+abs1(p[id].lasty-p[id].y); p[id].maxmove=max1(p[id].maxmove,dis); p[id].sp=(long)(speedEstimate*p[id].maxmove); } } } for (int i=1;i<=MAX_PLAYER;i++) if (i!=myID && p[i].status==DEAD) p[i].dietime++; }
/** * @brief GameEngine::rotateThroughPsi rotates Bike and its velocity Vector through angle dpsi in anticlockwise sense wrt X-Z plane * @param dpsi Angle through which bike and it's vector is to be rotated */ void GameEngine::rotateThroughPsi(float dpsi){ float psi = (sign(yf-yb))*asin( abs1 (yf-yb) / bikeLenght); psi+=dpsi*PI/180; xf = xb + bikeLenght*cos(psi)*cos(theta * PI /180); yf = yb + bikeLenght*sin(psi); zf = zb - bikeLenght*cos(psi)*sin(theta * PI /180); psi = (sign(velocity.getY()))*asin( abs1 (velocity.getY()) / velocity.magnitude()); psi+=dpsi*PI/180; velocity.setX(velocity.magnitude()*cos(psi)*cos(theta*PI/180)); velocity.setY(velocity.magnitude()*sin(psi)); velocity.setZ(-velocity.magnitude()*cos(psi)*sin(theta*PI/180)); }
double ch_att::risk(long x,long y) { double ans=0,rate; long id,estStrength=0,rest,dis; for (int i=1;i<=N;i++) for (int j=1;j<=M;j++) if (g[i][j]>0 && g[i][j]!=myID) { id=g[i][j]; estStrength=(long)(p[id].sp*1.2); rest=max1(0,hp-estStrength); rate=(double)rest/(double)maxhp; dis=abs1(i-x)+abs1(j-y); ans+=1/(rate+eps)/(rate+eps)*p[id].sp/dis; } return ans; }
double ch_att::benefit(long x,long y) { double ans=0,rate; long id,rest,dis; for (int i=1;i<=N;i++) for (int j=1;j<=M;j++) if (g[i][j]>0 && g[i][j]!=myID) { id=g[i][j]; rest=max1(0,p[id].hp-att); rate=(double)rest/(double)maxhp; dis=abs1(i-x)+abs1(j-y); ans+=1/(rate+eps)/(rate+eps)*sp/dis*(1+log(estLevel(id))); } else if (g[i][j]==FOOD) ans+=1/eps*sp/dis; return ans; }
/** * @brief GameEngine::init * @param xf X value of the Front Wheel co-ordinate * @param yf Y value of the Front Wheel co-ordinate * @param zf Z value of the Front Wheel co-ordinate * @param xb X value of the Rear Wheel co-ordinate * @param yb Y value of the Rear Wheel co-ordinate * @param zb Z value of the Rear Wheel co-ordinate * @param terrain Pointer to the terrain class of the Game which defines current Landscape */ void GameEngine::init(float xf, float yf, float zf, float xb, float yb, float zb, Terrain *terrain){ this->xf=xf; this->yf=yf; this->zf=zf; this->xb=xb; this->yb=yb; this->zb=zb; this->bikeLenght=sqrt( (xf-xb)*(xf-xb) + (yf-yb)*(yf-yb) + (zf-zb)*(zf-zb) ); { float r= sqrt((xf-xb)*(xf-xb) + (zf-zb)*(zf-zb)); if(abs1(zf-zb) ==r ) this->theta=-(sign(zf-zb))*(PI/2-.0000001); else this->theta=asin (-(zf-zb)/ r); if(xf - xb <= 0) this->theta = PI-this->theta; } this->velocity.setX(0); this->velocity.setY(0); this->velocity.setZ(0); this->terrain = terrain ; }
void problem6(){ cout<<"In problem # 6"<<endl<<endl; cout << "Problem 16.4 Gaddis 8th\n\n"; //declare variable Absolut <int>abs1(-5); Absolut <float> abs2(-4.3); //demonstrate templates using two different data types cout << "This program demonstrates Templates using different data types\n"; cout <<"_________________________\n"; cout << "This program returns the absolute value of a number inputed\n\n"; cout << "The absolute value of " << abs1.getA() << " is " << abs1.FndAbs(); cout << endl; cout << "The absolute value of " << abs2.getA() << " is " << abs2.FndAbs(); cout<<endl<<endl; }
int main(int argc,char** argv) { int ar_gen[mult+2]; int ar_imp[mult+2]; FILE *fp,*fp2,*imph,*genh; // time_t t=time(NULL); int No_val=atoi(argv[1]); fp=fopen(argv[2], "r"); fp2=fopen("FRR_FAR_Data.dat", "w"); imph=fopen("L4_I_Hist.dat", "w"); genh=fopen("L4_G_Hist.dat", "w"); int i=0; int true_val=0; float score=0.; int a,b,c,d; float temp=0.,temp2=0.; int imp=0,gen=0; int ar_addr=0; for (i=0; i<=(mult+1); i++) { ar_gen[i]=0; ar_imp[i]=0; } for (i=0; i<(No_val); i++) { fscanf(fp, "%d %d %d %d %d %f", &a, &b, &c, &d, &true_val, &score); ar_addr=(int) mult*score; if(true_val==1) { ar_gen[ar_addr]++; gen++; } else { ar_imp[ar_addr]++; imp++; } } for(i=0; i<=mult; i++) { if(ar_imp[i]) { temp=(((float)ar_imp[i])/((float)imp))*100; fprintf(imph, "%d %.6f\n", i,temp); } if(ar_gen[i]) { temp2=(((float)ar_gen[i])/((float)gen))*100; fprintf(genh, "%d %.6f\n", i,temp2); } } for (i=1; i<=mult; i++) { ar_imp[i]+=ar_imp[i-1]; ar_gen[mult-i]+=ar_gen[mult-(i-1)]; } float g1=0.,i1=0.,thresh1=0.,thresh2=0.; float min=100.0; float te=0.; ar_gen[mult]=0; for (i=0; i<=mult; i++) { g1=(((float)ar_gen[i])/((float)gen))*100; i1=(((float)ar_imp[i])/((float)imp))*100; if(abs1(g1-i1)<min) { min=abs1(g1-i1); thresh1=g1; te=(float)i/mult; thresh2=i1; } fprintf(fp2,"%d %d %f %d %f\n",i,(ar_gen[0]-ar_gen[i]),g1,ar_imp[i],i1); } float eer = (thresh1+thresh2)/2.0; // t=time(NULL)-t; // printf("Time Taken(s) >> %ld\n",t); printf("# of Gen >>\n%d\n# of Imp >>\n%d\n",gen, imp); printf("FRR>>\n%.6f\nFAR>>\n%.6f\nDifference>>\n%.6f\nEER>>\n%.6f\nThresh-Hold>>\n%.6f\n",thresh1,thresh2,min,eer,te); fclose(fp); fclose(fp2); return 0; }
/** * @brief GameEngine::motionFunction The core function which computes where the bike would be after time dt with the aid of above defined functions * @param accelerationCoefficient Value is 1 when bike is accelerating, -0.9 when the brakes are applied else 0. */ void GameEngine::motionFunction(float accelerationCoefficient){ doBoundCheck(); keepBikeOnPlane(); float height = queryHeight(xb, zb); /* * if the back wheel is on the plane */ if(yb <= height){ Vector normal = queryNormal(xb, zb); normal.normalize(); Vector bodyCentreLine(xf -xb, yf-yb, zf-zb); bodyCentreLine.normalize(); Vector alongPlane = vectorAlongPlane(xb, zb, bodyCentreLine); alongPlane.normalize(); /** * mod of the gravity component along the plane * and also int the plane created by the normal vector and the BikeVector */ float gravityComponentAlongPlane = Gravity*abs1( alongPlane.getY() ); /** * mod of the gravity component along the normal vector */ float gravityComponentAlongNormal = sqrt(Gravity*Gravity - gravityComponentAlongPlane*gravityComponentAlongPlane); int velocitySign = sign(velocity.dotProductV(alongPlane)); /* * adds gravity effect to the velocity * if the bike vector has downward component then its adds to it * otherwise subtracts from it */ Vector dv(0,0,0); if(velocity.getY()<0){ alongPlane.scalarMul(gravityComponentAlongPlane*Time); dv=dv.addV(alongPlane); } else{ alongPlane.scalarMul(-gravityComponentAlongPlane*Time); dv=dv.addV(alongPlane); } alongPlane=vectorAlongPlane(xb,zb,bodyCentreLine); alongPlane.normalize(); /* *adds friction effect in the direction opposite to the velocity */ float frictionalForce = (-velocitySign)*gravityComponentAlongNormal*meu; alongPlane.scalarMul(frictionalForce*Time); dv=dv.addV(alongPlane); alongPlane=vectorAlongPlane(xb,zb,bodyCentreLine); alongPlane.normalize(); /* *adds motor accelration effect to the velocity */ alongPlane.scalarMul(accelerationCoefficient*Front_Acceleration*Time); dv=dv.addV(alongPlane); /* * moves the bike according to the velocity along the plane */ { velocity=velocity.addV(dv); alongPlane=vectorAlongPlane(xb,zb,velocity); alongPlane.normalize(); alongPlane.scalarMul(velocity.magnitude()); velocity=alongPlane; if(velocity.magnitude()> Max_Speed){ velocity.normalize(); velocity.scalarMul(Max_Speed); } if(velocity.magnitude() <=2.5 && accelerationCoefficient ==0){ velocity.scalarMul(0); return; } xf+=velocity.getX()*Time; yf+=velocity.getY()*Time; zf+=velocity.getZ()*Time; xb+=velocity.getX()*Time; yb+=velocity.getY()*Time; zb+=velocity.getZ()*Time; } keepBikeOnPlane(); /* *if the front is inside plane it rotaes it to the plane * if it is in the air it rotates it downward about the back wheel */ if(queryHeight(xf, zf) > yf) rotateBikeOntoPlane(); else if( queryHeight(xf, zf) < yf ) { rotateThroughPsi(-.75); rotateBikeOntoPlane(); } else; // do Nothing } /* * if the back wheel is in the air */ else{ Vector temp(0,-Gravity*Time,0); velocity=velocity.addV(temp); if(velocity.magnitude()> Max_Speed){ velocity.normalize(); velocity.scalarMul(Max_Speed); } /* * projectile motion in differential form */ { xf+= velocity.getX()*Time; yf+= velocity.getY()*Time; zf+= velocity.getZ()*Time; xb+= velocity.getX()*Time; yb+= velocity.getY()*Time ; zb+= velocity.getZ()*Time; } keepBikeOnPlane(); if(queryHeight(xf, zf) > yf) rotateBikeOntoPlane(); else rotateThroughPsi(-.75); } }