⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 act.c

📁 足球机器人仿真组CMU97的源码
💻 C
📖 第 1 页 / 共 4 页
字号:
  *targetX = ballX + ballDx * t;   *targetY = ballY + ballDy * t;       /* First convert target back to relative to my position */  *targetX += myX; *targetY += myY;#if 0  printf("target: (%.1f, %.1f)\n",*targetX,*targetY);#endif  return !BallTooFast;}/****    ****    ****    ****    ****    ****    ****    ****    ****    ****/int AnalyticCollectBall (float CollectDist, float DashPower){#if SAVE_COLLECT_DATA      if ( Mem->RecordCollectData ){	RecordCollectData(0,0);   /* Record now and not */	Mem->RecordCollectData = FALSE;             /* again 'til result  */      }#endif  if ( !Mem->BallValid() ) {        /* If Can't see ball */    FINDBALL;                       /* Look for it       */     WAITUNTILFREETOACT;  }  if ( !Mem->BallValid() ) {    return FAILURE;  }  else if ( Mem->GetBallDistance() > CollectDist) { /* If Far from ball  */    FACEBALL;                                       /* wait              */    return TRYING;  }  else if ( Mem->GetBallDistance() > KICK_DISTANCE &&	    Mem->BallTrajectoryValid() )  { /* If it's in range  */    int minDashes = 1;    float targetX,targetY;    GetCollectTargetXY(&targetX,&targetY);#if TUNED_PARAMS    /* 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()) < 60 && /* ball going away */		fabs(Mem->GetBallAngle()) < 35 &&                       /* facing the ball */		Mem->GetMyStamina() > 200 )	minDashes =  MIN(3,((int)dist)/5 +3);      else if ( 0 && dist > 8 && Mem->GetMyStamina() > 200 ){	minDashes = MAX(3,MIN(2,((int)dist)/5));	//printf("minDashes = %d\n",minDashes);      }      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)*/#else    /*if ( Mem->DistanceToPoint(targetX,targetY) > 15 &&	 Mem->GetMyStamina() > 200 )      minDashes = 2;*/    if ( Mem->BallTrajectoryValid() &&	 fabs(Mem->GetBallTrajectoryRelativeDirection()) < 35 && /* ball going away */	 fabs(Mem->GetBallAngle()) < 35 &&                        /* facing the ball */	 Mem->GetMyStamina() > 200 ){      /* printf("%d:%d minDashes at 3\n",Mem->MyNumber,Mem->CurrentTime); */      /* printf("no 3 dashes\n"); */      minDashes = 3; /* Hurry if ball going away */    }    return GOTOPOINTMINDASHES(targetX,targetY,DashPower,1,minDashes);#endif  }  else if ( Mem->BallValid() == 1 )  {    /* Mem->ClearBallGlobalPosition(); */    return SUCCESS;                             /* Sure you're at it */  }  else {    /* Mem->ClearBallGlobalPosition(); */    FACEBALL;    return TRIED;                               /* Not sure          */  }}/*#define ANALYTICCOLLECTBALL(a,b) AnalyticCollectBall(a,b)*//*****************************************************************************/int GoalieHome (float DashPower ){    if ( !Mem->MarkerValid(MY_GOAL) ){    LOOKFORMARKER(MY_GOAL);    return FAILURE;  }  else if ( (Mem->GetMarkerDistance(MY_GOAL) > 5) ) {             FACEMARKER(MY_GOAL);    DASHMOVE(0,DashPower*Mem->GetMarkerDistance(MY_GOAL) ); /* If far, Move to it */    return TRYING;  }  else                                              /* Find ball          */    return LOOKFORBALL;     /* TRYING, TRIED (turned), or SUCCESS (seeing)*/}/*#define GOALIEHOME(a) GoalieHome(a)*//*****************************************************************************/int KamramHome (float DashPower ){    if ( !Mem->MarkerValid(THEIR_GOAL) ){    LOOKFORMARKER(THEIR_GOAL);    return FAILURE;  }  else if ( (Mem->GetMarkerDistance(THEIR_GOAL) > 15) ) {             FACEMARKER(THEIR_GOAL);    DASHMOVE(0,DashPower*Mem->GetMarkerDistance(THEIR_GOAL) );/* If far, Move to it */    return TRYING;  }  else                                              /* Find ball          */    return LOOKFORBALL;     /* TRYING, TRIED (turned), or SUCCESS (seeing)*/}/*#define KAMRAMHOME(a) KamramHome(a)*//*****************************************************************************/int GotoPoint (float x, float y, float DashPower, float Buffer, int minDashes){     float gx = Mem->GetGlobalX();  float gy = Mem->GetGlobalY();  float dist = GetDistance(&x,&y,&gx,&gy);  if (Mem->SetPlay){  /* Don't let the ball get in your way on set plays */    float balldist = Mem->GetBallDistance();    if ( balldist < KICK_DISTANCE ){      if (Mem->MyPositionInSetPlay() && 	  Mem->GetMySetPlayPositionType() == SETPLAY_STARTER ){	float aimx, aimy;	Mem->GetMySetPlayAimXY(&aimx, &aimy);	float goalAng = Mem->AngleToPoint(aimx,aimy);	if ( !NEEDTOCIRCLE(goalAng) )	  return SUCCESS;      }      /* WIDE_VIEW; */      float ballAng = Mem->GetBallAngle();      if (ballAng > 0)	DODGEBALL(ballAng-90,100);           else	DODGEBALL(ballAng+90,100);           FACEPOINT(x,y);      return FAILURE;    }  }  if ( dist > Buffer ) {             FACEPOINT(x,y);    GOMOVE(dist,0,DashPower*dist,minDashes,3);      /* If far, Move to it */    return TRYING;  }  else                                              /* Find ball          */    return LOOKFORBALL;     /* TRYING, TRIED (turned), or SUCCESS (seeing)*/}/*#define GOTOPOINT(x,y,z,a) GotoPoint(x,y,z,a,1)#define GOTOPOINTMINDASHES(x,y,z,a,b) GotoPoint(x,y,z,a,b)*//*****************************************************************************/int HoldHome(float DashPower){  Mem->UpdateHome();  if ( Mem->PlayMode != BEFORE_KICK_OFF &&        GOTOPOINT(Mem->GetCurrentHomeX(),Mem->GetCurrentHomeY(), /* Going to position */		 DashPower,Mem->GetMyPositionBuffer()) <= TRIED )    return TRYING;    /* Perhaps check if there's already a person there before returning */    /* If there is, say an announcemyposition message                   */    /* But just once--not repeatedly                                    */  /* Free time to talk at this point            */  /* This often says things to the wrong person */  Mem->CheckForPlayersInMyPosition();    return SUCCESS;}/*#define HOLDHOME(a) HoldHome(a)*//*****************************************************************************/int MarkPlayer( float DashPower ){  Mem->UpdateMark();  char side = Mem->TheirSide;  int  mark = Mem->GetMark();  /* No player to mark */  if ( mark == UNKNOWN_PLAYER){   /* printf("%d: No player to mark\n",Mem->MyNumber);*/    if ( !Mem->BallValid() ) {        /* If Can't see ball */      FINDBALL;                       /* Look for it       */       WAITUNTILFREETOACT;    }    return HOLDHOME( DashPower );  }  if ( !Mem->PlayerValid(side,mark) ) {      /* If Can't see mark */    /* printf("%d:%d Can't find my mark (%d)\n",Mem->MyNumber,Mem->CurrentTime,mark);*/    if ( FINDPLAYER(side,mark) == FAILURE ){      /* Look for it         */       Mem->SetMark(UNKNOWN_PLAYER);               /* Can't find it       */      return FAILURE;    }  }  if (!Mem->IsWithinMyMaxRange(side,mark)){    /* Should not call markplayer from hold position in this situation */    /* Or update mark should give a different player                   */#if 0    printf("%d: My mark (%d) is out of range:  ",Mem->MyNumber,mark);    printf("(%.1f, %.1f)\n",Mem->GetPlayerGlobalX(side,mark),	   Mem->GetPlayerGlobalX(side,mark));#endif    if ( !Mem->BallValid() ) {        /* If Can't see ball */      FINDBALL;                       /* Look for it       */       WAITUNTILFREETOACT;    }    return HOLDHOME( DashPower );  }  int MarkDist = 1;  /* How close you need to be to the correct position */  float playerX,playerY,markX,markY;  Mem->GetPlayerGlobalXY(side,mark,&playerX,&playerY);  markX = playerX - Mem->GetMarkBuffer()/2;  markY = playerY - playerY/10;  if ( GOTOPOINT(markX,markY,DashPower,MarkDist) <= TRIED )    /* gotopoint: returns TRIED if in position, looking for Ball,        SUCCESS if in position, seeing ball */    return TRYING;  else     return SUCCESS;}/*#define MARKPLAYER(a) MarkPlayer(a)*//*****************************************************************************/int HoldPosition( float DashPower ){  if ( Mem->GetMyPosition() == UNKNOWN_POSITION ){    /* printf("%d:%d Can't hold an unknown position",Mem->MyNumber, Mem->CurrentTime); */    Mem->SetMyPosition(GetNewPosition());  }  if ( Mem->HomeChangeMethod == HOME_MARK ||        Mem->HomeChangeMethod == HOME_MARK_ELSE_SHIFT )    return MARKPLAYER( DashPower );  else    return HOLDHOME( DashPower );}/* #define HOLDPOSITION(a) HoldPosition(a)*//*****************************************************************************//************        HIGHER LEVELS    ****************************************//*****************************************************************************/int ExecuteSetPlay(float DashPower, float ShotPower){  if ( Mem->GetMyActiveStatus() != INSETPLAY ) my_error("Shouldn't be doing a set play");  if ( !Mem->MyPositionInSetPlay() ){    /* printf("%d:%d  My position (%d) no longer in set play\n",       Mem->MyNumber,Mem->CurrentTime,Mem->GetMyPosition()); */    Mem->SetMyselfInactive();    return FAILURE;  }  int spPosType = Mem->GetMySetPlayPositionType();  int spStarterPos = Mem->GetSetPlayStarterPosition();  /* make sure there's a starter if there should be one */  if ( spPosType == SETPLAY_STARTER ){    if ( strcmp(Mem->GetMyStatus(),SETPLAY_STARTER_STAT) ){      Mem->SetMyStatus(SETPLAY_STARTER_STAT);      SAY(SETPLAY_STARTER_MSG);    }  }  else if ( spStarterPos != UNKNOWN_POSITION ){  /* there is a starter */    int player = Mem->GetPositionPlayer(spStarterPos);    if ( player == UNKNOWN_PLAYER ){      SAYTOPOSITION(spStarterPos,PING_MSG);    }    else if ( strcmp(Mem->GetStatus(Mem->MySide,player),SETPLAY_STARTER_STAT)){      if ( Mem->CurrentTime > Mem->SetPlayInvokeTime+Mem->SetPlayTimeLimit/4 &&	   (Mem->PlayMode == MY_KICK_IN || Mem->PlayMode == MY_FREE_KICK) ){	/* Only have to worry if ball's position could be in doubt */	/*printf("%d:%d Going to have to reinitialize (time)\n",	  Mem->MyNumber,Mem->CurrentTime);*/	Mem->SetPlay = FALSE; /* force reinitialization */	return FAILURE;      }      else if ( Mem->CurrentTime > Mem->SetPlayInvokeTime+10 ){	SAYTO(player,ARE_YOU_STARTER_MSG);  /* Wait before forcing starter issue */      }    }  }  float goalx, goaly, buffer;  if ( spPosType == SETPLAY_STARTER ){    Mem->GetBallGlobalXY(&goalx,&goaly);     buffer = BALL_SIZE + PLAYER_SIZE;  }  else{    Mem->GetMySetPlayXY(&goalx,&goaly);    buffer = Mem->GetMySetPlayPositionBuffer();  }    if ( Mem->PlayMode != PLAY_ON ){    if (spPosType == SETPLAY_STARTER){      if ( COLLECTSTOPPEDBALL(10) != SUCCESS )	return FAILURE;    }    else{      if ( GOTOPOINT(goalx,goaly,10,buffer) != SUCCESS ) /* Not worried about getting */	return FAILURE;                                  /* There quickly             */    }    if ( strcmp(Mem->GetMyStatus(),OPEN_STAT) &&       /* no ack yet         */	 spStarterPos != UNKNOWN_POSITION &&           /* no point in saying */	 spPosType != SETPLAY_STARTER ){                 SAY(READY_TO_RECEIVE_MSG);    }    /* If you're the one near the ball, wait until everyone's in position */    if ( spPosType == SETPLAY_STARTER ){      if ( Mem->AllInSetPlayPosition() ){	Mem->ModifySetPlayStartAction();          /* Choose best of 1st 2 */	/* Mem->SetPlayStartTime = Mem->CurrentTime; /* Starting */      }      else if (Mem->CurrentTime >Mem->SetPlayInvokeTime+Mem->SetPlayTimeLimit){	Mem->ModifySetPlayStartAction();          /* Just go with what you've got */	/* Mem->SetPlayStartTime = Mem->CurrentTime; /* Starting */      }	      else{	Mem->CheckForPlayersInMyPosition();	return TRYING;      }    }    else{  /* Not the starter */      Mem->CheckForPlayersInMyPosition();      return TRYING;    }  }  else if ( !Mem->SetPlayStartTime ){         /* We're in PLAY_ON mode                */    Mem->SetPlayStartTime = Mem->CurrentTime; /* Time that mode is changed to PLAY_ON */  }  /* Play has started */  int position = Mem->GetMySetPlayAimPosition();  int player   = UNKNOWN_PLAYER;  float aimx,aimy;  if ( position == UNKNOWN_POSITION ){ /* We're going for a point */    Mem->GetMySetPlayAimXY(&aimx,&aimy);  }  else {                              /* We're going for a player */    player = Mem->GetPositionPlayer(position);    if ( player == UNKNOWN_PLAYER )      my_error("Should know who's playing the position");  }    int SetPlayTime = Mem->GetMySetPlayWaitTime();  int CollectDist = 14;  if (spPosType == SETPLAY_STARTER)    DashPower = 0;  switch(spPosType){  case SETPLAY_SHOOTER:    COLLECTANDSHOOT(&ChooseNN,CollectDist,DashPower,100);    break;  case SETPLAY_STARTER:    /* Assuming the starter either passes or knocks */    if ( player != UNKNOWN_PLAYER )

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -