def update_current_line():
    global current_line, done

    if current_stick == target:
        done = True
        actr.modify_line_for_exp_window(current_line, [75, 330],
                                        [target + 75, 330])
        actr.add_text_to_exp_window(window, "Done", x=5, y=200)
        actr.add_text_to_exp_window(window,
                                    "对标成功!",
                                    x=300,
                                    y=200,
                                    color='red',
                                    height=20,
                                    width=75,
                                    font_size=24)
    elif current_stick == 0:
        if current_line:
            actr.remove_items_from_exp_window(window, current_line)
            current_line = None
    elif current_line:
        actr.modify_line_for_exp_window(current_line, [75, 330],
                                        [current_stick + 75, 330])
    else:
        current_line = actr.add_line_to_exp_window(window, [75, 330],
                                                   [current_stick + 75, 330],
                                                   "blue")
Example #2
0
def light1_off(window, text1, mode):
    global light1Color, light1_obj

    light1Color = "black"
    if light1_obj != None:
        actr.remove_items_from_exp_window(window, light1_obj)
    light1_obj = actr.add_text_to_exp_window(window,
                                             text1,
                                             x=125,
                                             y=100,
                                             color=light1Color)
Example #3
0
def light2_off(window, text2, mode):
    global light2Color, light2_obj

    light2Color = "red"
    if light2_obj != None:
        actr.remove_items_from_exp_window(window, light2_obj)
    light2_obj = actr.add_text_to_exp_window(window,
                                             text2,
                                             x=175,
                                             y=100,
                                             color=light2Color)
Example #4
0
def update_current_line():
    global current_line,done

    if current_stick == target:
        done = True
        actr.modify_line_for_exp_window(current_line, [75,135], [target + 75,135])
        actr.add_text_to_exp_window(window, "Done", x=180, y=200)
    elif current_stick == 0:
        if current_line:
            actr.remove_items_from_exp_window(window,current_line)
            current_line = None
    elif current_line:
        actr.modify_line_for_exp_window(current_line,[75,135],[current_stick + 75,135])
    else:
        current_line = actr.add_line_to_exp_window(window,[75,135],[current_stick + 75,135],"blue")
def reset_display():
    global current_stick

    if not (done):
        current_stick = 0
        update_current_line()
        overparking = actr.add_text_to_exp_window(window,
                                                  "停车超标!",
                                                  x=300,
                                                  y=200,
                                                  color='red',
                                                  height=20,
                                                  width=75,
                                                  font_size=24)
        time.sleep(1)
        actr.remove_items_from_exp_window(window, overparking)
Example #6
0
        # actr.start_hand_at_mouse()
        actr.add_command("sp-button-pressed-up-keep-down", button_pressed,
                         "sp press button(up\keep\down) task")
        actr.add_command("sp-number-sims", number_sims,
                         "Similarity hook function for building sticks task.")
        actr.add_command("sp-button-stop-pressed", button_stop_pressed,
                         "sp task output-key monitor")
        actr.add_command(
            "sp-compute-difference", compute_difference,
            "Imaginal action function to compute the difference between sticks."
        )

        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')
Example #7
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
Example #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")
Example #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