def finish_trial(exp):
    """Check for various end-of-block situations
    """
    if exp.var.dynamic['value'] == exp.var.dynamic['val_floor']:
        if exp.var.dynamic['cur_step'] == -1:
            exp.var.dynamic['val_floor_count'] += 1
            exp.var.dynamic['cur_status'] = 'f{:}'.format(exp.var.dynamic[
                'val_floor_count'])
        elif not exp.var.dynamic['cur_correct']:
            exp.var.dynamic['val_floor_count'] = 0
        if exp.var.dynamic['val_floor_count'] == exp.var.dynamic['val_floor_n'
            ]:
            exp.run.block_on = False
            exp.var.dynamic['msg'
                ] = '{:} consecutive floor trials reached'.format(exp.var.
                dynamic['val_floor_n'])
    else:
        exp.var.dynamic['val_floor_count'] = 0
    if exp.var.dynamic['value'] == exp.var.dynamic['val_ceil']:
        if exp.var.dynamic['cur_step'] == 1:
            exp.var.dynamic['val_ceil_count'] += 1
            exp.var.dynamic['cur_status'] = 'c{:}'.format(exp.var.dynamic[
                'val_ceil_count'])
        elif exp.var.dynamic['cur_correct']:
            exp.var.dynamic['val_ceil_count'] = 0
        if exp.var.dynamic['val_ceil_count'] == exp.var.dynamic['val_ceil_n']:
            exp.run.block_on = False
            exp.var.dynamic['msg'
                ] = '{:} consecutive ceiling trials reached'.format(exp.var
                .dynamic['val_ceil_n'])
    else:
        exp.var.dynamic['val_ceil_count'] = 0
    if exp.run.block_on:
        if exp.var.dynamic['run_n_trials'
            ] > 0 and exp.run.trials_block == exp.var.dynamic['run_n_trials']:
            exp.run.block_on = False
            exp.var.dynamic['good_run'] = True
            exp.var.dynamic['msg'] = '{:} trials reached'.format(exp.var.
                dynamic['run_n_trials'])
        elif exp.var.dynamic['max_trials'
            ] > 0 and exp.run.trials_block == exp.var.dynamic['max_trials']:
            exp.run.block_on = False
            exp.var.dynamic['good_run'] = True
            exp.var.dynamic['msg'] = 'A maximum of {:} trials reached'.format(
                exp.var.dynamic['max_trials'])
        elif exp.var.dynamic['n_reversals'] == len(exp.var.dynamic['steps']
            ) - 1:
            exp.run.block_on = False
            exp.var.dynamic['good_run'] = True
            exp.var.dynamic['msg'] = '{:} reversals reached'.format(len(exp
                .var.dynamic['steps']) - 1)
