Basic::Ubf::Action* PlaneSlowTurn::genAction(const Basic::Ubf::State* const state, const LCreal dt)
{
   PlaneAction* action = 0;
   const PlaneState* pState = dynamic_cast<const PlaneState*>(state->getUbfStateByType(typeid(PlaneState)));

   if (pState!=0 && pState->isAlive()) {
      action = new PlaneAction();
      //std::cout<<pState->getRoll()<<" "<<pState->getPitch()<<" "<<pState->getHeading()<<std::endl;
      //double currentAlt = pState->getAltitude();
      //double changeInAlt = currentAlt - prevAlt;

      //double pitch = 1;//.5;
      //action->setPitch(pitch);

      double roll;
      //if(pState->getPitch() >.015)
      //{
      //  roll = -1 * pState->getRoll() - 1.25;
      //}else if(pState->getPitch()< 0){
      //roll = -1 * pState->getRoll() - 1.0;
      //}else{
      roll = -1 * pState->getRoll() - 1.047;//1.25
      //}
      roll *= 100;
      //if(roll > 1)
      //  roll = 1;
      action->setRoll(roll);
      action->setThrottle(1.5);

      action->setVote(getVote());
   }
   return action;
}
示例#2
0
文件: FHLD.cpp 项目: ruescasd/FHLD
vector<vector <long> > readDelegateVotes(string fileName, int slots, int delegateLimit) {
  std::ifstream file(fileName.c_str());
  std::string str;

  vector<vector <long> > votes;
  votes.assign(delegateLimit, getVote(-1, slots));

  while (std::getline(file, str)) {
    vector<string> tokens = split(str, ' ');
    int delegate = atoi(tokens[0].c_str());
    int vote = atoi(tokens[1].c_str());

    // cerr << delegate << " " << vote << "\n";
    cerr << ".";

    votes[delegate - 1] = getVote(vote, slots);
  }

  return votes;
}
示例#3
0
文件: FHLD.cpp 项目: ruescasd/FHLD
Ctxt select(Ctxt ctxt, int value, EncryptedArray ea, const FHEPubKey& publicKey) {
  PlaintextArray mask(ea);
  mask.encode(getVote(value, ea.size()));

  Ctxt maskCtxt(publicKey);
  ea.encrypt(maskCtxt, publicKey, mask);

  Ctxt ret(ctxt);
  ret.multiplyBy(maskCtxt);

  return ret;
}
示例#4
0
文件: FHLD.cpp 项目: ruescasd/FHLD
vector<vector <long> > readVotes(string fileName, int slots) {
  std::ifstream file(fileName.c_str());
  std::string str;

  vector<vector <long> > votes;

  while (std::getline(file, str)) {
      votes.push_back(getVote(atoi(str.c_str()), slots));
      cerr << ".";
  }

  return votes;
}
Basic::Ubf::Action* PlaneFlyStraight::genAction(const Basic::Ubf::State* const state, const LCreal dt)
{
   PlaneAction* action = 0;
   const PlaneState* pState = dynamic_cast<const PlaneState*>(state->getUbfStateByType(typeid(PlaneState)));

   if (pState!=0 && pState->isAlive()) {
      action = new PlaneAction();
      
      //Reverse pitch to get level with the horizon
      double pitch = -1 * pState->getPitch();
      //For positive pitch values, multiply to counteract effects of the negative pitch rate
      //of the dynamics model
      if (pitch > 0) {
         pitch *= 1;
      }
      //If below the threshold, add an amount to the pitch based on the distance below the threshold
      if (pState->getAltitude() < holdingAltitude) {
         pitch += ((holdingAltitude - pState->getAltitude()) / (200));
      }
      action->setPitch(pitch);

      double roll = -1 * pState->getRoll();
      roll *= 0.5;
      action->setRoll(roll);

      if (pState->getRoll() > 1.57 || pState->getRoll() < -1.57) {
         action->setPitch(action->getPitch() * -1);                //change pitch in the opposite direction if upside-down
      }

      //double heading = 1;
      action->setHeading( pState -> getHeading() );
      //double pitchTrim = 0;
      action->setThrottle(0.50);

      if (pState->getSpeed() < 150.0 ) {
         action->setThrottle(2.0);
         if (pState->getSpeed() < 110.0 )
                action->setPitch(-1);
      }

      if (voteOnCriticalAltitude!=0 && pState->getAltitude() < criticalAltitude)
         action->setVote(voteOnCriticalAltitude);  // was 100
      else
         action->setVote(getVote());
   }
   return action;
}
Basic::Ubf::Action* PlaneRoll::genAction(const Basic::Ubf::State* const state, const LCreal dt)
{
   PlaneAction* action = 0;
   const PlaneState* pState = dynamic_cast<const PlaneState*>(state->getUbfStateByType(typeid(PlaneState)));

   if (pState!=0 && pState->isAlive()) {
      double roll=1;
      action = new PlaneAction();

      action->setRoll(roll);

      if (voteOnIncomingMissile!=0 && pState->isIncomingMissile() )
         action->setVote(voteOnIncomingMissile);   // was 100
      else
         action->setVote(getVote());

   }
   return action;
}
Basic::Ubf::Action* PlaneFire::genAction(const Basic::Ubf::State* const state, const LCreal dt)
{
    PlaneAction* action = 0;
    const PlaneState* pState = dynamic_cast<const PlaneState*>(state->getUbfStateByType(typeid(PlaneState)));
   
    if ( pState!=0 && pState->isAlive() )
    {
        action = new PlaneAction();
        action->setVote(getVote());
        action -> setFireMissile(false);
        
        if( pState->isTracking() && pState->getTargetTrack()<PlaneState::MAX_TRACKS )
        {
            if ( !pState->isMissileFired() && pState->getDistanceToTracked( pState->getTargetTrack()) < maxDistance )
            {
                action->setFireMissile(true);
            }
        }
    }
    return action;
}
Basic::Ubf::Action* PlaneLoop::genAction(const Basic::Ubf::State* const state, const LCreal dt)
{
   PlaneAction* action = 0;
   const PlaneState* pState = dynamic_cast<const PlaneState*>(state->getUbfStateByType(typeid(PlaneState)));

   if (pState!=0 && pState->isAlive()) {
      action = new PlaneAction();
      action->setRoll(0.0);
      if(pState->getSpeed() < 600 && !keepGoing) {
         action->setPitch(0);
      } else {
         keepGoing = true;
         action->setPitch(1);
      }

      if (voteOnIncomingMissile!=0 && pState->isIncomingMissile() )
         action->setVote(voteOnIncomingMissile); // was 75
      else
         action->setVote(getVote());

   }
   return action;
}
Basic::Ubf::Action* PlaneTrim::genAction(const Basic::Ubf::State* const state, const LCreal dt)
{
   PlaneAction* action = 0;
   const PlaneState* pState = dynamic_cast<const PlaneState*>(state->getUbfStateByType(typeid(PlaneState)));

   if (pState!=0 && pState->isAlive()) {
      double pitchTrim = 0;
      action = new PlaneAction();

      if(pState->getPitch() >0.0) {
         pitchTrim = -.1;
      }else{
         pitchTrim = .1;
      }
      action->setPitchTrim(pitchTrim);

      if (voteOnCriticalAltitude!=0 && pState->getAltitude() < criticalAltitude)
         action->setVote(voteOnCriticalAltitude);   // was 100
      else
         action->setVote(getVote());

   }
   return action;
}
示例#10
0
Basic::Ubf::Action* PlaneDive::genAction(const Basic::Ubf::State* const state, const LCreal dt)
{
   PlaneAction* action = 0;
   const PlaneState* pState = dynamic_cast<const PlaneState*>(state->getUbfStateByType(typeid(PlaneState)));

   if (pState!=0 && pState->isAlive()) {
      double pitch;
      action = new PlaneAction();

      if(pState->getPitch() > -Eaagles::PI/2) {
         pitch=-1;
      } else {
         pitch = 1;
      }
      action->setPitch(pitch);

      if (voteOnIncomingMissile!=0 && pState->isIncomingMissile() )
         action->setVote(voteOnIncomingMissile);   // was 100
      else
         action->setVote(getVote());
	  	  
   }
   return action;
}
示例#11
0
Basic::Ubf::Action* PlaneFollowEnemy::genAction(const Basic::Ubf::State* const state, const LCreal dt)
{
	PlaneAction* action = 0;
	const PlaneState* pState = dynamic_cast<const PlaneState*>(state->getUbfStateByType(typeid(PlaneState)));

	if (pState!=0 && pState->isAlive() && pState->isTracking() && pState->getTargetTrack()<PlaneState::MAX_TRACKS)
    {
        action = new PlaneAction();

        double pitch = -1 * pState->getPitch()+ .02;// pState->getPitchToEnemy() * 10;
        //For positive pitch values, multiply to counteract effects of the negative pitch rate
        //of the dynamics model
        if (pitch > 0)
        {
            pitch *= 5;
        }

        double roll = -1 * pState->getRoll();
        unsigned int targetTrack = pState->getTargetTrack();
        roll += pState->getHeadingToTracked(targetTrack) * 1;

        if (pState->getRoll() < -1.57079)
        {
            roll = -1 * pState->getRoll() - 1.57079;
        } 
        else if (pState->getRoll() > 1.57079)
        {
            roll = -1 * pState->getRoll() + 1.57079;
        }

        if(roll > 1.57079)
        {
            roll = 1.57079;
        }
        if(roll < -1.57079)
        {
            roll = -1.57079;
        }        

        if( pState -> getDistanceToTracked( pState -> getTargetTrack() ) > 4000 )
        {
	        action -> setThrottle( 1.0 );
            if( std::abs( pState -> getHeadingToTracked( pState -> getTargetTrack() ) ) < 0.1 )
            {
                if( std::abs( pState -> getRoll() ) < 0.1 )
                {
                    pitch += ( -0.5 * ( Eaagles::PI / 180.0 ) );
                }
            }
        }
        else// if( pState -> getDistanceToTracked( pState -> getTargetTrack() ) < 2000 )
        {
	        action -> setThrottle( 0.0 );
        }

        action->setRoll(roll);
        action->setPitch(pitch);

        action->setVote(getVote());
    }
    return action;
}