Esempio n. 1
0
bool Fleet::operator == (const Fleet& fleet) const{
    return (_ownerID==fleet.OwnerID() &&
		   _source_planet_id==fleet.SourcePlanetID() &&
		   _destination_planet_id==fleet.DestinationPlanetID() &&
		   _num_ships==fleet.NumShips() &&
			_turns_remaining==fleet.TurnsRemaining() );
}
Esempio n. 2
0
void Planet::advanceState(uint nr_turns, Fleets* arrivingFleets){
	Fleet* tempFleet;
	for(uint i=1;i<=nr_turns;i++){
		uint ships[NUM_PLAYERS];
		ships[PLAYER_NEUTRAL]=ships[PLAYER_1]=ships[PLAYER_2]=0;
		
		if(_ownerID!=PLAYER_NEUTRAL){
			ships_count+=_growth_rate;
		}
		ships[_ownerID]=ships_count;
		
		for(uint j=0;j<arrivingFleets->size();j++){
			tempFleet = arrivingFleets->at(j);
			if(tempFleet->TurnsRemaining()==i){
				ships[tempFleet->OwnerID()]+=tempFleet->NumShips();
			}
		}
		
		//std::cerr << "arriving ships: " << ships[0] << " " << ships[1] << " " << ships[2] << std::endl;
		uint greatest_id = _ownerID;
		uint second_greatest_id=0;
		for(uint j=0;j<NUM_PLAYERS;j++){
			if(ships[j]>ships[greatest_id]) greatest_id=j;
		}
		for(uint j=0;j<NUM_PLAYERS;j++){
			if(j!=greatest_id && ships[j]>ships[second_greatest_id]) second_greatest_id=j;
		}
		
		//std::cerr << "Player " << greatest_id << " has ships: " << ships[greatest_id] << " second: " << second_greatest_id << " " << ships[second_greatest_id] << std::endl;
		
		if(ships[greatest_id]==ships[second_greatest_id]){
			ships_count = 0;
		} else {
			//std::cerr << "setting owner: " << greatest_id << " new ship count: " << ships[greatest_id]-ships[second_greatest_id] << std::endl;
			_ownerID = greatest_id;
			ships_count = ships[greatest_id]-ships[second_greatest_id];
		}
	}
}