Exemple #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

    # 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()
Exemple #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] / (1E-10 + len(natives.natives_for_planet_type[p_type]))
            expectation = expectation_tally / (1E-10 + 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] / (1E-10 + native_potential_planet_total),
                 100.0 * species_summary[species] / (1E-10 + 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 / (1E-10 + 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)
Exemple #3
0
import freeorion as fo
import planets
import natives
import universe_tables


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())
import freeorion as fo
from common.print_utils import Float, Sequence, Table, Text

import natives
import planets
import universe_tables

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}
Exemple #5
0
def log_species_summary(native_freq):
    num_empires = sum(empire_species.values())
    num_species = len(fo.get_playable_species())
    exp_count = num_empires // num_species

    species_summary_table = Table(
        [Text('species'), Text('count'), Float('%', precession=1)],
        table_name=('Empire Starting Species Summary\n'
                    'Approximately %d to %d empires expected per species\n'
                    '%d Empires and %d playable species') % (max(0, exp_count - 1), exp_count + 1,
                                                             num_empires, num_species)
    )

    for species, count in sorted(empire_species.items()):
        species_summary_table.add_row((species, count, 100.0 * count / num_empires))
    print(species_summary_table)
    print()

    native_chance = universe_tables.NATIVE_FREQUENCY[native_freq]
    # as the value in the universe table is higher for a lower frequency, we have to invert it
    # a value of 0 means no natives, in this case return immediately
    if native_chance <= 0:
        return
    native_table = Table(
        [
            Text('settled natives'),
            Text('on planets'),
            Float('total', precession=1),
            Float('actual', precession=1),
            Float('expected', precession=1),
            Sequence('planet types')
        ],
        table_name="Natives Placement Summary (native frequency: %.1f%%)" % (100 * native_chance)
    )

    native_potential_planet_total = sum(potential_native_planet_summary.values())
    for species in sorted(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] /
                        (1E-10 + len(natives.natives_for_planet_type[p_type]))
                )
            expectation = expectation_tally / (1E-10 + settleable_planets)
            native_table.add_row(
                [species,
                 species_summary[species], 100.0 * species_summary[species] / (1E-10 + native_potential_planet_total),
                 100.0 * species_summary[species] / (1E-10 + settleable_planets),
                 expectation,
                 [str(p_t) for p_t in natives.planet_types_for_natives[species]]]
            )

    print(native_table)
    print()

    native_settled_planet_total = sum(settled_native_planet_summary.values())
    type_summary_table = Table(
        [Text('planet type'), Float('potential (% of tot)', precession=1),
         Float('settled (% of potential)', precession=1)],
        table_name=("Planet Type Summary for Native Planets (native frequency: %.1f%%)\n"
                    "Totals: native_potential_planet_total: %s; native_settled_planet_total %s"
                    ) % (100 * native_chance, native_potential_planet_total, native_settled_planet_total)
    )

    for planet_type, planet_count in sorted(potential_native_planet_summary.items()):
        settled_planet_count = settled_native_planet_summary.get(planet_type, 0)
        potential_percent = 100.0 * planet_count / (1E-10 + native_potential_planet_total)
        settled_percent = 100.0 * settled_planet_count / (1E-10 + planet_count)
        type_summary_table.add_row((planet_type.name, potential_percent, settled_percent))
    print(type_summary_table)
    print()
def log_species_summary(native_freq):
    num_empires = sum(empire_species.values())
    num_species = len(fo.get_playable_species())
    exp_count = num_empires // num_species

    species_summary_table = Table(
        [Text('species'), Text('count'), Float('%', precession=1)],
        table_name=('Empire Starting Species Summary\n'
                    'Approximately %d to %d empires expected per species\n'
                    '%d Empires and %d playable species') % (max(0, exp_count - 1), exp_count + 1,
                                                             num_empires, num_species)
    )

    for species, count in sorted(empire_species.items()):
        species_summary_table.add_row((species, count, 100.0 * count / num_empires))
    print species_summary_table
    print

    native_chance = universe_tables.NATIVE_FREQUENCY[native_freq]
    # as the value in the universe table is higher for a lower frequency, we have to invert it
    # a value of 0 means no natives, in this case return immediately
    if native_chance <= 0:
        return
    native_table = Table(
        [
            Text('settled natives'),
            Text('on planets'),
            Float('total', precession=1),
            Float('actual', precession=1),
            Float('expected', precession=1),
            Sequence('planet types')
        ],
        table_name="Natives Placement Summary (native frequency: %.1f%%)" % (100 * native_chance)
    )

    native_potential_planet_total = sum(potential_native_planet_summary.values())
    for species in sorted(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] /
                        (1E-10 + len(natives.natives_for_planet_type[p_type]))
                )
            expectation = expectation_tally / (1E-10 + settleable_planets)
            native_table.add_row(
                [species,
                 species_summary[species], 100.0 * species_summary[species] / (1E-10 + native_potential_planet_total),
                 100.0 * species_summary[species] / (1E-10 + settleable_planets),
                 expectation,
                 [str(p_t) for p_t in natives.planet_types_for_natives[species]]]
            )

    print native_table
    print

    native_settled_planet_total = sum(settled_native_planet_summary.values())
    type_summary_table = Table(
        [Text('planet type'), Float('potential (% of tot)', precession=1),
         Float('settled (% of potential)', precession=1)],
        table_name=("Planet Type Summary for Native Planets (native frequency: %.1f%%)\n"
                    "Totals: native_potential_planet_total: %s; native_settled_planet_total %s"
                    ) % (100 * native_chance, native_potential_planet_total, native_settled_planet_total)
    )

    for planet_type, planet_count in sorted(potential_native_planet_summary.items()):
        settled_planet_count = settled_native_planet_summary.get(planet_type, 0)
        potential_percent = 100.0 * planet_count / (1E-10 + native_potential_planet_total)
        settled_percent = 100.0 * settled_planet_count / (1E-10 + planet_count)
        type_summary_table.add_row((planet_type.name, potential_percent, settled_percent))
    print type_summary_table
    print