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

📄 bs03_neck_bmn.c

📁 这是bs球队的仿真2D比赛程序
💻 C
📖 第 1 页 / 共 4 页
字号:
  if(viewcone.inside(HIS_GOAL_RIGHT_CORNER)) {    neckinfo.opp_goal_right=0;  } else {    neckinfo.opp_goal_right++;  }  if(viewcone.inside(HIS_GOAL_LEFT_CORNER)) {    neckinfo.opp_goal_left=0;  } else {    neckinfo.opp_goal_left++;  }  if(viewcone.inside(HIS_GOAL_CENTER)) {    neckinfo.opp_goal=0;  } else {    neckinfo.opp_goal++;  }    return neckinfo;    }void BS03Neck::get_neckinfo_weights() {  ball_weight=0,goalie_weight=0;  //if(WSinfo::is_ball_pos_valid()) {  if(WSinfo::ball->age>MAX_BALL_AGE) ball_weight=20;  else {    ball_weight=(1-distance_to_ball/100);    ball_weight*=(0.05+WSinfo::ball->vel.norm()/2);    if((mdpInfo::get_my_intention() == DECISION_TYPE_INTERCEPTBALL) ||       (mdpInfo::get_my_intention() == DECISION_TYPE_INTERCEPTSLOWBALL) ||       (mdpInfo::get_my_intention() == DECISION_TYPE_EXPECT_PASS) ) {      ball_weight*=2;    }        if(players_near_ball.num>0) {      if(WSinfo::ball->age==0) {	need_lookto_ball=true;      } else {	ball_weight*=2.5;  // Ball nicht aus den Augen verlieren!	//DBLOG_POL(1,"Ball near other player, so look at it!");      }    }  }  //}  if(mdpInfo::my_distance_to(mdpInfo::opponent_goalpos())<30) {    if(ballinfeelrange) {      goalie_weight=0.8;      if(mdpInfo::my_distance_to(mdpInfo::opponent_goalpos())<16) {	goalie_weight=0.95;      }    }    else goalie_weight=0.3;  } else goalie_weight=0;    sector_weight=1.2;  //get_single_sector_weights();  opp_weight=1.5;  team_weight=1.0;    DBLOG_POL(3,"Calculated value weights are");  DBLOG_POL(3,"ball_weight="<<ball_weight<<", goalie_weight="<<goalie_weight	  <<", sector_weight="<<sector_weight);}/** calculate the individual weight for every sector on field */void BS03Neck::get_single_sector_weights() {  Set2d *high_importance=0;  Set2d *med_importance=0;    switch(DeltaPositioning::get_role(WSinfo::me->number)) {  case PT_DEFENDER:    /* rectangle around the enemy offside line, including me */    high_importance =      new XYRectangle2d(Vector(WSinfo::my_team_pos_of_offside_line()-10,			       FIELD_BORDER_Y),			Vector(Tools::max(WSinfo::my_team_pos_of_offside_line()+20,				   WSinfo::me->pos.x+5),-FIELD_BORDER_Y));    break;  case PT_MIDFIELD:    high_importance =      new XYRectangle2d(Vector(WSinfo::me->pos.x-10,FIELD_BORDER_Y),			Vector(FIELD_BORDER_X,-FIELD_BORDER_Y));    break;  case PT_ATTACKER:    high_importance =      new Quadrangle2d(WSinfo::me->pos,HIS_GOAL_CENTER,PENALTY_AREA_WIDTH,PENALTY_AREA_WIDTH);    med_importance =      new XYRectangle2d(Vector(WSinfo::me->pos.x-10,FIELD_BORDER_Y),			Vector(FIELD_BORDER_X,-FIELD_BORDER_Y));    break;  }  if(high_importance) {    DBLOG_DRAW(0,*high_importance);    //DBLOG_POL(0,"high importance " << *high_importance);  }  if(med_importance) {    DBLOG_DRAW(0,*med_importance);    //DBLOG_POL(0,"med importance " << *high_importance);  }  /* now value the sectors... */  single_sector_divisor=0;  Vector pos;  pos.y=-(SECT_Y-1)/2*yunit;  for(int y=0; y<SECT_Y;y++, pos.y+= yunit) {    pos.x=-(SECT_X-1)/2*xunit;    for(int x=0;x<SECT_X;x++,pos.x+= xunit) {      if(high_importance && high_importance->inside(pos)) single_sector_weight[x][y]=1;      else if(med_importance && med_importance->inside(pos)) single_sector_weight[x][y]=.5;      else single_sector_weight[x][y]=0;      single_sector_divisor+=single_sector_weight[x][y];    }  }        delete high_importance; delete med_importance;}/** Get the value of a given neckinfo *//*  This one really does the trick... */Value BS03Neck::get_neckinfo_value(Neck_Info neckinfo) {  //Value totalval=0;  Value val_ball=neckinfo.ball;  Value val_sector;  Value val_goalie;  Value val_opp;  Value val_team;    val_sector=(neckinfo.sector_avg-(cur_info.sector_avg+1));  if(neckinfo.opp_goalie>=0) val_goalie=neckinfo.opp_goalie;  else val_goalie=(2*neckinfo.opp_goal+neckinfo.opp_goal_left+neckinfo.opp_goal_right)/4.0;  if(val_goalie==1) val_goalie=0;  // nicht zweimal nacheinander zum Goalie schauen!  val_opp=(neckinfo.opponents-(cur_info.opponents+1));  val_team=(neckinfo.teammates-(cur_info.teammates+1));    DBLOG_POL(4,"val_ball="<<val_ball*ball_weight	    <<", val_sector="<<val_sector*sector_weight	    <<", val_goalie="<<val_goalie*goalie_weight	    <<", val_opp="<<val_opp*opp_weight);  return val_ball*ball_weight+val_sector*sector_weight+val_goalie*goalie_weight    + val_opp*opp_weight+val_team*team_weight;}Angle BS03Neck::get_best_angle(Angle &target) {  //Vector my_new_pos,my_new_vel,new_ball_pos,new_ball_vel;  //Angle my_new_angle;  //LOG_MOV(2,<<"_2D_ CIRCLE col=ff0000 ("<<new_ball_pos.x<<","<<new_ball_pos.y<<",3);");    ANGLE myang=ANGLE(my_new_angle);  ANGLE startang=myang+ServerOptions::minneckang;  ANGLE preset;  if(target!=-1) preset=ANGLE(target);    Angle bestang=-1;  Value bestval=10000000;  for(int i=0;i<NUM_ANGLES;i++) {    ANGLE aktang=startang+ ANGLE(      i*(ServerOptions::maxneckang-ServerOptions::minneckang).get_value()/(NUM_ANGLES-1.0)      );        /* ignore angle if preset target can't be seen */    if(target!=-1 && fabs((aktang-preset).get_value()) >       (mdpInfo::next_view_angle_width()-ANGLE(DEG2RAD(8/.5))).get_value()*.5) {      continue;    }    #if 0    Vector pol;    pol.init_polar(20,aktang.get_value());pol+=WSinfo::me->pos;    //DBLOG_DRAW(2,L2D(WSinfo::me->pos.x,WSinfo::me->pos.y,pol.x,pol.y,"#cc88ff"));#endif    //long time1=Tools::get_current_ms_time();      next_info=get_neck_info(my_new_pos,aktang,new_ball_pos,cur_info);    //long time2=Tools::get_current_ms_time();        if(ballinfeelrange) next_info.ball=0;    Value dum=get_neckinfo_value(next_info);    DBLOG_POL(4,"aktang: "<<aktang<<", value: "<<dum);    if(dum<bestval) {      bestval=dum;bestang=aktang.get_value();    }    //long time2=Tools::get_current_ms_time();    //LOG_MOV(2,<<"BS02_Neck: Check needed "<<time2-time1<<" ms.");  }  if(bestang!=-1) target=bestang;  return target;  }Angle BS03Neck::neck_value_based(Angle target) {  DBLOG_POL(0,"Calculating value based neck policy...");  get_neckinfo_weights();  return get_best_angle(target);}#else/*********************************************************************** * New (sector based) default neck policy ***********************************************************************/Angle BS03Neck::neck_default(Angle preset) {  ANGLE minang,maxang;  minang=Tools::my_minimum_abs_angle_to_see();  maxang=Tools::my_maximum_abs_angle_to_see();  ANGLE myang=ANGLE(my_new_angle);  ANGLE startang=myang+ServerOptions::minneckang;  Vector mypos=my_new_pos;    // TODO: preset  int mark[SECT_X][SECT_Y];  for(int x=0;x<SECT_X;x++)    for(int y=0;y<SECT_Y;y++)      mark[x][y]=0;    Cone2d cone(mypos,maxang,minang); // cone is the _invisible_ area!  Vector dum1,dum2;  dum1=10*cone.dir1;  dum2=10*cone.dir2;  DBLOG_DRAW(0,"LINE("<<mypos.x<<","<<mypos.y<<","<<(mypos+dum1).x<<","<<(mypos+dum1).y<<");");  DBLOG_DRAW(0,"LINE("<<mypos.x<<","<<mypos.y<<","<<(mypos+dum2).x<<","<<(mypos+dum2).y<<");");  WSpset players=WSinfo::valid_opponents;players+=WSinfo::valid_teammates_without_me;  for(int p=0;p<players.num;p++) {    int x=(int)((players[p]->pos.x+FIELD_BORDER_X)/xunit);    int y=(int)((players[p]->pos.y+FIELD_BORDER_Y)/yunit);    mark[x][y]=-1;    if(players[p]->age>2) {      for(int xi=x-1;xi<=x+1;xi++)	for(int yi=y-1;yi<=y+1;yi++) {	  if(xi>=0 && xi<SECT_X && yi>=0 && yi<SECT_Y) mark[xi][yi]=-1;	}    }  }    long maxage=0;  Vector pos;  pos.y=-(SECT_Y-1)/2*yunit;  for(int y=0; y<SECT_Y;y++, pos.y+= yunit) {    pos.x=-(SECT_X-1)/2*xunit;    for(int x=0;x<SECT_X;x++,pos.x+= xunit) {      if(!mark[x][y]) continue; // no objects!      if((mypos-pos).sqr_norm()<SQR_MAX_VISIBLE_DISTANCE && !cone.inside(pos)) {	if(cur_info.sector[x][y]>maxage) maxage=cur_info.sector[x][y];      } else mark[x][y]=0;    }  }  #if 1  pos.y=-(SECT_Y-1)/2*yunit;  for(int y=0; y<SECT_Y;y++, pos.y+= yunit) {    pos.x=-(SECT_X-1)/2*xunit;    for(int x=0;x<SECT_X;x++,pos.x+= xunit) {      if(mark[x][y]<0) {	DBLOG_DRAW(0,"STRING("<<pos.x<<","<<pos.y<<",\""<<cur_info.sector[x][y]<<"\");");      }    }  }#endif    Angle bestang=-1;  int maxagesect=0;  Value bestage=0;  for(int i=0;i<NUM_ANGLES;i++) {    ANGLE aktang=startang+ ANGLE(i*(ServerOptions::maxneckang-ServerOptions::minneckang).get_value()				 /(NUM_ANGLES-1.0));        /* ignore angle if preset target can't be seen */    //if(target!=-1 && fabs((aktang-preset).get_value()) >    //   (mdpInfo::next_view_angle_width()-ANGLE(DEG2RAD(8/.5))).get_value()*.5) {    //  continue;    //}    Vector dum;    dum.init_polar(1.0,aktang);    Cone2d viewcone(mypos,dum,ANGLE(Tools::next_view_angle_width().get_value()-DEG2RAD(7)));    int mas=0;    Value age=0;    int sectcnt=0;    pos.y=-(SECT_Y-1)/2*yunit;    for(int y=0; y<SECT_Y;y++, pos.y+= yunit) {      pos.x=-(SECT_X-1)/2*xunit;      for(int x=0;x<SECT_X;x++,pos.x+= xunit) {	if(mark[x][y]>=0) continue;	if(!viewcone.inside(pos)) continue;	if(cur_info.sector[x][y]>=maxage) mas++;	age+=cur_info.sector[x][y];	sectcnt++;      }    }    if(sectcnt==0) continue;    //age/=sectcnt;    if(mas>maxagesect || (mas==maxagesect && age>bestage)) {      maxagesect=mas;      bestang=aktang.get_value();      bestage=age;    }      }  if(bestang<0) {    DBLOG_POL(0,"WARNING: No default neck move selected!");    return -1;  }  DBLOG_POL(0,"neck_default selected ang "<<bestang<<" ("<<RAD2DEG(bestang)<<"); maxage sect="	    <<maxagesect<<", avg age="<<bestage);	  return bestang;}#endif  // VALUE_BASED/*********************************************************************** * Simple moves (or special moves) ***********************************************************************//** Special consideration when defense is based on direct opponents.*/Angle BS03Neck::check_direct_opponent_defense(){  MYLOG_POL(0,"TURN NECK: check direct opponent defense ");  Angle target=-1;  if(    ! ignore_neck_intentions       && neck_intention.type == NECK_INTENTION_DIRECTOPPONENTDEFENSE)   {    target = intention_direct_opponent_defense();    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 = "<<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;    }  }  else    MYLOG_POL(0,"TURN NECK: neck_intention.type =="<<neck_intention.type);  return target;}/** Fallback routine if ball not known - looks directly to guessed ball pos! */Angle BS03Neck::check_search_ball() {  MYLOG_POL(0,"TURN NECK: check search ball ");  if(WSinfo::ball->age>=MAX_BALL_AGE /*|| need_lookto_ball*/) {    //cerr << "\nP"<<WSinfo::me->number<<"cyc #"<<WSinfo::ws->time<<": Search ball!";    if(got_update) need_lookto_ball=false;    if(got_update && ball_already_searched) {      DBLOG_POL(1,"check_search_ball(): Ball not at guessed position, continuing");      return -1;  // Ball not at guessed position    }    if(!Tools::could_see_in_direction(dir_to_ball.get_value())) {      DBLOG_POL(1,"check_search_ball(): Cannot look to guessed ballpos!");      return -1;     }    DBLOG_POL(0,"check_search_ball(): Looking to guessed ballpos "<<dir_to_ball<<"!");    ball_already_searched=true;      return dir_to_ball.get_value();  }  return -1;}Angle BS03Neck::check_relevant_teammates() {  MYLOG_POL(0,"TURN NECK: Check relevant teammates ");  Angle target=-1; // default  center_target=false; // default  PPlayer teammate;    for(int i=0; i<WSinfo::num_relevant_teammates;i++){    if(WSinfo::get_teammate(WSinfo::relevant_teammate[i],teammate)){      MYLOG_POL(0,"TURN NECK: Checking relevant teammate "	      <<teammate->number<<" age "<<teammate->age);      if(teammate->age >1){	target=(teammate->pos - WSinfo::me->pos).arg();	Vector pol;	pol.init_polar(25,target);	pol+=WSinfo::me->pos;	MYLOG_DRAW(0, L2D(WSinfo::me->pos.x,WSinfo::me->pos.y,pol.x,pol.y,"#000080"));	if(!Tools::could_see_in_direction(target)) {	  MYLOG_POL(0,"TURN NECK: Cannot look in direction of teammate "<<teammate->number);	  target = -1;	}	else{	  MYLOG_POL(0,"TURN NECK: YEP! Let's look to teammate  "<<teammate->number		  <<" in dir "<<RAD2DEG(target));	  center_target=true;	  break;	}      } // if teammate age > 1    } // if teammate is alive  } // for all relevant teammates  return target;}Angle BS03Neck::check_neck_intention() {  MYLOG_POL(0,"Entered neck intention type: "<<neck_intention.type<<" ignore_neck_intentions: "<<ignore_neck_intentions);  Angle target=-1;

⌨️ 快捷键说明

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