/*! */ void CrossGenerator::updateOpponents( const WorldModel & wm ) { const double opponent_dist_thr2 = std::pow( 20.0, 2 ); const Vector2D goal = ServerParam::i().theirTeamGoalPos(); const AngleDeg goal_angle_from_ball = ( goal - M_first_point ).th(); for ( AbstractPlayerCont::const_iterator p = wm.theirPlayers().begin(), end = wm.theirPlayers().end(); p != end; ++p ) { AngleDeg opponent_angle_from_ball = ( (*p)->pos() - M_first_point ).th(); if ( ( opponent_angle_from_ball - goal_angle_from_ball ).abs() > 90.0 ) { continue; } if ( (*p)->pos().dist2( M_first_point ) > opponent_dist_thr2 ) { continue; } M_opponents.push_back( *p ); #ifdef DEBUG_PRINT dlog.addText( Logger::PASS, "Cross opponent %d pos(%.1f %.1f)", (*p)->unum(), (*p)->pos().x, (*p)->pos().y ); #endif } }
/*! */ int TackleGenerator::predictOpponentsReachStep( const WorldModel & wm, const Vector2D & first_ball_pos, const Vector2D & first_ball_vel, const AngleDeg & ball_move_angle ) { int first_min_step = 50; #if 1 const ServerParam & SP = ServerParam::i(); const Vector2D ball_end_point = inertia_final_point( first_ball_pos, first_ball_vel, SP.ballDecay() ); if ( ball_end_point.absX() > SP.pitchHalfLength() || ball_end_point.absY() > SP.pitchHalfWidth() ) { Rect2D pitch = Rect2D::from_center( 0.0, 0.0, SP.pitchLength(), SP.pitchWidth() ); Ray2D ball_ray( first_ball_pos, ball_move_angle ); Vector2D sol1, sol2; int n_sol = pitch.intersection( ball_ray, &sol1, &sol2 ); if ( n_sol == 1 ) { first_min_step = SP.ballMoveStep( first_ball_vel.r(), first_ball_pos.dist( sol1 ) ); #ifdef DEBUG_PRINT dlog.addText( Logger::CLEAR, "(predictOpponent) ball will be out. step=%d reach_point=(%.2f %.2f)", first_min_step, sol1.x, sol1.y ); #endif } } #endif int min_step = first_min_step; for ( AbstractPlayerCont::const_iterator o = wm.theirPlayers().begin(), end = wm.theirPlayers().end(); o != end; ++o ) { int step = predictOpponentReachStep( *o, first_ball_pos, first_ball_vel, ball_move_angle, min_step ); if ( step < min_step ) { min_step = step; } } return ( min_step == first_min_step ? 1000 : min_step ); }