int tick() { // Handle user input Direction in = get_direction(); if (in != NO_DIRECTION) { push_move(move_list, in); } // Handle snake movement update_direction(snake, move_list); move_snake(snake); // Draw everything draw_frame(snake, food_list); Collision collision = find_collision(snake, food_list, screen); switch(collision){ case SNAKE: case SCREEN: return 0; case FOOD: grow_snake(); new_food(); break; case NONE: break; } snake_sleep(); return 1; }
int main (int argc, char **argv) { FILE *prefix_file, *output_file; MD5_CTX context; uint32_t msg1block0[16], msg1block1[16], msg2block0[16], msg2block1[16]; int len, i; unsigned char buffer[1024], digest[16]; if (argc != 4) { printf("usage : %s [prefix file] [output 1] [output 2]\n\n", argv[0]); printf("This generates two files, [output 1] and [output 2] such that :\n"); printf(" #cat [prefix file] [output 1] | md5sum\n"); printf(" #cat [prefix file] [output 2] | md5sum\n"); printf("are equal. The size of [prefix file] must be a multiple of 64.\n\n"); exit(0); } prefix_file = fopen(argv[1], "rb"); if (prefix_file == NULL) { fprintf (stderr, "%s can't be opened\n", argv[1]); exit(1); } MD5Init (&context); while ( (len = fread (buffer, 1, 1024, prefix_file)) ) { MD5Update (&context, buffer, len); if ((len % 64) != 0) { fprintf (stderr, "The size of %s is not a multiple of 512 bits\n", argv[1]); exit(1); } } fclose(prefix_file); find_collision(context.state, msg1block0, msg1block1, msg2block0, msg2block1, 1); output_file = fopen(argv[2], "wb"); if (output_file == NULL) { fprintf (stderr, "%s can't be opened\n", argv[2]); exit(1); } fwrite(msg1block0, 1, 64, output_file); fwrite(msg1block1, 1, 64, output_file); fclose(output_file); output_file = fopen(argv[3], "wb"); if (output_file == NULL) { fprintf (stderr, "%s can't be opened\n", argv[3]); exit(1); } fwrite(msg2block0, 1, 64, output_file); fwrite(msg2block1, 1, 64, output_file); fclose(output_file); return 0; }
int main(int argc, char **argv) { int fd; char *text_orig = "%s\n{'title':'%s', 'contents': 'my contents' , 'serverip': '127.0.0.1'} // %s"; char *tokenised_text, *collided_text, *token, *junk; fd = init_socket(); token = read_token(fd); junk = overflow_tags(); asprintf(&tokenised_text, text_orig, token, junk, "%x"); collided_text = find_collision(tokenised_text, token); write(fd, collided_text, strlen(collided_text)); return EXIT_SUCCESS; }
/** * Check collisions in method definition. */ EscapeReason OptimizationImpl::check_method_collision(DexType* intf, SingleImplData& data) { for (auto method : data.methoddefs) { auto meth_it = new_methods.find(method); if (meth_it != new_methods.end()) method = meth_it->second; auto proto = get_or_make_proto(intf, data.cls, method->get_proto()); assert(proto != method->get_proto()); DexMethod* collision = find_collision(method->get_name(), proto, type_class(method->get_class()), method->is_virtual()); if (collision) return SIG_COLLISION; } return NO_ESCAPE; }
/* *The timestep and collision situations are used to find points of * contact and new velocities after balls hit each other */ void compute_velocities() { double rt,rt2,rt4,lamda=10000; TVector norm,uveloc; TVector normal,point; double RestTime,BallTime; TVector col_pos; int ball=0,ball1,ball2; TVector Nc; int j; RestTime = TimeStep; lamda = 1000; /* Compute velocity for next timestep using Euler equations */ for (j = 0; j < ball_count; j++) { ball_vel[j]-= (ball_vel[j] * friction); } /* while timestep not over */ while (RestTime>ZERO) { lamda = 10000; /* initialize to very large value */ /* For all the balls find closest intersection between * balls and planes/cylinders */ for (int i = 0; i < ball_count; i++) { /* compute new position and distance */ old_pos[i] = ball_pos[i]; TVector::unit(ball_vel[i],uveloc); ball_pos[i] = ball_pos[i]+ball_vel[i]*RestTime; rt2 = old_pos[i].dist(ball_pos[i]); /* Now test intersection with the outer cylinder */ if (intersect_cylinder(cyl1,old_pos[i],uveloc,rt,norm,Nc)) { rt4 = rt*RestTime / rt2; if (rt4 <= lamda) { if (rt4 <= RestTime+ZERO) if (! ((rt <= ZERO)&&(uveloc.dot(norm) < ZERO)) ) { normal=norm; point=Nc; lamda=rt4; ball=i; } } } } /* After all balls were tested with planes/cylinders test for collision * between them and replace if collision time smaller */ if (find_collision(col_pos,BallTime,RestTime,ball1,ball2)) { if ( (lamda == 10000) || (lamda > BallTime) ) { RestTime = RestTime-BallTime; TVector pb1,pb2,xaxis,U1x,U1y,U2x,U2y,V1x,V1y,V2x,V2y; double a,b; pb1=old_pos[ball1]+ball_vel[ball1]*BallTime; // Find position of ball1 pb2=old_pos[ball2]+ball_vel[ball2]*BallTime; // Find position of ball2 xaxis=(pb2-pb1).unit(); a=xaxis.dot(ball_vel[ball1]); /* U1 and U2 are the velocity vectors of the two spheres at the * time of impact */ U1x=xaxis*a; U1y=ball_vel[ball1]-U1x; xaxis=(pb1-pb2).unit(); b=xaxis.dot(ball_vel[ball2]); U2x=xaxis*b; U2y=ball_vel[ball2]-U2x; /* V1,V2 are the new velocities after the impact */ V1x=( (U1x*mass[ball1]+U2x*mass[ball2] - (U1x-U2x))*mass[ball2] ) * (1 / (mass[ball1] + mass[ball2])); V2x=( (U1x*mass[ball1]+U2x*mass[ball2] - (U2x-U1x))*mass[ball1] ) * (1 / (mass[ball1] + mass[ball2])); V1y=U1y; V2y=U2y; for (j=0;j<ball_count;j++) ball_pos[j]=old_pos[j]+ball_vel[j]*BallTime; ball_vel[ball1]=V1x+V1y; ball_vel[ball2]=V2x+V2y; /* continue; */ give_point(ball1, ball2); } } /* End of tests */ /* If test occured move simulation for the correct timestep */ /* and compute response for the colliding ball */ if (lamda!=10000) { RestTime-=lamda; for (j=0;j<ball_count;j++) ball_pos[j]=old_pos[j]+ball_vel[j]*lamda; rt2=ball_vel[ball].mag(); ball_vel[ball].unit(); ball_vel[ball]=TVector::unit( (normal*(2*normal.dot(-ball_vel[ball]))) + ball_vel[ball] ); ball_vel[ball]=ball_vel[ball]*rt2; } else { RestTime=0; } } }