Example #1
0
/**
 * Update data used by tackle.
 * \param agent.
 */
void Tackler::UpdateTackleData(const Agent & agent)
{
    if (mAgentID == agent.GetAgentID())  {
        return; /** no need to update */
    }

    mAgentID = agent.GetAgentID();

    const BallState & ball_state     = agent.GetWorldState().GetBall();
    const PlayerState & player_state = agent.GetSelf();
    Vector ball_2_player = (ball_state.GetPos() - player_state.GetPos()).Rotate(-player_state.GetBodyDir());

    Vector ball_vel;
    mMaxTackleSpeed = -1.0;
    mDirMap.clear();

    const double max_tackle_power = ServerParam::instance().maxTacklePower();
    const double min_back_tackle_power = ServerParam::instance().maxBackTacklePower();

    double factor = 1.0 - 0.5 * (fabs(Deg2Rad(ball_2_player.Dir())) / M_PI);

    for (AngleDeg tackle_angle = -180.0 + FLOAT_EPS; tackle_angle <= 180.0 + FLOAT_EPS; tackle_angle += 1.0) {
    	Vector ball_vel(ball_state.GetVel());
        double eff_power = (min_back_tackle_power + ((max_tackle_power - min_back_tackle_power) * (1.0 - fabs(Deg2Rad(tackle_angle)) / M_PI))) * ServerParam::instance().tacklePowerRate();
        eff_power *= factor;
        ball_vel += Polar2Vector(eff_power, tackle_angle + player_state.GetBodyDir());
        ball_vel = ball_vel.SetLength(Min(ball_vel.Mod(), ServerParam::instance().ballSpeedMax()));

        int angle_idx = ang2idx(tackle_angle);
        int dir_idx = dir2idx(ball_vel.Dir());

        mTackleAngle[angle_idx] = tackle_angle;
        mBallVelAfterTackle[angle_idx] = ball_vel;
        mDirMap[dir_idx].push_back(std::make_pair(angle_idx, ang2idx(tackle_angle + 1.0)));

        if (ball_vel.Mod() > mMaxTackleSpeed){
            mMaxTackleSpeed = ball_vel.Mod();
        }

        if (ball_vel.Mod() * ServerParam::instance().ballDecay() < FLOAT_EPS) {
        	mCanTackleStopBall = true;
        	mTackleStopBallAngle = tackle_angle;
        }
    }
//
//
//    for (AngleDeg tackle_angle = -180.0 + 0.3; tackle_angle <= 180.0 + FLOAT_EPS; tackle_angle += 1.0) {
//    	Vector ball_vel = GetBallVelAfterTackle(agent, tackle_angle);
//    	AngleDeg tackle_angle2 = 0.0;
//    	GetTackleAngleToDir(agent, ball_vel.Dir(), & tackle_angle2);
//
//    	std::cout << tackle_angle << " " << tackle_angle2 << std::endl;
//    }
//
//    exit(0);
}
Example #2
0
void AI_logPlayer::recordLog(WorldModel *wm, QList<RobotCommand> RCs)
{
    log_chunk data_chunk;

    data_chunk.set_chunk_number(this->counter++);

    Ball_message* ball(data_chunk.mutable_ball());
    ball->set_isvalid(wm->ball.isValid);
    position_message* ball_pos(ball->mutable_position());
    ball_pos->set_x(wm->ball.pos.loc.x);
    ball_pos->set_y(wm->ball.pos.loc.y);
    ball_pos->set_dir(wm->ball.pos.dir);
    position_message* ball_vel(ball->mutable_velocity());
    ball_vel->set_x(wm->ball.vel.loc.x);
    ball_vel->set_y(wm->ball.vel.loc.y);
    ball_vel->set_dir(wm->ball.vel.dir);

    for(int i = 0; i < PLAYERS_MAX_NUM; i++ )
    {
        Robot_message *our = data_chunk.add_ours();
        our->set_isvalid(wm->ourRobot[i].isValid);

        Robot_message_AgentRole role = returnProtoRole(wm->ourRobot[i].Role);
        our->set_role(role);

        Robot_message_AgentStatus status = returnProtoStatus(wm->ourRobot[i].Status);
        our->set_status(status);

        Robot_message_AgentRegion region = returnProtoRegion(wm->ourRobot[i].Region);
        our->set_region(region);

        position_message* robo_pos(our->mutable_position());
        robo_pos->set_x(wm->ourRobot[i].pos.loc.x);
        robo_pos->set_y(wm->ourRobot[i].pos.loc.y);
        robo_pos->set_dir(wm->ourRobot[i].pos.dir);

        position_message* robo_vel(our->mutable_velocity());
        robo_vel->set_x(wm->ourRobot[i].vel.loc.x);
        robo_vel->set_y(wm->ourRobot[i].vel.loc.y);
        robo_vel->set_dir(wm->ourRobot[i].vel.dir);

        //        RobotCommand_message rc = our->rc();
        //        position_message fin_pos = rc.fin_pos();
        //        fin_pos.set_x(wm->ourRobot[i].);
    }

    for(int i = 0; i < PLAYERS_MAX_NUM; i++ )
    {
        Robot_message *opp = data_chunk.add_opps();
        opp->set_isvalid(wm->oppRobot[i].isValid);

        position_message* robo_pos(opp->mutable_position());
        robo_pos->set_x(wm->oppRobot[i].pos.loc.x);
        robo_pos->set_y(wm->oppRobot[i].pos.loc.y);
        robo_pos->set_dir(wm->oppRobot[i].pos.dir);

        position_message* robo_vel(opp->mutable_velocity());
        robo_vel->set_x(wm->oppRobot[i].vel.loc.x);
        robo_vel->set_y(wm->oppRobot[i].vel.loc.y);
        robo_vel->set_dir(wm->oppRobot[i].vel.dir);
    }

    chunks.append(data_chunk);
}