📄 act.c
字号:
return TRIED; /* Kicked */ }}/*#define SHOOTONGOAL(a) Shoot(a,Mem->GetMarkerAngle(THEIR_GOAL),MAX_ACTS,1,1)#define SHOOTATMARKER(a,b) Shoot(b*Mem->GetMarkerDistance(a),Mem->GetMarkerAngle(a),MAX_ACTS,1,0)#define SHOOTATANGLE(a,b) Shoot(a,b,MAX_ACTS,0,0)#define DRIBBLEATMARKER(a,b) Shoot(b,Mem->GetMarkerAngle(a),1,0,0)#define DRIBBLEATTEAMMATE(a,b) Shoot(b,Mem->GetPlayerAngle(Mem->MySide,a),1,0,0)#define DRIBBLEATOPPONENT(a,b) Shoot(b,Mem->GetPlayerAngle(Mem->TheirSide,a),1,0,0)#define PASSTOTEAMMATE(a,b) Shoot(b*Mem->GetPlayerDistance(Mem->MySide,a),Mem->GetPlayerAngle(Mem->MySide,a),MAX_ACTS,1,0)#define EASYPASSTOTEAMMATE(a,b) Shoot(b*Mem->GetPlayerDistance(Mem->MySide,a),Mem->GetPlayerAngle(Mem->MySide,a),MAX_ACTS,0,0)/* If don't know player's distance #define PASSTOWARDTEAMMATE(a,b) Shoot(b,Mem->GetPlayerAngle(Mem->MySide,a),MAX_ACTS,1,0)#define EASYPASSTOWARDTEAMMATE(a,b) Shoot(b,Mem->GetPlayerAngle(Mem->MySide,a),MAX_ACTS,0,0)*//*****************************************************************************/#define HARD_SHOT_DIST 15int ShootAtPoint(float kpow, float x, float y, int trap_ball, int hard_shot){ float dx = x - Mem->GetGlobalX(); float dy = y - Mem->GetGlobalY(); float dist = sqrt(dx*dx + dy*dy); float angle = my_atan2(dy,dx); float da = rad_to_deg(Mem->GetGlobalAngle() - angle);#if 0 printf("(shoot) dx: %f,dy: %f,angle: %f, da: %f\n",dx,dy,180*angle/M_PI,da);#endif if ( dist < HARD_SHOT_DIST ){ hard_shot = FALSE; trap_ball = FALSE; } return Shoot(kpow,da,MAX_ACTS,trap_ball,hard_shot);}/* #define SHOOTATPOINT(a,b,c) ShootAtPoint(a,b,c,0,1)#define BLASTATPOINT(a,b) ShootAtPoint(100,a,b,0,0)#define SHOOTONGOALATCORNER(a) ShootAtPoint(a,X0,(GOAL_WIDTH/2 - 3) * (int_random(2) ? 1 : -1),0,1) #define SHOOTATNEARPOST(a) ShootAtPoint(a,X0,(GOAL_WIDTH/2 -3) * (Mem->GetGlobalY()>0 ? 1 : -1),0,1)#define SHOOTATFARPOST(a) ShootAtPoint(a,X0,(GOAL_WIDTH/2 -3) * (Mem->GetGlobalY()>0 ? -1 : 1),0,1)*//*****************************************************************************/#define CHECK_CLEAR_DIST 12 /* There should be no players closer than this dist */#define CHECK_CLEAR_ANGLE 10 /* whithin this ang of the ball's trajectory */#define MAX_CLEAR_OFFSET 90 /* Don't consider angles this much different */#define SUPER_DANGER_DIST 10 /* When this close to own goal, clear sideways */int ClearTowards(float kpow, float ang){ if ( !Mem->BallValid() || Mem->GetBallDistance() > KICK_DISTANCE ) return FAILURE; /* Ball's not in range*/ if ( Mem->FacingBackNearOwnGoal() /*FacingBackInOwnPA()*/ || Mem->InOwnPenaltyArea() ){ /* If in goal mouth, just get it out */ float clearSide = Mem->GetMyLocationSide(); switch( Mem->GetCurrentFormationType() ){ case fRT_FORMATION: //clearSide = RIGHT; break; clearSide = 0; break; case fLT_FORMATION: //clearSide = LEFT; break; clearSide = 0; break; } float Xtarget = 0; if ( Mem->GetMarkerDistance(MY_GOAL) < SUPER_DANGER_DIST ) Xtarget = -X0/2; ang = Mem->AngleToPoint(Xtarget, Y0*clearSide); /* Clear to center flag */ float startAng = ang;#if CLEAR_DEBUG printf("%d:%d want to clear to point (%.1f %.1f)\n", Mem->MyNumber, Mem->CurrentTime,Xtarget,Y0*clearSide);#endif while ( NEEDTOCIRCLE(ang) ){ /* Don't want to circle */ if ( startAng > 0 ) ang -= 5; else ang += 5; } } float clearAng = ang; float clearOffset = 0;#if CLEAR_DEBUG printf("%d:%d want to clear %.1f\n",Mem->MyNumber, Mem->CurrentTime,ang); printf(" %d in way\n",Mem->NumPlayersWithin(CHECK_CLEAR_DIST/2, CHECK_CLEAR_ANGLE, CHECK_CLEAR_DIST/2, clearAng));#endif while ( Mem->NumPlayersWithin(CHECK_CLEAR_DIST/2, CHECK_CLEAR_ANGLE, CHECK_CLEAR_DIST/2, clearAng) ){ clearOffset *= -1; /* Flip offset angle */ if (clearOffset >= 0) /* increment it if even iteration */ clearOffset += 2*CHECK_CLEAR_ANGLE; if ( clearOffset >= MAX_CLEAR_OFFSET ){ clearAng = ang; break; } else clearAng = ang + clearOffset; CleanAngle(&clearAng);#if CLEAR_DEBUG printf(" --- checking %.1f\n",clearAng); printf(" %d in way\n",Mem->NumPlayersWithin(CHECK_CLEAR_DIST/2, CHECK_CLEAR_ANGLE, CHECK_CLEAR_DIST/2, clearAng));#endif } return SHOOTATANGLE(kpow, clearAng);}/*#define CLEARTOWARDSMARKER(a,b) ClearTowards(b*Mem->GetMarkerDistance(a),Mem->GetMarkerAngle(a))#define CLEARTOWARDSPOINT(a,b,c) ClearTowards(c*Mem->DistanceToPoint(a,b),Mem->AngleToPoint(a,b))*//*****************************************************************************/int CollectStoppedBall(float CollectDist, float DashPower){ if ( !Mem->BallValid() ) { /* If Can't see ball */ FINDBALL; /* Look for it */ WAITUNTILFREETOACT; } if ( !Mem->BallValid() ) { return FAILURE; } else if ( (Mem->PlayMode==THEIR_KICK_OFF || Mem->PlayMode==THEIR_KICK_IN || Mem->PlayMode==THEIR_GOAL_KICK || Mem->PlayMode==THEIR_FREE_KICK || Mem->PlayMode==THEIR_CORNER_KICK) && Mem->GetBallDistance() < 10 ) { /* If can't go closer */ return SUCCESS; /* Don't waste stamina */ } else if ( Mem->GetBallDistance() > CollectDist) { /* If Far from ball */ FACEBALL; /* wait */ return TRYING; } else if ( Mem->GetBallDistance() > KICK_DISTANCE - .2 ) { /* If it's in range */ GOMOVE(Mem->GetBallDistance(),Mem->GetBallAngle(),DashPower*Mem->GetBallDistance(), 1,2); return TRYING; } else if ( Mem->BallValid() == 1 ) { return SUCCESS; /* Sure you're at it */ } else { FACEBALL; return TRIED; /* Not sure */ }}/*#define COLLECTSTOPPEDBALL(a) CollectStoppedBall(150,a)*//*****************************************************************************/int CollectBall (int (*ChoiceFunction)(float*,float*), float CollectDist, float DashPower){#if PRACTICE if (0) /* Don't use analytic method */#endif if ( Mem->PlayMode == PLAY_ON ) return ANALYTICCOLLECTBALL(CollectDist,DashPower); float TurnAng = 0; /* By default, just go straight at ball */ if ( !Mem->BallValid() ) { /* If Can't see ball */ FINDBALL; /* Look for it */ WAITUNTILFREETOACT; }#if 0 float bdist = Mem->GetBallDistance(); float ang = Mem->GetBallAngle(); float relvelmag = Mem->GetBallRelVelMagnitude(); float relvelang = Mem->GetBallRelVelDirection(); /* My calculation */ float velmag = Mem->GetBallVelMagnitude(); /* from the server */ float velang = Mem->GetBallVelDirection(); /* In relative terms */ float ballvalid = Mem->BallValid(); float relvelvalid = Mem->BallRelVelocityValid(); int velvalid = Mem->BallVelValid(); float ballx = Mem->GetBallGlobalX(); float bally = Mem->GetBallGlobalY(); float trajvalid = Mem->BallTrajectoryValid(); float trajdir,trajmag; if (trajvalid){ trajdir = rad_to_deg(Mem->GetBallTrajectoryAbsoluteDirection()); trajmag = Mem->GetBallTrajectoryMagnitude(); } printf ("%d:%d me(%.1f) (%.1f,%.1f %.1f) ball(%.1f): (%.1f %.1f) global: (%.1f,%.1f)\n", Mem->MyNumber,Mem->CurrentTime, Mem->MarkerValid(THEIR_GOAL), Mem->GetGlobalX(),Mem->GetGlobalY(), rad_to_deg(Mem->GetGlobalAngle()), ballvalid,bdist,ang, ballx,bally); if (trajvalid && trajmag < 5) /* else a jump */ printf (" **** traj conf = (%.1f) dir = %.1f mag = %.1f **** \n", trajvalid,trajdir,trajmag); /* printf ("%d(%.1f,%.1f) ball(%.1f): (%.1f %.1f) relvel(%.1f): (%.1f %.1f) vel(%d): (%.1f %.1f)\n", Mem->CurrentTime,Mem->GetGlobalX(),Mem->GetGlobalY(), ballvalid,dist,ang, relvelvalid,relvelmag,relvelang, velvalid,velmag,velang); */#endif if ( !Mem->BallValid() ) { return FAILURE; } else if ( (Mem->PlayMode==THEIR_KICK_OFF || Mem->PlayMode==THEIR_KICK_IN || Mem->PlayMode==THEIR_GOAL_KICK || Mem->PlayMode==THEIR_FREE_KICK || Mem->PlayMode==THEIR_CORNER_KICK) && Mem->GetBallDistance() < 10 ) { /* If can't go closer */ return SUCCESS; /* Don't waste stamina */ } else if ( Mem->GetBallDistance() > CollectDist) { /* If Far from ball */ FACEBALL; /* wait */ return TRYING; } else if ( Mem->GetBallDistance() > KICK_DISTANCE ) { /* If it's in range */#if CHOICE_FUNCTION_DEBUG if ( ChoiceFunction == &ChooseNN ) printf("Player %d is trying to use the NN --- ",Mem->MyNumber);#endif#if 0 float tmp1,tmp2; if ( /* (*ChoiceFunction)( &tmp1, &tmp2) == WAIT || */ Mem->BallValid() < 1 || !Mem->BallRelVelocityValid() || /* Really want to do this if I moved on last step (Dashed) */ Mem->GetBallDistance() < 6 || Mem->GetBallDistance() > NN_CDIST+10 || Mem->Dashed || Mem->GetBallVelDirection() == NODIR || !Mem->GetBallVelMagnitude() || fabs(Mem->GetBallVelDirection()) < 135 || Mem->GetBallRelVelMagnitude() < NN_MIN_VEL)/* Moving too slowly for NN */ ChoiceFunction = &ChooseStraight; /* Only use nets when ball is approaching and near*/#else if ( Mem->BallValid() < 1 || !Mem->BallTrajectoryValid() || Mem->GetBallTrajectoryMagnitude() > 5 || Mem->GetBallTrajectoryMagnitude() < .3) ChoiceFunction = &ChooseStraight; else ChoiceFunction = &ChooseAnalytic; #endif#if CHOICE_FUNCTION_DEBUG printf("relvelvalid: %.1f -- RelVelMag: %.1f -- ", Mem->BallRelVelocityValid(),Mem->GetBallRelVelMagnitude()); if ( ChoiceFunction == &ChooseNN ) printf("YES using it(%.1f)\n",Mem->GetBallVelDirection()); else printf("NOT using it\n");#endif if ( ((*ChoiceFunction)( &TurnAng, &DashPower) == TRY) && Mem->PlayMode != BEFORE_KICK_OFF ){ /* Not at a pause */#if SAVE_COLLECT_DATA if ( Mem->RecordCollectData ){ RecordCollectData(TurnAng,DashPower); /* Record now and not */ Mem->RecordCollectData = FALSE; /* again 'til result */ } else TurnAng =0; /* Stop after dash */#endif float BallAng = Mem->GetBallAngle(); int moveRes; /* Go more quickly after the NN attempt */ if (ChoiceFunction != &ChooseNN){ int dashTimes = MAX_ACTS; float distFactor = 1; if (Mem->GetBallDistance() < 5) dashTimes =2; moveRes = GOMOVE(distFactor*Mem->GetBallDistance(),TurnAng+BallAng, DashPower*Mem->GetBallDistance(),1,dashTimes); } else{ moveRes = DASHMOVE(TurnAng+BallAng, DashPower*Mem->GetBallDistance()); /* move: returns TRIED if dash, TRYING if dodgeplayer */ } /* if ( TurnAng ) TURN ( -TurnAng ); /* If you didn't move straight, look back */ return moveRes; } else { /* ChoiceFunction == WAIT or In between trials (before_kick_off) */ FACEBALL; return TRYING; } } else if ( Mem->BallValid() == 1 ) { Mem->ClearBallGlobalPosition(); return SUCCESS; /* Sure you're at it */ } else { Mem->ClearBallGlobalPosition(); FACEBALL; return TRIED; /* Not sure */ }}/*#define CHASEBALL(a) CollectBall(&ChooseStraight,150,a)#define COLLECTBALL(a,b,c) CollectBall(a,b,c)#define ACTIVECOLLECTBALL(a,b) Collectball(a,150,b)*//*****************************************************************************//* Returns TRUE if I can intercept it, else FALSE */ int GetCollectTargetXY(float *targetX, float *targetY){ if ( !Mem->BallTrajectoryValid() ) printf("Why here if ball trajectory isn't valid??");#if TUNED_PARAMS float playerSpeed = TunedParams[0];#else float playerSpeed = .5;#endif float ballX,ballY, myX,myY; Mem->GetGlobalXY(&myX,&myY); Mem->GetBallGlobalXY(&ballX,&ballY); /* Convert my position to origin (0,0)*/ ballX -= myX; ballY -= myY; float ballDistance = Mem->GetBallDistance(); float ballDirection = Mem->GetBallTrajectoryAbsoluteDirection(); float ballSpeed = Mem->GetBallTrajectoryMagnitude(); float ballDx = ballSpeed * cos(ballDirection); float ballDy = ballSpeed * sin(ballDirection); float a = ballX*ballX + ballY*ballY; float b = 2*(ballX*ballDx + ballY*ballDy); float c = ballDx*ballDx + ballDy*ballDy - playerSpeed*playerSpeed; float disc = b*b - 4*a*c;#if COLLECT_DEBUG printf("%d:%d me (%.1f, %.1f), ball (%.1f, %.1f) -- s/d: %.1f %.1f\n", Mem->MyNumber,Mem->CurrentTime, myX,myY,ballX,ballY,ballSpeed,rad_to_deg(ballDirection)); printf(" ballD (%.1f, %.1f)......",ballDx,ballDy);#endif int BallTooFast = FALSE; if (disc < 0){#if 0 printf("%d:%d The ball is too fast!\n",Mem->MyNumber,Mem->CurrentTime);#endif BallTooFast = TRUE; } float t; /* Time to intersection point */ if ( !BallTooFast ){ float u1 = (-b + sqrt(disc)) / (2*a); float u2 = (-b - sqrt(disc)) / (2*a); float u = (u1 > u2) ? u1 : u2; t = 1.0 / u; #if TUNED_PARAMS t *= TunedParams[1];#endif#if 0 printf("%d:%d Chose between %.1f and %.1f\n", Mem->MyNumber,Mem->CurrentTime, 1.0/u1, 1.0/u2);#endif if (u <= 0){#if 0 printf("%d:%d Why negative time? Chose between %.1f and %.1f\n", Mem->MyNumber,Mem->CurrentTime, 1.0/u1, 1.0/u2);#endif BallTooFast = TRUE; } } if ( BallTooFast )#if TUNED_PARAMS t = (ballDistance/ballSpeed)*TunedParams[2];#else t = (int)(ballDistance/ballSpeed); /* Aim for where ball is going anyway */#endif /* else printf("%d:%d Using analytic method\n",Mem->MyNumber,Mem->CurrentTime); */#if TUNED_PARAMS#else t *= 1.1;#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -