void FoeReaper4000RobotCpp::hitWallWithSideAndAngle(RobotWallHitSide::RobotWallHitSide side, float hitAngle)
{
    this->cancelActiveAction();
    RWSize areaSize = arenaDimensions();
    switch (side)
    {
        case RobotWallHitSide::FRONT:
        {
            float x = generateRandomNumber(areaSize.width/4,areaSize.width/4*3);
            float y = 0.0f;
            int angle = (int) angleBetweenHeadingDirectionAndWorldPosition(RWVec(x, y));
            randomWalk(angle,angle,150,200);
        }
            break;
            
        case RobotWallHitSide::REAR:
        {
            float x = generateRandomNumber(areaSize.width/4,areaSize.width/4*3);
            float y = areaSize.height;
            int angle = (int) angleBetweenHeadingDirectionAndWorldPosition(RWVec(x, y));
            randomWalk(angle,angle,150,200);

        }
            break;
            
        case RobotWallHitSide::LEFT:
        {
            float x = 0.0;
            float y = generateRandomNumber(areaSize.height/4, areaSize.height/4*3);
            int angle = (int) angleBetweenHeadingDirectionAndWorldPosition(RWVec(x, y));
            randomWalk(angle,angle,150,200);

        }
            break;
        case RobotWallHitSide::RIGHT:
        {
            float x = areaSize.width;
            float y = generateRandomNumber(areaSize.height/4, areaSize.height/4*3);
            int angle = (int) angleBetweenHeadingDirectionAndWorldPosition(RWVec(x, y));
            randomWalk(angle,angle,150,200);

        }
            break;
      
        case RobotWallHitSide::NONE:
            break;
    }
}
void FoeReaper4000RobotCpp::bulletHitEnemy(RWVec enemyPosition)
{
    this->cancelActiveAction();
    lastEnemyPos = enemyPosition;
    keepStay = true;
    randomWalk();
}
void FoeReaper4000RobotCpp::run()
{
    while (true)
    {
        randomWalk();
    }
}
void LandingTabuSearch<TTabuSearch, TSolution>::run(const size_t numberOfSteps)
{
    // 1. create random solutions via randomWalk procedure
    std::srand(unsigned (time(0)));
    std::vector<TSolution> randomSolutions;
    for (size_t i = 0; i < numberOfLandings; ++i)
    {
        randomSolutions.emplace_back(randomWalk(bestSolution, depth, data.getNumberOfServers(), data.getNumberOfDisks()));
    }

    // 2. ditribute random solution
    auto task = [&randomSolutions, numberOfSteps](TTabuSearch tabuSearch, size_t idx) -> void
    {
        tabuSearch.setStartSolution(randomSolutions[idx]);
        tabuSearch.run(numberOfSteps);

        assert(idx >= 0 && idx < randomSolutions.size());
        randomSolutions[idx] = tabuSearch.getBestSolution();
    };

    std::vector<std::future<void>> futures(numberOfLandings - 1);
    for (size_t i = 0; i < futures.size(); ++i)
    {
        futures[i] = scheduler->schedule(task, tabuSearch, i);
    }
    tabuSearch.run(numberOfSteps);
    randomSolutions.back() = tabuSearch.getBestSolution();

    // 3. gather results and choise best solution
    for (auto& future : futures) { future.get(); }
    auto best = std::min_element(randomSolutions.begin(), randomSolutions.end());
    bestSolution = *best;
}
示例#5
0
bool SampleSAT::walk()
{
  int ca;
  if(ssdebug == true){
    printf("step:%3d\n",step_);
  }
  step_++;
  if(sat_->getNumSat() > numClause){
    printf("illigal sat clause: %d / %d\n",sat_->getNumSat(),numClause);
  }
  if(sat_->getGrand() < ssparams_->walksatProb){
    if(sat_->getGrand() < ssparams_->randomWalkProb){
      ca = randomWalk();
      if(ca == -1){
        return false;
      }
    }else ca = greedyWalk();
  }else{
    ca = simAnnealing();
    if(ca == -1){
      return false;
    }
  }

  if(ssdebug == true){
    printModels();
  }
  if(sat_->getNumSat() == numClause){
    return true;
  }
  return false;
}
void FoeReaper4000RobotCpp::scannedRobotAtPosition(RWVec position)
{
    this->cancelActiveAction();
    lastEnemyPos = position;
    keepStay = true;
    randomWalk();

}
//if got hit, make a random move
void FoeReaper4000RobotCpp::gotHit() {
    //TODO: if enemy is in the area of scanner, do not move to enemy?
   keepStay = false;
   randomWalk(0,360,150,200);
    
}