コード例 #1
0
def test_wheel_timer():
    task_data = Path(utils.project_root() / 'tasks' / 'part-0-mock' / 'wheels.desc').read_text()
    task = GridTask(Task.parse(task_data))

    actionlist = ('QQDD' + 
                     'F' +
                     'ZZZZZZZZZZZZZZZZZZZZ' +
                     'F' +
                     'ZZZZZZZZZZZZZZZZZZZZ' + 
                     'ZZZZZZZZZ' +
                     'ZZZZZZZZZZZZZZZZZZZZ' +
                     'ZZZZZZZZZZZZZZZZZZZZ' +
                     'ZZZZZZZZZZ' + 
                     'D')

    game = Game(task)
    for a in actionlist:
        game.apply_action(Action.simple(a))

    solution = compose_actions(game.get_actions())
    expected_score = game.finished()
    assert expected_score is None

    game = Game(task)
    for a in actionlist:
        game.apply_action(Action.simple(a))
    game.apply_action(Action.WSAD('D'))

    solution = compose_actions(game.get_actions())
    expected_score = game.finished()
    er = validate.run(task_data, solution)

    assert er.time is not None
    assert er.time == expected_score
コード例 #2
0
def validate_replay(task_data, expected_score, actions):
    import logging
    logging.basicConfig(
        level=logging.INFO,
        format='%(levelname).1s %(module)10.10s:%(lineno)-4d %(message)s')

    solution_data = compose_actions(actions)
    sr = interface.SolverResult(data=solution_data,
                                expected_score=expected_score)

    scent = f'manual ({getpass.getuser()})'

    logging.info('Checking with validator...')
    er = validate.run(task_data, sr.data)
    if er.time is None:
        result = solver_worker.Result(status='CHECK_FAIL',
                                      scent=scent,
                                      score=None,
                                      solution=solution_data,
                                      extra=dict(
                                          validator=er.extra,
                                          expected_score=sr.expected_score))
        logging.info(result)
    else:
        result = solver_worker.Result(status='DONE',
                                      scent=scent,
                                      score=er.time,
                                      solution=solution_data,
                                      extra=dict(
                                          validator=er.extra,
                                          expected_score=sr.expected_score))
        logging.info(f'Validator score: {er.time}')
    return result
コード例 #3
0
def test_compose():
    actions = [[Action.WSAD(c) for c in 'WSAD'] + [
        Action.wait(),
        Action.turnCW(),
        Action.turnCCW(),
        Action.attach(1, -2),
        Action.wheels(),
        Action.drill(),
    ]]
    assert compose_actions(actions) == 'WSADZEQB(1,-2)FL'
    actions = [
        [Action.WSAD(c) for c in 'WSAD'] +
        [Action.wait(), Action.turnCW(),
         Action.turnCCW()],
        [
            Action.attach(1, -2),
            Action.wheels(),
            Action.drill(),
        ]
    ]
    assert compose_actions(actions) == 'WSADZEQ#B(1,-2)FL'
コード例 #4
0
def run_one_bot_game(actions: List[Action]):
    task_data = Path(utils.project_root() / 'tasks' / 'part-0-mock' / 'prob-2003.desc').read_text()
    task = GridTask(Task.parse(task_data))
    game = Game(task)
    for a in actions:
        game.apply_action(a)

    solution = compose_actions(game.get_actions())
    expected_score = game.finished()
    er = validate.run(task_data, solution)

    assert er.time is not None
    assert er.time == expected_score
コード例 #5
0
def run_cloned_game(actions: List[List[Action]]):
    task_data = Path(utils.project_root() / 'tasks' / 'part-0-mock' / 'prob-2003.desc').read_text()
    task = GridTask(Task.parse(task_data))
    game = Game(task)

    indices = [0] * len(actions)
    current = 0
    while not game.finished():
        if current == 0:
            botcount = len(game.bots)
        i = indices[current]
        game.apply_action(actions[current][i], current)
        indices[current] += 1
        current = (current + 1) % botcount

    solution = compose_actions(game.get_actions())
    expected_score = game.finished()
    er = validate.run(task_data, solution)

    assert er.time is not None
    assert er.time == expected_score