コード例 #1
0
ファイル: fleet.py プロジェクト: jaesivsm/pyogame
    def for_moving(self, resources):
        # FIXME dirty hack to count deuterium, highly wrong
        fleet, amount = Fleet(), resources.movable.total
        assert self, "fleet is empty !"
        if self.capacity < amount:
            logger.error(
                "Too many resources (%s) for fleet %r with capacity " "%s",
                pretty_number(amount),
                self,
                pretty_number(self.capacity),
            )
            return self
        cmp_func = lambda x, y: cmp(x.capacity, y.capacity)
        for ships in sorted(self, cmp=cmp_func, reverse=True):
            if fleet.capacity > amount:
                break
            ships = ships.copy()
            total_ship = ships.quantity
            ships.quantity = amount / ships.single_ship_capacity
            if ships.quantity > total_ship:
                ships.quantity = total_ship

            quantity_eq_capacity = amount % ships.single_ship_capacity == 0
            is_ship_left = total_ship - ships.quantity > 0
            if quantity_eq_capacity and is_ship_left:
                ships.quantity += 1
            fleet.add(ships=ships)
        return fleet
コード例 #2
0
ファイル: ui.py プロジェクト: erkantaylan/pyogame-1
def pstr(value, is_title=False):
    if isinstance(value, (list, set, tuple)):
        value = value[0]
    if is_title:
        return ' '.join(v.capitalize() for v in value.split())
    if isinstance(value, bool):
        return '+' if value else ''
    if isinstance(value, int):
        return pretty_number(value)
    return unicode(value)
コード例 #3
0
def pstr(value, is_title=False):
    if isinstance(value, (list, set, tuple)):
        value = value[0]
    if is_title:
        return ' '.join(v for v in value.split())
    if isinstance(value, bool):
        return '+' if value else ''
    if isinstance(value, int):
        return pretty_number(value)
    return str(value)
コード例 #4
0
ファイル: fleet.py プロジェクト: jaesivsm/pyogame
    def for_moving(self, resources):
        fleet, amount = Fleet(), resources.movable.total
        assert self, 'fleet is empty !'
        if self.capacity < amount:
            logger.error('Too many resources (%s) for fleet %r with capacity '
                         '%s', pretty_number(amount), self,
                               pretty_number(self.capacity))
            return self

        def cmp_func(x):
            return x.capacity

        for ships in sorted(self, key=cmp_func, reverse=True):
            if fleet.capacity > amount:
                break
            nb_ships = ceil(amount / ships.single_ship_capacity)
            if nb_ships > ships.quantity:
                fleet.add(ships.copy(quantity=ships.quantity))
            else:
                fleet.add(ships.copy(quantity=nb_ships))
        return fleet
コード例 #5
0
ファイル: fleet.py プロジェクト: jaesivsm/pyogame
    def for_moving(self, resources):
        fleet, amount = Fleet(), resources.movable.total
        assert self, 'fleet is empty !'
        if self.capacity < amount:
            logger.error(
                'Too many resources (%s) for fleet %r with capacity '
                '%s', pretty_number(amount), self,
                pretty_number(self.capacity))
            return self

        def cmp_func(x):
            return x.capacity

        for ships in sorted(self, key=cmp_func, reverse=True):
            if fleet.capacity > amount:
                break
            nb_ships = ceil(amount / ships.single_ship_capacity)
            if nb_ships > ships.quantity:
                fleet.add(ships.copy(quantity=ships.quantity))
            else:
                fleet.add(ships.copy(quantity=nb_ships))
        return fleet