示例#1
0
def play(player1, player2):
    global p1, p2, p1_position, p2_position, game_over, current_player, next_move

    # make sure that both names are valid model names

    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.reset()

        actr.add_command('make-move', make_move,
                         "Model action function in simple capture game.")

        # create the goal chunks

        actr.set_current_model(player1)

        actr.define_chunks([
            'goal', 'isa', 'play', 'my-pos', 'p1', 'p1', 0, 'p2', 5, 'state',
            'move'
        ])

        actr.goal_focus('goal')

        actr.set_current_model(player2)

        actr.define_chunks([
            'goal', 'isa', 'play', 'my-pos', 'p1', 'p2', 0, 'p2', 5, 'state',
            'move'
        ])

        actr.goal_focus('goal')

        # initialize the game information

        p1 = player1
        p2 = player2
        p1_position = 0
        p2_position = 5
        game_over = False
        current_player = player1
        next_move = None

        while not (game_over):
            # until a move is made which breaks the run
            # or 1000 simulated seconds pass which is a forfeit
            actr.run(1000)
            process_move(next_move)

        # Give them a chance to process results

        actr.run_full_time(3)

        actr.remove_command('make-move')

    return game_over
def test_it ():

    actr.reset()
  
    actr.add_command("relay-speech-output", relay_speech_output, "Handle player speak actions")
    actr.monitor_command("output-speech","relay-speech-output")

    for m in actr.mp_models():
        actr.set_current_model(m)
        actr.install_device(["speech","microphone"])

    actr.run(10)
    
    actr.remove_command_monitor("output-speech", "relay-speech-output")    
    actr.remove_command("relay-speech-output")
def relay_speech_output (model, string):

    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)
示例#4
0
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
示例#5
0
def play(player1, player2):
    global window, p1, p2, p1_position, p2_position, current_player, game_over, safety_stop, p1_text, p2_text

    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.reset()

        actr.set_current_model(player1)

        # create a goal chunk with the player's color and name
        actr.define_chunks([
            'goal', 'isa', 'play', 'my-color', 'red', 'my-name',
            "'%s'" % player1
        ])
        actr.goal_focus('goal')
        actr.set_parameter_value(':show-focus', 'red')

        actr.set_current_model(player2)

        # create a goal chunk with the player's color and name
        actr.define_chunks([
            'goal', 'isa', 'play', 'my-color', 'blue', 'my-name',
            "'%s'" % player2
        ])
        actr.goal_focus('goal')
        actr.set_parameter_value(':show-focus', 'blue')

        window = actr.open_exp_window("game",
                                      visible=True,
                                      width=200,
                                      height=100)
        safety_window = actr.open_exp_window('Safety',
                                             visible=True,
                                             height=100,
                                             width=100,
                                             x=100,
                                             y=100)

        actr.add_command('stop-a-run', stop_a_run,
                         'Set the flag to terminate the game.')

        actr.add_button_to_exp_window(safety_window,
                                      text="STOP",
                                      x=0,
                                      y=0,
                                      action='stop-a-run',
                                      height=80,
                                      width=80,
                                      color='red')

        p1 = player1
        p2 = player2
        game_over = False
        safety_stop = False
        current_player = player1
        p1_position = 0
        p2_position = 5

        for m in actr.mp_models():
            actr.set_current_model(m)
            actr.install_device(window)

        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)

        actr.add_command("process-moves", process_moves,
                         "Handle player speak actions")
        actr.monitor_command("output-speech", "process-moves")

        # speak to all models telling them the name
        # of the first player.

        for m in actr.mp_models():
            actr.set_current_model(m)
            actr.new_word_sound(p1, 0, 'start')

        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', True)

        actr.remove_command_monitor("output-speech", "process-moves")
        actr.remove_command("process-moves")
        actr.remove_command('stop-a-run')
        actr.remove_command('is-game-over')
        actr.remove_command('set_game_over')

    return game_over
示例#6
0
def process_move(dist):
    global p1_position, p2_position, game_over, current_player

    forfeit = False
    winner = None
    if isinstance(dist, numbers.Number):
        if (current_player == p1):
            p1_position += dist
        else:
            p2_position -= dist
    else:
        forfeit = current_player

    if (forfeit or (p2_position <= p1_position)):  # game over
        if forfeit:
            if (current_player == p1):
                winner = p2
            else:
                winner = p1
        else:
            winner = current_player

        game_over = winner

        # create new chunks with the results

        actr.set_current_model(p1)

        if p1 == winner:
            result = 'win'
        else:
            result = 'lose'

        actr.goal_focus(
            actr.define_chunks([
                'isa', 'play', 'my-pos', 'p1', 'p1', p1_position, 'p2',
                p2_position, 'state', 'game-over', 'result', result
            ])[0])
        # update player 2 goal

        actr.set_current_model(p2)

        if p2 == winner:
            result = 'win'
        else:
            result = 'lose'

        actr.goal_focus(
            actr.define_chunks([
                'isa', 'play', 'my-pos', 'p2', 'p1', p1_position, 'p2',
                p2_position, 'state', 'game-over', 'result', result
            ])[0])
    elif current_player == p1:

        # player 1 moved so update player 2 goal

        actr.set_current_model(p2)

        actr.goal_focus(
            actr.define_chunks([
                'isa', 'play', 'my-pos', 'p2', 'p1', p1_position, 'p2',
                p2_position, 'state', 'move'
            ])[0])
        current_player = p2

    else:

        # player 2 moved so update player 1

        actr.set_current_model(p1)

        actr.goal_focus(
            actr.define_chunks([
                'isa', 'play', 'my-pos', 'p1', 'p1', p1_position, 'p2',
                p2_position, 'state', 'move'
            ])[0])
        current_player = p1
示例#7
0
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])
示例#8
0
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
示例#9
0
def play(player1, player2):
    global p1, p2, game_over, safety_stop, current_player, p1_position, p2_position, window

    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.reset()

        # initialize game info

        p1 = player1
        p2 = player2
        game_over = False
        safety_stop = False
        current_player = player1
        p1_position = 0
        p2_position = 5

        window = actr.open_exp_window("game",
                                      visible=True,
                                      width=300,
                                      height=100)
        safety_window = actr.open_exp_window('Safety',
                                             visible=True,
                                             height=100,
                                             width=100,
                                             x=100,
                                             y=100)

        actr.add_command('stop-a-run', stop_a_run,
                         'Set the flag to terminate the game.')
        actr.add_command('pick-button', pick_button, 'Button action function.')

        actr.add_button_to_exp_window(safety_window,
                                      text="STOP",
                                      x=0,
                                      y=0,
                                      action='stop-a-run',
                                      height=80,
                                      width=80,
                                      color='red')

        for m in actr.mp_models():
            actr.set_current_model(m)
            actr.install_device(window)

        for i in range(6):
            if i == 0:
                b = "1"
                c = 'red'
            elif i == 5:
                b = "2"
                c = 'white'
            else:
                b = ""
                c = 'white'

            spaces[i] = actr.add_button_to_exp_window(
                window,
                text=b,
                x=10 + (i * 40),
                y=10,
                action=['pick-button', i],
                height=35,
                width=35,
                color=c)

        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.')

        # Run ACT-R until the game is over

        actr.run_until_condition('is-game-over')

        actr.remove_command('stop-a-run')
        actr.remove_command('pick-button')
        actr.remove_command('is-game-over')
        actr.remove_command('set_game_over')

    return game_over
示例#10
0
def play(player1, player2):
    global p1, p2, game_over, safety_stop, current_player, p1_position, p2_position, p1_window, p2_window, p1_spaces, p2_spaces

    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.reset()

        # initialize game info

        p1 = player1
        p2 = player2
        game_over = False
        current_player = player1
        p1_position = 0
        p2_position = 5

        # open a window for each model and the safety stop button

        p1_window = actr.open_exp_window("player1",
                                         visible=True,
                                         width=300,
                                         height=100,
                                         x=100,
                                         y=100)
        p2_window = actr.open_exp_window("player2",
                                         visible=True,
                                         width=300,
                                         height=100,
                                         x=450,
                                         y=100)
        safety_window = actr.open_exp_window('Safety',
                                             visible=True,
                                             height=100,
                                             width=100,
                                             x=100,
                                             y=300)

        actr.add_command('stop-a-run', stop_a_run,
                         'Set the flag to terminate the game.')
        actr.add_command('pick-button', pick_button, 'Button action function.')

        actr.add_button_to_exp_window(safety_window,
                                      text="STOP",
                                      x=0,
                                      y=0,
                                      action='stop-a-run',
                                      height=80,
                                      width=80,
                                      color='red')

        for i in range(6):

            if i == 0:
                b = "1"
                p1_c = 'red'
            elif i == 5:
                b = "2"
                p1_c = 'white'
            else:
                b = ""
                p1_c = 'white'

            p1_spaces[i] = actr.add_button_to_exp_window(
                p1_window,
                text=b,
                x=(10 + (i * 40)),
                y=10,
                action=['pick-button', p1, i],
                height=35,
                width=35,
                color=p1_c)
            p2_spaces[i] = actr.add_button_to_exp_window(
                p2_window,
                text=b,
                x=(10 + (i * 40)),
                y=10,
                action=['pick-button', p2, (5 - i)],
                height=35,
                width=35,
                color='white')

        actr.set_current_model(p1)
        actr.install_device(p1_window)

        actr.set_current_model(p2)
        actr.install_device(p2_window)

        actr.run(10000, True)

        actr.remove_command('stop-a-run')
        actr.remove_command('pick-button')

    return game_over
示例#11
0
import actr
import actcv as cv
import actms as ms



# LOAD ACT-R MODELS
def loadmodels():
    actr.load_act_r_model(directory_path_lisp + ";EF-metamodel.lisp")
    actr.load_act_r_model(directory_path_lisp + ";EF-submodel-left.lisp")
    actr.load_act_r_model(directory_path_lisp + ";EF-submodel-middle.lisp")
    actr.load_act_r_model(directory_path_lisp + ";EF-submodel-right.lisp")

loadmodels()
actr.set_current_model("main-model")          

ms.getutility()
ms.saveutility()


## ----- -----
# loop over all datasets
timesRun = 1
session = [2,7]

printer = pd.DataFrame(columns=[], index = range(0))

for tr in range(timesRun):
    random.shuffle(session)