def agi (): actr.reset() # open a window and add the text window = actr.open_exp_window("Moving X", visible=True) text = actr.add_text_to_exp_window(window, "x", x=10, y=10) y = 10 actr.install_device(window) # schedule an event to move it but don't have the # periodic-event command available at this point so # just use a relative event which schedules itself actr.add_command("agi-move-it",move_text) actr.schedule_event_relative (1, "agi-move-it",params=[text,y],maintenance=True) # run the model in real time since it's a visible window actr.run(3,True) actr.remove_command("agi-move-it")
def setup(self, win=None): """Sets up and prepares for first trial""" self.window = win self.index = 0 self.log = [] self.phase = "fixation" self.current_trial = StroopTrial(self.stimuli[self.index]) self.update_window() actr.schedule_event_relative(1, "stroop-next")
def task(which=False): global response, response_time actr.reset() alphabet = [ "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" ] letter = actr.permute_list(alphabet)[0] alphabet = ["Z"] + alphabet if which == 'next' or which == 'previous': task = which elif actr.random(2) == 0: task = 'next' else: task = 'previous' time = 1500 + actr.random(1000) window = actr.open_exp_window("Simple task") actr.install_device(window) actr.add_command("pm-issues-response", respond_to_key_press, "Perceptual-motor issues task response") actr.monitor_command("output-key", "pm-issues-response") actr.add_text_to_exp_window(window, letter, x=130, y=150) actr.add_command("pm-issue-display", display_prompt, "Perceptual-motor issues task prompt display") actr.schedule_event_relative(time, "pm-issue-display", params=[window, task], time_in_ms=True) response = [] response_time = False actr.run(10, True) actr.remove_command("pm-issue-display") actr.remove_command_monitor("output-key", "pm-issues-response") actr.remove_command("pm-issues-response") if (len(response) == 2 and response_time > time and response[0] == letter and ((task == 'next' and alphabet.index(response[0]) == (alphabet.index(response[1]) - 1)) or (task == 'previous' and alphabet.index(response[0]) == (alphabet.index(response[1]) + 1)))): result = True else: result = False return [task, result]
def get_response(model, key): global current_response global i actr.schedule_event_relative(0, 'present_feedback') current_response[i] = key return current_response
def trial(onset_time): actr.reset() letters = actr.permute_list([ "B", "C", "D", "F", "G", "H", "J", "K", "L", "M", "N", "P", "Q", "R", "S", "T", "V", "W", "X", "Y", "Z" ]) answers = [] row = actr.random(3) window = actr.open_exp_window("Sperling Experiment", visible=True) for i in range(3): for j in range(4): txt = letters[j + (i * 4)] if i == row: answers.append(txt) actr.add_text_to_exp_window(window, txt, x=(75 + (j * 50)), y=(100 + (i * 50))) actr.install_device(window) if row == 0: freq = 2000 elif row == 1: freq = 1000 else: freq = 500 actr.new_tone_sound(freq, .5, onset_time) actr.schedule_event_relative(900 + actr.random(200), "clear-exp-window", params=[window], time_in_ms=True) global responses responses = [] actr.add_command("sperling-response", respond_to_key_press, "Sperling task key press response monitor") actr.monitor_command("output-key", "sperling-response") actr.run(30, True) actr.remove_command_monitor("output-key", "sperling-response") actr.remove_command("sperling-response") if show_responses: print("answers: %s" % answers) print("responses: %s" % responses) return (compute_score(answers))
def schedule_text(self, text, time): if text == "done": self.event_id_dict["done"] = actr.schedule_event_relative( time, "modify-text-for-exp-window", [self.textIdDict["text_id"], { "text": text }]) else: actr.schedule_event_relative( time, "modify-text-for-exp-window", [self.textIdDict["text_id"], { "text": text }])
def present_choose(): actr.goal_focus('initial-goal') if actr.random(1.0) < .6: answer = 'a' elif actr.random(1.0) > .5: answer = 'b' else: answer = None actr.schedule_event_relative(5, 'utility-learning-issues-show-result', params=[answer], output='medium')
def model_loop(): global win actr.add_command('present_stim', present_stim, 'presents stimulus') actr.add_command('present_feedback', present_feedback, 'presents feedback') actr.add_command('get_response', get_response, 'gets response') #open window for interaction win = actr.open_exp_window("test", visible=False) actr.install_device(win) actr.schedule_event_relative(0, 'present_stim') #waits for a key press? actr.monitor_command("output-key", 'get_response') actr.run(45)
def schedule_initial_stimuli(self, time=0): self.event_id_dict["initial_stimuli"] = actr.schedule_event_relative( time, "add-text-to-exp-window", [self.window, "BeginTest", { "x": 150, "y": 150 }])
def schedule_next_stimulus(self, time): self.event_id_dict["next_stimulus"] = actr.schedule_event_relative( time, "modify-text-for-exp-window", [ self.textIdDict["text_id"], { "text": self.initial_set_stimuli[self.sequence_num][:] } ]) self.sequence_num += 1
def move_y(gauge1_obj, gauge1_starty): global text3, gauge1_startx if gauge1_starty < 150 or gauge1_starty > 250: gauge1_starty += -5 else: gauge1_starty += 5 actr.modify_text_for_exp_window(gauge1_obj, text3, x=gauge1_startx, y=gauge1_starty, color='black') actr.schedule_event_relative(.05, "move_y", params=[gauge1_obj, gauge1_starty], maintenance=True)
def next(self): """Moves on in th task progression""" if self.phase == "fixation": self.phase = "stimulus" self.current_trial.onset = actr.mp_time() elif self.phase == "stimulus": self.current_trial.offset = actr.mp_time() self.index += 1 self.log.append(self.current_trial) if self.index >= len(self.stimuli): self.phase = "done" else: self.current_trial = StroopTrial(self.stimuli[self.index]) self.phase = "fixation" actr.schedule_event_relative(1, "stroop-next") actr.schedule_event_now("stroop-update-window")
def arbitrary (): actr.reset() feature = actr.add_visicon_features(['screen-x',15,'screen-y',20,'value',"'x'"])[0] x = 15 # schedule an event to move it but don't have the # periodic-event command available at this point so # just use a relative event which schedules itself actr.add_command("arbitrary-move-it",move_feat) actr.schedule_event_relative (1, "arbitrary-move-it",params=[feature,x],maintenance=True) # run the model in real time since it's a visible window actr.run(3,True) actr.remove_command("arbitrary-move-it")
def present_feedback(): global i global current_response global accuracy feedback = 'no' # check if response matches the appropriate key for the current stimulus in cue #need list of correct responses if current_response[i] == cor_resps[i]: feedback = 'yes' accuracy[i] = 1 chunks = actr.define_chunks(['isa', 'feedback', 'feedback', feedback]) actr.set_buffer_chunk('visual', chunks[0]) print("Feedback given: ", feedback) #increase index for next stimulus i = i + 1 actr.schedule_event_relative(1, 'present_stim')
def schedule_initial_stimuli(self, stim_size, initial=False, time=0): if initial == True: if stim_size == 3: for row in range(3): actr.add_text_to_exp_window( self.window, self.initial_set_stimuli[self.current_block][row][:], x=self.my_x[row], y=self.my_y[row]) else: for row in range(6): actr.add_text_to_exp_window( self.window, self.initial_set_stimuli[self.current_block][row][:], x=self.my_x[row], y=self.my_y[row]) else: if stim_size == 3: for row in range(3): self.event_id_dict[ "initial_stimuli"] = actr.schedule_event_relative( time, "add-text-to-exp-window", [ None, self.initial_set_stimuli[ self.current_block][row][:], { "x": self.my_x[row], "y": self.my_y[row] } ]) else: for row in range(6): self.event_id_dict[ "initial_stimuli"] = actr.schedule_event_relative( time, "add-text-to-exp-window", [ None, self.initial_set_stimuli[ self.current_block][row][:], { "x": self.my_x[row], "y": self.my_y[row] } ])
def move_text(text,y): y += 10 actr.current_connection.evaluate_single("modify-text-for-exp-window",text,None,None,y) actr.schedule_event_relative (.500, "agi-move-it",params=[text,y],maintenance=True)
def move_feat(feature, x): x += 10 actr.modify_visicon_features([feature,'screen-x',x]) actr.schedule_event_relative (.5, "arbitrary-move-it",params=[feature,x],maintenance=True)
def setup(self, win=None): self.window = win self.update_window() # self.current_trial = Game(self.stimuli[self.index]) actr.schedule_event_relative(1, "stroop-next")
def process_moves(model, string): global p1_position, p2_position, current_player, p1_text, p2_text # Let all other models hear this for m in actr.mp_models(): if not (m.lower() == model.lower()): # all other models will hear this actr.set_current_model(m) # Create the originating model's name as a simple chunk if # it isn't one already to avoid a warning of it being # created by default when the sound is generated. if not (actr.chunk_p(model)): actr.define_chunks(model) # Create the sound as a word with location indicating # the speaker. actr.new_word_sound(string, actr.mp_time(), model) if (string.lower() == "one"): move = 1 elif (string.lower() == "two"): move = 2 else: print("Wrong move assumed to be 1: %s" % string) move = 1 if current_player == p1: p1_position += move else: p2_position -= move actr.clear_exp_window(window) if (p2_position <= p1_position): # if there's a winner actr.schedule_event_relative(3, 'set_game_over', params=[current_player]) actr.add_text_to_exp_window(window, current_player, x=60, y=20, color='green', height=30, width=80, font_size=20) else: # not a winner so update the display with the new position p1_text = actr.add_text_to_exp_window(window, str(p1_position), x=20, y=10, color='red', height=30, width=30, font_size=20) p2_text = actr.add_text_to_exp_window(window, str(p2_position), x=140, y=10, color='blue', height=30, width=30, font_size=20) if current_player == p1: current_player = p2 else: current_player = p1
def show_result(choice): actr.mod_chunk('response', 'answer', choice) actr.set_buffer_chunk('imaginal', 'response') actr.schedule_event_relative(2, 'utility-learning-issues-choose', output='medium')
def schedule_clear_screen(self, time): actr.schedule_event_relative(time, "clear-exp-window", priority=1, details="clr with 1")
def schedule_too_slow(self, time): self.event_id_dict["too_slow"] = actr.schedule_event_relative( time, "modify-text-for-exp-window", [self.textIdDict["text_id"], { "text": "TooSlow" }])
def make_move(model, key): global p1_position, p2_position, winner, current_player if (model.lower() == current_player.lower()) and (key == '1' or key == '2'): if key == '1': dist = 1 else: dist = 2 if model.lower() == p1.lower(): p1_position += dist else: p2_position -= dist if p2_position <= p1_position: # the game is over winner = current_player actr.schedule_event_relative(3, 'set_game_over') if winner == p1: p1_result = 'win' p2_result = 'lose' else: p1_result = 'lose' p2_result = 'win' # update player 1 visual features actr.set_current_model(p1) actr.modify_visicon_features([ p1p1, 'position', p1_position, 'turn', False, 'result', p1_result ]) actr.modify_visicon_features([ p1p2, 'position', p2_position, 'turn', False, 'result', p2_result ]) # update player 2 visual features actr.set_current_model(p2) actr.modify_visicon_features([ p2p1, 'position', p1_position, 'turn', False, 'result', p1_result ]) actr.modify_visicon_features([ p2p2, 'position', p2_position, 'turn', False, 'result', p2_result ]) else: # update the game and all visual features if current_player == p1: current_player = p2 p1_turn = False p2_turn = True else: current_player = p1 p1_turn = True p2_turn = False # update player 1 visual features actr.set_current_model(p1) actr.modify_visicon_features( [p1p1, 'position', p1_position, 'turn', p1_turn]) actr.modify_visicon_features( [p1p2, 'position', p2_position, 'turn', p2_turn]) # update player 2 visual features actr.set_current_model(p2) actr.modify_visicon_features( [p2p1, 'position', p1_position, 'turn', p1_turn]) actr.modify_visicon_features( [p2p2, 'position', p2_position, 'turn', p2_turn])
def pick_button(index): global spaces, p1_position, p2_position, current_player # Make sure the right player made the action if actr.current_model().lower() == current_player.lower(): if (current_player == p1) and (index > p1_position) and ( (index - p1_position) <= 2): actr.remove_items_from_exp_window(window, spaces[p1_position], spaces[index]) # old space is now white and blank spaces[p1_position] = actr.add_button_to_exp_window( window, x=(10 + (p1_position * 40)), y=10, action=['pick-button', p1_position], height=35, width=35, color='white') if index >= p2_position: # set the game over after 3 seconds actr.schedule_event_relative(3, 'set_game_over', params=[p1]) # new space is green to indicate a win spaces[index] = actr.add_button_to_exp_window( window, text="1", x=(10 + (index * 40)), y=10, action=['pick-button', index], height=35, width=35, color='green') else: # update the p1 position and make p2 the current player # p1 position is white spaces[index] = actr.add_button_to_exp_window( window, text="1", x=(10 + (index * 40)), y=10, action=['pick-button', index], height=35, width=35, color='white') # set p2 position to be blue actr.remove_items_from_exp_window(window, spaces[p2_position]) spaces[p2_position] = actr.add_button_to_exp_window( window, text="2", x=(10 + (p2_position * 40)), y=10, action=['pick-button', p2_position], height=35, width=35, color='blue') # update position and player p1_position = index current_player = p2 elif (current_player == p2) and (index < p2_position) and ( (p2_position - index) <= 2): # if p2 makes a valid move actr.remove_items_from_exp_window(window, spaces[p2_position], spaces[index]) # old space is now white and blank spaces[p2_position] = actr.add_button_to_exp_window( window, x=(10 + (p2_position * 40)), y=10, action=['pick-button', p2_position], height=35, width=35, color='white') if index <= p1_position: # set the game over after 3 seconds actr.schedule_event_relative(3, 'set_game_over', params=[p2]) # new space is green to indicate a win spaces[index] = actr.add_button_to_exp_window( window, text="2", x=(10 + (index * 40)), y=10, action=['pick-button', index], height=35, width=35, color='green') else: # update the p2 position and make p2 the current player # p2 position is white spaces[index] = actr.add_button_to_exp_window( window, text="2", x=(10 + (index * 40)), y=10, action=['pick-button', index], height=35, width=35, color='white') # set p1 position to be red actr.remove_items_from_exp_window(window, spaces[p1_position]) spaces[p1_position] = actr.add_button_to_exp_window( window, text="1", x=(10 + (p1_position * 40)), y=10, action=['pick-button', p1_position], height=35, width=35, color='red') # update position and player p2_position = index current_player = p1
def schedule_fixation_cross(self, time): self.event_id_dict["fixation_cross"] = actr.schedule_event_relative( time, "modify-text-for-exp-window", [self.textIdDict["text_id"], { "text": "+" }])