Exemplo n.º 1
0
double Fleet::MaxFuel() const {
    if (NumShips() < 1)
        return 0.0;

    // determine the maximum amount of fuel that can be stored by the ship in the fleet that
    // can store the least amount of fuel
    double max_fuel = Meter::LARGE_VALUE;
    bool is_fleet_scrapped = true;
    for (const_iterator ship_it = begin(); ship_it != end(); ++ship_it) {
        const Ship* ship = GetShip(*ship_it);
        if (!ship) {
            Logger().errorStream() << "Fleet::MaxFuel couldn't get ship with id " << *ship_it;
            continue;
        }
        const Meter* meter = ship->UniverseObject::GetMeter(METER_FUEL);
        if (!meter) {
            Logger().errorStream() << "Fleet::MaxFuel skipping ship with no fuel meter";
            continue;
        }
        if (!ship->OrderedScrapped()) {
            max_fuel = std::min(max_fuel, meter->Current());
            is_fleet_scrapped = false;
        }
    }
    if (is_fleet_scrapped) {
        max_fuel = 0.0;
    }
    return max_fuel;
}
Exemplo n.º 2
0
// If the game is not yet over (ie: at least two players have planets or
// fleets remaining), returns -1. If the game is over (ie: only one player
// is left) then that player's number is returned. If there are no
// remaining players, then the game is a draw and 0 is returned.
int GameState::Winner(bool maxTurnsReached) const {
	std::set<int> remainingPlayers;
	for (Planets::const_iterator p = planets.begin(); p != planets.end(); ++p) {
		remainingPlayers.insert(p->owner);
	}
	for (Fleets::const_iterator f = fleets.begin(); f != fleets.end(); ++f) {
		remainingPlayers.insert(f->owner);
	}
	remainingPlayers.erase(0);
	if (maxTurnsReached) {
		int leadingPlayer = -1;
		int mostShips = -1;
		for (std::set<int>::iterator p = remainingPlayers.begin(); p != remainingPlayers.end(); ++p) {
			int playerID = *p;
			int numShips = NumShips(playerID);
			if (numShips == mostShips) {
				leadingPlayer = 0;
			} else if (numShips > mostShips) {
				leadingPlayer = playerID;
				mostShips = numShips;
			}
		}
		return leadingPlayer;
	}
	switch (remainingPlayers.size()) {
		case 0:
			return 0;
		case 1:
			return *remainingPlayers.begin();
	}
	return -1;
}
Exemplo n.º 3
0
double Fleet::Fuel() const {
    if (NumShips() < 1)
        return 0.0;

    // determine fuel available to fleet (fuel of the ship that has the least fuel in the fleet)
    double fuel = Meter::LARGE_VALUE;
    bool is_fleet_scrapped = true;
    for (const_iterator ship_it = begin(); ship_it != end(); ++ship_it) {
        const Ship* ship = GetShip(*ship_it);
        if (!ship) {
            Logger().errorStream() << "Fleet::Fuel couldn't get ship with id " << *ship_it;
            continue;
        }
        const Meter* meter = ship->UniverseObject::GetMeter(METER_FUEL);
        if (!meter) {
            Logger().errorStream() << "Fleet::Fuel skipping ship with no fuel meter";
            continue;
        }
        if (!ship->OrderedScrapped()) {
            fuel = std::min(fuel, meter->Current());
            is_fleet_scrapped = false;
        } 
    }
    if (is_fleet_scrapped) {
        fuel = 0.0;
    }
    return fuel;
}