예제 #1
0
    def can_place_at(self, system, plan):
        """
        Check if the starlane altering monster fleet ''plan'' can be placed at ''system''
        without disjoining the galaxy map.
        Compute the disjoint set of the galaxy without the starlanes
        from the proposed system.  Return False if there will be more
        connected regions than the number of placed starlane altering
        monsters plus one, otherwise True.
        """
        local_lanes = {(min(system, s), max(system, s)) for s in fo.sys_get_starlanes(system)}

        dsets = DisjointSets()
        for s in self.systems:
            dsets.add(s)

        for lane in self.starlanes:
            if lane in self.removed_lanes or lane in local_lanes:
                continue
            dsets.link(lane[0], lane[1])

        num_contiguous_regions = len(dsets.complete_sets())
        expected_num_contiguous_regions = (len(self.placed) + 2)

        if num_contiguous_regions > expected_num_contiguous_regions:
            return False

        if num_contiguous_regions < expected_num_contiguous_regions:
            report_error("Number of contiguous regions %d is below the expected number "
                         "of contiguous regions %d when placing %d monster %s that can "
                         "break starlanes."
                         % (num_contiguous_regions, expected_num_contiguous_regions,
                            len(self.placed) + 1, plan.name()))
            return False

        return True
예제 #2
0
    def can_place_at(self, system, plan):
        """
        Check if the starlane altering monster fleet ''plan'' can be placed at ''system''
        without disjoining the galaxy map.
        Compute the disjoint set of the galaxy without the starlanes
        from the proposed system.  Return False if there will be more
        connected regions than the number of placed starlane altering
        monsters plus one, otherwise True.
        """
        local_lanes = {(min(system, s), max(system, s)) for s in fo.sys_get_starlanes(system)}

        dsets = DisjointSets()
        for s in self.systems:
            dsets.add(s)

        for lane in self.starlanes:
            if lane in self.removed_lanes or lane in local_lanes:
                continue
            dsets.link(lane[0], lane[1])

        num_contiguous_regions = len(dsets.complete_sets())
        expected_num_contiguous_regions = (len(self.placed) + 2)

        if num_contiguous_regions > expected_num_contiguous_regions:
            return False

        if num_contiguous_regions < expected_num_contiguous_regions:
            report_error("Number of contiguous regions %d is below the expected number "
                         "of contiguous regions %d when placing %d monster %s that can "
                         "break starlanes."
                         % (num_contiguous_regions, expected_num_contiguous_regions,
                            len(self.placed) + 1, plan.name()))
            return False

        return True
예제 #3
0
    def place(self, system, plan):
        """
        Create map altering monster fleet ''plan'' at ''system''.
        """
        local_lanes = {(min(system, s), max(system, s)) for s in fo.sys_get_starlanes(system)}

        populate_monster_fleet(plan, system)
        if system not in self.placed:
            self.placed.add(system)
            self.removed_lanes |= local_lanes
예제 #4
0
    def place(self, system, plan):
        """
        Create map altering monster fleet ''plan'' at ''system''.
        """
        local_lanes = {(min(system, s), max(system, s)) for s in fo.sys_get_starlanes(system)}

        populate_monster_fleet(plan, system)
        if system not in self.placed:
            self.placed.add(system)
            self.removed_lanes |= local_lanes
예제 #5
0
def log_systems():
    universe = fo.get_universe()

    systems_table = Table(
        [Text('id'), Text('name'), Sequence('planets'), Sequence('connections'), Text('star')],
        table_name='System summary')
    for sid in fo.get_systems():
        system = universe.getSystem(sid)
        systems_table.add_row([
            sid, system.name, fo.sys_get_planets(sid), fo.sys_get_starlanes(sid), system.starType.name
        ])

    # Printing too much info at once will lead to truncation of text
    for line in systems_table.get_table().split('\n'):
        print(line)
예제 #6
0
def log_systems():
    universe = fo.get_universe()

    systems_table = Table(
        [Text('id'), Text('name'), Sequence('planets'), Sequence('connections'), Text('star')],
        table_name='System summary')
    for sid in fo.get_systems():
        system = universe.getSystem(sid)
        systems_table.add_row([
            sid, system.name, fo.sys_get_planets(sid), fo.sys_get_starlanes(sid), system.starType.name
        ])

    # Printing too much info at once will lead to truncation of text
    for line in systems_table.get_table().split('\n'):
        print line
예제 #7
0
def get_systems_within_jumps(origin_system, jumps):
    """
    Returns all systems within jumps jumps of system origin_system (including origin_system).
    If jumps is 0, return list that only contains system origin_system.
    If jumps is negative, return empty list.
    """
    if jumps < 0:
        return []
    matching_systems = [origin_system]
    next_origin_systems = [origin_system]
    while jumps > 0:
        origin_systems = list(next_origin_systems)
        next_origin_systems = []
        for system in origin_systems:
            neighbor_systems = [s for s in fo.sys_get_starlanes(system) if s not in matching_systems]
            next_origin_systems.extend(neighbor_systems)
            matching_systems.extend(neighbor_systems)
        jumps -= 1
    return matching_systems
예제 #8
0
def get_systems_within_jumps(origin_system, jumps):
    """
    Returns all systems within jumps jumps of system origin_system (including origin_system).
    If jumps is 0, return list that only contains system origin_system.
    If jumps is negative, return empty list.
    """
    if jumps < 0:
        return []
    matching_systems = [origin_system]
    next_origin_systems = [origin_system]
    while jumps > 0:
        origin_systems = list(next_origin_systems)
        next_origin_systems = []
        for system in origin_systems:
            neighbor_systems = [s for s in fo.sys_get_starlanes(system) if s not in matching_systems]
            next_origin_systems.extend(neighbor_systems)
            matching_systems.extend(neighbor_systems)
        jumps -= 1
    return matching_systems
예제 #9
0
def log_systems():
    universe = fo.get_universe()

    systems_table = Table(
        Text("id"),
        Text("name"),
        Sequence("planets"),
        Sequence("connections"),
        Text("star"),
        table_name="System summary",
    )
    for sid in fo.get_systems():
        system = universe.getSystem(sid)
        systems_table.add_row(
            sid,
            system.name,
            fo.sys_get_planets(sid),
            fo.sys_get_starlanes(sid),
            system.starType.name,
        )
    systems_table.print_table(print)
예제 #10
0
 def __init__(self, systems):
     self.systems = systems
     self.placed = set()
     self.removed_lanes = set()
     self.starlanes = [(s1, s2) for s1 in systems for s2 in fo.sys_get_starlanes(s1) if s1 < s2]
예제 #11
0
 def __init__(self, systems):
     self.systems = systems
     self.placed = set()
     self.removed_lanes = set()
     self.starlanes = [(s1, s2) for s1 in systems
                       for s2 in fo.sys_get_starlanes(s1) if s1 < s2]