📄 act.c
字号:
EASYCOLLECTANDPASSTO(player,&ChooseNN,CollectDist,DashPower,3); else COLLECTANDCLEARTOPOINT(aimx,aimy,&ChooseNN,CollectDist,DashPower,100); break; case SETPLAY_PASSER: EASYCOLLECTANDPASSTO(player,&ChooseNN,CollectDist,DashPower,ShotPower); break; case SETPLAY_KNOCKER: COLLECTANDKNOCKTOPOINT(aimx,aimy,&ChooseNN,CollectDist,DashPower,100); break; case SETPLAY_BLASTER: BLASTATPOINT(aimx,aimy); break; default: my_error("what's my set play position type???"); } //printf("%d SetPlayTime: %d currentTime: %d started at:%d\n", // Mem->MyNumber,SetPlayTime,Mem->CurrentTime,Mem->SetPlayStartTime); if ( Mem->SetPlayStartTime && /* into play_on mode */ Mem->CurrentTime - Mem->SetPlayStartTime >= SetPlayTime ){ Mem->SetMyselfAtAttention(); return SUCCESS; } return TRIED;}/* #define EXECUTESETPLAY(a,b) ExecuteSetPlay(a,b) *//*****************************************************************************/int DribbleToMarker(int Marker, float DashPower, float ShotPower){ if ( CHASEBALL(DashPower) != SUCCESS ) { /* If not at ball */ return TRYING; /* Not done */ } else { if ( Marker > 0 && Mem->MarkerValid(Marker) ){ if ( DRIBBLEATMARKER(Marker,ShotPower) == TRYING ) /* Dribble */ return TRYING; /* Circling Ball */ else #if DRIBBLE_DEBUG printf("%d:%d Facing Marker %d\n",Mem->MyNumber, Mem->CurrentTime, Marker);#endif if ( fabs(Mem->GetMarkerAngle(Marker)) > 3 ){ /* Arbitrary */ WAITUNTILFREETOACT; if ( !Mem->NewSight ){ FACEMARKER(Marker); return TRIED; /* Means you won't dash after facing */ } } } else { /* No marker or it's not valid */ KICKANDFACE(ShotPower,Mem->GetBallAngle()); /* Dribble straight*/#if DRIBBLE_DEBUG printf("%d:%d Kicking and facing\n",Mem->MyNumber, Mem->CurrentTime );#endif } if ( fabs(Mem->GetBallAngle()) < 45 ){ /* Don't move if ball was behind */ /* WAITUNTILFREETOACT; if ( !Mem->NewSight ){ DASHMOVE(0,DashPower); }*/ DASHMOVE(0,DashPower); /* Always dash at least once after a kick */ } return TRIED; }}/*#define DRIBBLETOMARKER(a,b,c) DribbleToMarker(a,b,c)#define DRIBBLESTRAIGHT(a,b) DribbleToMarker(-1,a,b)*//*****************************************************************************/int CollectAndKnock (int Marker, float x, float y, int (*ChoiceFunction)(float*,float*), float CollectDist, float ShootDist, float DashPower, float DribblePower, float ShotPower, int clear ){ #if 0 printf(">>>BValid=%f\n",Mem->BallValid()); printf(">>>GValid=%f\n",Mem->MarkerValid(THEIR_GOAL));#endif /* Can put in a different choice function here for CollectBall */ if ( !Mem->BallValid() || Mem->GetBallDistance() > KICK_DISTANCE ){ if ( COLLECTBALL(ChoiceFunction, CollectDist, DashPower) <= TRYING ) return FAILURE; /* Ball's not in range*/ else return TRYING; /* Dashing for it */ } if ( !Mem->MarkerValid(Marker) ){ LOOKFORMARKER(Marker); return TRYING; /* Facing goal */ } else if ( Mem->GetMarkerDistance(Marker) > ShootDist ){ /* goal is far */ DRIBBLETOMARKER(Marker,50,DribblePower);#if DRIBBLE_DEBUG printf("DRIBBLING to %d (%d)\n",Marker,Mem->MyNumber);#endif return TRYING; } else{ /* Goal is near */#if DRIBBLE_DEBUG printf("KNOCKING to %d (%d)\n",Marker,Mem->MyNumber);#endif#if PRACTICE return SHOOTATMARKER(Marker, ShotPower);#endif /* printf("clear: %d, Marker: %d\n",clear,Marker); */ if ( clear ){ /* Don't worry about exact aim. Instead avoid players */ if ( !Marker ) CLEARTOWARDSPOINT(x,y,ShotPower); else return CLEARTOWARDSMARKER(Marker, ShotPower); } if ( !Marker ) return SHOOTATPOINT(ShotPower,x,y); if (Marker == THEIR_GOAL) /* If far enough away, shoot at center??? */ return SHOOTATNEARPOST(100); else return SHOOTATMARKER(Marker,ShotPower); /* circling ball (trying) */ /* or Kicked (tried) */ }}int CollectAndKnock (int Marker, int (*ChoiceFunction)(float*,float*), float CollectDist, float ShootDist, float DashPower, float DribblePower, float ShotPower, int clear ){ /* ignore the x and y positions */ return CollectAndKnock(Marker,0,0,ChoiceFunction,CollectDist,ShootDist, DashPower,DribblePower,ShotPower,clear);}/*#define COLLECTANDSHOOT(a,b,c,d) CollectAndKnock(THEIR_GOAL,a,b,150,c,0,d,0)#define CHASEANDSHOOT(a,b) CollectAndKnock(THEIR_GOAL,&ChooseStraight,150,150,a,0,b,0)#define DRIBBLEANDSHOOT(a,b,c,d) CollectAndKnock(THEIR_GOAL,&ChooseStraight,150,a,b,c,d,0)#define STAYANDSHOOT(a) CollectAndKnock(THEIR_GOAL,&ChooseStraight,0,150,0,0,a,0)#define COLLECTANDKNOCK(a,b,c,d,e) CollectAndKnock(a,b,c,150,d,0,e,0)#define ACTIVECOLLECTANDKNOCK(a,b,c,d) CollectAndKnock(a,b,150,150,c,0,d,0)#define CHASEANDKNOCK(a,b,c) CollectAndKnock(a,&ChooseStraight,150,150,b,0,c,0)#define DRIBBLEANDKNOCK(a,b,c,d,e) CollectAndKnock(a,&ChooseStraight,150,b,c,d,e,0)#define COLLECTANDDRIBBLE(a,b,c,d,e) CollectAndKnock(a,b,c,0,d,e,0,0)#define ACTIVECOLLECTANDDRIBBLE(a,b,c,d) CollectAndKnock(a,b,150,0,c,d,0,0)#define COLLECTANDCLEAR(a,b,c,d,e) CollectAndKnock(a,b,c,150,d,0,e,1)#define COLLECTANDCLEARTOPOINT(a,b,c,d,e,f) CollectAndKnock(0,a,b,c,d,150,e,0,f,1)#define COLLECTANDKNOCKTOPOINT(a,b,c,d,e,f) CollectAndKnock(0,a,b,c,d,150,e,0,f,0)*//*****************************************************************************/int CollectAndPassTo (int Receiver, int (*ChoiceFunction)(float*,float*), float CollectDist, float PassDist, float DashPower, float DribblePower, float PassPower, int trap ){ char MySide = Mem->MySide; /* Can put in a different choice function here for CollectBall */ if ( !Mem->BallValid() || Mem->GetBallDistance() > KICK_DISTANCE ){ if ( COLLECTBALL(ChoiceFunction, CollectDist, DashPower) <= TRYING ) return FAILURE; /* Ball's not in range*/ else return TRYING; /* Dashing for it */ } if ( Receiver > TEAM_SIZE ) { /* Going by position */ my_error("Receiver should never be > teamsize anymore"); } if ( Receiver == Mem->MyNumber ){ my_error("Shouldn't be trying to pass to myself"); return TRYING; /* Can't pass to myself */ } /*if ( !Mem->PlayerAngleValid(MySide,Receiver) ){*/ /* For passes, only trusting visual or audial info from the last tick */ if ( Mem->PlayerAngleValid(MySide,Receiver) < HEARSAY_CONFIDENCE - .01 ){ LOOKFORTEAMMATE(Receiver); return TRYING; /* looking for player */ } else if ( !Mem->PlayerDistanceValid(MySide,Receiver) ){ /* The angle's valid, but the player's too far to see */#if SAVE_PASS_DATA RecordPassData(Receiver, Mem);#endif if ( strcmp(Mem->GetStatus(Mem->MySide,Receiver),RECEIVER_STAT) ){ /* Announce who's getting the ball */ char Announcement[MAXMESG]; sprintf(Announcement,PASSING_DECISION,Receiver); SAY(Announcement); }#if DRIBBLE_DEBUG printf("PASSING toward %d (%d)\n",Receiver,Mem->MyNumber);#endif Mem->ClearData(); if (trap) return PASSTOWARDTEAMMATE(Receiver,80); /* circling ball (trying) */ else /* or Kicked (tried) */ return EASYPASSTOWARDTEAMMATE(Receiver,80); } else if ( Mem->GetPlayerDistance(MySide,Receiver) > PassDist ){ /* player is far */ DRIBBLEATTEAMMATE(Receiver,DribblePower); return TRYING; } else { /* Player is near */#if SAVE_PASS_DATA RecordPassData(Receiver, Mem);#endif if ( Mem->GetMyActiveStatus() != INSETPLAY && /* Don't want to change receiver's Active Status by talking */ strcmp(Mem->GetStatus(Mem->MySide,Receiver),RECEIVER_STAT) ){ /* Announce who's getting the ball */ /* When passing, the receiver is marked (communications.c) */ /* The indicated receiver then watches the ball until the */ /* ball is within CollectDist (HoldPositionAndAct). then */ /* it marks itself as no longer the reciever. When the */ /* pass is made, the old receiver is erased and the new */ /* receiver is marked (communications.c) */ char Announcement[MAXMESG]; sprintf(Announcement,PASSING_DECISION,Receiver); SAY(Announcement); }#if DRIBBLE_DEBUG printf("PASSING to %d (%d)\n",Receiver,Mem->MyNumber); PassPower = 100; /* Just to test */#endif Mem->ClearData(); if (trap) /* ball too far (failure) */ return PASSTOTEAMMATE(Receiver,PassPower); /* circling ball (trying) */ else /* or Kicked (tried) */ return EASYPASSTOTEAMMATE(Receiver,PassPower); }}/*#define COLLECTANDPASSTO(a,b,c,d,e) CollectAndPassTo(a,b,c,150,d,10,e,1)#define EASYCOLLECTANDPASSTO(a,b,c,d,e) CollectAndPassTo(a,b,c,150,d,10,e,0)#define ACTIVECOLLECTANDPASSTO(a,b,c,d) CollectAndPassTo(a,b,150,150,c,10,d,1)#define DRIBBLEANDPASSTO(a,b,c,d,e) CollectAndPassTo(a,&ChooseStraight,150,b,c,d,e,1)#define APPROACHANDPASSTO(a,b,c,d,e,f) CollectAndPassTo(a,&ChooseNN,b,c,d,e,f,1)/* a is receiver, b is CollectDist (collect when ball is < b), c is PassDist (pass when ball < c), d is DashPower, e is DribblePower, f is PassPower #define STAYANDPASSTO(a,b) CollectAndPassTo(a,&ChooseStraight,0,150,0,0,b,0)/* a is receiver, b is PassPower *//*****************************************************************************/int CollectAndAct (int (*ActFunction)(char*,int*), int (*ChoiceFunction)(float*,float*), float CollectDist, float ShotDist, float DashPower, float DribblePower, float ShotPower){ char KnockOrPass; int BallTo; ActFunction( &KnockOrPass,&BallTo ); /* act */ /* printf("Action %c, To %d\n",KnockOrPass,BallTo); */ switch (KnockOrPass){ case 'k': /* knock */ return COLLECTANDKNOCK( BallTo, ChoiceFunction, CollectDist, DashPower, ShotPower); break; case 'p': /* pass */ return COLLECTANDPASSTO( BallTo, ChoiceFunction, CollectDist, DashPower, ShotPower); break; case 'd': /*dribble*/ /* COLLECTANDDRIBBLE--enforces dribble */ return COLLECTANDDRIBBLE( BallTo, ChoiceFunction, CollectDist, DashPower, DribblePower); break; case 'c': /* clear */ return COLLECTANDCLEAR( BallTo, ChoiceFunction, CollectDist, DashPower, ShotPower); break; default: my_error("Should be a 'p' or a 'k' or a 'd' or a 'c'"); }} /*#define COLLECTANDACT(a,b,c,d) CollectAndAct(a,&ChooseNN,b,0,c,10,d)#define ACTIVECOLLECTANDACT(a,b,c) CollectAndAct(a,&ChooseNN,150,0,b,10,c)*//*****************************************************************************/int HoldPositionAndAct (int (*ActFunction)(char*,int*), int (*ChoiceFunction)(float*,float*), float ShotDist, float DashPower, float DribblePower, float ShotPower){ if ( !Mem->BallValid() ){ my_error("should never get to ballvalid in Holdpositionandact"); int with_ball; if ( !strcmp(Mem->GetMyStatus(),RECEIVER_STAT) && /*I'm receive */ (with_ball = Mem->FindTeammateWithStatus(WITH_BALL_STAT)) ){ FACETEAMMATE(with_ball); /*that's where the ball*/ Mem->ClearStatus(Mem->MySide,with_ball); /*should be */ /* Clearing the status, because this cue should only be used once */ /* Otherwise, the ball might never be found */ } } else if ( Mem->GetMyActiveStatus() == ACTIVE ){#if 0 if ( !strcmp(Mem->GetMyStatus(),RECEIVER_STAT) ){ /* I'm receiver */ Mem->ClearMyStatus(); /* no need to remember */ }#endif if ( Mem->ChangePositions && Mem->GetMyPosition() != UNKNOWN_POSITION &&!Mem->AmWithinMyMaxRange() ){ int old_position = Mem->GetMyPosition(); if ( old_position != UNKNOWN_POSITION ){ /*if ( !old_position ) printf ("%d:%d Goalie leaving\n",Mem->MyNumber,Mem->CurrentTime);*/ Mem->ClearMyPosition(); ANNOUNCELEAVINGPOSITION(old_position); } } ACTIVECOLLECTANDACT(ActFunction, DashPower, ShotPower); return TRIED; } else if ( Mem->GetMyActiveStatus() == AT_ATTENTION ){ FACEBALL; /* Should know where the ball is if get here */ return TRYING; } else if ( Mem->GetMyActiveStatus() == INSETPLAY ){ return EXECUTESETPLAY(DashPower,ShotPower); } else if ( Mem->GetMyActiveStatus() == AUXILIARY ){ ; } else { /* active status is INACTIVE */ /* Should take this out-- should be at attention */ if ( !strcmp(Mem->GetMyStatus(),RECEIVER_STAT) ){ /*ball should be coming*/ printf("shouldn't be inactive when receiver. Clearing status?\n"); Mem->ClearMyStatus(); /* no need to remember */ } DashPower = MIN(20,DashPower); return HOLDPOSITION(DashPower); /* TRYING if going or wandering, SUCCESS if in pos.*/ }} /* a is action func. b is collectdist. c,d are dash/shot power #define HOLDPOSITIONANDACT(a,b,c) HoldPositionAndAct(a,&ChooseNN,0,b,10,c)*//*****************************************************************************/int ReceivePass(int (*ChoiceFunction)(float*,float*), float CollectDist, float DashPower){ int Result, with_ball, ball_coming; ball_coming = Mem->FindTeammateWithStatus(RECEIVER_STAT); /* The player to whom the ball is coming */ if ( ball_coming && ball_coming != Mem->MyNumber ){ return FAILURE; /* Someone else is getting the ball */ } Result = COLLECTBALL(ChoiceFunction, CollectDist, DashPower); with_ball = Mem->FindTeammateWithStatus(WITH_BALL_STAT); if ( Result == TRYING ){ /* Ball's not in range (or dodging a player) */ if ( strcmp(Mem->GetStatus(Mem->MySide,Mem->MyNumber),ANNOUNCED_OPEN_STAT) && with_ball && Mem->PlayerDistanceValid(Mem->MySide,with_ball) ){ /* Only say ready to receive if the passer is close enough to see distance */ SAY(READY_TO_RECEIVE_MSG); Mem->SetStatus(Mem->MySide,with_ball,ANNOUNCED_OPEN_STAT); } return TRYING; } if ( Result == FAILURE ) /* Still trying to face the ball */ return TRYING; else /* TRYING until at the ball */ return Result; }/*#define RECEIVEPASS(a,b,c) ReceivePass(a,b,c)*/#if 0OLD CODE FOR NUM DASHES /* Blowing up GOTOPOINT to put in params */ float dist = Mem->DistanceToPoint(targetX,targetY); if ( dist > TunedParams[6] ) { /* GoToPointBuffer */ FacePoint(targetX,targetY,TunedParams[4]); /* facePointBuffer */ if (dist >= TunedParams[3]) /* dashTwiceBuffer */ minDashes = 2; else if ( Mem->BallTrajectoryValid() && fabs(Mem->GetBallTrajectoryRelativeDirection()) < 35 && /* ball going away */ fabs(Mem->GetBallAngle()) < 35 && /* facing the ball */ Mem->GetMyStamina() > 200 ) minDashes = 6; /* Three dashes at least */ else /* DashPower */ minDashes = 1; /* One dash at least */ GOMOVE(dist,0,TunedParams[5]*dist,minDashes,3); return TRYING; } else /* Find ball */ return TRIED; /* TRYING, TRIED (turned), or SUCCESS (seeing)*/#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -