/* Purpose: check collision with explosions Input : friendly missile array enemyMis array and explosions Returns: nothing Assume : nothing */ void processCollisions(struct missile friendlyMis[], struct missile enemyMis[], struct explosion exp) { int i,j; for (i = 0; i < NUM_MISSILES; i++) { if (enemyMis[i].destroyed == FALSE) { if (enemyMis[i].currentX < (exp.pX + exp.size * EXPLOSION_MAGNITUDE) && enemyMis[i].currentX > (exp.pX - exp.size * EXPLOSION_MAGNITUDE) && enemyMis[i].currentY < (exp.pY + exp.size * EXPLOSION_MAGNITUDE) && enemyMis[i].currentY > (exp.pY - exp.size * EXPLOSION_MAGNITUDE)) { reset_positions(&enemyMis[i]); } } } }
/* Purpose: animate the enemy missiles and the lines following them Input : a missile struct, an explosion struct, and the clock Returns: nothing, but updates the missiles current position, and updates the explosion if necessary Assume : nothing */ void processEnemyMissiles(struct missile *mis, struct explosion *exp, long clock,int speed){ if ((*mis).shortest == -1) { calculateLine(mis); } if ((*mis).currentX < (*mis).endX || (*mis).currentX > (*mis).endX) { getPositions(mis,speed); } if ((*mis).currentX == (*mis).endX || (*mis).currentY == (*mis).endY && (*mis).endX != 0) { (*mis).destroyed = TRUE; make_explosion(exp,(*mis).endX,(*mis).endY); explosion_sound(); reset_positions(&(*mis)); } }
/* * brief - Employ Metropolis Monte-Carlo */ void apply_metropolis() { double eps=0.0, acc=0.0; if((U_new-U_old) < 0){ // Accept the move count_acc++; U = U_new; } else{ eps = double(rand())/double(RAND_MAX); acc = exp(-beta*(U_new-U_old)); if(eps <= acc){ // Accept count_acc++; U = U_new; } else{ // Reject the move and retain the old positions reset_positions(); U = U_old; } } }