Exemple #1
0
def head2head(configuration, outpath, iterations=10000):
    """
    Run a head to head simulation using the configuration for the black
    team against the red team. Write detailed stats out to the outpath.
    Can also specificy the number of iterations to run the simulation for.
    """
    start = time.time()
    world = World(ally_conf_path=configuration, maximum_time=iterations)

    with open(outpath, 'w') as outfile:
        writer = csv.writer(outfile)
        header = (
            'black',
            'red',
        ) + ('deposit', ) * world.deposits
        writer.writerow(header)
        writer.writerow(world.status())

        for step in xrange(world.iterations):
            try:
                world.update()
                writer.writerow(world.status())
            except Exception as e:
                break

    finit = time.time()
    delta = finit - start

    return {
        'fitness': world.ally_home.stash,
        'run_time': delta,
        'iterations': world.time,
        'home_stash': world.ally_home.stash,
        'enemy_stash': world.enemy_home.stash,
    }
Exemple #2
0
def head2head(configuration, outpath, iterations=10000):
    """
    Run a head to head simulation using the configuration for the black
    team against the red team. Write detailed stats out to the outpath.
    Can also specificy the number of iterations to run the simulation for.
    """
    start = time.time()
    world = World(ally_conf_path=configuration, maximum_time=iterations)

    with open(outpath, 'w') as outfile:
        writer = csv.writer(outfile)
        header = ('black', 'red',) + ('deposit',) * world.deposits
        writer.writerow(header)
        writer.writerow(world.status())

        for step in xrange(world.iterations):
            try:
                world.update()
                writer.writerow(world.status())
            except Exception as e:
                break

    finit = time.time()
    delta = finit - start

    return {
        'fitness':     world.ally_home.stash,
        'run_time':    delta,
        'iterations':  world.time,
        'home_stash':  world.ally_home.stash,
        'enemy_stash': world.enemy_home.stash,
    }