⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bs03_neck_bmn.c

📁 这是bs球队的仿真2D比赛程序
💻 C
📖 第 1 页 / 共 4 页
字号:
  if(!ignore_neck_intentions && neck_intention.type!=NECK_INTENTION_NONE) {    switch(neck_intention.type) {    case NECK_INTENTION_LOOKINDIRECTION: target=intention_lookindirection();break;    case NECK_INTENTION_PASSINDIRECTION: target=intention_passindirection();break;    case NECK_INTENTION_FACEBALL: target=intention_faceball();break;    case NECK_INTENTION_BLOCKBALLHOLDER: target=intention_blockballholder();break;    default: DBLOG_POL(0,"WARNING: NECK_INTENTION type "		     <<neck_intention.type		     <<" not (yet) supported, continuing in normal mode!");    cerr << "\nBS02_Neck: WARNING: NECK_INTENTION type "	 <<neck_intention.type	 <<" not (yet) supported, continuing in normal mode!";    break;    } // end switch       if(!Tools::could_see_in_direction(target)) {      MYLOG_POL(0,"WARNING: I cannot look in the direction ("<<target<<") forced by NECK_INTENTION!");      target=-1;center_target=false; // statt dessen Standardmove machen!    }     else{      MYLOG_POL(0,"I am forced to look to target NECK_INTENTION, target is "<<target<<"!");      Vector pol;      pol.init_polar(20.,target);      pol+=WSinfo::me->pos;            MYLOG_DRAW(0,L2D(WSinfo::me->pos.x,WSinfo::me->pos.y,pol.x,pol.y,"cyan"));      center_target=true;    }  }  return target;}Angle BS03Neck::check_intercept() {  MYLOG_POL(0,"TURN NECK: check intercept ");  LOG_POL(0,"TURN NECK: check intercept ! ballinfeelrange "<<ballinfeelrange<<" potent. coll "<<potentialcollision);  if(!WSinfo::is_ball_pos_valid()) {    DBLOG_POL(1,"check_intercept: I don't know where the ball is, ignoring!");    return -1;  }   if(intercept_look_mode!=0 &&     ((mdpInfo::get_my_intention() == DECISION_TYPE_INTERCEPTBALL) ||      (mdpInfo::get_my_intention() == DECISION_TYPE_INTERCEPTSLOWBALL) //||      /*(mdpInfo::get_my_intention() == DECISION_TYPE_EXPECT_PASS)*/)) {    if(ballinfeelrange && potentialcollision == false) {      LOG_POL(0,"Turn Neck: Intercepting,ball will be in feelrange next time. But Not close. Ridi05!");      return -1;    } else {      if(!Tools::could_see_in_direction(dir_to_ball.get_value())) {	DBLOG_POL(1,"Intercepting, but I can't look to ball!");	return -1;      } else {	DBLOG_POL(0,"Intercepting, trying to look to ball...");	if(intercept_look_mode==2) center_target=true;	return dir_to_ball.get_value();      }    }  }  return -1;}Angle BS03Neck::check_players_near_ball() {  MYLOG_POL(0,"TURN NECK: check players near ball ");  if(!WSinfo::is_ball_pos_valid()) {    DBLOG_POL(1,"check_players_near_ball: I don't know where the ball is, ignoring!");    return -1;  }  Angle target=-1;    if(target<0 && opp_has_ball_look_mode!=0 && opp_players_near_ball.num>0) {    DBLOG_POL(0,"Opponents near ball, trying to look...");    target=0;    if(opp_has_ball_look_mode==2) center_target=true;  }  if(target<0 && own_has_ball_look_mode!=0 && own_players_near_ball.num>0) {    DBLOG_POL(0,"Teammates near ball, trying to look...");    target=0;    if(own_has_ball_look_mode==2) center_target=true;  }  if(!target) {    if(!Tools::could_see_in_direction(dir_to_ball.get_value())) {      DBLOG_POL(0,"Intercepting, but I can't look to ball!");      center_target=false;      return -1;    } else {      return dir_to_ball.get_value();    }  }  return -1;}/* obsolete, should be covered by neck intention! */Angle BS03Neck::check_block_ball_holder() {  if(ball_holder_look_mode==0) return -1;  if(mdpInfo::get_my_intention()!=DECISION_TYPE_BLOCKBALLHOLDER) return -1;  LOG_POL(3,<<"BS02_Neck - check_block_ball_holder: Got BLOCKBALLHOLDER intention!");  Angle target;  if((target=get_dir_of_nearest_opponent())==-1) return -1;  if(!Tools::could_see_in_direction(target)) {    //MYLOG_POL(3,"BS02_Neck - check_block_ball_holder: Can't look to fastest opp!");    return -1;  }  Angle target_dist=Tools::get_angle_between_mPI_pPI(dir_to_ball.get_value()-target);  if(fabs(target_dist)     < (mdpInfo::next_view_angle_width().get_value())-DEG2RAD(10)) {    //MYLOG_POL(3,"BS02_Neck - check_block_ball_holder: Looking to ball and fastest opponent!");    target+=target_dist*.5;    center_target=true;  } else {    MYLOG_POL(3,"BS02_Neck - check_block_ball_holder: Looking to fastest opponent!");    ;  }  if(ball_holder_look_mode==2) center_target=true;  return target;}Angle BS03Neck::check_offside() {  MYLOG_POL(0,"TURN NECK: check offside ");  if(mdpInfo::is_ball_infeelrange() || ballinfeelrange) {    DBLOG_POL(1,"check_offside: I am carrying the ball, ignoring!");    return -1; // I am carrying the ball!  }  if(WSinfo::ball->pos.x>WSinfo::me->pos.x+OFFSIDE_TOLERANCE) {    DBLOG_POL(1,"check_offside: Ball in front of me, ignoring!");    return -1; // Ball in front of me  }  if(WSinfo::me->pos.x>(FIELD_BORDER_X-IGNORE_OFFSIDE_GOAL_DISTANCE)) {    DBLOG_POL(1,"check_offside: Too close to goal, ignoring!");    return -1;  // too close to goal!  }  if(WSinfo::me->pos.x < WSinfo::his_team_pos_of_offside_line()-OFFSIDE_TOLERANCE) {    DBLOG_POL(1,"check_offside: Too far away from last known offside line, ignoring!");    return -1;  }  WSpset opp_in_left_offside_box,opp_in_right_offside_box,opp_in_offside_box;  opp_in_offside_box=WSinfo::valid_opponents;  opp_in_offside_box.keep_players_in_rectangle(Vector(WSinfo::me->pos.x-OFFSIDE_TOLERANCE,-FIELD_BORDER_Y),					       Vector(FIELD_BORDER_X,+FIELD_BORDER_Y));  opp_in_offside_box.keep_and_sort_players_by_x_from_right(11);  if(WSinfo::his_goalie) opp_in_offside_box.remove(WSinfo::his_goalie);  opp_in_left_offside_box=opp_in_offside_box;  opp_in_right_offside_box=opp_in_offside_box;  opp_in_left_offside_box.keep_players_in_halfplane(WSinfo::me->pos,Vector(0,1));  opp_in_right_offside_box.keep_players_in_halfplane(WSinfo::me->pos,Vector(0,-1));    //for(int i=0;i<opp_in_left_offside_box.num;i++) {  //  LOG_MOV(0,<<_2D<<C2D(opp_in_left_offside_box[i]->pos.x,opp_in_left_offside_box[i]->pos.y,2.5,"#111111"));  //}  //for(int i=0;i<opp_in_right_offside_box.num;i++) {  //  LOG_MOV(0,<<_2D<<C2D(opp_in_right_offside_box[i]->pos.x,opp_in_right_offside_box[i]->pos.y,2.5,"#ff0000"));  //}    MYLOG_POL(1,_2D<<L2D(WSinfo::his_team_pos_of_offside_line(),FIELD_BORDER_Y,		       WSinfo::his_team_pos_of_offside_line(),-FIELD_BORDER_Y,"#000000"));    long left_age=1000;  long right_age=1000;  static long last_left_check=-10;  static long last_right_check=-10;  static long last_left_age=0;  static long last_right_age=0;    if(opp_in_left_offside_box.num>0 &&      Tools::could_see_in_direction(Tools::my_abs_angle_to(opp_in_left_offside_box[0]->pos))) {    for(int i=0;i<opp_in_left_offside_box.num;i++) {      if(opp_in_left_offside_box[i]->age<left_age) left_age=opp_in_left_offside_box[i]->age;    }  }  if(opp_in_right_offside_box.num>0 &&      Tools::could_see_in_direction(Tools::my_abs_angle_to(opp_in_right_offside_box[0]->pos))) {    for(int i=0;i<opp_in_right_offside_box.num;i++) {      if(opp_in_right_offside_box[i]->age<right_age) right_age=opp_in_right_offside_box[i]->age;    }  }      if(left_age<right_age && right_age<999 && right_age>=MAX_OFFSIDE_LINE_AGE) {    DBLOG_POL(0,"check_offside: checking righthand offside line!");    if(last_right_check==WSinfo::ws->time-1 && last_right_age==right_age-1) {      DBLOG_POL(0,"check_offside: Something is wrong, I already checked last cycle!");      return -1;    }    last_right_check=WSinfo::ws->time;    last_right_age = right_age;    center_target=true;    //DBLOG_POL(3,<<_2D<<C2D(opp_in_right_offside_box[0]->pos.x,opp_in_right_offside_box[0]->pos.y,2.5,"#ffffff"));    return Tools::my_abs_angle_to(opp_in_right_offside_box[0]->pos).get_value();  } else {    if(left_age<999 && left_age>=MAX_OFFSIDE_LINE_AGE) {      DBLOG_POL(0,"check_offside: checking lefthand offside line!");      //LOG_POL(3,<<_2D<<C2D(opp_in_left_offside_box[0]->pos.x,opp_in_left_offside_box[0]->pos.y,2.5,"#ffffff"));      if(last_left_check==WSinfo::ws->time-1 && last_left_age==left_age-1) {	DBLOG_POL(0,"check_offside: Something is wrong, I already checked last cycle!");	return -1;      }      last_left_check=WSinfo::ws->time;      last_left_age = left_age;      center_target=true;      return Tools::my_abs_angle_to(opp_in_left_offside_box[0]->pos).get_value();    }  }  return -1;}Angle BS03Neck::check_neck_1v1() {  MYLOG_POL(0,"TURN NECK: check 1v1 ");  switch(WSinfo::ws->play_mode) {  case PM_my_BeforePenaltyKick:  case PM_his_BeforePenaltyKick:  case PM_my_PenaltyKick:  case PM_his_PenaltyKick:    break;  default:    if(!use_1v1_mode) return -1;    break;  }  Angle target;  //if(mdpInfo::my_distance_to(mdpInfo::opponent_goalpos())>30) return -1;  if(!WSinfo::is_ball_pos_valid() || !ballinfeelrange) return -1;  if(!WSinfo::his_goalie) return -1;  if(WSinfo::is_opponent_pos_valid(WSinfo::his_goalie)) {    target=Tools::my_abs_angle_to(WSinfo::his_goalie->pos).get_value();    if(Tools::could_see_in_direction(target)) return target;  }  target=Tools::my_abs_angle_to(mdpInfo::opponent_goalpos()).get_value();  if(Tools::could_see_in_direction(target)) return target;  return -1;}Angle BS03Neck::check_goalie() {  MYLOG_POL(0,"TURN NECK: check goalie ");  if(last_looked_to_goalie>=WSinfo::ws->time-1) return -1;  if(my_new_pos.distance(HIS_GOAL_CENTER)>30) return -1;  Angle target=-1;  if(WSinfo::his_goalie) {    if(WSinfo::his_goalie->age<MAX_GOALIE_AGE) return -1;    if(!ballinfeelrange) return -1;    DBLOG_POL(0,"check_goalie: Goalie too old, trying to look");    if(Tools::could_see_in_direction(Tools::my_abs_angle_to(WSinfo::his_goalie->pos))) {      target=Tools::my_abs_angle_to(WSinfo::his_goalie->pos).get_value();      DBLOG_POL(0,"check_goalie: Looking to last goalie pos");    }  }  if(!WSinfo::his_goalie &&     (cur_info.opp_goal_left+2*cur_info.opp_goal+cur_info.opp_goal_right)/4.0     < MAX_GOALIE_AGE) return -1;  if(Tools::could_see_in_direction(Tools::my_abs_angle_to(HIS_GOAL_CENTER))) {    center_target=true;    DBLOG_POL(0,"check_goalie: Looking to opp goal center");    target=Tools::my_abs_angle_to(HIS_GOAL_CENTER).get_value();  } else if(Tools::could_see_in_direction(Tools::my_abs_angle_to(HIS_GOAL_LEFT_CORNER))) {    center_target=true;    DBLOG_POL(0,"check_goalie: Looking to left goal corner");    target=Tools::my_abs_angle_to(HIS_GOAL_LEFT_CORNER).get_value();  } else if(Tools::could_see_in_direction(Tools::my_abs_angle_to(HIS_GOAL_RIGHT_CORNER))) {    center_target=true;    DBLOG_POL(0,"check_goalie: Looking to right goal corner");    target=Tools::my_abs_angle_to(HIS_GOAL_RIGHT_CORNER).get_value();  }  if(target!=-1) {    last_looked_to_goalie=WSinfo::ws->time;  }  return target;}/*********************************************************************************** * Reaction to NECK_INTENTION **********************************************************************************/Angle BS03Neck::intention_lookindirection() {  DBLOG_POL(0,"intention_lookindirection: Should turn to "<<neck_intention.p1<<"!");  return neck_intention.p1;}Angle BS03Neck::intention_direct_opponent_defense() {  DBLOG_POL(0,"intention_direct_opponent_defense: Should turn to "<<neck_intention.p1<<"!");  return neck_intention.p1;}Angle BS03Neck::intention_passindirection() {  DBLOG_POL(0,"intention_passindirection: Should turn to "<<neck_intention.p1<<"!");  return neck_intention.p1;}Angle BS03Neck::intention_faceball() {  Angle target = Tools::my_abs_angle_to(WSinfo::ball->pos+WSinfo::ball->vel).get_value();  DBLOG_POL(0,"intention_faceball: Should turn to "<<target<<"!");  return target;}Angle BS03Neck::intention_blockballholder() {  if(ball_holder_look_mode==0) return -1;    DBLOG_POL(0,"intention_blockballholder: Got BLOCKBALLHOLDER neck intention!");  Angle target;  if((target=get_dir_of_nearest_opponent())==-1) return -1;  if(!Tools::could_see_in_direction(target)) {    DBLOG_POL(0,"intention_blockballholder: Can't look to fastest opp!");    return -1;  }  Angle target_dist=Tools::get_angle_between_mPI_pPI(dir_to_ball.get_value()-target);  if(fabs(target_dist)     < (mdpInfo::next_view_angle_width().get_value())-DEG2RAD(10)) {    DBLOG_POL(0,"intention_blockballholder: Looking to ball and fastest opponent!");    target+=target_dist*.5;    center_target=true;  } else {    DBLOG_POL(0,"intention_blockballholder: Looking to fastest opponent!");  }  if(ball_holder_look_mode==2) center_target=true;  return target; }/******************************************************************************** * Helper functions ********************************************************************************//** locks neck angle to body angle */bool BS03Neck::neck_lock(Cmd &cmd) {  DBLOG_POL(0,"neck_lock: Locking neck angle to body angle");  neck_cmd->set_turn_neck_rel(0.0);  return neck_cmd->get_cmd(cmd);  //return Move_Factory::get_Neck_Turn_Rel(0);}/** returns -1 also when opponent has an age < MAX_FASTEST_OPP_AGE! */Angle BS03Neck::get_dir_of_nearest_opponent() {  static long last_calculated=-1;  static Angle cache=0;  int opp_number=-1;    if(last_calculated==WSinfo::ws->time) return cache;  last_calculated=WSinfo::ws->time;  Policy_Tools::go2ball_steps_update();  for(int i=0;i<22;i++) {    if(Policy_Tools::go2ball_steps_list()[i].side == Go2Ball_Steps::THEIR_TEAM) {      opp_number=Policy_Tools::go2ball_steps_list()[i].number;      if(opp_number==WSinfo::ws->his_goalie_number) {	opp_number=-1;continue;      }      break;    }  }  if(opp_number==-1) {    DBLOG_POL(1,"I don't know which opponent is fastest to ball!");    return -1;  }  PPlayer p=WSinfo::get_opponent_by_number(opp_number);  if(p->age<MAX_FASTEST_OPP_AGE) {    DBLOG_POL(1,"Fastest opponent has been seen recently, ignoring...");    return -1;  }  cache=(p->pos-my_new_pos).angle();  DBLOG_POL(1,"Fastest opponent is #"<<opp_number<<"!");  return cache;}////////////////////////////////////////////////////////////////////////////////////////////////////////#if 0/************************************************************************************ * OBSOLETE * * This is all old unused stuff, but still kept for reference purposes. ************************************************************************************//** This routine replaces the buggy one in mdpInfo - dirty workaround! */bool BS03Neck::is_ball_in_feelrange_next_time() {  return ballinfeelrange;#if 0  //return mdpInfo::is_ball_infeelrange();  FPlayer *me=mdpInfo::mdp->me;  Vector my_new_pos,my_new_vel,new_ball_pos,new_ball_vel;  Angle my_new_angle;  Tools::model_cmd_main(me->pos(),me->vel(),me->ang.v,mdpInfo::mdp->ball.pos(),mdpInfo::mdp->ball.vel(),			cmd->cmd_main,			my_new_pos,my_new_vel,my_new_angle,new_ball_pos,new_ball_vel);  if((my_new_pos-new_ball_pos).norm()<0.95*ServerOptions::visible_distance) return true;    return false;#endif}/** old routines, will maybe be changed after Seattle *///#define ATTACKER_DIST 6./** lock neck angle to body angle */Neck_Move* BS03Neck::neck_face_ball() {  LOG_POL(2,<<"BS02_Neck - neck_face_ball: Locking neck angle to body angle");  return Move_Factory::get_Neck_Turn_Rel(0);}/* Subroutines return -1 if they do not want to turn neck; target vector otherwise *//* Add true as param if they should be forced to react.                            *//* They do nothing if target is already a valid angle.                             *//* Reaction to NECK_INTENTION *//* They have priority!        */Neck_Move* BS03Neck::bs02_neck_main() {  LOG_POL(3,<<"BS02_Neck: Executing main behaviour...");  //FPlayer *me=mdpInfo::mdp->me;  Angle minang,maxang;  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -