gr_Robot_Command TDefendPoint::execute(const BeliefState &state, const Param& tParam) { // Select the skill to the executed next Strategy::SkillSet::SkillID sID = SkillSet::DefendPoint; SkillSet::SParam sParam; sParam.DefendPointP.x = tParam.DefendPointP.x ; sParam.DefendPointP.y = tParam.DefendPointP.y ; sParam.DefendPointP.radius = tParam.DefendPointP.radius; // Execute the selected skill Strategy::SkillSet *ptr = SkillSet::instance(); return ptr->executeSkill(sID, sParam, state, botID); }
gr_Robot_Command TCharge::execute(const BeliefState &state, const Param& tParam) { // Select the skill to the executed next Strategy::SkillSet::SkillID sID = SkillSet::DribbleToPoint; SkillSet::SParam sParam; sParam.DribbleToPointP.x = HALF_FIELD_MAXX; sParam.DribbleToPointP.y = (OPP_GOAL_MAXY+OPP_GOAL_MINY)/2; // Execute the selected skill Strategy::SkillSet *ptr = SkillSet::instance(); return ptr->executeSkill(sID, sParam, state, botID); // if((state->homePos[botID] - Vector2D<int>(tParam.PositionP.x, tParam.PositionP.y)).absSq() < BOT_POINT_THRESH * BOT_POINT_THRESH) // { // tState = COMPLETED; // } }
gr_Robot_Command TPosition::execute(const BeliefState &state, const Param& tParam) { // Select the skill to the executed next // printf("botpos x:%d\ty:%d\n", state->homePos[botID].x, state->homePos[botID].y); Strategy::SkillSet::SkillID sID = SkillSet::GoToPoint; SkillSet::SParam sParam; sParam.GoToPointP.x = tParam.PositionP.x ; sParam.GoToPointP.y = tParam.PositionP.y ; sParam.GoToPointP.align = tParam.PositionP.align; sParam.GoToPointP.finalslope = tParam.PositionP.finalSlope ; sParam.GoToPointP.finalVelocity = tParam.PositionP.finalVelocity; // Execute the selected skill Strategy::SkillSet *ptr = SkillSet::instance(); if((Vector2D<int>(state.homePos[botID].x,state.homePos[botID].y) - Vector2D<int>(tParam.PositionP.x, tParam.PositionP.y)).absSq() < BOT_POINT_THRESH * BOT_POINT_THRESH) { iState = COMPLETED; } return ptr->executeSkill(sID, sParam, state, botID); }
gr_Robot_Command TDefend::execute(const BeliefState &state, const Param& tParam) { // Select the skill to the executed next // printf("botpos x:%d\ty:%d\n", state->homePos[botID].x, state->homePos[botID].y); Strategy::SkillSet::SkillID sID = SkillSet::GoToPoint; SkillSet::SParam sParam; sParam.GoToPointP.x = tParam.DefendP.x ; sParam.GoToPointP.y = state.ballPos.y; sParam.GoToPointP.align = true; sParam.GoToPointP.finalslope = PI/2; // Execute the selected skill Strategy::SkillSet *ptr = SkillSet::instance(); return ptr->executeSkill(sID, sParam, state, botID); // if((state->homePos[botID] - Vector2D<int>(tParam.PositionP.x, tParam.PositionP.y)).absSq() < BOT_POINT_THRESH * BOT_POINT_THRESH) // { // tState = COMPLETED; // } }
gr_Robot_Command TDefendLine::execute(const BeliefState &state, const Param& tParam) { float x1,x3,x2,x4,y1,y2,y3,y4; x1=tParam.DefendLineP.x1; x2=tParam.DefendLineP.x2; y1=tParam.DefendLineP.y1; y2=tParam.DefendLineP.y2; x3=state.ballPos.x; y3=state.ballPos.y; x4=state.ballPos.x + state.ballVel.x; y4=state.ballPos.y+ state.ballVel.y; if(state.ballVel.x==0) { // printf("here1\n"); //return; x4=(x1+x2)/2; //y4=(y1+y2)/2; } Vector2D<int> targetPoint; // intersection formula copied from http://en.wikipedia.org/wiki/Line-line_intersection float denominator= (x1-x2)*(y3-y4) - (y1-y2)*(x3-x4); if(denominator==0) { // printf("here2\n"); targetPoint.x=(x1+x2)/2; targetPoint.y =state.ballPos.y+ state.ballVel.y; } else { targetPoint.x = ((x1*y2-y1*x2)* (x3-x4) - (x1-x2) *(x3*y4-y3*x4))/denominator; targetPoint.y = ((x1*y2-y1*x2)* (y3-y4) - (y1-y2) *(x3*y4-y3*x4))/denominator; } if(fabs(targetPoint.x) > fabs(HALF_FIELD_MAXX)) { targetPoint.x=(x1+x2)/2; } if(fabs(targetPoint.y) > fabs(HALF_FIELD_MAXY)) { targetPoint.y=(y1+y2)/2; } // if(x3 < x1) // { // /**Shifts the defence line if the ball has already crossed it.*/ // targetPoint.x = state->ballPos.x + 4*BOT_BALL_THRESH; // targetPoint.y = state->ballPos.y; + state->ballVel.y*0.3; // } // else // { // /**Continue moving along the line if the ball has not crossed it.*/ // targetPoint.x = x1; // targetPoint.y = state->ballPos.y; + state->ballVel.y*0.3; // } // // /**Set DefendPoint coordinates on the defence line*/ // int xfinal = targetPoint.x < HALF_FIELD_MAXX ? targetPoint.x : HALF_FIELD_MAXX; // int yfinal = targetPoint.y; /**Tactic completed if ball comes in our possession or if ball crosses the defence line.*/ if(state.pr_ourBall && x3>x1) { //tState = COMPLETED; } // Select the skill to the executed next // printf("botpos x:%d\ty:%d\n", state->homePos[botID].x, state->homePos[botID].y); Strategy::SkillSet::SkillID sID = SkillSet::DefendPoint; SkillSet::SParam sParam; sParam.DefendPointP.x = targetPoint.x ; sParam.DefendPointP.y = targetPoint.y ; sParam.DefendPointP.radius = tParam.DefendLineP.radius; // Execute the selected skill Strategy::SkillSet *ptr = SkillSet::instance(); return ptr->executeSkill(sID, sParam, state, botID); // if((state->homePos[botID] - Vector2D<int>(tParam.PositionP.x, tParam.PositionP.y)).absSq() < BOT_POINT_THRESH * BOT_POINT_THRESH) // { // tState = COMPLETED; // } }