void action_t::execute() { if ( sim -> log && ! dual ) { log_t::output( sim, "%s performs %s (%.0f)", player -> name(), name(), player -> resource_current[ player -> primary_resource() ] ); } if ( observer ) *observer = 0; player_buff(); target_debuff( DMG_DIRECT ); calculate_result(); consume_resource(); if ( result_is_hit() ) { calculate_direct_damage(); if ( direct_dmg > 0 ) { assess_damage( direct_dmg, DMG_DIRECT ); } if ( num_ticks > 0 ) { if ( dot_behavior == DOT_REFRESH ) { current_tick = 0; if ( ! ticking ) schedule_tick(); } else { if ( ticking ) cancel(); snapshot_haste = haste(); schedule_tick(); } } } else { if ( sim -> log ) { log_t::output( sim, "%s avoids %s (%s)", sim -> target -> name(), name(), util_t::result_type_string( result ) ); log_t::miss_event( this ); } } update_ready(); if ( ! dual ) update_stats( DMG_DIRECT ); schedule_travel(); if ( repeating && ! proc ) schedule_execute(); if ( harmful ) player -> in_combat = true; }
double Energy::calculate_binding(Soup * protein, Soup * ligand) { simple_parameters.prepare(protein); simple_parameters.prepare(ligand); BM.assign_bonds(ligand); // force field components de_apo = de.calculate(protein); de_holo = de.calculate(protein, ligand); //Desolvation_Factor must be calculated first, as desolvation_factor is needed in hb, vdw, es, wb de_component = de_holo - de_apo; wb.find_water_contacts(protein); //mark which acceptors and donors can be replaced by water //cout<<" de:"<<de_component<<flush; hb_component = hb.calculate(protein, ligand); //Hydrogen bonds must be calculated before es and vdw, as info on hydrogen bonds is needed in es and vdw //cout<<" hb:"<<hb_component<<flush; vdw_component = vdw_line.calculate(protein, ligand, 10); //cout<<" vw:"<<vdw_component<<flush; es_component = es.calculate(protein, ligand, 0); //cout<<" es:"<<es_component<<flush; bb_component = 0.0; pe_component = 0.0;//pe.calculate(proteins[s], ligands[s]); //cout<<" pe:"<<pe_component<<flush; le_component = le.calculate_using_desolvation(protein, ligand); // le_component = le.calculate(ligand); //cout<<" le:"<<le_component<<flush; wb_component = wb.calculate(protein, ligand); //cout<<" wb:"<<wb_component<<flush; //cout<<" wb:"<<r_wb <<flush; //cout<<endl; // Insert in matrices components(0) = vdw_component; components(1) = es_component; components(2) = hb_component; components(3) = de_component; components(4) = bb_component; components(5) = pe_component; components(6) = le_component; components(7) = wb_component; if(are_coefficients_set) { calculate_result(); return total_binding; } return 0.0; }
int main (int argc, char **argv) { int balls[6]; int count_balls = 0; int favorite = 0; for (int i = 1; i < argc; i++) { const char *arg = argv[i]; if ('-' == arg[0]) { if (0 == strcmp (arg, "-favorite")) { favorite = 1; } else { goto usage_error; } } else { char *endptr = NULL; long val = strtol (arg, &endptr, 10); if (*endptr) { goto usage_error; } balls[count_balls++] = (int) val; } } if (6 != count_balls) { goto usage_error; } int power_ball = balls[5]; int result = calculate_result (balls, power_ball); if (result < 0) { goto usage_error; } if (LUCKY_NUMBER == power_ball) { result = result * 2; } if (favorite) { result = result * 2; } printf ("%d percent chance of winning\n", result); return 0; usage_error: fprintf (stderr, "Usage: %s [-favorite] (5 white balls) power_ball\n", argv[0]); return -1; }
void heal_t::execute() { if ( ! initialized ) { sim -> errorf( "action_t::execute: action %s from player %s is not initialized.\n", name(), player -> name() ); assert( 0 ); } if ( sim -> log && ! dual ) { log_t::output( sim, "%s performs %s (%.0f)", player -> name(), name(), player -> resource_current[ player -> primary_resource() ] ); } player_buff(); total_heal = 0; for ( unsigned int i = 0; i < heal_target.size(); i++ ) { target_debuff( heal_target[ i ], HEAL_DIRECT ); calculate_result(); direct_dmg = calculate_direct_damage(); schedule_travel( heal_target[ i ] ); } consume_resource(); update_ready(); if ( ! dual ) stats -> add_execute( time_to_execute ); if ( harmful ) player -> in_combat = true; if ( repeating && ! proc ) schedule_execute(); // Add options found in spell_t::execute() if ( player -> last_foreground_action == this ) player -> debuffs.casting -> expire(); if ( harmful && callbacks ) { if ( result != RESULT_NONE ) { action_callback_t::trigger( player -> heal_callbacks[ result ], this ); } if ( ! background ) // OnSpellCast { action_callback_t::trigger( player -> heal_callbacks[ RESULT_NONE ], this ); } } }
int main(void) { int child_pipe_fd[2]; //pipe_fd[0] -> r , pipe_fd[1] -> w int parent_pipe_fd[2]; pid_t child_pid; int pipe_status = 0; int child_buff[3]; int parent_buff[3]; pipe_status = pipe(parent_pipe_fd); if(pipe_status == -1) { perror("pipe()"); } else { pipe_status = pipe(child_pipe_fd); if(pipe_status == -1) { perror("pipe()"); return EXIT_FAILURE; } child_pid = fork(); if(child_pid == -1) { perror("fork()"); } else if(child_pid == 0) { /*child*/ child_buff[0] = 2; child_buff[1] = 3; child_buff[2] = -5; close(parent_pipe_fd[0]); close(child_pipe_fd[1]); write(parent_pipe_fd[1],child_buff,sizeof(child_buff)); close(parent_pipe_fd[1]); read(child_pipe_fd[0],child_buff,sizeof(child_buff)); printf("Parent said: %d,%d,%d\n",child_buff[0],child_buff[1],child_buff[2]); _Exit(EXIT_SUCCESS); // or _exit() } else { /*parent*/ close(parent_pipe_fd[1]); close(child_pipe_fd[0]); read(parent_pipe_fd[0],parent_buff,sizeof(parent_buff)); close(parent_pipe_fd[0]); printf("Child said: %d,%d,%d\n",parent_buff[0],parent_buff[1],parent_buff[2]); calculate_result(parent_buff); write(child_pipe_fd[1] , parent_buff , sizeof(parent_buff)); wait(NULL); } } return 0; }
task4_5::solution::solution( const data_type& data ) { if(!data.empty()) { m_max = data[0][0]; m_min = data[0][0]; m_current_vector = data.size(); calculate_result(data); } else { m_max = 0; m_min = 0; } }
int main(int argc, char** argv) { if (argc != 7) { fprintf(stderr, "Usage: %s (5 white balls) power_ball\n", argv[0]); return -1; } int power_ball = atoi(argv[6]); int white_balls[5]; for (int i=0; i<5; i++) { white_balls[i] = atoi(argv[1+i]); } int result = calculate_result(white_balls, power_ball); printf("%d percent chance of winning\n", result); return 0; }
double MSC::calculate_stability(Soup * soup) { if(include_ff_components) simple_parameters.prepare(soup); cout<<soup->name<<flush; de_component = de.calculate(soup);//Desolvation_Factor must be calculated first, as desolvation_factor is needed in hb, vdw, es, wb cout<<" de:"<<de_component <<flush; hb_component = hb.calculate(soup); //Hydrogen bonds must be calculated before es and vdw, as info on hydrogen bonds is needed in es and vdw cout<<" hb:"<<hb_component <<flush; vdw_component = vdw_line.calculate(soup, 10); cout<<" vdw:"<<vdw_component<<flush; es_component = es.calculate(soup, 0); cout<<" es:"<<es_component <<flush; bb_component = bb.calculate(soup); cout<<" bb:"<<bb_component <<flush; pe_component = 0.0;//pe.calculate(soup); cout<<" pe:"<<pe_component <<flush; le_component = 0.0;//le.calculate(soup); cout<<" le:"<<le_component <<flush; wb_component = wb.calculate(soup); cout<<endl; cout << "calc is done" <<flush; // Insert in matrices components(0) = vdw_component; components(1) = es_component; components(2) = hb_component; components(3) = de_component; components(4) = bb_component; components(5) = pe_component; components(6) = le_component; components(7) = wb_component; /* A.resize(A.size1()+1,A.size2(),true); for(int i=0; i<components.size();i++) A(A.size1()-1,i) = components(i); names.push_back(soup->name); count++; */ if(coefficients_are_set) { calculate_result(); return total_stability; } return 0.0; }
int main(void) { int state= 0; double result; DDRC |= 0x10; // LED pin PORTC |= 0xC0; //Enabling pull up for SW1 and SW2 PORTC &= 0b11001111; // LED OFF DDRB |= 0b10000000; // Buzzer pin PORTB &= 0b01111111; // Buzzer off inti_ADC(); //ADC intialization while(1) { switch(state) // State case implementation using switch case { case 0: display_Start(); i=0; if(keyPressAndRelease(1)) { intialize_7Segment(); //CH02- Seven segment init autocalibrate(); state=1; } break; case 1: display_DAQ(); record_ADC_data(); display_4_digit(i); //CH02 - Display on 7-segment if(keyPressAndRelease(1)) state=3; else if(keyPressAndRelease(2)) state=4; else if(i>=7999) state=2; break; case 2: display_4_digit(i); //CH02 - Display on 7-segment display_Memory_Full(); PORTB |= 0b10000000; // Buzzer ON if(keyPressAndRelease(1)) { PORTB &= 0b01111111; state = 4; } break; case 3: display_4_digit(i); //CH02 - Display on 7-segment display_Pause(); if(keyPressAndRelease(1)) state= 1; break; case 4: display_4_digit(i); //CH02 - Display on 7-segment display_Stop(); PORTC &= 0b11101111; // Buzzer OFF if(keyPressAndRelease(1)) state=6; else if (keyPressAndRelease(2)) state = 5; break; case 5: display_4_digit(i); //CH02 - Display on 7-segment result=calculate_result(); display_Result(result); while (!(keyPressAndRelease(1))); state=6; break; case 6: i=0; state=0; break; } } }
int hpx_main(int argc, char* argv[]) { // Print help message on wrong argument count if(argc < 2) { hpx::cerr << "Usage: " << argv[0] << " matrixsize" << hpx::endl; return hpx::finalize(); } { //////////////////////////////////////////// // Initializes all matrices // size_t vector_size = std::stoul(argv[1]); hpx::cout << "Vector size: " << vector_size << std::endl; hpx::cout << "Generating matrix A ..." << hpx::endl; auto a = generate_input_matrix(vector_size); hpx::cout << "Generating matrix B ..." << hpx::endl; auto b = generate_input_matrix(vector_size); hpx::cout << "Generating matrix C ..." << hpx::endl; auto c = generate_input_matrix(vector_size); hpx::cout << "Calculating reference result on CPU ..." << hpx::endl; double time_cpu; auto z = calculate_result(a,b,c,&time_cpu); hpx::cout << " ... " << time_cpu << " ms" << hpx::endl; //////////////////////////////////////////// // Direct OpenCL calculation // hpx::cout << hpx::endl; hpx::cout << "///////////////////////////////////////" << hpx::endl; hpx::cout << "// Direct OpenCL" << hpx::endl; hpx::cout << "//" << hpx::endl; // initializes hpx::cout << "Initializing ..." << hpx::endl; directcl_initialize(vector_size); // main calculation with benchmark double time_directcl_nonblock; double time_directcl_total; hpx::cout << "Running calculation ..." << hpx::endl; boost::shared_ptr<std::vector<float>> z_directcl = directcl_calculate(a, b, c, &time_directcl_nonblock, &time_directcl_total); // shuts down hpx::cout << "Shutting down ..." << hpx::endl; directcl_shutdown(); // checks for correct result check_for_correct_result(z_directcl->data(), (*z_directcl).size(), z.data(), z.size()); // Prints the benchmark statistics hpx::cout << hpx::endl; hpx::cout << " Nonblocking calls: " << time_directcl_nonblock << " ms" << hpx::endl; hpx::cout << " Total Calculation Time: " << time_directcl_total << " ms" << hpx::endl; hpx::cout << hpx::endl; //////////////////////////////////////////// // HPXCL local calculation // hpx::cout << hpx::endl; hpx::cout << "///////////////////////////////////////" << hpx::endl; hpx::cout << "// HPXCL local" << hpx::endl; hpx::cout << "//" << hpx::endl; // initializes hpx::cout << "Initializing ..." << hpx::endl; hpxcl_single_initialize(hpx::find_here(), vector_size); // main calculation with benchmark hpx::cout << "Running calculation ..." << hpx::endl; double time_hpxcl_local_nonblock; double time_hpxcl_local_total; auto z_hpxcl_local = hpxcl_single_calculate(a, b, c, &time_hpxcl_local_nonblock, &time_hpxcl_local_total); // shuts down hpx::cout << "Shutting down ..." << hpx::endl; hpxcl_single_shutdown(); // checks for correct result check_for_correct_result( z_hpxcl_local.data(), z_hpxcl_local.size(), z.data(), z.size()); // Prints the benchmark statistics hpx::cout << hpx::endl; hpx::cout << " Nonblocking calls: " << time_hpxcl_local_nonblock << " ms" << hpx::endl; hpx::cout << " Total Calculation Time: " << time_hpxcl_local_total << " ms" << hpx::endl; hpx::cout << hpx::endl; //////////////////////////////////////////// // HPXCL remote calculation // hpx::cout << hpx::endl; hpx::cout << "///////////////////////////////////////" << hpx::endl; hpx::cout << "// HPXCL remote" << hpx::endl; hpx::cout << "//" << hpx::endl; // initializes hpx::cout << "Initializing ..." << hpx::endl; hpx::id_type remote_node = hpx_get_remote_node(); if(remote_node){ hpxcl_single_initialize(remote_node, vector_size); // main calculation with benchmark hpx::cout << "Running calculation ..." << hpx::endl; double time_hpxcl_remote_nonblock; double time_hpxcl_remote_total; auto z_hpxcl_remote = hpxcl_single_calculate(a, b, c, &time_hpxcl_remote_nonblock, &time_hpxcl_remote_total); // shuts down hpx::cout << "Shutting down ..." << hpx::endl; hpxcl_single_shutdown(); // checks for correct result check_for_correct_result( z_hpxcl_remote.data(), z_hpxcl_remote.size(), z.data(), z.size()); // Prints the benchmark statistics hpx::cout << hpx::endl; hpx::cout << " Nonblocking calls: " << time_hpxcl_remote_nonblock << " ms" << hpx::endl; hpx::cout << " Total Calculation Time: " << time_hpxcl_remote_total << " ms" << hpx::endl; hpx::cout << hpx::endl; } //////////////////////////////////////////// // HPXCL distributed calculation // hpx::cout << hpx::endl; //hpx::cout << "///////////////////////////////////////" << hpx::endl; //hpx::cout << "// HPXCL distributed" << hpx::endl; //hpx::cout << "//" << hpx::endl; /////////////////////////////////////////// // Shutdown // hpx::cout << hpx::endl; hpx::cout << "Shutting down hpx ... " << hpx::endl; } hpx::cout << "Program finished." << hpx::endl; // End the program return hpx::finalize(); }
static char Calculator(char *msg)//2.计算器 { unsigned char abuff[50]; //因为abuff 要做结果存储,所以要申请大一点,否则如果数值太大,会segmentation fault unsigned char bbuff[22]; signed char jjcc[2]={0,0}; signed char input09,inputcnt; signed char inputFlag; unsigned char keyval; enum {WaitFirst,WaitFirst_inputed,WaitSecond,WaitSecond_inputed}ope; ope=WaitFirst; inputcnt=0; clear_lcd(); text_out_to_row_x_Language2(0,34,"【计算器】","Calculator"); draw_line(0,12,132,12,1); draw_line(0,11,132,11,1); text_out_to_row_fillSpace(1,"0"); while(1){ keyval=GetKeyValue(); if(keyval==0)continue; KeyEventPost(); inputFlag=0; switch(keyval){ case KEY0: inputFlag=1; input09= '0';break; //号码键 case KEY1: inputFlag=1; input09= '1';break; case KEY2: inputFlag=1; input09= '2';break; case KEY3: inputFlag=1; input09= '3';break; case KEY4: inputFlag=1; input09= '4';break; case KEY5: inputFlag=1; input09= '5';break; case KEY6: inputFlag=1; input09= '6';break; case KEY7: inputFlag=1; input09= '7';break; case KEY8: inputFlag=1; input09= '8';break; case KEY9: inputFlag=1; input09= '9';break; case KEYJING: inputFlag=1; input09= '.';break; //小数点键 case KEY_UP: inputFlag=2; input09= '+';break; //加 case KEY_DOWN: inputFlag=2; input09= '-';break; //减 case KEY_LEFT: inputFlag=2; input09= '*';break; //乘 case KEY_RIGHT: inputFlag=2; input09= '/';break; //除 case KEYXING: inputFlag=2; input09= '&';break; case KEY_Enter: //等于键 if(ope==WaitSecond_inputed){ if(strlen((char const *)abuff)<sizeof(bbuff)-3){ calculate_result(abuff,(char const *)bbuff,(char const *)jjcc); }else{ clear_area_to_row(1,3); text_out_to_row_fillSpace(2,"数据太大!无法计算!"); } ope=WaitFirst_inputed; inputcnt=0; }else{ //如果只是输入了第一个数据,按确认则清0。 clear_area_to_row(1,3); text_out_to_row_fillSpace(1,"0"); ope=WaitFirst; inputcnt=0; } break; case KEY_DEL: //删除返回键 if(inputcnt){ inputcnt--; if(ope==WaitFirst_inputed){abuff[inputcnt]=0;text_out_to_row_fillSpace(1,abuff);} else if(ope==WaitSecond_inputed){bbuff[inputcnt]=0;text_out_to_row_fillSpace(3,bbuff);} }else{ //return 1; } case KEY_ReturnInitInterface: case KEY_ReturnPrevious: KeyIsResponse(); return keyval; } if(inputFlag==1&&inputcnt<sizeof(bbuff)-3){ //如果有0到9.输入并且没有超过规定的位数 if(inputcnt==0&&input09=='.'){ if(ope==WaitFirst||ope==WaitFirst_inputed){ope=WaitFirst_inputed;abuff[inputcnt++]='0';abuff[inputcnt++]='.';abuff[inputcnt]=0;text_out_to_row_fillSpace(1,abuff);} else if(ope==WaitSecond||ope==WaitSecond_inputed){ope=WaitSecond_inputed;bbuff[inputcnt++]='0';bbuff[inputcnt++]='.';bbuff[inputcnt]=0;text_out_to_row_fillSpace(3,bbuff);} }else if(inputcnt!=0||input09!='0'){ //如果输入的第一个数不为0 if(ope==WaitFirst||ope==WaitFirst_inputed){ope=WaitFirst_inputed;abuff[inputcnt++]=input09;abuff[inputcnt]=0;text_out_to_row_fillSpace(1,abuff);} else if(ope==WaitSecond||ope==WaitSecond_inputed){ope=WaitSecond_inputed;bbuff[inputcnt++]=input09;bbuff[inputcnt]=0;text_out_to_row_fillSpace(3,bbuff);} } } if(inputFlag==2){ if(ope==WaitFirst_inputed||ope==WaitSecond){ //如果输入了第一个并在等待第二个时,可以更换运算符。 if(input09=='&'){if(jjcc[0]=='+')jjcc[0]='-';else if(jjcc[0]=='-')jjcc[0]='*';else if(jjcc[0]=='*')jjcc[0]='/';else jjcc[0]='+';} else jjcc[0]=input09; text_out_to_row_x_fillSpace(2,6,(unsigned char const *)jjcc); ope=WaitSecond; inputcnt=0; }else if(ope==WaitSecond_inputed){ //如果输入了第二个数据,则计算出结果,并可以连算。 calculate_result(abuff,(char const *)bbuff,(char const *)jjcc); if(input09=='&')jjcc[0]='+'; else jjcc[0]=input09; text_out_to_row_x_fillSpace(2,6,(unsigned char const *)jjcc); ope=WaitSecond; inputcnt=0; } } #ifdef DEBUG_PRINTF printf("inputFlag=%d, inputcnt=%d\n",inputFlag,inputcnt); #endif KeyIsResponse(); } }
int main(int argc, char** argv) { int balls[6]; int lott[6]; int count_balls = 0; bool favourite = false; for (int i=1; i<argc; i++) { const char* arg = argv[i]; if ('-' == arg[0]) { if (0 == strcmp(arg, "-favourite")) { favourite = true; } else { goto usage_error; } } else { char* endptr = NULL; long val = strtol(arg, &endptr, 10); if (*endptr) { goto usage_error; } balls[count_balls++] = (int) val; } } if (6 != count_balls) { for (int i = 0; i < 5; i++){ balls[i] = whiteballs_computer_generated(); checkwhiteballs(balls, i); } balls[5] = powerball_computer_generated(); // Power ball printf("Your numbers are: "); for (int i = 0; i < 5; i++){ printf("%d ", balls[i]); } printf("\nAnd the power ball:"); printf(" %d\n", balls[5]); } // the power ball is always the last one given int power_ball = balls[5]; // calculate result can return -1 if the ball numbers // are out of range // Head for the lottery numbers printf("\n--- The lottery numbers---\n"); lottery_numbers_simulation(lott); // Head for my numbers printf("\n--- Your lottery numbers---\n"); float result = calculate_result(balls, power_ball, lott); showing_results(balls, power_ball); if (result < 0) { goto usage_error; } if (LUCKY_NUMBER == power_ball) { result = result * 2; } if (favourite) { result = result * 2; } printf("%f percent chance of winning\n", result); return 0; usage_error: fprintf(stderr, "Usage: %s [-favourite] (5 white balls) power_ball\n", argv[0]); return -1; }