Example #1
0
    while parent is not None and parent.time < time:
        if parent.parent is not None and parent.parent.time < time:
            parent = parent.parent
        else:
            break

    if parent is None:
        return hit
    else:
        return parent


def build_tree(f, args, chrom, pop_sizes):
    for line in f:
        # Skip over a line, which contains the seed for a simulation run.
        line = f.next()
        data = eval(line)
        for r in range(args.reps):
            generate_trees(data[chrom],
                           args.size1,
                           args.size2,
                           pop_sizes,
                           args.internal)

if __name__ == '__main__':
    parser = parse_common_arguments('Construct gene tree.')
    parser.add_argument('-i', '--internal',
                        action = 'store_true',
                        help = 'output names of internal nodes')
    run(parser.parse_args(), build_tree)
Example #2
0
def activate(zone_id):
	global ACTIVE_ZONE
	
	ACTIVE_ZONE = zone_id
	
	_zone = ZONES[zone_id]
	_noise = tcod.noise_new(2)
	
	logging.info('Bringing zone \'%s\' online...' % _zone['name'])
	
	_zone['astar_map'] = pathfinding.setup(_zone['width'], _zone['height'], _zone['solids'])
	_zone['los_map'] = mapgen.generate_los_map(_zone['width'], _zone['height'], _zone['solids'])
	
	display.create_surface('tiles', width=_zone['width'], height=_zone['height'])
	
	maps.render_map(_zone['tile_map'], _zone['width'], _zone['height'])
	
	post_processing.start()
	
	events.register_event('logic', post_processing.tick_sun)
	
	_static_lighting = display.create_shader(_zone['width'], _zone['height'], start_offset=1)
	_zone['shaders'].append(post_processing.generate_shadow_map(_zone['width'], _zone['height'], _zone['solids'], _zone['trees'], _zone['inside']))
	_zone['shaders'].append(post_processing.generate_light_map(_zone['width'], _zone['height'], _zone['solids'], _zone['trees']))
	_zone['light_maps']['static_lighting'] = _static_lighting
	_zone['shaders'].append(_static_lighting)
	
	_noise = tcod.noise_new(3)
	_zoom = 2.0
	_zone['fader'] = display.create_shader(_zone['width'], _zone['height'])
	_shader = display.create_shader(_zone['width'], _zone['height'])
	
	for y in range(0, _zone['height']):
		for x in range(0, _zone['width']):
			if (x, y) in _zone['inside']:
				_height = .75
			else:
				_noise_values = [(_zoom * x / _zone['width']),
					             (_zoom * y / _zone['height'])]
				_height = .35 + numbers.clip(tcod.noise_get_turbulence(_noise, _noise_values, tcod.NOISE_SIMPLEX), .35, 1)
			
			_shader[0][y, x] = 1.3 * _height
			_shader[1][y, x] = 1.3 * _height
			_shader[2][y, x] = 1.1 * _height
	
	_zone['shaders'].append(_shader)
	
	for light in _zone['lights']:
		effects.light(light[0], light[1], light[2], r=light[3], g=light[4], b=light[5], light_map='static_lighting')
	
	#if not '--no-fx' in sys.argv:
	#	post_processing.run(time=8,
	#		                repeat=-1,
	#		                repeat_callback=lambda _: post_processing.post_process_clouds(constants.MAP_VIEW_WIDTH,
	#		                                                                              constants.MAP_VIEW_HEIGHT,
	#		                                                                              8,
	#		                                                                              _noise,
	#		                                                                              _zone['inside']))
	post_processing.run(time=0,
		                repeat=-1,
		                repeat_callback=lambda _: post_processing.post_process_lights())
	#post_processing.run(time=0,
	#                    repeat=-1,
	#                    repeat_callback=lambda _: post_processing.sunlight())
	
	camera.set_limits(0, 0, _zone['width']-constants.MAP_VIEW_WIDTH, _zone['height']-constants.MAP_VIEW_HEIGHT)
	
	logging.info('Zone \'%s\' is online' % _zone['name'])
Example #3
0
def activate(zone_id):
    global ACTIVE_ZONE

    ACTIVE_ZONE = zone_id

    _zone = ZONES[zone_id]
    _noise = tcod.noise_new(2)

    logging.info('Bringing zone \'%s\' online...' % _zone['name'])

    _zone['astar_map'] = pathfinding.setup(_zone['width'], _zone['height'],
                                           _zone['solids'])
    _zone['los_map'] = mapgen.generate_los_map(_zone['width'], _zone['height'],
                                               _zone['solids'])

    display.create_surface('tiles',
                           width=_zone['width'],
                           height=_zone['height'])

    maps.render_map(_zone['tile_map'], _zone['width'], _zone['height'])

    post_processing.start()

    events.register_event('logic', post_processing.tick_sun)

    _static_lighting = display.create_shader(_zone['width'],
                                             _zone['height'],
                                             start_offset=1)
    _zone['shaders'].append(
        post_processing.generate_shadow_map(_zone['width'], _zone['height'],
                                            _zone['solids'], _zone['trees'],
                                            _zone['inside']))
    _zone['shaders'].append(
        post_processing.generate_light_map(_zone['width'], _zone['height'],
                                           _zone['solids'], _zone['trees']))
    _zone['light_maps']['static_lighting'] = _static_lighting
    _zone['shaders'].append(_static_lighting)

    _noise = tcod.noise_new(3)
    _zoom = 2.0
    _zone['fader'] = display.create_shader(_zone['width'], _zone['height'])
    _shader = display.create_shader(_zone['width'], _zone['height'])

    for y in range(0, _zone['height']):
        for x in range(0, _zone['width']):
            if (x, y) in _zone['inside']:
                _height = .75
            else:
                _noise_values = [(_zoom * x / _zone['width']),
                                 (_zoom * y / _zone['height'])]
                _height = .35 + numbers.clip(
                    tcod.noise_get_turbulence(_noise, _noise_values,
                                              tcod.NOISE_SIMPLEX), .35, 1)

            _shader[0][y, x] = 1.3 * _height
            _shader[1][y, x] = 1.3 * _height
            _shader[2][y, x] = 1.1 * _height

    _zone['shaders'].append(_shader)

    for light in _zone['lights']:
        effects.light(light[0],
                      light[1],
                      light[2],
                      r=light[3],
                      g=light[4],
                      b=light[5],
                      light_map='static_lighting')

    #if not '--no-fx' in sys.argv:
    #	post_processing.run(time=8,
    #		                repeat=-1,
    #		                repeat_callback=lambda _: post_processing.post_process_clouds(constants.MAP_VIEW_WIDTH,
    #		                                                                              constants.MAP_VIEW_HEIGHT,
    #		                                                                              8,
    #		                                                                              _noise,
    #		                                                                              _zone['inside']))
    post_processing.run(
        time=0,
        repeat=-1,
        repeat_callback=lambda _: post_processing.post_process_lights())
    #post_processing.run(time=0,
    #                    repeat=-1,
    #                    repeat_callback=lambda _: post_processing.sunlight())

    camera.set_limits(0, 0, _zone['width'] - constants.MAP_VIEW_WIDTH,
                      _zone['height'] - constants.MAP_VIEW_HEIGHT)

    logging.info('Zone \'%s\' is online' % _zone['name'])
Example #4
0
              if coal_gen.count(i) == 2][0]
    unchanged = [0, 0]

    for s1 in coal_gen[:size1]:
        if s1 < pop_size / 2 and s1 != merged:
            unchanged[0] += 1
    for s2 in coal_gen[size1:]:
        if s2 < pop_size / 2 and s2 != merged:
            unchanged[1] += 1

    merged1 = coal_gen.index(merged)
    merged2 = coal_gen.index(merged, merged1 + 1)
    if merged1 < size1 and merged2 < size1:
        ctype = 0
    elif merged1 < size1:
        ctype = 1
    else:
        ctype = 2
    if merged < pop_size / 2:
        deme = 1
    else:
        deme = 2

    print('{}, {}, {}, {}, {}'.format(
        time, unchanged[0], unchanged[1], deme, ctype))
    return True


if __name__ == '__main__':
    run(parse_common_arguments('Summarize coalescence time and exit states').parse_args(), get_exit_states)