Exemple #1
0
def reward_2d(pumppy, controller):
    if not 'SReward' in controller.sensors:
        return
    radar = controller.sensors['SReward']
    reward = radar.hitObject

    if reward is not None:
        gc.runPump(pumppy, buzz=settings.reward_buzz)
        nrew = len(GameLogic.Object['rewpos'])
        GameLogic.Object['rewcount'] += 1
        newx, newy = 0, GameLogic.Object['rewpos'][np.mod(GameLogic.Object['rewcount'],nrew)] * 145.0 # newCoords()
        reward.localPosition = [newx,newy,reward.position[2]]
							
        gio.write_reward(newy)
Exemple #2
0
def reward_linear_double(pumppy, controller):

    scene = GameLogic.getCurrentScene()
    if scene.name == "Scene":
        teleportName = 'Cylinder.003'
    else:
        teleportName = 'Cylinder.000'

    if not 'SReward' in controller.sensors:
        return
    radar = controller.sensors['SReward']
    reward = radar.hitObject
    if reward is None:
        return
    if reward.name == teleportName:
        # This is not a reward in this case but a teleport detector
        if GameLogic.Object['RewardTicksCounter'] is not None:
            if GameLogic.Object[
                    'RewardTicksCounter'] == settings.reward_delay_ticks_pre + settings.reward_delay_ticks_post:
                zeroPos()
                GameLogic.Object['RewardTicksCounter'] += 1
            elif GameLogic.Object[
                    'RewardTicksCounter'] >= settings.reward_delay_ticks_pre + settings.reward_delay_ticks_post + 1:
                GameLogic.Object['RewardTicksCounter'] = None
                GameLogic.Object['WallTouchTicksCounter'] = None
            else:
                # Still touching pump but not long enough yet
                GameLogic.Object['RewardTicksCounter'] += 1
        else:
            # First reward touch, buzz and start counter
            GameLogic.Object['RewardTicksCounter'] = 0

        return

    # Move to fantasy land to avoid multiple rewards:
    oldy = reward.localPosition[1]
    reward.localPosition = [0, 1000.0, reward.position[2]]
    if reward.name[-1] == GameLogic.Object['select_rew']:
        gc.runPump(pumppy, reward=True, buzz=settings.reward_buzz)
        GameLogic.Object['rewcount'] += 1
        reward_success = True
    else:
        reward_success = False
        GameLogic.Object['rewfail'] += 1

    gio.write_reward(oldy, reward_success)
Exemple #3
0
def reward_linear(pumppy, controller):
    
    if not 'SReward' in controller.sensors:
        return
    radar = controller.sensors['SReward']
    reward = radar.hitObject
    if GameLogic.Object['RewardTicksCounter'] is not None:
        if GameLogic.Object['RewardTicksCounter'] == settings.reward_delay_ticks_pre and not GameLogic.Object['RewardChange']:
            # Give reward
            if reward is not None:
                nrew = len(GameLogic.Object['rewpos'])
                newy = GameLogic.Object['rewpos'][np.mod(GameLogic.Object['rewcount'],nrew)] * settings.reward_pos_linear # newCoords()
                if GameLogic.Object['WallTouchTicksCounter'] is None:
                    rand = np.random.uniform(0,1)
                    if rand <= settings.reward_probability:
                        if settings.gratings:
                            give_reward = GameLogic.Object["current_walls"] == settings.rewarded_env
                        else:
                            give_reward = True
                        if settings.replay_track is None:
                            gc.runPump(pumppy, reward=give_reward, buzz=settings.reward_buzz)
                        GameLogic.Object['rewcount'] += 1
                        reward_success = True
                        #Matthias 2016/02/15
                        if settings.reward_delay_ticks_pre <= settings.reward_change_max:
                            settings.reward_delay_ticks_pre += settings.reward_change_step
                            print('\n{}'.format(settings.reward_delay_ticks_pre))
                            GameLogic.Object['RewardChange'] = True
                    else:
                        reward_success = False
                        GameLogic.Object['rewfail'] += 1

                    if settings.replay_track is None:
                        gio.write_reward(newy, reward_success)
                else:
                    sys.stdout.write('WallTouchTicksCounter is not None\n')
            GameLogic.Object['RewardTicksCounter'] += 1

        elif GameLogic.Object['RewardTicksCounter'] == settings.reward_delay_ticks_pre + settings.reward_delay_ticks_post:
            # Return animal with delay after reward
            if reward is not None:
                newx = 0
                # Move to fantasy land to avoid multiple rewards:
                reward.localPosition = [newx,1000.0,reward.position[2]]
            GameLogic.Object['RewardChange'] = False
            GameLogic.Object['RewardTicksCounter'] += 1
            zeroPos()

        elif GameLogic.Object['RewardTicksCounter'] >= settings.reward_delay_ticks_pre + settings.reward_delay_ticks_post + 1:
            # Reward was just given, animal is back at beginning of track,
            # so it's now safe to return the pump
            gc.zeroPump()
            GameLogic.Object['RewardChange'] = False
            GameLogic.Object['RewardTicksCounter'] = None
            GameLogic.Object['WallTouchTicksCounter'] = None
        else:
            # Still touching pump but not long enough yet
            GameLogic.Object['RewardTicksCounter'] += 1
    else:
        # First reward touch, buzz and start counter
        GameLogic.Object['RewardTicksCounter'] = 0
        # CSH 2013-11-19 Muted pump
        gc.runPump(pumppy, reward=False, buzz=False)