int snake_move(void) { int sx[100] = {250, 200, 150, 100, 50}; int sy[100] = {300, 300, 300, 300, 300}; int fx = 0; int fy = 0; int f_count = 100; int step = 50; int x_offset = step; int y_offset = 0; int s_len = 5; char dict = 'd'; char new_dict = 0; char flag = 0; char eat_state = 0; barriar(); system("stty raw -echo"); while(flag == 0) { show_food(&fx, &fy, sx, sy, s_len, &f_count); if(move_one_step(sx, sy, x_offset,y_offset, s_len, eat_state) == -1) { restart_game(sx, sy, s_len); dict = 'd'; new_dict = 0; x_offset = step; y_offset = 0; s_len = 5; } eat_state = eat_food(&fx, &fy, sx, sy, &s_len,&f_count); new_dict = get_key(); switch(new_dict) { case 'a' : if(dict != 'd') dict = new_dict;break; case 'd' : if(dict != 'a') dict = new_dict;break; case 'w' : if(dict != 's') dict = new_dict;break; case 's' : if(dict != 'w') dict = new_dict;break; case 'q' : dict = new_dict; default : break; } switch(dict) { case 'a' : x_offset=-step; y_offset=0;break; case 'd' : x_offset=step; y_offset=0;break; case 'w' : x_offset=0; y_offset=-step;break; case 's' : x_offset=0; y_offset=step;break; case 'q' : flag = 1;break; default : break; } usleep(1000); } system("stty cooked echo"); return 0; }
int ray(int N_r_cells, int N_theta_cells, float radius_min, float radius_max, float angle_min, float angle_max, int Num_rays, float *density_map, float *r_final, float *theta_final){ /* assign global variables */ N_r = N_r_cells; N_theta = N_theta_cells; N_ray = Num_rays; r_min = radius_min; r_max = radius_max; theta_min = angle_min; theta_max = angle_max; dr = (r_max - r_min) / N_r; dtheta = (theta_max - theta_min) / N_theta; density = density_map; srand(time(NULL)); int i,j; /* allocate memory, initialize the ray */ allocate_ray(); initialize_ray(); /* start the mail loop */ for (i=0; i<N_ray; i++) { if ( !(i % 10000) ) { printf("...ray=%d...\n",i); } while (rays[i]->out_flag == NO) { move_one_step(i); } } /* write the final results */ for (i=0; i<N_ray; i++) { *(r_final+i) = rays[i]->r; *(theta_final+i) = rays[i]->theta; } /* free the memory */ free_ray(); return 1; }