"""
Exercise: verify most (e.g., most letters are As).

You have to make modifications at the place indicated.
"""

import pyactr as actr

#create chunktype counting to fit your needs
#actr.chunktype("counting", "...")

environment = actr.Environment(focus_position=(20, 20))

counter = actr.ACTRModel(environment, #rule_firing=0.05
        rule_firing=0.5)

counter.visualBuffer("visual", "visual_location", counter.decmem,
        finst=10)#this is to keep 10 objects in finst (fingers of
                #instatiation

#uncomennt and modify the chunk in the goal buffer - you probably have to
#prepare slots for counting As and counting Bs

#counter.goal.add(actr.chunkstring(name="reading", string="""
#        isa     counting
#        state   start
#        """)

counter.productionstring(name="move attention", string="""
        =g>
        isa     counting
        state   start
        ?visual_location>
        buffer  full
        =visual_location>
        isa     _visuallocation
        ?visual>
        buffer  empty
        state   free
        ==>
        =g>
        isa     counting
        state   encode
        ~visual_location>
        +visual>
        isa     _visual
        cmd     move_attention
        screen_pos =visual_location""")

#create rules - encode first A, encode second A,...
#create rules - encode first B, encode second B,...

counter.productionstring(name="find_A_probe", string="""
        =g>
        isa     counting
        state   search
        ?visual_location>
        buffer  empty
        ==>
        =g>
        isa     counting
        state   start
        ?visual_location>
        attended False
        +visual_location>
        isa _visuallocation
        value       A
        screen_x lowest""")

#add a new rule, find_B_probe

#add a rule or rules that checks whether there are more As than Bs

#uncomment and work on the the rule

#counter.productionstring(name="finding_probe_failed", string="""
#        =g>
#        isa     counting
#        state   start
#        ?visual_location>
#        state   error
#        ==>
#        """)

if __name__ == "__main__":
    text = {1: {'text': 'A', 'position': (100,100)}, 2: {'text': 'B', 'position': (240,120)}, 3: {'text': 'A', 'position': (400,200)}, 4: {'text': 'B', 'position': (150,190)}, 5: {'text': 'A', 'position': (320,230)}}
    sim = counter.simulation(realtime=True, environment_process=environment.environment_process, stimuli=text, triggers='A', times=1)
    sim.run()
