def grade_win_and_lose_paths():
    assertHas(student, "WIN_PATH", types=list)
    assertHas(student, "LOSE_PATH", types=list)
    student.call('render_introduction')
    student.run("# I am going to try your WIN_PATH", context=None)
    test_path(student.data['WIN_PATH'], 'won', 'WIN_PATH')
    student.call('render_introduction')
    student.run("# I am going to try your LOSE_PATH", context=None)
    test_path(student.data['LOSE_PATH'], 'lost', 'LOSE_PATH')
    compliment("I was able to play your game!")
    give_partial(FUNCTION_VALUE * 2)
def grade_render():
    assertGenerally(match_signature('render', 1))
    assertHasFunction(student, 'render', args=['World'], returns='str')
    initial_world = student.call('create_world', target='world')
    message = student.call('render',
                           initial_world,
                           keep_context=True,
                           target='message',
                           context='message = render(world)')
    assertIsInstance(message, str)
    give_partial(FUNCTION_VALUE)
def grade_records():
    body = parse_program().body
    for statement in body:
        if statement.ast_name == "Expr":
            if statement.value.ast_name == "Str":
                contents = statement.value.s
                for line in contents.split("\n"):
                    if line.strip().lower().startswith("records:"):
                        give_partial(FUNCTION_VALUE)
                        return True
    explain("You have not created a Records definition at the top level.")
    return False
def grade_choose():
    assertGenerally(match_signature('choose', 1))
    assertHasFunction(student, 'choose', args=['list[str]'], returns='str')
    assertEqual(
        student.call('choose', ['Quit', 'Run', 'Fight'],
                     inputs=['Walk', 'Skip', 'Fight']), 'Fight')
    assertEqual(
        student.call('choose', ['Quit', 'Run', 'Fight'], inputs=['Quit']),
        'Quit')
    assertEqual(
        student.call('choose', ['Open', 'Close', 'Sleep'],
                     inputs=['Walk', 'Walk', 'Sleep']), 'Sleep')
    give_partial(FUNCTION_VALUE)
def grade_update():
    assertGenerally(match_signature('update', 2))
    assertHasFunction(student, 'update', args=['World', 'str'], returns='str')
    initial_world = student.call('create_world', target='world')
    options = student.call('get_options',
                           initial_world,
                           keep_context=True,
                           target='options',
                           context='options = get_options(world)')
    message = student.call('update',
                           initial_world,
                           options[0],
                           keep_context=True,
                           target='message',
                           context='message = update(world, options[0])')
    assertIsInstance(message, str)
    give_partial(FUNCTION_VALUE)
def grade_get_options():
    assertGenerally(match_signature('get_options', 1))
    assertHasFunction(student,
                      'get_options',
                      args=['World'],
                      returns='list[str]')
    initial_world = student.call('create_world', target='world')
    options = student.call('get_options',
                           initial_world,
                           keep_context=True,
                           target='options',
                           context='options = get_options(world)')
    assertIsInstance(options, list)
    assertGreater(options,
                  0,
                  message="I expected there to be more than one option.")
    assertIsInstance(options[0], str)
    assertIn('Quit', options)
    give_partial(FUNCTION_VALUE)
def grade_render_introduction():
    assertGenerally(match_signature('render_introduction', 0))
    assertHasFunction(student, 'render_introduction', args=[], returns='str')
    introduction = student.call('render_introduction')
    assertIsInstance(introduction, str)
    give_partial(FUNCTION_VALUE)
def grade_create_world_finished():
    give_partial(FUNCTION_VALUE)