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

📄 bs03_neck_bmn.c

📁 这是bs球队的仿真2D比赛程序
💻 C
📖 第 1 页 / 共 4 页
字号:
  //Vector pol;#if 1  Vector pol;  FPlayer *me=mdpInfo::mdp->me;  pol.init_polar(45,minang);pol+=me->pos();  LOG_MOV(2,<< _2D << L2D(me->pos().x,me->pos().y,pol.x,pol.y,"#000080"));  pol.init_polar(25,maxang);pol+=me->pos();  LOG_MOV(2,<< _2D << L2D(me->pos().x,me->pos().y,pol.x,pol.y,"#000080"));#endif  Angle target=-1;  LOG_POL(3,<<"BS02_Neck: Checking for special situations!");    // care for neck intention types  if(!ignore_neck_intentions && neck_intention.type!=NECK_INTENTION_NONE) {    LOG_POL(3,<<"BS02_Neck: Got NECK_INTENTION type "<<neck_intention.type);    //cout << "\nGot NECK_INTENTION!" << endl;    switch(neck_intention.type) {      //case NECK_INTENTION_LOCKNECK: intention_lockneck(target);break;      //case NECK_INTENTION_LOOKTOGOAL: intention_looktogoal(target);break;      //case NECK_INTENTION_LOOKTOGOALIE: intention_looktogoalie(target);break;      //case NECK_INTENTION_LOOKTOBALL: intention_looktoball(target);break;      //case NECK_INTENTION_LOOKTOCLOSESTOPPONENT: intention_looktoclosestopponent(target);break;      //case NECK_INTENTION_CHECKOFFSIDE: intention_checkoffside(target);break;    case NECK_INTENTION_LOOKINDIRECTION: intention_lookindirection(target);break;    case NECK_INTENTION_PASSINDIRECTION: intention_passindirection(target);break;      //case NECK_INTENTION_SCANFORBALL: intention_scanforball(target);break;    case NECK_INTENTION_FACEBALL: intention_faceball(target);break;      //case NECK_INTENTION_EXPECTPASS: intention_expectpass(target);break;    case NECK_INTENTION_BLOCKBALLHOLDER: intention_blockballholder(target);break;    default: LOG_MOV(2,<<"BS02_Neck: 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;    }      } else {    // look always to ball in certain situations!    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(is_ball_in_feelrange_next_time()) {	LOG_POL(3,<<"BS02_Neck: Intercepting, but ball will be in feelrange next time!");      } else {	LOG_POL(3,<<"BS02_Neck: Intercepting, trying to look to ball...");	target=0;	if(intercept_look_mode==2) center_target=true;      }    }    //LOG_POL(2,<<"BS02_Neck: Opp "<<opp_players_near_ball.num<<" Own "<<own_players_near_ball.num);    if(target<0 && opp_has_ball_look_mode!=0 && opp_players_near_ball.num>0) {      LOG_POL(3,<<"BS02_Neck: 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) {      LOG_POL(3,<<"BS02_Neck: Teammates near ball, trying to look...");      target=0;      if(own_has_ball_look_mode==2) center_target=true;    }    if(!target) {      if(!mdpInfo::is_ball_pos_valid()) {	LOG_POL(3,<<"BS02_Neck: I don't know where the ball is, ignoring!");	target=-1;      } else {	ANGLE balldir=(new_ball_pos-my_new_pos).angle();	target=balldir.get_value();      }    }  }      // check, ob g?ltiger Winkel  if(target!=-1) {    LOG_POL(3,"BS02_Neck: Should look to "<<target<<" ("<<RAD2DEG(target)<<")!");    if(!mdpInfo::could_see_in_direction(target)) {      LOG_POL(3,"BS02_Neck: WARNING: I cannot look into that direction - ignoring!");      //LOG_ERR(2,"BS02_Neck: WARNING: I cannot look in the direction forced by NECK_INTENTION!");      //cerr << "\nBS02_Neck: WARNING: I cannot look in the direction forced by NECK_INTENTION!";      target=-1;center_target=false; // statt dessen Standardmove machen!    }  }  if(target==-1 || !center_target) {    LOG_POL(0,<<"TURN_NECK: I am free to look where I want!");    LOG_POL(3,<<"BS02_Neck: Starting value-based calculation of best neck direction!");    // hier kommt die Wertfunktion ins Spiel.    //long time1=Tools::get_current_ms_time();    Value oldtarget=-1;    if(target!=-1) {      oldtarget=target;    }    get_neckinfo_weights();    get_best_angle(target);        if(oldtarget!=-1) {      //Neck_Info next_info=get_neck_info(my_new_pos,oldtarget,new_ball_pos,cur_info);      if(fabs(target-oldtarget)<mdpInfo::view_angle_width_rad()*.5-DEG2RAD(4)) {	LOG_POL(3,<<"BS02_Neck: Modifying preset target by "<<fabs(target-oldtarget)<<".");      } //else {      //target=oldtarget;      //}    }  }  if(target>-1) {    #if 1    Vector pol;    FPlayer *me=mdpInfo::mdp->me;    pol.init_polar(40,target);pol+=me->pos();    LOG_MOV(3,<< _2D << L2D(me->pos().x,me->pos().y,pol.x,pol.y,"#cccccc"));#endif    LOG_POL(3,<< "BS02_Neck: Turning to " <<target<<" ("<<RAD2DEG(target)<<")...");    return Move_Factory::get_Neck_Turn_Abs(target);  }  LOG_POL(1,<<"BS02_Neck: WARNING: No neck turn executed!");  return Move_Factory::get_Neck_Move();}#endif/**************************************************************************** * Old Stuff - taken from BS01_Neck and only put here for reference! ****************************************************************************/#if 0/* This is the old daisy chain of BS01_Neck, only here for reference! */// highest priority first!if(mdpInfo::get_my_intention()==DECISION_TYPE_LOOKFORGOALIE)     look_for_goalie(target);       if(is_ball_in_feelrange_next_time())     ball_in_feelrange(target);       if((mdpInfo::get_my_intention() == DECISION_TYPE_INTERCEPTBALL) ||	(mdpInfo::get_my_intention() == DECISION_TYPE_INTERCEPTSLOWBALL) ||	(mdpInfo::get_my_intention() == DECISION_TYPE_EXPECT_PASS) )     intercept_ball(target);     check_offside(target);     look_to_ball(target);     if(mdpInfo::my_distance_to(mdpInfo::opponent_goalpos())<GOAL_NEAR)     goal_is_near(target);     if(mdpInfo::my_distance_to_ball()<BALL_NEAR)     ball_is_near(target);          do_nothing_special(target);  /* nothing to do, so simply scan */     /* Normal neck moves */Angle BS03Neck::look_for_goalie(Angle &target,bool force) {  if(!force && target>-1) return target;  Angle toobj=mdpInfo::my_abs_angle_to(mdpInfo::opponent_goalpos());  int nr=mdpInfo::mdp->his_goalie_number;  if(nr>=0) {    int i=mdpInfo::opponent_array_index(nr);    if(i>=0) {      if(!force && mdpInfo::age_playerpos(&(mdpInfo::mdp->his_team[i]))<MAX_GOALIE_AGE+1) {	LOG_MOV(2,<<"BS02_Neck - look_for_goalie: Goalie information newer than "		<< MAX_GOALIE_AGE+1 << " cycles");	return -1;      }      Angle toobj2=mdpInfo::my_abs_angle_to(mdpInfo::mdp->his_team[i].pos());      if(mdpInfo::could_see_in_direction(toobj2)) toobj=toobj2;      if(!mdpInfo::could_see_in_direction(toobj)) {	LOG_MOV(2,<<"BS02_Neck - look_for_goalie: Cannot look into goalie direction!");	return -1;      }      LOG_MOV(2,<<"BS02_Neck - look_for_goalie: Looking to goalie!");      target=toobj;return toobj;    }  }  LOG_MOV(2,<<"BS02_Neck - look_for_goalie: Goalie unknown!");  return -1;}Angle BS03Neck::look_to_ball(Angle &target,bool force) {  if(target>-1) return target;  if(!mdpInfo::is_ball_pos_valid()) {    LOG_MOV(2,<<"BS02_Neck - look_to_ball: Ball position not known!");    return -1;  }  if(WSinfo::ball->age<MAX_BALL_AGE+1) {    LOG_MOV(2,<<"BS02_Neck - look_to_ball: Ball information newer than "	    << MAX_BALL_AGE+1 << " cycles");    return -1;  }    Angle toobj=mdpInfo::my_abs_angle_to(mdpInfo::ball_next_time_pos_abs());  if(!mdpInfo::could_see_in_direction(toobj)) {    LOG_MOV(2,<<"BS02_Neck - look_to_ball: Cannot turn neck into ball direction!");    return -1;  }  LOG_MOV(2,<<"BS02_Neck - look_to_ball: Looking to ball!");  target=toobj;return target;  }Angle BS03Neck::ball_is_near(Angle &target,bool force) {  if(target>-1) return target;  int maxage=MAX_PLAYER_AGE;Angle toobj=-1,akttarget=-1;  int targetplayer=0;  for(int i=0;i<11;i++) {    if(!mdpInfo::mdp->my_team[i].alive) continue;    if(mdpInfo::mdp->my_team[i].number==mdpInfo::mdp->me->number) continue;    toobj=mdpInfo::my_abs_angle_to(mdpInfo::mdp->my_team[i].pos());    if(!mdpInfo::could_see_in_direction(toobj)) continue;    if(mdpInfo::my_distance_to(mdpInfo::mdp->my_team[i].pos())>MAX_TEAMMATE_DISTANCE) continue;    if(mdpInfo::age_playerpos(&mdpInfo::mdp->my_team[i])>maxage) {	      maxage=mdpInfo::age_playerpos(&mdpInfo::mdp->my_team[i]);      targetplayer=mdpInfo::mdp->my_team[i].number;akttarget=toobj;    }  }  for(int i=0;i<11;i++) {    if(!mdpInfo::mdp->his_team[i].alive) continue;    toobj=mdpInfo::my_abs_angle_to(mdpInfo::mdp->his_team[i].pos());    if(!mdpInfo::could_see_in_direction(toobj)) continue;     if(mdpInfo::my_distance_to(mdpInfo::mdp->his_team[i].pos())>MAX_OPPONENT_DISTANCE) continue;    if(mdpInfo::age_playerpos(&mdpInfo::mdp->his_team[i])>maxage) {	      maxage=mdpInfo::age_playerpos(&mdpInfo::mdp->his_team[i]);      targetplayer=-mdpInfo::mdp->his_team[i].number;akttarget=toobj;    }  }  if(targetplayer==0) {    LOG_MOV(2,<<"BS02_Neck - ball_is_near: No players to update available!");    return -1;  }  if(targetplayer>0) {     LOG_MOV(2,<<"BS02_Neck - ball_is_near: Looking to teammate #"<<targetplayer<<"!");  } else {    LOG_MOV(2,<<"BS02_Neck - ball_is_near: Looking to opponent #"<<-targetplayer<<"!");  }  target=akttarget;  return target;}Angle BS03Neck::goal_is_near(Angle &target,bool force) {  if(target>-1) return target;  Angle akttarget=-1;  LOG_MOV(2,<<"BS02_Neck - goal_is_near: Executing look_for_goalie.");  if(look_for_goalie(akttarget)>-1) {    target=akttarget;return target;  }  return -1;}Angle BS03Neck::intercept_ball(Angle &target,bool force) {  if(target>-1) return target;    if(is_ball_in_feelrange_next_time()) {    if(mdpInfo::my_distance_to(mdpInfo::opponent_goalpos())<30       && (!mdpInfo::is_ball_infeelrange()) // always look to goal when getting the ball!       && (mdpInfo::opponent_goalie_age()!=0)) {      LOG_MOV(2,<<"BS02_Neck - intercept_ball: Ball is just entering feelrange, looking "	      <<"to goal!");      return look_for_goalie(target,true);    }           LOG_MOV(2,<<"BS02_Neck - intercept_ball: Ball in feelrange, doing nothing");    return -1;  }  if(!mdpInfo::is_ball_pos_valid()) {    LOG_MOV(2,<<"BS02_Neck - intercept_ball: Ball position not known!");    return -1;  }  int maxage=1;  Value ballvel=WSinfo::ball->vel().norm();  if(ballvel<1.0) maxage=3;  else if(ballvel<1.5) maxage=2;  if(WSinfo::ball->age<maxage) {    LOG_MOV(2,<<"BS02_Neck - intercept_ball: Ball information newer than "<<maxage<<" cycles!");    return -1;  }    Angle toobj=mdpInfo::my_abs_angle_to(mdpInfo::ball_next_time_pos_abs());  if(!mdpInfo::could_see_in_direction(toobj)) {    LOG_MOV(2,<<"BS02_Neck - intercept_ball: Cannot turn neck into ball direction!");    return -1;  }  LOG_MOV(2,<<"BS02_Neck - intercept_ball: Looking to ball!");  time_intercept=mdpInfo::mdp->time_current;  target=toobj;return target;  }Angle BS03Neck::ball_in_feelrange(Angle &target,bool force) {  if(target>-1) return target;  if(mdpInfo::my_distance_to(mdpInfo::opponent_goalpos())<30     && (!mdpInfo::is_ball_infeelrange())   // always look to goal when getting the ball!     && (mdpInfo::opponent_goalie_age!=0)) {    LOG_MOV(2,<<"BS02_Neck - ball_in_feelrange: Ball is just entering feelrange, looking "	    <<"to goalie!");    return look_for_goalie(target,true);  }  int attacker=mdpInfo::opponent_closest_to(mdpInfo::my_pos_abs());    Vector attackerpos=0;int attackeridx=-1;Angle attackerdir=0;  if(attacker>0) {    attackerpos = mdpInfo::opponent_pos_abs(attacker);    attackeridx = mdpInfo::opponent_array_index(attacker);    attackerdir = mdpInfo::my_abs_angle_to(attackerpos);    if(attackeridx<0) {      LOG_MOV(2,<<"BS02_Neck - ball_in_feelrange: Could not find attacker #"<<attacker	      <<" in mdpstate!");      attacker=0;    }  }  else attacker=0;    if(!attacker || mdpInfo::my_distance_to(attackerpos)>ATTACKER_DIST) {    LOG_MOV(2,<<"BS02_Neck - ball_in_feelrange: No attacker nearby!");  } else if(mdpInfo::age_playerpos(&mdpInfo::mdp->his_team[attackeridx])<MAX_ATTACKER_AGE+1) {    LOG_MOV(2,<<"BS02_Neck - ball_in_feelrange: Attacker information newer than "	     <<MAX_ATTACKER_AGE+1 <<" cycles!");  } else if(!mdpInfo::could_see_in_direction(attackerdir)) {    LOG_MOV(2,<<"BS02_Neck - ball_in_feelrange: Cannot turn neck to attacker #"	    <<attacker<<"!");  } else {    LOG_MOV(2,<<"BS02_Neck - ball_in_feelrange: Turning neck to attacker #"<<attacker<<"!");    target=attackerdir;    return target;  }  if(mdpInfo::my_distance_to(mdpInfo::opponent_goalpos())<GOAL_NEAR) {          Angle toobj=mdpInfo::my_abs_angle_to(mdpInfo::opponent_goalpos());    int nr=mdpInfo::mdp->his_goalie_number;    if(nr<0) {      LOG_MOV(2,<<"BS02_Neck - ball_in_feelrange: Goalie unknown!");      return -1;    }    int i=mdpInfo::opponent_array_index(nr);    if(i<0) {      LOG_MOV(2,<<"BS02_Neck - ball_in_feelrange: Could not find goalie in mdpstate!");      return -1;    }    if(mdpInfo::age_playerpos(&mdpInfo::mdp->his_team[i])>=MAX_GOALIE_AGE+1) {      Angle toobj2=mdpInfo::my_abs_angle_to(mdpInfo::mdp->his_team[i].pos());      if(mdpInfo::could_see_in_direction(toobj2)) toobj=toobj2;        if(mdpInfo::could_see_in_direction(toobj)) {	LOG_MOV(2,<<"BS02_Neck - ball_in_feelrange: Looking to goalie!");	target=toobj;return target;      }    } else {      LOG_MOV(2,<<"BS02_Neck - ball_in_feelrange: No need to look to goal, so do nothing");      return -1;    }  }  return -1;} Angle BS03Neck::check_offside(Angle &target,bool force) {  if(target>-1) return target;  if(mdpInfo::is_ball_infeelrange() || is_ball_in_feelrange_next_time()) {    LOG_MOV(2,<<"BS02_Neck - check_offside: I am carrying the ball, no check needed!");    return -1;  }    if(mdpInfo::mdp->me->pos_x.v > DeltaPositioning::get_my_offence_line()-OFFENCE_LINE_DIST) {        Value line=-1000,pline=-1000,posx;    int ind=-1,pind=-1;    for(int i=0;i<11;i++) {      if(!mdpInfo::mdp->his_team[i].alive) continue;      posx=mdpInfo::mdp->his_team[i].pos_x.v;      if(posx>pline) {line=pline;ind=pind;pline=posx;pind=i;continue;}      if(posx>line) {line=posx;ind=i;}    }    if(ind<0) return -1;    //LOG_MOV(2,<<"BS02_Neck - check_offside: Last opponent is #"    //    <<mdpInfo::mdp->his_team[ind].number<<"!");    if(mdpInfo::age_playerpos(&mdpInfo::mdp->his_team[ind])<OFFENCE_LINE_AGE+1) {            LOG_MOV(2,<<"BS02_Neck - check_offside: Last opponent information newer than "	      <<OFFENCE_LINE_AGE+1<<" cycles");      return -1;    }    Angle toobj=mdpInfo::my_abs_angle_to(mdpInfo::mdp->his_team[ind].pos());    if(!mdpInfo::could_see_in_direction(toobj)) {      LOG_MOV(2,<<"BS02_Neck - check_offside: Cannot turn neck to last opponent!");      return -1;    }    LOG_MOV(2,<<"BS02_Neck - check_offside: Looking to last opponent #"	    <<mdpInfo::mdp->his_team[ind].number<<"!");    target=toobj;    return target;  }  return -1;}     Angle BS03Neck::do_nothing_special(Angle &target,bool force) {  if(target>-1) return target;    if(mdpInfo::my_distance_to(mdpInfo::opponent_goalpos())<30     && (mdpInfo::opponent_goalie_age()>1)) {    LOG_MOV(2,<<"BS02_Neck - do_nothing_special: Nothing to do, looking "	    <<"to goalie!");    target = look_for_goalie(target,true);    if(target>-1) return target;  }  int oldestval=100000;int oldestrad=-1;int i;  for(i=0;i<16;i++) {    Angle ang=i*2.*PI/16;    if(!mdpInfo::could_see_in_direction(ang)) {      i++; // don't let the sectors overlap so often [dirty stuff!]      continue;    }    if(radian_last_seen[i]<oldestval) {      oldestval=radian_last_seen[i];oldestrad=i;    }  }  target=oldestrad*2.*PI/16;  LOG_MOV(2,<<"BS02_Neck - do_nothing_special: Turning to radian "<<oldestrad	  << " at "<<RAD2DEG(target)<<", last seen "	  <<mdpInfo::mdp->time_current-radian_last_seen[oldestrad]<<" cycles ago");  return target;}#endif

⌨️ 快捷键说明

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