当前位置: 首页>>代码示例>>Python>>正文


Python World.from_file方法代码示例

本文整理汇总了Python中world.World.from_file方法的典型用法代码示例。如果您正苦于以下问题:Python World.from_file方法的具体用法?Python World.from_file怎么用?Python World.from_file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在world.World的用法示例。


在下文中一共展示了World.from_file方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fuzzy_tests

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_file [as 别名]
def fuzzy_tests():
    from glob import glob
    from random import choice, randrange, seed

    seed(666)

    print "preprocessor fuzzy tests:"

    maps = []
    maps += glob("../data/sample_maps/trampoline*.map")
    maps += glob("../data/sample_maps/contest*.map")
    maps += glob("../data/sample_maps/flood*.map")
    maps += glob("../data/maps_manual/*.map")

    exclude = ["abort_immediately", "tricky"]

    for map_path in maps:
        print map_path,
        if any(e in map_path for e in exclude):
            print "ignored"
            continue
        world = World.from_file(map_path)

        for i in range(50):
            commands = "".join(choice("LRUDW") for _ in range(randrange(1000)))
            check_preprocessor(world, commands, verbose=False)
            if i % 10 == 0:
                print ".",
        print

    print "fuzzy tests ok"
开发者ID:fj128,项目名称:icfpc2012-tbd,代码行数:33,代码来源:test_preprocessor.py

示例2: run_test

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_file [as 别名]
def run_test(map_path, timeout):
    start = clock()
    world = World.from_file(map_path)
    print 'solving {:50}'.format(map_path),
    
    start = clock()
    solver = Solver(world, timeout=timeout)
    solver.solve()
    score, solution = solver.get_best()
    solver.log_stats()
    t = clock()-start    
    
    
    world = World.from_file(map_path)
    for cmd in solution:
        world = world.apply_command(cmd)
        if world.terminated:
            break
    validated_score = world.score
    
    assert score == validated_score, (score, validated_score)
    print '{:>10} {:>10.3f}s'.format(score, t)
开发者ID:Vlad-Shcherbina,项目名称:icfpc2012-tbd,代码行数:24,代码来源:search_runner.py

示例3: main

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_file [as 别名]
def main():
    
    FORMAT = '%(levelname)7s: %(message)s'
    logging.basicConfig(level=logging.DEBUG, format=FORMAT)
    
    from world import World
    from dual_world import DualWorld
    from dict_world import DictWorld
    from test_emulators import validate_custom, validate

    
    #map_name = 'beard1'
    #map_path = '../data/sample_maps/{}.map'.format(map_name)
    map_path = '../data/maps_manual/simple_beard.map'
    world = World.from_file(map_path)
    
    world.show()
    
    sleep(0.1) # for stdout to flush
    
    solver = Solver(world)
    solver.solve()
    score, solution = solver.get_best()
    solver.log_stats()

    sleep(0.1) # for stderr to flush
    
    print '****'
    print 'Solution:', score, repr(solution)
    
    '''
    print 'validating...',
    
    world = DualWorld.from_file(map_path)
    for cmd in solution:
        world = world.apply_command(cmd)
        if world.terminated:
            break
    validated_score = world.score
    
    assert score == validated_score, (score, validated_score)
    '''
    
    #validate(map_name, solution, [World])
    validate_custom(map_path, solution, [World])#, DictWorld, DualWorld])
    
    print 'ok'
开发者ID:Vlad-Shcherbina,项目名称:icfpc2012-tbd,代码行数:49,代码来源:search.py

示例4: set

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_file [as 别名]
        
        keys1 = set(dists1.keys())
        keys2 = set(dists2.keys())
        if len(keys1) == 0 or keys1 != keys2:
            max_dist = 0 # something went wrong (perhaps portals?)
        else:    
            max_dist = max(dists1[i]+dists2[i] for i in dists1)

    else:
        if dists1 == {}:
            assert world.collected_lambdas != world.total_lambdas
            max_dist = 0
            #world.show()
            #print world.total_lambdas
            #raw_input()
        else:
            max_dist = max(dists1.values())
                
    #assert max_dist == salesman_lower_bound_(world, need_exit)            
    return max_dist


if __name__ == '__main__':
    from world import World
    
    world = World.from_file('../data/sample_maps/contest3.map')
    
    world.show()
    
    #print salesman_lower_bound_naive(world)
    print salesman_lower_bound(world)
开发者ID:Vlad-Shcherbina,项目名称:icfpc2012-tbd,代码行数:33,代码来源:salesman.py

示例5: superposition

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_file [as 别名]
    
    def superposition(self, index):
        result = 0
        for ffs in self.fields:
            result += ffs[1][index]
        return result
    
    @property
    def infty(self):
        10 * len(self.world.data)
    
if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    #world = World.from_file('../data/maps_manual/the_best.map')
    #world = World.from_file('../data/maps_manual/lambda_wave1.map')
    world = World.from_file('../data/maps_random/mp_random1.map')
    #vorber_world = VorberWorld.from_file('../data/maps_manual/lambda_wave1.map')
    #vorber_world = VorberWorld.from_file('../data/maps_manual/tricky.map')
    lambda_fields = LambdaFields(world)
    index = 0
    for i in range(0, len(world.data) / world.width):
        print
        for ii in range(0, world.width):
            field_potential = 0
            for ffs in lambda_fields.fields:
                source, potentials = ffs
                field_potential += potentials[index]
            print field_potential,
            index+=1               
    print
    #for k, v in trp.itervalues():
开发者ID:fj128,项目名称:icfpc2012-tbd,代码行数:33,代码来源:lambda_fields.py

示例6: clock

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_file [as 别名]
            print '({} states per second)'.format(num_states/(clock()-start+0.01))            
        
    print '{} states visited total, ({} states per second)'.format(num_states, num_states/(clock()-start+0.01))
    
    return best.score, best.solution
        

if __name__ == '__main__':
    
    from dual_world import DualWorld
    from dict_world import DictWorld
    from test_emulators import validate
    
    map_name = 'flood3'
    map_path = '../data/sample_maps/{}.map'.format(map_name)
    world = World.from_file(map_path)
    
    world.show()
    
    start = clock()

    score, solution = solve(world)
    
    print 'it took', clock()-start

    print '****'
    print score, solution
    
    print 'validating...',
    
    world = DualWorld.from_file(map_path)
开发者ID:Vlad-Shcherbina,项目名称:icfpc2012-tbd,代码行数:33,代码来源:backtrack.py

示例7: raw_input

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_file [as 别名]
    while not finished:
        print '>>>',
        commands = raw_input()
        for c in commands:
            if c == 'A':
                finished = True
                break
            world, e = world.apply_command(c)
            world.show()
            if e is not None:
                finished = True
                break


    if e is None:
        e = world.get_score_abort()
    
    print 'Final score:', e
    
    
if __name__ == '__main__':
    from dict_world import DictWorld
    from world import World
    from dual_world import DualWorld
    
    map_name = '../data/sample_maps/contest1.map'
    world = DualWorld(DictWorld.from_file(map_name),
                      World.from_file(map_name))
    
    play(world)
开发者ID:Vlad-Shcherbina,项目名称:icfpc2012-tbd,代码行数:32,代码来源:play.py

示例8: infty

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_file [as 别名]
    
    @property
    def infty(self):
        10 * len(self.world.data)
    
if __name__ == '__main__':
    #logging.basicConfig(level=logging.DEBUG)
    #world = World.from_file('../data/maps_manual/the_best.map')
    #world = World.from_file('../data/maps_random/pizdets.map')
    #world = World.from_file('../data/maps_random/yushi.map')
    #vorber_world = VorberWorld.from_file('../data/maps_manual/lambda_wave1.map')
    #vorber_world = VorberWorld.from_file('../data/maps_manual/tricky.map')
    #lambda_fields = LambdaFields(world)
    #index = 0
    #for i in range(0, len(world.data) / world.width):
    #    print
    #    for ii in range(0, world.width):
    #        field_potential = 0
    #        for ffs in lambda_fields.fields:
    #            source, potentials = ffs
    #            field_potential += potentials[index]
    #       print field_potential,
    #        index+=1               
    #print
    #for k, v in trp.itervalues():
    #    print k, v
    #pprint.pprint(lambda_fields.superposition(lambda_fields))
    #pprint.pprint(lambda_fields.fields)
    #world.show()
    run_interactively(World.from_file('../data/maps_random/yushi.map'), '')
开发者ID:Vlad-Shcherbina,项目名称:icfpc2012-tbd,代码行数:32,代码来源:lambda_fields.py

示例9: int

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_file [as 别名]
# Initialize pygame.
pygame.init()

fps_clock   = pygame.time.Clock()
fps         = 10
tpt         = 1.0 / fps

# Determine action interval.
action_interval_s = 0.5
action_interval_t = int(fps * action_interval_s)

# Initialize world.
full_transform = True#False

if full_transform:
    world = World.from_file("resources/initial_state_2x1.xml")
else:
    world = World.from_file("resources/initial_state_10x10.xml")
world.redraw()

# Initialize transforms.
transform_set = transforms.TransformSet("resources", world, full_transform)

# Initialize window.
padding = (world._cell_pixel_width, 2*world._cell_pixel_height)
window_surface = pygame.display.set_mode((world.get_width() + 2*padding[0], world.get_height() + 2*padding[1]))
pygame.display.set_caption('CAP 6671 - Final Project')

# Execute application.
ticks_to_next_action = action_interval_t
won = False
开发者ID:anthonytw,项目名称:transformed-qlearner,代码行数:33,代码来源:run_demo.py

示例10: min

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_file [as 别名]
                xy = world.index_to_coords(idx)
                return min(dist(xy, world.index_to_coords(i[1])) for i in interesting)
            a = max(actions, key=dist_to_others)
            interesting.append(a)
            actions.remove(a)

    #print '---'
    #for a in interesting:
    #    print a, data[a[1]], world.index_to_coords(a[1])
        
    return [a[2] for a in interesting]
  
                
if __name__ == '__main__':

    from preprocessor import preprocess_world
    
    #world = World.from_file('../data/sample_maps/trampoline3.map')
    
    world = World.from_file('../data/maps_manual/simple_beard.map')
    
    world.show()
    
    #print path_to_nearest_lambda_or_lift(world)
    
    print interesting_actions(preprocess_world(world))
    
    
    
    
    
开发者ID:Vlad-Shcherbina,项目名称:icfpc2012-tbd,代码行数:28,代码来源:utils.py


注:本文中的world.World.from_file方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。