def example(): global ids actr.reset() actr.add_command("custom-object-chunk", custom_object_chunk, "Command to dynamically create visual object") # Here we install our custom function using an object-creator device actr.install_device(["vision", "object-creator", "custom-object-chunk"]) # Now we add two features to the display, the first of which will # have the object created by the custom function and the other by # the default mechanism. ids = actr.add_visicon_features(["screen-x", 10, "screen-y", 20], ["screen-x", 100, "screen-y", 20]) # run to give vision module a chance to # process those features and then print the # visicon. actr.run_n_events(3) actr.print_visicon() # run to have model complete task actr.run(1) actr.remove_command("custom-object-chunk")
def example (): actr.reset() """ We will create two items in the display and have the model find them and move the mouse to them to see the difference in timing based on the width function setting. One feature will use the normal visual-location and object chunk-types and the other will use a custom visual-location type defined like this which replaces screen-x, screen-y, and distance with slots named x, y, and z instead. (chunk-type custom-location x y z height width size) The feature with using the standard visual-location slots will include a custom width function to make it act like a circle with twice its given height. """ actr.add_command("custom-width", custom_width, "Return twice the height of a visual feature.") actr.add_visicon_features(['screen-x', 50, 'screen-y', 500, 'height', 20, 'width', 20, ':width-fn', "'custom-width'"], ['isa', 'custom-location', 'x', 150, 'y', 500, 'height', 20, 'width', 20, ':x-slot', 'x', ':y-slot', 'y', ':z-slot', 'z']) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to move the cursor to 100,0 as a starting point. # and from there move to the left location, back to the start, and then # the right location. actr.run(10) actr.remove_command('custom-width')
def run_test(visible=False): actr.reset() win = actr.open_exp_window("background test", visible=visible, width=390, height=390, x=100, y=100) actr.install_device(win) actr.start_hand_at_mouse() actr.add_image_to_exp_window(win, "background", "ref-brain.gif", x=0, y=0, width=390, height=390) for x in range(3): for y in range(3): actr.add_visicon_features([ "screen-x", 164 + (x * 130), "screen-y", 164 + (y * 130), "height", 128, "width", 128, "name", ["'brain'", "'brain-%d'" % (x + (y * 3))] ]) # run for the vision module to process the scene actr.run_n_events(2) actr.print_visicon() # run for up to 5 seconds using real-time if the window is visible actr.run(10, visible)
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 example(): actr.reset() """ Add-visicon-features returns a list of names which can be used to update the features which were added to the visicon. The modify-visicon-features command can be used to adjust the location and object representation of an item that was added to the visicon. The delete-visicon-features and delete-all-visicon-features commands can be used to remove items which were added to the visicon. For this example these chunk-types are defined in the model which subclass the standard visual-location and visual-object chunk-types as were used for the new-visicon-features example. (chunk-type (polygon-feature (:include visual-location)) regular) (chunk-type (polygon (:include visual-object)) sides) """ features = actr.add_visicon_features([ 'isa', ['polygon-feature', 'polygon' ], 'screen-x', 0, 'screen-y', 50, 'value', ('polygon', "'poly1'"), 'height', 20, 'width', 40, 'color', 'blue', 'regular', ['false', None], 'sides', [None, 7] ], [ 'isa', ['polygon-feature', 'polygon'], 'screen-x', 50, 'screen-y', 70, 'value', ['polygon', "'square'"], 'height', 30, 'width', 30, 'color', 'red', 'regular', ['true', None], 'sides', [None, 4] ]) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to show the current chunks actr.run(10) """ Modify the first of those features to change the color to green, adjust the x position, and change the number of sides to 8. The parameters for modify-visicon-features are very similar to add except that the list of features must start with the name of the feature to update which was returned from add-visicon-features. One thing to note is that because nil is used in the list of values to indicate that a slot should not be applied to the location or object means that you can't use nil to 'remove' a slot from a feature through a modification. """ actr.modify_visicon_features( [features[0], 'color', 'green', 'screen-x', 5, 'sides', [None, 8]]) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to show the update actr.run(10) # Modify the second of those features to change the regular value to false and the # height to 25 actr.modify_visicon_features( [features[1], 'height', 25, 'regular', ['false', None]]) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to show the update actr.run(10) # delete the second feature. delete-visicon-features takes any number # of parameters each of which should be the name of a feature that was # returned by add-visicon-feature and those features are removed from # the visicon. actr.delete_visicon_features(features[1]) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to show the update actr.run(10) # delete all of the visicon features. delete-all-visicon-features # removes all of the features from the visicon. actr.delete_all_visicon_features() # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # run the model to show the update actr.run(10)
def play(player1, player2): global p1, p2, p1_position, p2_position, game_over, current_player, safety_stop, winner, p1p1, p1p2, p2p1, p2p2 if (player1.lower() in (x.lower() for x in actr.mp_models())) and ( player2.lower() in (x.lower() for x in actr.mp_models())): actr.add_command('stop-a-run', stop_a_run, 'Set the flag to terminate the game.') win = actr.open_exp_window('Safety', visible=True, height=100, width=100, x=100, y=300) actr.add_button_to_exp_window('Safety', text='STOP', x=0, y=0, action='stop-a-run', height=90, width=90, color='red') actr.add_command('move', make_move, 'Handle player key presses') actr.monitor_command('output-key', 'move') actr.reset() # initialize the game information p1 = player1 p2 = player2 p1_position = 0 p2_position = 5 game_over = False current_player = player1 safety_stop = False winner = None actr.set_current_model(player1) actr.define_chunks(player2) feats = actr.add_visicon_features([ 'isa', ['player-loc', 'player'], 'screen-x', 0, 'screen-y', 0, 'name', player1, 'position', [False, p1_position], 'turn', [False, True] ], [ 'isa', ['player-loc', 'player'], 'screen-x', 100, 'screen-y', 0, 'name', player2, 'position', [False, p2_position] ]) p1p1 = feats[0] p1p2 = feats[1] actr.set_current_model(player2) actr.define_chunks(player1) feats = actr.add_visicon_features([ 'isa', ['player-loc', 'player'], 'screen-x', 0, 'screen-y', 0, 'name', player1, 'position', [False, p1_position], 'turn', [False, True] ], [ 'isa', ['player-loc', 'player'], 'screen-x', 100, 'screen-y', 0, 'name', player2, 'position', [False, p2_position] ]) p2p1 = feats[0] p2p2 = feats[1] actr.add_command('is-game-over', is_game_over, 'Test whether game should stop running.') actr.add_command('set_game_over', set_game_over, 'Set the flag to stop the game.') actr.run_until_condition('is-game-over') actr.clear_exp_window(win) actr.remove_command('stop-a-run') actr.remove_command_monitor('output-key', 'move') actr.remove_command('move') actr.remove_command('is-game-over') actr.remove_command('set_game_over') return winner
def example(): actr.reset() """ Add-visicon-features allows the modeler to specify arbirary visual features for the visicon of a model. Any number of features can be provided at once, and each feature represents an object and its location. The description of those items is provided in much the same way that one specifies a chunk i.e. as slot-value pairs, and internally the vision module uses three chunks to represent that item (the location, the object, and a feature which contains the information that can be 'found' through a visual-location request). All features must have an x and y position which default to being in the screen-x and screen-y slots (see the new-location-slots example for how to change that). The distance (z position) can be specified, but if not the default distance will be included. Similarly, a size (which is measured in degrees of visual angle squared) can be provided, but if not it will be computed from the height and width if specified or set to a default size if those are not provided. When specifying the slot-value pairs to describe a feature the slot must be a valid slot for chunks (or the name isa to declare a chunk-type). The value can be provided as either an explict value or a list of two values. If an explicit value is provided then that value represents the value of that slot for both the location and object except when it is one of the x, y, or z coordinates which are only provided in the location. If a list of values is provided then the first one represents the value of that slot for the visual-location chunk and the second one represents the value of the slot for the object. Either of the items can be specified as None to indicate that the corresponding chunk should not have that slot. The value for the feature which can be found through the visual-location request is the value for the object if one is provided otherwise it will be the value for the location. The isa specification can also take a list of two values which indicate the chunk-types to specify when creating the chunks for the location and object, which can include default slot values. In addition to that, if a chunk-type is declared for the object and no slot named kind is specified for the feature then the location chunk will include a kind slot with a value that matches the chunk-type declared for the object. For this example these chunk-types are defined in the model which subclass the standard visual-location and visual-object chunk-types. (chunk-type (polygon-feature (:include visual-location)) regular) (chunk-type (polygon (:include visual-object)) sides) (chunk-type (square (:include polygon)) (sides 4) (square t)) and the oval type is predefined by the vision module like this: (chunk-type (oval (:include visual-object)) (oval t)) One final thing to note is that if one wants to specify a string as a value for a slot it must be specified using a set of single quotes inside the double quotes of a string because when sent to ACT-R strings are interpreted as names/symbols by default for the visicon features. """ actr.add_visicon_features(['screen-x', 0, 'screen-y', 5, 'regular', 'true'], ['isa', ['visual-location', 'oval'], 'screen-x', 12, 'screen-y', 20, 'value', ['oval', "'the oval'"], 'height', 10, 'width', 40, 'color', 'blue'], ['isa', ['polygon-feature', 'polygon'], 'screen-x', 50, 'screen-y', 50, 'value', ('polygon', "'poly 1'"), 'height', 20, 'width', 40, 'color', 'blue', 'regular', ['false', None], 'sides', [None, 7]], ['isa', ['polygon-feature', 'square'], 'screen-x', 10, 'screen-y', 50, 'value', ['square', "'the square'"], 'height', 30, 'width', 30, 'color', 'red', 'regular', ['true', None], 'sides', [None, 4]], ['isa', ['polygon-feature', 'polygon'], 'screen-x', 5, 'screen-y', 70, 'value', ['polygon', "'poly 2'"], 'height', 50, 'width', 45, 'color', 'green', 'regular', ['false', None], 'sides', [None, 5]]) # Give the vision module a chance to process the display # before printing the visicon. actr.run_n_events(3) actr.print_visicon() # Then just run the model actr.run(10)