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)
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)
def move_player(move): controller = GameLogic.getCurrentController() own = controller.owner if settings.replay_track is not None: currentpos = own.localPosition if GameLogic.Object['nreplay'] >= len(GameLogic.Object['replay_pos'][0]): print("BLENDER: Reached end of replay track; starting over") GameLogic.Object['nreplay'] = 0 if GameLogic.Object['nreplay'] == 0: GameLogic.Object['replay_time0'] = time.time() GameLogic.Object['nreplay_rewards'] = 0 if GameLogic.Object['nreplay_rewards'] < len(GameLogic.Object['replay_rewards']) and \ time.time()-GameLogic.Object['replay_time0'] >= \ GameLogic.Object['replay_rewards'][GameLogic.Object['nreplay_rewards']]: print("BLENDER: Delivering replay reward no {0}".format( GameLogic.Object['nreplay_rewards'])) GameLogic.Object['nreplay_rewards'] += 1 gc.runPump(GameLogic.Object['pumppy'], reward=True, buzz=settings.reward_buzz) newposx = GameLogic.Object['replay_pos'][0][GameLogic.Object['nreplay']] newposy = GameLogic.Object['replay_pos'][1][GameLogic.Object['nreplay']] newposz = GameLogic.Object['replay_pos'][2][GameLogic.Object['nreplay']] GameLogic.Object['nreplay'] += 1 xtranslate = newposx-currentpos[0] ytranslate = newposy-currentpos[1] zrotate = 0 own.localPosition = [newposx, newposy, newposz] # print(own.localPosition) return xtranslate, ytranslate, zrotate # Note that x is mirrored if the dome projection is used. xtranslate = 0 # ytranslate = 0 zrotate = 0 # Swap mice if we use only one mouse: ytranslate_move = move[3] if GameLogic.Object['m1conn'] is not None and GameLogic.Object['m2conn'] is None: ytranslate_move = move[1] * -1 # y axis front mouse if len(ytranslate_move): # pass ytranslate = float(ytranslate_move.sum())/ settings.gain_trans2 * settings.gain_trans# 500.0 # 1.4e-5 m per reading # x axis front mouse / side mouse if len(move[0]) and len(move[2]): # pass zrotate = float((move[0].sum()+move[2].sum())/settings.gain_rot_ave_02)/ -settings.gain_rot2 * settings.gain_rot#-5000.0 # y axis side mouse if len(move[1]): # pass zrotate += float((move[1].sum())/settings.gain_rot_ave_1)/ settings.gain_rot2 * settings.gain_rot #-5000.0 own = controller.owner # pos = np.array(own.position) # Get the actuators act_xtranslate = controller.actuators["xtranslate"] act_ytranslate = controller.actuators["ytranslate"] act_zrotate = controller.actuators["zrotate"] GameLogic.Object['speed_tracker'][GameLogic.Object['nframes'] % len(GameLogic.Object['speed_tracker'])] = ytranslate_move.sum()*settings.calibration_x act_ytranslate.dLoc = [0.0, ytranslate, 0.0] act_ytranslate.useLocalDLoc = True # set the values if not settings.linear: act_xtranslate.dLoc = [xtranslate, 0.0, 0.0] act_xtranslate.useLocalDLoc = True act_zrotate.dRot = [0.0, 0.0, zrotate] act_zrotate.useLocalDRot = False # Use the actuators controller.activate(act_xtranslate) controller.activate(act_zrotate) if not settings.looming: controller.activate(act_ytranslate) return xtranslate, ytranslate, zrotate
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)