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


Python World.from_string方法代码示例

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


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

示例1: start

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_string [as 别名]
    def start(self):
        '''Starts trying to solve the task, slowly making the solution better.
        It's ok if start() finishes by itself (e.g. if it thinks it found the best possible solution).
        Should periodically (at least once in 10 seconds) check if self.stopped is True, and if it is, stop executing.
        '''
        self.stopped = False
        while True:
            m = World.from_string(self.data)
            program = ''
            while True:
                if random.randint(1, 100) <= 33:
                    ch = 'A'
                else:
                    ch = random.choice('ULDR')
                program += ch
                m, final_score = m.apply_command(ch)
                if final_score is not None:
                    break
            if final_score > self.solution[1]:
                self.solution = (program, final_score)

            if self.stopped:
                break
开发者ID:Vlad-Shcherbina,项目名称:icfpc2012-tbd,代码行数:25,代码来源:manager.py

示例2: test_processing_step

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_string [as 别名]
def test_processing_step(tests, step, verbose=False):
    fails = 0
    for test, result in tests:
        if verbose:
            print "-" * 10
            print test
        assert test.startswith("\n")
        test = test[1:]
        world = World.from_string(test)
        width = world.width
        data = world.data

        reachable = step(width, data)

        if verbose:
            print data_to_string(width, reachable)

        w, expected = parse_result(result)

        assert w == width
        assert len(expected) == len(data), (len(expected), len(data))

        expected_bool = [{"0": False, "1": True}[e] for e in expected]
        actual_string = [{False: "0", True: "1"}[e] for e in reachable]

        if expected_bool != reachable:
            if not verbose:
                print "-" * 10
                print test
                print data_to_string(width, actual_string)
            print "fail, expected"
            print data_to_string(width, expected)
            fails += 1

    assert fails == 0, fails
    print "ok"
开发者ID:fj128,项目名称:icfpc2012-tbd,代码行数:38,代码来源:test_preprocessor.py

示例3: World

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_string [as 别名]
    score = World(world).apply_commands(solution).score
    print 'genetic done', score
    if score > 0:
        solver.best_score = score
        solver.best_solution = solution
        


if __name__ == '__main__':
    realout = sys.stdout
    sys.stdout = sys.stderr

    signal.signal(signal.SIGINT, handler)
    
    data = sys.stdin.read()
    world = World.from_string(data)
    
    world.show()
    
    solver = Solver(world, timeout=1000000)
    
    greedy(World(world))
    
    call_genetic(World(world))
    
    solver.solve()
    
    print>>realout, solver.get_best()[1]
    print 'final score', solver.get_best()[0]
    
    sys.stdout = realout
开发者ID:Vlad-Shcherbina,项目名称:icfpc2012-tbd,代码行数:33,代码来源:entry_point.py

示例4: from_string

# 需要导入模块: from world import World [as 别名]
# 或者: from world.World import from_string [as 别名]
 def from_string(s):
     from dict_world import DictWorld
     from world import World
     return DualWorld(DictWorld.from_string(s), 
                      World.from_string(s))
开发者ID:Vlad-Shcherbina,项目名称:icfpc2012-tbd,代码行数:7,代码来源:dual_world.py


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