📄 dribble_between.c
字号:
targetTimeCounter = 0; }else if(isOldTargetInBadAngleButNewNot){ lastTarget = dest; dribbleAroundTargetValue = bestValue; dribbleAround->resetRequest(); targetTimeCounter = 0; } else{ dest = lastTarget; dribbleAroundTargetValue = dribbleAroundTargetValue; targetTimeCounter++; } if(iAmAttacked()){ POL("I am attacked, going straight"); dribbleAroundTargetValue = 10; dest.init_polar(10,WSinfo::me->ang); dest += WSinfo::me->pos; } return dest;}bool DribbleBetween::is_dribble_safe(bool getcmd){ isDribblingSafe = false; dribblingInsecure = false; setRelevantOpponents(); // has to be here to generate stats // otherwise move a little down dribbleAroundTarget = getTargetPos(); bool isTargetVeryCool = dribbleAroundTargetValue <= 5; bool amIAttacked = iAmAttacked();#ifdef DRIBBLE_STATS stats.updateTestDribbling(); stats.getStatistics();#endif /* if(WSinfo::me->pos.x > FIELD_BORDER_X-3){ POL("Dribblink not safe: too close to field border"); return false; } */ //if(WSinfo::me->pos.x < -FIELD_BORDER_X+16){ //if (WSinfo::me->pos.distance(MY_GOAL_CENTER) < 25.0 ) { //CHANGE BY TG /* if(WSinfo::me->pos.distance( WSinfo::ball->pos ) >= 0.95*WSinfo::me->kick_radius //CHANGE BY TG (old value == 0.98) && !(mode==DB_NO_OPP && fabs((WSinfo::ball->vel.ARG() - WSinfo::me->ang).get_value_mPI_pPI())<PI/5)){ POL("Dribblink not safe: ball not close enough, not in my dir or opp ahead"); return false; } */ /* if ( fabs(FIELD_BORDER_Y) - fabs(WSinfo::me->pos.y) < 2.0 && fabs ( fabs ( WSinfo::me->ang.get_value_mPI_pPI() ) - PI/2.0 ) < PI/4.0 ) { POL("Dribblink not safe: ball too close to field side border (and heading towards it)."); return false; }*/ /* if(fabs(Tools::my_angle_to(dribbleAroundTarget).get_value_mPI_pPI())>DEG2RAD(90)){ POL("Looking in wrong dir. Do not dribble."); return false; } */ /* if ( fabs(FIELD_BORDER_Y) - fabs(WSinfo::me->pos.y) < WSinfo::me->kick_radius*1.1 ) { POL("Dribblink not safe: I am too close to field border."); return false; } */ // TODO: this aint make use of dribble_around /* if(mode!=DB_NO_OPP){ if(WSinfo::me->pos.distance(opps[0]->pos)<1){ POL("Dribblink not safe: Opponent in range."); return false; } } */ if(mode==DB_TOO_MANY_OPP){ POL("Dribblink not safe: Too many opponents in range"); return false; } if(mode==DB_ONE_OPP||mode==DB_TWO_OPP){ if(WSinfo::ws->time - opps[0]->time > 2 && opps[0]->pos.distance(WSinfo::me->pos)<4){ POL("Dribblink not safe: Opponent age too old."); dribblingInsecure=true; //return false; } } if(mode != DB_NO_OPP){ if(opps[0]->pos.distance(WSinfo::ball->pos)< opps[0]->kick_radius){ POL("Dribblink not safe: Opponent has ball."); return false; } } // TODO: account for catchable_area_l /* if(mode==DB_TWO_OPP && opps[0]->pos.distance(WSinfo::me->pos)< 1.0*(WSinfo::me->kick_radius+opps[0]->kick_radius) // two very close opps && opps[1]->pos.distance(WSinfo::me->pos)< 1.0*(WSinfo::me->kick_radius+opps[1]->kick_radius)){ // two very close opps POL("Dribblink not safe: Two opps very close to me"); return false; } */ /* if(mode==DB_TWO_OPP && opps[0]->pos.distance(opps[1]->pos)<2.5*WSinfo::me->kick_radius){ POL("Dribblink not safe: Two opps very close to each other"); return false; } */ if(mode==DB_TWO_OPP && fabs(WSinfo::me->pos.y)>FIELD_BORDER_X-3){ POL("Dribblink not safe: Two opps close to me, I'm close to border -- I'm cornered!"); dribblingInsecure=true; } isDribblingSafe=true; bool res; if(getcmd){ res = get_cmd(cachedCmd); cachedCmdTime = WSinfo::ws->time; }else res = true; if(res) POL("Dribblink is safe."); return res;}bool DribbleBetween::is_dribble_insecure(){ return dribblingInsecure;}bool DribbleBetween::iAmAttacked(){ WSpset opps; bool oppVeryClose; bool oppInMyDir; bool thereIsOppInMyDir = false; bool thereIsVeryCloseOpp = false; static bool result = false;; static int time = -1; if(time == WSinfo::ws->time){ return result; } opps = WSinfo::valid_opponents; opps.keep_and_sort_closest_players_to_point(2,WSinfo::me->pos); for(int i=0;i<opps.num;i++){ oppVeryClose = opps[i]->pos.distance(WSinfo::me->pos)<2; oppInMyDir = fabs(Tools::my_angle_to(opps[i]->pos).get_value_mPI_pPI())<PI/4; if(oppVeryClose) thereIsVeryCloseOpp = true; if(oppInMyDir && oppVeryClose) thereIsOppInMyDir = true; } time = WSinfo::ws->time; result = thereIsVeryCloseOpp && !thereIsOppInMyDir; return result;}bool DribbleBetween::get_cmd(Cmd& cmd){ if(cachedCmdTime == WSinfo::ws->time){ cmd = cachedCmd; dribbleAround->setDribbled(true); lastDribbleTime = WSinfo::ws->time; return true; }#ifdef DRIBBLE_STATS stats.updateGetCmd();#endif long starttime = Tools::get_current_ms_time(); /* * DEBUGGING PURPOSES set_target(Vector(50,WSinfo::me->pos.y)); is_dribble_safe(false); if(!isDribblingSafe && dribbleAround->get_dribble_straight_cmd(cmd)) return true; */ DRAW(C2D(dribbleAroundTarget.x,dribbleAroundTarget.y,WSinfo::me->kick_radius,"red")); // keep the ball in own kickrange if 2nd opponent ahead bool keepBall = (mode==DB_TWO_OPP && (opps[1]->pos.distance(WSinfo::me->pos)<4) && fabs(Tools::my_angle_to(opps[1]->pos).get_value_mPI_pPI())<PI/3); bool isOppJustAhead = mode!=DB_NO_OPP && (opps[0]->pos.distance(WSinfo::me->pos)<4) && (opps[0]->pos.distance(WSinfo::me->pos)>.8*(WSinfo::me->kick_radius+opps[0]->kick_radius)) && fabs(Tools::my_angle_to(opps[0]->pos).get_value_mPI_pPI())<PI/2.5; int maxSpeed; if(mode==DB_NO_OPP){ maxSpeed = 100; }else if(isOppJustAhead){ maxSpeed = 100; } else{ maxSpeed = 100; } dribbleAround->set_max_speed(maxSpeed); dribbleAround->set_target(dribbleAroundTarget); dribbleAround->set_keepBall(keepBall); bool ret = dribbleAround->get_cmd(cmd); if(dribbleAround->isDribbleInsecure()) dribblingInsecure=true; dribbleAround->setDribbled(false); long endtime = Tools::get_current_ms_time(); POL("DribbleBetween took "<< (endtime-starttime)<< "ms."); return ret;}bool DribbleBetween::is_neck_req_set(){ return dribbleAround->neckReqSet;}ANGLE DribbleBetween::get_neck_req(){ return dribbleAround->neckReq;}void DribbleBetween::set_target(const Vector& t){ dribbleTo = t; POL("DribbleTo set to " << t );}Vector DribbleBetween::get_target(){ return dribbleTo;}DribbleBetween::~DribbleBetween(){ // do not delete: could be deleted twice! (singleton!) // delete dribbleAround;}DribbleBetween::Stats::Stats(){#ifdef DRIBBLE_STATS dribbleStates[0].closestOpp = NULL; dribbleStates[0].xDistToClosestOpp = 0; dribbleStates[0].actionTaken = DA_NO_ACTION; dribbleStates[0].actionSucceeded = false; dribbleStates[0].didDribble = false; for(int i=1;i<DRIBBLE_STATS_BUFFER_LENGTH;i++){ dribbleStates[i] = dribbleStates[0]; } bufferPos=0;#endif}// #define MARK(X) cerr << "mark " << #X << endl << flush;void DribbleBetween::Stats::updateTestDribbling(){#ifdef DRIBBLE_STATS db = DribbleBetween::getInstance(); static const int maxHorizon = 5; // cycles until an action has "failed" if(dribbleStates[bufferPos].didDribble){ dribbleStates[bufferPos].actionTaken = db->dribbleAround->lastActionTaken; dribbleStates[bufferPos].actionSucceeded = dribbleStates[bufferPos].didDribble // && WSmemory::team_last_at_ball() // doesnt make sense since there may have been lots of time in between && WSinfo::ws->time - dribbleStates[bufferPos].time<maxHorizon; } ++bufferPos; bufferPos = bufferPos % DRIBBLE_STATS_BUFFER_LENGTH; dribbleStates[bufferPos].time = WSinfo::ws->time; dribbleStates[bufferPos].didDribble = false; dribbleStates[bufferPos].actionTaken = DA_NO_ACTION; if(db->mode != DB_NO_OPP){ dribbleStates[bufferPos].closestOpp = db->opps[0]; dribbleStates[bufferPos].xDistToClosestOpp = db->opps[0]->pos.x-WSinfo::me->pos.x; } else{ dribbleStates[bufferPos].closestOpp = NULL; dribbleStates[bufferPos].xDistToClosestOpp = FIELD_BORDER_X; }#endif}void DribbleBetween::Stats::updateGetCmd(){#ifdef DRIBBLE_STATS dribbleStates[bufferPos].didDribble = true;#endif}void DribbleBetween::Stats::getStatistics(){#ifdef DRIBBLE_STATS int pos = ((bufferPos<1)? DRIBBLE_STATS_BUFFER_LENGTH-1:bufferPos-1); const DribbleState ds = dribbleStates[pos]; if(!ds.didDribble) return; POL("LastDribble: ("<< ds.time << ") " << dribbleActionNames[ds.actionTaken] << "\t" << (ds.actionSucceeded?"Success":"Failure"));#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -