Exemplo n.º 1
0
def build_display(a, b, c, goal):
    global window, target, current_stick, done, current_line, choice

    target = goal
    current_stick = 0
    done = False
    choice = None
    current_line = None
    window = actr.open_exp_window("Building Sticks Task",
                                  visible=visible,
                                  width=600,
                                  height=400)

    actr.add_button_to_exp_window(window,
                                  text="A",
                                  x=5,
                                  y=23,
                                  action=["bst-button-pressed", a, "under"],
                                  height=24,
                                  width=40)
    actr.add_button_to_exp_window(window,
                                  text="B",
                                  x=5,
                                  y=48,
                                  action=["bst-button-pressed", b, "over"],
                                  height=24,
                                  width=40)
    actr.add_button_to_exp_window(window,
                                  text="C",
                                  x=5,
                                  y=73,
                                  action=["bst-button-pressed", c, "under"],
                                  height=24,
                                  width=40)
    actr.add_button_to_exp_window(window,
                                  text="Reset",
                                  x=5,
                                  y=123,
                                  action="bst-reset-button-pressed",
                                  height=24,
                                  width=65)

    actr.add_line_to_exp_window(window, [75, 35], [a + 75, 35], "black")
    actr.add_line_to_exp_window(window, [75, 60], [b + 75, 60], "black")
    actr.add_line_to_exp_window(window, [75, 85], [c + 75, 85], "black")
    actr.add_line_to_exp_window(window, [75, 110], [goal + 75, 110], "green")
Exemplo n.º 2
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
Exemplo n.º 3
0
def build_display(a, b, c, d, e, f, goal):
    global window, target, current_stick, done, current_line, choice

    target = goal
    current_stick = 0
    done = False
    choice = None
    current_line = None
    window = actr.open_exp_window("停车对标",
                                  visible=visible,
                                  width=600,
                                  height=400)

    actr.add_button_to_exp_window(window,
                                  text="A",
                                  x=5,
                                  y=23,
                                  action=["bst-button-pressed", a, "under"],
                                  height=24,
                                  width=40)
    actr.add_button_to_exp_window(window,
                                  text="B",
                                  x=5,
                                  y=48,
                                  action=["bst-button-pressed", b, "over"],
                                  height=24,
                                  width=40)
    actr.add_button_to_exp_window(window,
                                  text="C",
                                  x=5,
                                  y=73,
                                  action=["bst-button-pressed", c, "under"],
                                  height=24,
                                  width=40)
    actr.add_button_to_exp_window(window,
                                  text="D",
                                  x=5,
                                  y=98,
                                  action=["bst-button-pressed", d, "under"],
                                  height=24,
                                  width=40)
    actr.add_button_to_exp_window(window,
                                  text="E",
                                  x=5,
                                  y=120,
                                  action=["bst-button-pressed", e, "under"],
                                  height=24,
                                  width=40)
    actr.add_button_to_exp_window(window,
                                  text="F",
                                  x=5,
                                  y=140,
                                  action=["bst-button-pressed", f, "under"],
                                  height=24,
                                  width=40)

    # actr.add_text_to_exp_window(window, text="实际距离: ", x=5, y=123, height=24, width=65)
    actr.add_button_to_exp_window(window,
                                  text="Reset",
                                  x=5,
                                  y=340,
                                  action="bst-reset-button-pressed",
                                  height=24,
                                  width=65)
    actr.add_line_to_exp_window(window, [75, 35], [a + 75, 35], "black")
    actr.add_line_to_exp_window(window, [75, 60], [b + 75, 60], "black")
    actr.add_line_to_exp_window(window, [75, 85], [c + 75, 85], "black")
    actr.add_line_to_exp_window(window, [75, 110], [d + 75, 110], "black")
    actr.add_line_to_exp_window(window, [75, 135], [e + 75, 135], "black")
    actr.add_line_to_exp_window(window, [75, 160], [f + 75, 160], "black")
    actr.add_line_to_exp_window(window, [75, 310], [goal + 75, 310], "green")
    # actr.add_line_to_exp_window(window, [75, 320], [current_stick + 75, 215], "blue")
    actr.add_text_to_exp_window(
        window,
        "注意!\nB表示目标距离;模型先注视ABCDEF四条线,之后将目标线与C对比,求其差值,依次比较A,D,E,F,直至出现Done,结束对标。\nA表示四级制动,制动距离较长;"
        "\nC表示一级制动,制动距离最长;",
        x=400,
        y=310,
        color='blue',
        height=200,
        width=150,
        font_size=12)
Exemplo n.º 4
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
Exemplo n.º 5
0
        actr.monitor_command("output-key", "sp-key-press")
        experiment(human=False)
        actr.reset()
        actr.remove_items_from_exp_window(window, x1_target_speed)
        actr.remove_items_from_exp_window(window, x2_actual_speed)
        actr.remove_items_from_exp_window(window, x3_delta_speed)
        actr.remove_items_from_exp_window(window, x4_delta_distance)
        actr.remove_items_from_exp_window(window, x5)
        targetgroup.append(speed_target[0])
        actualgroup.append(speed_actual[0])

        actr.add_button_to_exp_window(window,
                                      text="7",
                                      x=500,
                                      y=60,
                                      action=["sp-button-pressed", 0.2, "up"],
                                      height=20,
                                      width=100,
                                      color='yellow')
        actr.add_button_to_exp_window(window,
                                      text="6",
                                      x=500,
                                      y=80,
                                      action=["sp-button-pressed", 0.2, "up"],
                                      height=20,
                                      width=100,
                                      color='yellow')
        actr.add_button_to_exp_window(window,
                                      text="5",
                                      x=500,
                                      y=100,
Exemplo n.º 6
0
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
Exemplo n.º 7
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
Exemplo n.º 8
0
def run_experiment(start_point, end_point, verbose=True, visible=True, trace=True):
        """Runs an experiment"""
        actr.reset()
        # current directory
        actr.load_act_r_model(r"C:\Users\syl\Desktop\ACTR_ATO\sp_new_2.lisp")
        window = actr.open_exp_window("* Speed trace *", width=800, height=600, visible=visible)
        actr.install_device(window)


        # actr.add_text_to_exp_window(window, text="当前推荐速度:", x=10, y=60, height=40, width=95, color='black', font_size=22)
        # actr.add_text_to_exp_window(window, text="当前速度差值:", x=10, y=20, height=40, width=180, color='black', font_size=22)
        # actr.add_text_to_exp_window(window, text="当前实际速度:", x=10, y=100, height=40, width=95, color='black', font_size=22)
        # actr.add_text_to_exp_window(window, text="距离车站位置:", x=10, y=140, height=40, width=95, color='black', font_size=22)
        # actr.add_text_to_exp_window(window, text="当前速度差值:", x=10, y=180, height=40, width=95, color='black', font_size=22)

        # actr.add_button_to_exp_window(window, text="7", x=500, y=80, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow')
        # actr.add_button_to_exp_window(window, text="6", x=500, y=100, action=["sp-button-pressed", 0.2, "up"],height=20, width=100, color='yellow')
        # actr.add_button_to_exp_window(window, text="5", x=500, y=120, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow')
        # actr.add_button_to_exp_window(window, text="4", x=500, y=140, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow')
        # actr.add_button_to_exp_window(window, text="3", x=500, y=160, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow')
        # actr.add_button_to_exp_window(window, text="2", x=500, y=180, action=["sp-button-pressed", 0.2, "up"], height=20, width=100, color='yellow')
        actr.add_button_to_exp_window(window, text="up", x=500, y=200, action=["sp-button-pressed-up-keep-down", 1, "up"], height=20, width=100,color='yellow')
        actr.add_button_to_exp_window(window, text="keep", x=500, y=220, action=["sp-button-pressed-up-keep-down", 0, "keep"], height=20, width=100, color='gray')
        actr.add_button_to_exp_window(window, text="down", x=500, y=240, action=["sp-button-pressed-up-keep-down", 1, "down"], height=20, width=100, color='green')
        # actr.add_button_to_exp_window(window, text="-2", x=500, y=260, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
        # actr.add_button_to_exp_window(window, text="-3", x=500, y=280, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
        # actr.add_button_to_exp_window(window, text="-4", x=500, y=300, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
        # actr.add_button_to_exp_window(window, text="-5", x=500, y=320, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
        # actr.add_button_to_exp_window(window, text="-6", x=500, y=340, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
        # actr.add_button_to_exp_window(window, text="-7", x=500, y=360, action=["sp-button-pressed", 0.2, "down"], height=20, width=100, color='green')
        actr.add_button_to_exp_window(window, text="10", x=500, y=260, action=["sp-button-pressed-up-keep-down", 1, "EB"], height=20, width=100, color='red')
        actr.add_command("sp-button-pressed-up-keep-down", button_pressed, "sp press button(up\keep\down) task")

        actr.start_hand_at_mouse()



        for i in range(start_point, end_point):

            target_speed = train_model().target_v(i)
            actual_speed = 10
            delta_speed = actual_speed - target_speed
            print(delta_speed)
            t_group.append(i)
            target_group.append(target_speed)
            actual_group.append(actual_speed)
            if delta_speed > 0:
                delta_speed_show = "+"
            elif delta_speed < 0:
                delta_speed_show = "-"
            else:
                delta_speed_show = "0"


            print(i, str(int(target_speed)))
            deltasudu = actr.add_text_to_exp_window(window, delta_speed_show, x=200, y=30, height=40, width=95,color='red', font_size=22)
            # mubiaosudu = actr.add_text_to_exp_window(window, "*", x=220, y=30, height=40, width=95,color='red', font_size=22)
            mubiaosudu = actr.add_text_to_exp_window(window, str(round(target_speed)), x=240, y=30,height=40, width=95, color='red', font_size=22)
            # shijisudu = actr.add_text_to_exp_window(window, str(int(actual_speed)), x=200, y=100, height=40, width=95,color='red', font_size=22)
            EB = actr.add_text_to_exp_window(window, "10", x=280, y=30,height=40, width=95, color='red', font_size=22)


            actualline = actr.add_line_to_exp_window(window, [180, 80], [280+ round(target_speed), 80], "red")
            modifyline = actr.modify_line_for_exp_window(actualline, [180, 80], [280 + round(target_speed), 80], "blue")
            # actualline = modifyline

            # actr.remove_items_from_exp_window(window, modifyline)





            actr.run(100, True)
            # actr.print_visicon()
            # print("****************************end cmd actr.print_visicon()**********************************")
            # actr.all_productions()
            # print("****************************end cmd actr.all_productions()**********************************")
            # actr.clear_buffer("visual")
            # actr.act_r_output(actr.dm())
            # actr.buffer_read("manual")
            # print("****************************end cmd actr.buffer_read(manual)**********************************")
            actr.remove_items_from_exp_window(window, deltasudu)






            actr.remove_items_from_exp_window(window, mubiaosudu)
            # actr.remove_items_from_exp_window(window, shijisudu)


        Game().draw_target_actual_speed(t_group, target_group, actual_group)
        actr.remove_command_monitor("output-key", "sp-key-press")
Exemplo n.º 9
0
def pick_button(model, index):
    global spaces, p1_position, p2_position, current_player, p1_spaces, p2_spaces, game_over

    # 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):  # valid move

            if index >= p2_position:

                # end the run after 3 seconds

                actr.schedule_break_relative(3)
                game_over = p1

                # remove the current position

                actr.remove_items_from_exp_window(p1_window,
                                                  p1_spaces[p1_position],
                                                  p1_spaces[index])
                actr.remove_items_from_exp_window(p2_window,
                                                  p2_spaces[5 - p1_position],
                                                  p2_spaces[5 - index])

                # add the blank old one and the new one marked green to indicate a win
                # don't need to store them or provide the action function because game is over

                actr.add_button_to_exp_window(p1_window,
                                              x=(10 + (p1_position * 40)),
                                              y=10,
                                              height=35,
                                              width=35,
                                              color='white')
                actr.add_button_to_exp_window(p1_window,
                                              text="1",
                                              x=(10 + (index * 40)),
                                              y=10,
                                              height=35,
                                              width=35,
                                              color='green')

                # mirror image for p2 window
                actr.add_button_to_exp_window(p2_window,
                                              x=(10 +
                                                 ((5 - p1_position) * 40)),
                                              y=10,
                                              height=35,
                                              width=35,
                                              color='white')
                actr.add_button_to_exp_window(p2_window,
                                              text="2",
                                              x=(10 + ((5 - index) * 40)),
                                              y=10,
                                              height=35,
                                              width=35,
                                              color='green')

            else:  # update the p1 position and make p2 the current player

                actr.remove_items_from_exp_window(p1_window,
                                                  p1_spaces[p1_position],
                                                  p1_spaces[index])
                actr.remove_items_from_exp_window(p2_window,
                                                  p2_spaces[5 - p1_position],
                                                  p2_spaces[5 - index],
                                                  p2_spaces[5 - p2_position])

                # No action needed for spaces that can't be used again

                p1_spaces[p1_position] = actr.add_button_to_exp_window(
                    p1_window,
                    x=(10 + (p1_position * 40)),
                    y=10,
                    height=35,
                    width=35,
                    color='white')
                p1_spaces[index] = actr.add_button_to_exp_window(
                    p1_window,
                    text="1",
                    x=(10 + (index * 40)),
                    y=10,
                    height=35,
                    width=35,
                    color='white')

                p2_spaces[5 - p2_position] = actr.add_button_to_exp_window(
                    p2_window,
                    text="1",
                    x=(10 + ((5 - p2_position) * 40)),
                    y=10,
                    height=35,
                    width=35,
                    color='red')
                p2_spaces[5 - p1_position] = actr.add_button_to_exp_window(
                    p2_window,
                    x=(10 + ((5 - p1_position) * 40)),
                    y=10,
                    action=['pick-button', p2, p1_position],
                    height=35,
                    width=35,
                    color='white')
                p2_spaces[5 - index] = actr.add_button_to_exp_window(
                    p2_window,
                    text="2",
                    x=(10 + ((5 - index) * 40)),
                    y=10,
                    action=['pick-button', p2, index],
                    height=35,
                    width=35,
                    color='white')

                p1_position = index
                current_player = p2

        elif (current_player == p2) and (index < p2_position) and (
            (p2_position - index) <= 2):  # valid move

            if index <= p1_position:

                # end the run after 3 seconds

                actr.schedule_break_relative(3)
                game_over = p2

                # remove the current position

                actr.remove_items_from_exp_window(p2_window,
                                                  p2_spaces[5 - p2_position],
                                                  p2_spaces[5 - index])
                actr.remove_items_from_exp_window(p1_window,
                                                  p1_spaces[p2_position],
                                                  p1_spaces[index])

                # add the blank old one and the new one marked green to indicate a win
                # don't need to store them or provide the action function because game is over

                actr.add_button_to_exp_window(p2_window,
                                              x=(10 +
                                                 ((5 - p2_position) * 40)),
                                              y=10,
                                              height=35,
                                              width=35,
                                              color='white')
                actr.add_button_to_exp_window(p2_window,
                                              text="1",
                                              x=(10 + ((5 - index) * 40)),
                                              y=10,
                                              height=35,
                                              width=35,
                                              color='green')

                actr.add_button_to_exp_window(p1_window,
                                              x=(10 + (p2_position * 40)),
                                              y=10,
                                              height=35,
                                              width=35,
                                              color='white')
                actr.add_button_to_exp_window(p1_window,
                                              text="2",
                                              x=(10 + (index * 40)),
                                              y=10,
                                              height=35,
                                              width=35,
                                              color='green')

            else:  # update the p2 position and make p1 the current player

                actr.remove_items_from_exp_window(p2_window,
                                                  p2_spaces[5 - p2_position],
                                                  p2_spaces[5 - index])
                actr.remove_items_from_exp_window(p1_window,
                                                  p1_spaces[p2_position],
                                                  p1_spaces[index],
                                                  p1_spaces[p1_position])

                # No action needed for spaces that can't be used again

                p2_spaces[5 - p2_position] = actr.add_button_to_exp_window(
                    p2_window,
                    x=(10 + ((5 - p2_position) * 40)),
                    y=10,
                    height=35,
                    width=35,
                    color='white')
                p2_spaces[5 - index] = actr.add_button_to_exp_window(
                    p2_window,
                    text="1",
                    x=(10 + ((5 - index) * 40)),
                    y=10,
                    height=35,
                    width=35,
                    color='white')

                p1_spaces[p2_position] = actr.add_button_to_exp_window(
                    p1_window,
                    x=(10 + (p2_position * 40)),
                    y=10,
                    action=['pick-button', p1, p2_position],
                    height=35,
                    width=35,
                    color='white')
                p1_spaces[p1_position] = actr.add_button_to_exp_window(
                    p1_window,
                    text="1",
                    x=(10 + (p1_position * 40)),
                    y=10,
                    action=['pick-button', p1, p1_position],
                    height=35,
                    width=35,
                    color='red')
                p1_spaces[index] = actr.add_button_to_exp_window(
                    p1_window,
                    text="2",
                    x=(10 + (index * 40)),
                    y=10,
                    action=['pick-button', p1, index],
                    height=35,
                    width=35,
                    color='white')

                p2_position = index
                current_player = p1
Exemplo n.º 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