Пример #1
0
def get_starting_species_pool():
    """
    Empire species pool generator, return random empire species and ensure somewhat even distribution
    """
    # fill the initial pool with two sets of all playable species
    # this way we have somewhat, but not absolutely strict even distribution of starting species at least when there
    # is only a few number of players (some species can occur twice at max while others not at all)
    pool = fo.get_playable_species() * 2

    # check all players setup data for players that have their starting species already set, and remove one instance
    # of that species from our initial pool to preserve correct distribution (as it has already been picked once)
    for psd_entry in fo.get_player_setup_data():
        species = psd_entry.data().starting_species
        if species in pool:
            pool.remove(species)

    # randomize order in initial pool so we don't get the same species all the time
    random.shuffle(pool)
    # generator loop
    while True:
        # if our pool is exhausted (because we have more players than species instances in our initial pool)
        # refill the pool with one set of all playable species
        if not pool:
            pool = fo.get_playable_species()
            # again, randomize order in refilled pool so we don't get the same species all the time
            random.shuffle(pool)
        # pick and return next species, and remove it from our pool
        yield pool.pop()
Пример #2
0
def log_species_summary():
    num_empires = sum(empire_species.values())
    num_species = len(fo.get_playable_species())
    exp_count = num_empires // num_species
    print "Empire Starting Species Summary for %d Empires and %d playable species" % (num_empires, num_species)
    print "Approximately %d to %d empires expected per species" % (max(0, exp_count - 1), exp_count + 1)
    print "%-16s :   # --     %%" % ("species")
    for species, count in empire_species.items():
        if count:
            print "%-16s : %3d -- %5.1f%%" % (species, count, 100.0 * count / num_empires)
    print
    inverse_native_chance = fo.native_frequency(fo.get_galaxy_setup_data().nativeFrequency)
    native_chance = 1.0 / (1e-5 + inverse_native_chance)
    print "Natives Placement Summary (native frequency: %.1f%%)" % (inverse_native_chance and (100 * native_chance))
    # as the value in the universe table is higher for a lower frequency, we have to invert it
    # exception: a value of 0 means no natives, in this case return immediately
    if inverse_native_chance <= 0:
        return
    native_potential_planet_total = sum(potential_native_planet_summary.values())
    for species in species_summary:
        if species_summary[species] > 0:
            settleable_planets = 0
            expectation_tally = 0.0
            for p_type in natives.planet_types_for_natives[species]:
                settleable_planets += potential_native_planet_summary[p_type]
                expectation_tally += native_chance * 100.0 * potential_native_planet_summary[p_type] / len(natives.natives_for_planet_type[p_type])
            expectation = expectation_tally / settleable_planets
            print "Settled natives %18s on %3d planets -- %5.1f%% of total and %5.1f%% vs %5.1f%% (actual vs expected) of %s planets" % \
                (species, species_summary[species], 100.0 * species_summary[species] / native_potential_planet_total,
                 100.0 * species_summary[species] / settleable_planets, expectation, [str(p_t) for p_t in natives.planet_types_for_natives[species]])
    print
    native_settled_planet_total = sum(settled_native_planet_summary.values())
    print "Planet Type Summary for Native Planets (native frequency: %.1f%%)" % (inverse_native_chance and (100 * native_chance))
    print "%19s : %-s" % ("Potential (% of tot)", "Settled (% of potential)")
    print "%-13s %5d : %5d" % ("Totals", native_potential_planet_total, native_settled_planet_total)
    for planet_type, planet_count in potential_native_planet_summary.items():
        settled_planet_count = settled_native_planet_summary.get(planet_type, 0)
        potential_percent = 100.0 * planet_count / native_potential_planet_total
        settled_percent = 100.0 * settled_planet_count / (1E-10 + planet_count)
        print "%-12s %5.1f%% : %5.1f%%" % (planet_type.name, potential_percent, settled_percent)
Пример #3
0
import fo_universe_generator as fo
import planets
import natives


species_summary = {species: 0 for species in fo.get_native_species()}
empire_species = {species: 0 for species in fo.get_playable_species()}
potential_native_planet_summary = {planet_type: 0 for planet_type in planets.planet_types}
settled_native_planet_summary = {planet_type: 0 for planet_type in planets.planet_types}
monsters_summary = []
tracked_monsters_chance = {}
tracked_monsters_tries = {}
tracked_monsters_summary = {}
tracked_monsters_location_summary = {}
tracked_nest_location_summary = {}
specials_summary = {special: 0 for special in fo.get_all_specials()}
specials_repeat_dist = {count: 0 for count in [0, 1, 2, 3, 4]}

def log_planet_count_dist(sys_list):
    planet_count_dist = {}
    planet_size_dist = {size : 0 for size in planets.planet_sizes}
    for system in sys_list:
        planet_count = 0
        for planet in fo.sys_get_planets(system):
            this_size = fo.planet_get_size(planet)
            if this_size in planets.planet_sizes:
                planet_count += 1
                planet_size_dist[this_size] += 1
        planet_count_dist.setdefault(planet_count, [0])[0] += 1
    planet_tally = sum(planet_size_dist.values())
    print "Planet Count Distribution: planets_in_system | num_systems | % of systems"