/*! */ void ShootGenerator::evaluateCourses( const WorldModel & wm ) { const double y_dist_thr2 = std::pow( 8.0, 2 ); const ServerParam & SP = ServerParam::i(); const PlayerObject * goalie = wm.getOpponentGoalie(); const AngleDeg goalie_angle = ( goalie ? ( goalie->pos() - M_first_ball_pos ).th() : 180.0 ); const Container::iterator end = M_courses.end(); for ( Container::iterator it = M_courses.begin(); it != end; ++it ) { double score = 1.0; if ( it->kick_step_ == 1 ) { score += 50.0; } if ( it->goalie_never_reach_ ) { score += 100.0; } if ( it->opponent_never_reach_ ) { score += 100.0; } double goalie_rate = 1.0; if ( goalie ) { #if 1 double variance2 = ( it->goalie_never_reach_ ? 1.0 // 1.0*1.0 : std::pow( 10.0, 2 ) ); double angle_diff = ( it->ball_move_angle_ - goalie_angle ).abs(); goalie_rate = 1.0 - std::exp( - std::pow( angle_diff, 2 ) / ( 2.0 * variance2 ) ); #else double angle_diff = ( it->ball_move_angle_ - goalie_angle ).abs(); goalie_rate = 1.0 - std::exp( - std::pow( angle_diff * 0.1, 2 ) // / ( 2.0 * 90.0 * 0.1 ) ); // / ( 2.0 * 40.0 * 0.1 ) ); // 2009-07 // / ( 2.0 * 90.0 * 0.1 ) ); // 2009-12-13 / ( 2.0 * 20.0 * 0.1 ) ); // 2010-06-09 #endif } double y_rate = 1.0; if ( it->target_point_.dist2( M_first_ball_pos ) > y_dist_thr2 ) { double y_dist = std::max( 0.0, it->target_point_.absY() - 4.0 ); y_rate = std::exp( - std::pow( y_dist, 2.0 ) / ( 2.0 * std::pow( SP.goalHalfWidth() - 1.5, 2 ) ) ); } #ifdef DEBUG_PRINT_EVALUATE dlog.addText( Logger::SHOOT, "(shoot eval) %d: score=%f(%f) pos(%.2f %.2f) speed=%.3f goalie_rate=%f y_rate=%f", it->index_, score * goalie_rate * y_rate, score, it->target_point_.x, it->target_point_.y, it->first_ball_speed_, goalie_rate, y_rate ); #endif score *= goalie_rate; score *= y_rate; it->score_ = score; } }
/*! */ void ShootGenerator::createShoot( const WorldModel & wm, const Vector2D & target_point ) { const AngleDeg ball_move_angle = ( target_point - M_first_ball_pos ).th(); const PlayerObject * goalie = wm.getOpponentGoalie(); if ( goalie && 5 < goalie->posCount() && goalie->posCount() < 30 && wm.dirCount( ball_move_angle ) > 3 ) { #ifdef DEBUG_PRINT dlog.addText( Logger::SHOOT, "%d: __ xxx goalie_count=%d, low dir accuracy", M_total_count, goalie->posCount() ); #endif return; } const ServerParam & SP = ServerParam::i(); const double ball_speed_max = ( wm.gameMode().type() == GameMode::PlayOn || wm.gameMode().isPenaltyKickMode() ? SP.ballSpeedMax() : wm.self().kickRate() * SP.maxPower() ); const double ball_move_dist = M_first_ball_pos.dist( target_point ); const Vector2D max_one_step_vel = ( wm.self().isKickable() ? KickTable::calc_max_velocity( ball_move_angle, wm.self().kickRate(), wm.ball().vel() ) : ( target_point - M_first_ball_pos ).setLengthVector( 0.1 ) ); const double max_one_step_speed = max_one_step_vel.r(); double first_ball_speed = std::max( ( ball_move_dist + 5.0 ) * ( 1.0 - SP.ballDecay() ), std::max( max_one_step_speed, 1.5 ) ); bool over_max = false; #ifdef DEBUG_PRINT_FAILED_COURSE bool success = false; #endif while ( ! over_max ) { if ( first_ball_speed > ball_speed_max - 0.001 ) { over_max = true; first_ball_speed = ball_speed_max; } if ( createShoot( wm, target_point, first_ball_speed, ball_move_angle, ball_move_dist ) ) { Course & course = M_courses.back(); if ( first_ball_speed <= max_one_step_speed + 0.001 ) { course.kick_step_ = 1; } #ifdef DEBUG_PRINT_SUCCESS_COURSE dlog.addText( Logger::SHOOT, "%d: ok shoot target=(%.2f %.2f)" " speed=%.3f angle=%.1f", M_total_count, target_point.x, target_point.y, first_ball_speed, ball_move_angle.degree() ); dlog.addRect( Logger::SHOOT, target_point.x - 0.1, target_point.y - 0.1, 0.2, 0.2, "#00ff00" ); char num[8]; snprintf( num, 8, "%d", M_total_count ); dlog.addMessage( Logger::SHOOT, target_point, num, "#ffffff" ); #endif #ifdef DEBUG_PRINT_FAILED_COURSE success = true; #endif #ifdef SEARCH_UNTIL_MAX_SPEED_AT_SAME_POINT if ( course.goalie_never_reach_ && course.opponent_never_reach_ ) { return; } ++M_total_count; #else return; #endif } first_ball_speed += 0.3; } #ifdef DEBUG_PRINT_FAILED_COURSE if ( success ) { return; } dlog.addText( Logger::SHOOT, "%d: xxx shoot target=(%.2f %.2f)" " speed=%.3f angle=%.1f", M_total_count, target_point.x, target_point.y, first_ball_speed, ball_move_angle.degree() ); dlog.addRect( Logger::SHOOT, target_point.x - 0.1, target_point.y - 0.1, 0.2, 0.2, "#ff0000" ); char num[8]; snprintf( num, 8, "%d", M_total_count ); dlog.addMessage( Logger::SHOOT, target_point, num, "#ffffff" ); #endif }