void Controller::createBalloon(){ //BALLOON CREATION RATE based on difficulty if (--iTimeBetweenBalloonCreation !=0) return; iTimeBetweenBalloonCreation = QUANTUM_WAIT_TIME + QUANTUM_WAIT_TIME*(FAST-mSpeed); //if set to fast last term drops to 0 then balloons are created quickly //LOCATION number between 0 and max balloon size for location int ilocx = rand()%(myScreenBufferSize.x -BALLOON_WIDTH); int ilocy = rand()%BALLOON_APPEAR_BAND_SIZE; //anywhere withen first 5 lines location myLoc(ilocx, ilocy); //HOW LONG BEFORE IT FALLS int iHowLongBeforeFall = MIN_BALLOON_HOVER_TIME + ((FAST-mSpeed)*QUANTUM_WAIT_TIME); //SPEED OF FALL SPEED iBalloonSpeed = (SPEED)((rand()%mSpeed) +1); //make sure this falls between SLOW=1 and FAST=4 Balloon aBalloon(myScreenBufferSize,myLoc,iHowLongBeforeFall,iBalloonSpeed); myBalloons.push_back(aBalloon); }
bool AI::runZombie() { cout<<"Zombie Turn: "<<turnNum()<<endl; int freeToSpawn = (getZombieCap() - zombies.size()<getZombiesReady()?getZombieCap() - zombies.size():getZombiesReady()); //cout<<"Cap: "<<getZombieCap()<<" Size: "<<zombies.size()<<" Ready: "<<getZombiesReady()<<" Spawning: "<<freeToSpawn<<endl; for(int s=0;s<freeToSpawn;s++) { Zombie::spawn(spawnzones[rand()%spawnzones.size()],rand()%6); } int index; for(unsigned int z=0;z<zombies.size();z++) { location myLoc(zombies[z].x(),zombies[z].y()); location inFrontOfMe = myLoc + offset[zombies[z].facing()]; if(!inBounds(inFrontOfMe.x,inFrontOfMe.y)) { zombies[z].turn( (rand()%2==0?TURN_LEFT:TURN_RIGHT) ); } //if there is a wall in front of you else if((index=atLocation(walls,inFrontOfMe))!=-1) { // cout<<"Zombie Facing Wall["<<index<<"] at "<<walls[index].x()<<" "<<walls[index].y()<<endl; //turns at random either left or right zombies[z].turn( (rand()%2==0?TURN_LEFT:TURN_RIGHT) ); } //if a human is directly in front of you else if((index=atLocation(humans,inFrontOfMe)) != -1) { zombies[z].turn( (rand()%2==0?TURN_LEFT:TURN_RIGHT) ); } else //if nothing is directly in front of you { zombies[z].move(); } } cout<<"EndTurn"<<endl; return true; }
void TypicalTimeOfLocalisationBuilt(std::string iInstance) { // Creation of the instance Testio Instance(iInstance); // Time needed to build the localisation double ConstructionUserTime = 0; double ConstructionCPUTime = 0; // Time to explore a neighbourhood for Hamming distance equal to 1 double Exploration1UserTime = 0; double Exploration1CPUTime = 0; // Time to explore a neighbourhood for Hamming distance equal to 2 double Exploration2UserTime = 0; double Exploration2CPUTime = 0; // Time to explore a neighbourhood for Hamming distance equal to 3 double Exploration3UserTime = 0; double Exploration3CPUTime = 0; // Time to execute a complete local search double LocalSearchUserTime = 0; double LocalSearchCPUTime = 0; int NbIter = 10; int i; for (i = 0; i < NbIter; i++) { Localisation myLoc(Instance, 0, 0); // Construction of the localisation double BeginUserTime = get_wall_time(); double BeginCPUTime = get_cpu_time(); myLoc.Construction(3); double EndCPUTime = get_cpu_time(); double EndUserTime = get_wall_time(); ConstructionUserTime = ConstructionUserTime + EndUserTime - BeginUserTime; ConstructionCPUTime = ConstructionCPUTime + EndCPUTime - BeginCPUTime; // Exploration of a neighbourhood for Hamming distance equal to 1 BeginUserTime = get_wall_time(); BeginCPUTime = get_cpu_time(); myLoc.NeighbourhoodSearch(1); EndCPUTime = get_cpu_time(); EndUserTime = get_wall_time(); Exploration1UserTime = Exploration1UserTime + EndUserTime - BeginUserTime; Exploration1CPUTime = Exploration1CPUTime + EndCPUTime - BeginCPUTime; // Exploration of a neighbourhood for Hamming distance equal to 1 BeginUserTime = get_wall_time(); BeginCPUTime = get_cpu_time(); myLoc.NeighbourhoodSearch(2); EndCPUTime = get_cpu_time(); EndUserTime = get_wall_time(); Exploration2UserTime = Exploration2UserTime + EndUserTime - BeginUserTime; Exploration2CPUTime = Exploration2CPUTime + EndCPUTime - BeginCPUTime; // Exploration of a neighbourhood for Hamming distance equal to 1 BeginUserTime = get_wall_time(); BeginCPUTime = get_cpu_time(); myLoc.NeighbourhoodSearch(3); EndCPUTime = get_cpu_time(); EndUserTime = get_wall_time(); Exploration3UserTime = Exploration3UserTime + EndUserTime - BeginUserTime; Exploration3CPUTime = Exploration3CPUTime + EndCPUTime - BeginCPUTime; } int NbLocalSearch = 5; for (i = 0; i < NbLocalSearch; i++) { Localisation myLoc(Instance, 0, 0); // Construction of the localisation myLoc.Construction(3); // Computation of a complete local search double BeginUserTime = get_wall_time(); double BeginCPUTime = get_cpu_time(); myLoc.LocalSearchAlgorithm(3); double EndCPUTime = get_cpu_time(); double EndUserTime = get_wall_time(); LocalSearchUserTime = LocalSearchUserTime + EndUserTime - BeginUserTime; LocalSearchCPUTime = LocalSearchCPUTime + EndCPUTime - BeginCPUTime; } std::cout.precision(4); std::cout << "Time needed to build the localisation\n"; std::cout << " CPU time : " << ConstructionCPUTime/NbIter << "s\n"; std::cout << " User time: " << ConstructionUserTime/NbIter << "s\n"; std::cout << "Time to explore a neighbourhood for Hamming distance equal to 1\n"; std::cout << " CPU time : " << Exploration1CPUTime/NbIter << "s\n"; std::cout << " User time: " << Exploration1UserTime/NbIter << "s\n"; std::cout << "Time to explore a neighbourhood for Hamming distance equal to 2\n"; std::cout << " CPU time : " << Exploration2CPUTime/NbIter << "s\n"; std::cout << " User time: " << Exploration2UserTime/NbIter << "s\n"; std::cout << "Time to explore a neighbourhood for Hamming distance equal to 3\n"; std::cout << " CPU time : " << Exploration3CPUTime/NbIter << "s\n"; std::cout << " User time: " << Exploration3UserTime/NbIter << "s\n"; std::cout << "Time to execute a complete local search\n"; std::cout << " CPU time : " << LocalSearchCPUTime/NbLocalSearch << "s\n"; std::cout << " User time: " << LocalSearchUserTime/NbLocalSearch << "s\n"; std::cout << "\n"; }