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

📄 knockorpass.c

📁 足球机器人仿真组CMU97的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
//  if (hurry)//    printf("Gotta Hurry (%d)\n",Mem->MyNumber);//#endif////  /* choose the eligible receivers *///  int teammates[TEAM_SIZE];//  int NumOpen = 0;//  for (int i=0; i<NumOptions; i++){//    if ( Mem->PositionOccupied(PreferenceList[i]) && //         Mem->GetPositionPlayer(PreferenceList[i]) != Mem->MyNumber ){//      int PossibleReceiver = Mem->GetPositionPlayer(PreferenceList[i]);//      //      if ( Mem-> PlayerValid(Mem->MySide,PossibleReceiver) &&//           Mem->GetPlayerDistance(Mem->MySide,PossibleReceiver) > 10 &&//           Mem->GetPlayerDistance(Mem->MySide,PossibleReceiver) < 50 &&//           (!hurry || !NEEDTOCIRCLETOPASSTO(PossibleReceiver)) )//        teammates[NumOpen++] = PossibleReceiver;//    }//  }//  teammates[NumOpen]=Mem->MyNumber;//////#if PASSER_DEBUG//  printf("NumOpen: %d\n",NumOpen);//#endif////#if 0//  int WaitForData = FALSE;//  for (int j=0; j<NumOpen; j++){//    if ( !strcmp(Mem->GetData(teammates[j]),BLANK_DAT) ){//      SAYTO(teammates[j],GIVE_DATA_MSG);    /* Ping the individual for data *///      WaitForData = TRUE;//    }//  }//#endif/////* Ask for the data, but don't wait for it *///#if 0  //  if ( WaitForData ){     /* waiting for data:  don't bother evaluating yet *///    *KnockOrPass = 'd';//    *BallTo = THEIR_GOAL;//    printf("ChooseReceiverTree returned FALSE\n");//    return WHATEVER;//  }//#endif////  if ( 0 && !NumOpen /* let the clear be selected */){////    printf("%d:%d          None open\n", Mem->MyNumber, Mem->CurrentTime);////    /* Was at top of function *///    if ( Mem->FacingBackNearOwnGoal() ||/*FacingBackInOwnPA()*/ //         Mem->InOwnPenaltyArea() ){//      /* Similar condition in Cleartowards --- change there too *///      *KnockOrPass = 'c';//      if ( Mem->GetMyLocationSide() == RIGHT )//        *BallTo = RC_FLAG;//      else//        *BallTo = LC_FLAG;//      return WHATEVER;//    }////    if ( hurry || //         (Mem->MarkerValid(THEIR_GOAL) && //          Mem->GetMarkerDistance(THEIR_GOAL) < SHOOT_DIST) )//      *KnockOrPass = 'k';//    else //      *KnockOrPass = 'd';//    *BallTo = THEIR_GOAL;//    int myType = Mem->GetMyLocationsPositionType();//    int mySide = Mem->GetMyLocationsPositionSide();//    if ( myType <= DEFENDER &&   mySide == CENTER ){//      if (Mem->GetMyLocationSide() == RIGHT) /* Actual side *///        *BallTo = RF_FLAG;   /* center backs shouldn't clear it up the middle *///      else//        *BallTo = LF_FLAG;   //    }//    if ( myType != FORWARD )//      *KnockOrPass = 'c';  /* avoid players *///    return WHATEVER;//  }////#if PASSER_DEBUG//  printf("Running the DT stuff\n");//#endif////  /* Find the best teammate *///  float Confidences[NumOpen+1];  /* Array to keep confidence that pass will succeed */////  /* Limit the options that are considered *///  /* if (NumOpen > 3) NumOpen = 3;         */////#if PASS_DEBUG//  /* Random choice among DT options *///  /* int receiverIndex = int_random(NumOpen);*///  /* First choice among DT options (like WTW)*///  printf("random pass\n");//  int receiverIndex = 0;//  int receiver = teammates[receiverIndex];//  float PassSuccessConf = 1;//#else //  int receiverIndex = FindTreeConfidences(NumOpen,teammates,Confidences);//  Confidences[NumOpen]=KNOCK_CONF;//  if (receiverIndex<0) receiverIndex=0;  /* To adjust for passing in self *///  /* Overwrite the max value *///  receiverIndex = RLforReceiver(NumOpen,teammates,Confidences);////  int receiver = teammates[receiverIndex];//  float PassSuccessConf = Confidences[receiverIndex];//#endif////  //printf("%d passing to %d\n",Mem->MyNumber,receiver);////  static int Attempts = 0, Shots = 0;//  if (receiver == Mem->MyNumber)//    Shots++;//  if ( Attempts++%100 == 0 ){//    char fileName[100];//    sprintf(fileName,"rlDat/rlDatShots%d.dat",Mem->MyNumber);//    FILE *shotsFile = fopen(fileName,"w");//    fprintf(shotsFile,"%d shots out of %d attempts (%.1f\%)\n",//            Shots,Attempts,100*((float)Shots)/Attempts);//    fclose(shotsFile);//  }////  if (receiver == Mem->MyNumber /* || PassSuccessConf < 0 */){////#if 1//    *KnockOrPass = 'k';//    *BallTo = THEIR_GOAL;//    return WHATEVER;//#endif////    /* Was up top *///    if ( Mem->FacingBackNearOwnGoal() ||/*FacingBackInOwnPA()*/ //         Mem->InOwnPenaltyArea() ){//      /* Similar condition in Cleartowards --- change there too *///      *KnockOrPass = 'c';//      if ( Mem->GetMyLocationSide() == RIGHT )//        *BallTo = RC_FLAG;//      else//        *BallTo = LC_FLAG;//      return WHATEVER;//    }////    /* printf("          None will succeed\n");    *///    if ( hurry || //         (Mem->MarkerValid(THEIR_GOAL) && //          Mem->GetMarkerDistance(THEIR_GOAL) < SHOOT_DIST) )//      *KnockOrPass = 'k';//    else //      *KnockOrPass = 'd';//    *BallTo = THEIR_GOAL;//    int myType = Mem->GetMyLocationsPositionType();//    int mySide = Mem->GetMyLocationsPositionSide();//    if ( myType <= DEFENDER &&   mySide == CENTER ){//      if (Mem->GetMyLocationSide() == RIGHT)  /* Actual side *///        *BallTo = RF_FLAG;   /* center backs shouldn't clear it up the middle *///      else//        *BallTo = LF_FLAG;   //    }//    if ( myType != FORWARD )//      *KnockOrPass = 'c';  /* avoid players *///#if PASSER_DEBUG//    printf("Don't pass with confidence of %.1f\n",PassSuccessConf);//#endif//    return WHATEVER;//  }//  else{//    /* printf("ChooseReceiverTree returned %d\n",receiver); *///    *BallTo = receiver;//  }////  if ( *KnockOrPass == 'p' && ( !*BallTo || *BallTo>TEAM_SIZE ) )//    my_error("Need to pass to a teammate with a valid number");////  return WHATEVER;//}int ImmediatelyBlocked(float x, float y){  if (!UnderPressure()) return FALSE;  float ballX,ballY;  Mem->GetBallGlobalXY(&ballX,&ballY);  LINEP PassLine=LnFrom2Pts(ballX,ballY,x,y);  POSN Ball, Dest, Player;  Ball.x = ballX; Ball.y = ballY;  Dest.x = x, Dest.y = y;  float DistAlong, DistFrom;  int blocked = FALSE;  int blockedBy = 0;  for (int i=1; i<=TEAM_SIZE; i++){    if (i == Mem->MyNumber) continue;    if (!Mem->TeammateValid(i)) continue;    if (Mem->GetTeammateDistance(i) > 11) continue;    Mem->GetTeammateGlobalXY(i,&(Player.x),&(Player.y));    if ( !LnDistanceIfBetween(&Player,&Ball,&Dest,PassLine,&DistFrom,&DistAlong) )      continue;    if (fabs(DistAlong) < 10 && fabs(DistFrom) < 2){      blocked = TRUE;      blockedBy = i;      break;    }  }  if (!blocked){    for (int i=1; i<=TEAM_SIZE; i++){      if (!Mem->OpponentValid(i)) continue;      if (Mem->GetOpponentDistance(i) > 11) continue;      if (x == X0 && y == 0 && i==1) continue; /* At the goal, ignore goalie */      Mem->GetOpponentGlobalXY(i,&(Player.x),&(Player.y));      if ( !LnDistanceIfBetween(&Player,&Ball,&Dest,PassLine,&DistFrom,&DistAlong) )	continue;      if (fabs(DistAlong) < 10 && fabs(DistFrom) < 2){	blocked = TRUE;	blockedBy = i+100;	break;      }    }  }  /*if (Mem->MyNumber==11 && blocked)     printf("%d:%d **** To (%.1f %.1f) is blocked (by %d: %.1f %.1f)! ****\n",	   Mem->MyNumber, Mem->CurrentTime, x, y, blockedBy, DistAlong, DistFrom);*/  delete PassLine;  return blocked;}int ImmediatelyBlocked(int receiver){  return ImmediatelyBlocked(Mem->GetTeammateGlobalX(receiver),			    Mem->GetTeammateGlobalY(receiver));}int UseRL(char *KnockOrPass, int *BallTo){  if ( !Mem->BallValid() || Mem->GetBallDistance() > KICK_DISTANCE ){    /* Doesn't matter -- won't get used anyway, just collecting the ball */    *KnockOrPass = 'd';    *BallTo = THEIR_GOAL;    return WHATEVER;  }  *KnockOrPass = 'p';            /* otherwise pass         */#if PASSER_DEBUG  printf("*** player %d passing *** %d *** %d *** %d ***\n",         Mem->MyNumber,Mem->MyNumber,Mem->MyNumber,Mem->MyNumber);#endif  int PreferenceList[TEAM_SIZE];#if 0  /* Only consider from list */  int NumOptions = Mem->GetMyReceiverList(PreferenceList); #else  /* Consider all positions*/  int NumOptions=TEAM_SIZE;  for (int i=0; i<TEAM_SIZE; i++)    PreferenceList[i]=i;#endif  int hurry = UnderPressure(); #if PASSER_DEBUG  if (hurry)    printf("Gotta Hurry (%d)\n",Mem->MyNumber);#endif  /* choose the eligible receivers */  int actions[NUM_RL_ACTIONS];  int action_types[NUM_RL_ACTIONS];  int NumOpen = 0;  for (int i=0; i<NumOptions; i++){    if ( Mem->PositionOccupied(PreferenceList[i]) &&          Mem->GetPositionPlayer(PreferenceList[i]) != Mem->MyNumber &&	 PreferenceList[i] != Mem->GetPositionOfMyLocation() ){      int PossibleReceiver = Mem->GetPositionPlayer(PreferenceList[i]);            if ( Mem-> PlayerValid(Mem->MySide,PossibleReceiver) &&           Mem->GetPlayerDistance(Mem->MySide,PossibleReceiver) > 10 &&           Mem->GetPlayerDistance(Mem->MySide,PossibleReceiver) < 50 &&           (!hurry || !NEEDTOCIRCLETOPASSTO(PossibleReceiver)) &&	   !ImmediatelyBlocked(PossibleReceiver)){	action_types[NumOpen] = RL_PASS_ACTION;        actions[NumOpen++] = PossibleReceiver;      }    }  }  int NumActions = NumOpen;#if 1  for (int i=0; i<NUM_RL_KNOCK_ACTIONS; i++){    if ( (!hurry || !NEEDTOCIRCLE(Mem->GetMarkerAngle(i+MY_GOAL))) ){      float markerX,markerY;      Mem->GetMarkerGlobalXY(i+MY_GOAL,&markerX,&markerY);      if ( !ImmediatelyBlocked(markerX,markerY) ){	action_types[NumActions] = RL_KNOCK_ACTION;	actions[NumActions++] = i+MY_GOAL;      }    }  }  if (NumActions == NumOpen){ /* all knocks blocked */    action_types[NumActions] = RL_KNOCK_ACTION;    actions[NumActions++] = THEIR_GOAL;  }#else  /* Only shoot */  action_types[NumActions] = RL_KNOCK_ACTION;  actions[NumActions++] = THEIR_GOAL;#endif#if PASSER_DEBUG  printf("NumOpen: %d\n",NumOpen);#endif#if 0  int WaitForData = FALSE;  for (int j=0; j<NumOpen; j++){    if ( !strcmp(Mem->GetData(actions[j]),BLANK_DAT) ){      SAYTO(actions[j],GIVE_DATA_MSG);    /* Ping the individual for data */      WaitForData = TRUE;    }  }#endif/* Ask for the data, but don't wait for it */#if 0    if ( WaitForData ){     /* waiting for data:  don't bother evaluating yet */    *KnockOrPass = 'd';    *BallTo = THEIR_GOAL;    printf("ChooseReceiverTree returned FALSE\n");    return WHATEVER;  }#endif#if 0  if ( 0 && !NumOpen /* let the clear be selected */){    printf("%d:%d          None open\n", Mem->MyNumber, Mem->CurrentTime);    /* Was at top of function */    if ( Mem->FacingBackNearOwnGoal() ||/*FacingBackInOwnPA()*/          Mem->InOwnPenaltyArea() ){      /* Similar condition in Cleartowards --- change there too */      *KnockOrPass = 'c';      if ( Mem->GetMyLocationSide() == RIGHT )        *BallTo = RC_FLAG;      else        *BallTo = LC_FLAG;      return WHATEVER;    }    if ( hurry || 

⌨️ 快捷键说明

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