summaryrefslogtreecommitdiff
path: root/modeling/productions_math.py
blob: 7ac1257a604982d9c0f670bcbfb2e8aa87b85844 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/usr/bin/env python3

import pyactr as actr
from pprint import pprint

from model_init import init
import prod_addition
import prod_subtraction
import prod_comp
import prod_multi
import prod_numbers
import prod_procedure
import prod_motor
import prod_vis
import model_env


def add_goal(goal, op, arg1, arg2):

    goal.add(actr.makechunk("", "math_goal", op=op, task=op, arg1=arg1, arg2=arg2))


def general_prod(Model):

    Model.productionstring(
        name="continue_with_next_op",
        string="""
            =g>
            isa     math_goal
            op      done
            nextop  ~None
            nextop  =nextop
            ==>
            =g>
            isa     math_goal
            op      =nextop
            nextop  None
        """,
    )


def wait_input():
    op = input("op\n")
    arg1 = input("arg1\n")
    arg2 = input("arg2\n")
    return op, int(arg1), int(arg2)


def add_proc(goal, proc):
    # input()
    goal.add(actr.makechunk("", "math_goal", proc=proc, ones_carry="hello"))


def start():
    loop = True
    while loop:
        loop = False
        # op, arg1, arg2 = wait_input()
        Model, DM, goal, imaginal, env = init()
        # add_goal(goal, op, arg1, arg2)
        add_proc(goal, "proc1")
        envs = model_env.generate_environments()

        general_prod(Model)
        prod_procedure.procedures(Model)
        number_prods = prod_numbers.number(Model)
        add_prods = prod_addition.addition(Model)
        sub_prods = prod_subtraction.subtraction(Model)
        greater_prods = prod_comp.greater_than(Model)
        less_prods = prod_comp.lesser_than(Model)
        multi_prods = prod_multi.multiplication(Model)
        motor_prods = prod_motor.procedures(Model)
        visual_prods = prod_vis.procedures(Model)

        # for prod in multi_prods:
        #     print(prod)
        #     print("\n")

        print("goal: ", goal)
        # print("imaginal: ", imaginal)
        sim = Model.simulation(
            gui=False,
            environment_process=env.environment_process,
            stimuli=envs,
            # triggers="space",
            triggers="b",
        )
        i = 1
        userinput = ""
        while True:
            sim.step()
            if sim.current_event.time >= 50:
                print(sim.current_event)
                break
            if "KEY PRESSED" in sim.current_event.action:
                userinput = userinput + sim.current_event.action.split(":")[1]
            # if sim.current_event.action == "NO RULE FOUND":
            #     print(goal)
            if sim.current_event.action == "KEY PRESSED: SPACE":
                sim._Simulation__env.stimulus["Answer5"]["text"] = "99"
                i += 1
                print(userinput)
                print("NEW PROC")
                if i <= 6:
                    goal.add(
                        actr.makechunk(
                            "", "math_goal", proc=f"proc{i}", ones_carry="hello"
                        )
                    )
                elif i == 7:
                    goal.add(
                        actr.makechunk(
                            "", "math_goal", proc="proc_overall", ones_carry="hello"
                        )
                    )
                elif i > 7:
                    print("DONE")
                    break

        # sim.run(max_time=25)
        print(userinput)
        print("Simulation time: ", sim.show_time())
        print("goal: ", goal)
        print(sim.current_event)
        pprint(vars(sim))
        pprint(vars(sim._Simulation__env))
        # print(sim.__env)
        # sim.__printenv__()
        # print(envs.stimulus)
        # print("imaginal: ", imaginal)
        math_goals = [sim for sim in list(DM) if sim.typename == "procedure"]
        # print(math_goals)


if __name__ == "__main__":
    start()