Example #1
0
    def test_mouse(self, output=False):
        agent = Agent(output=output)
        env = Environment()
        vision = Vision(agent, env.display)
        motor = Motor(agent, vision, env)
        self.button = None
        end = 20.0

        def update():
            if agent.time() < end:

                def fn():
                    vision.clear()
                    agent.wait(1.0)
                    self.button = env.display.add_button(
                        random.randint(0, 500), random.randint(0, 500), 'X')

                agent.run_thread(fn)

        update()

        def fn(visual):
            if visual.obj == 'X':
                update()

        env.mouse.add_click_fn(fn)
        while agent.time() < end:
            visual = vision.wait_for(isa='button')
            motor.point_and_click(visual)
        agent.wait_for_all()
        self.assertGreaterEqual(agent.time(), end)
Example #2
0
 def test_typing(self, output=False):
     agent = Agent(output=output)
     env = Environment()
     vision = Vision(agent, env.display)
     motor = Motor(agent, vision, env)
     motor.type('Hello there. What\'s up?')
     agent.wait_for_all()
     self.assertAlmostEqual(6.597, agent.time(), 1)
Example #3
0
class PVTAgent(Agent):
    def __init__(self, env):
        """Initializes the agent"""
        super().__init__(output=True)
        self.vision = Vision(self, env.display)  #, eyes=Eyes(self))
        self.motor = Motor(self, self.vision, env)

    def run(self, time=60):
        while self.time() < time:
            visual = self.vision.wait_for(isa='letter',
                                          region='pvt',
                                          seen=False)
            self.vision.start_encode(visual)
            self.motor.type(' ')
            self.vision.get_encoded()
Example #4
0
class VSAgent(Agent):

    def __init__(self, env):
        """Initializes the agent"""
        super().__init__(output=True)
        self.vision = Vision(self, env.display) #, eyes=Eyes(self))
        self.motor = Motor(self, self.vision, env)

    def run(self, time):
        while self.time() < time:
            self.vision.wait_for(isa='letter', seen=False)
            visual = self.vision.search_for(
                Query(isa='letter', color='red', region='vs'), 'X')
            if visual:
                # self.log('target present')
                self.motor.type('w')
                self.wait(1.0)
            else:
                # self.log('target absent')
                self.motor.type('r')
                self.wait(1.0)
Example #5
0
    def __init__(self, env, output=True):
        super().__init__(output=output)

        #basic pass-ins for now for speed of testing
        self.memory = OntologyMemory(self,stopOldServer=False,owlFile='uagent.owl')
        self.vision = Vision(self, env.display)
        self.audition = Audition(self, env.speakers)
        self.motor = Motor(self, self.vision, env)

        self.interpreter = Interpreter(self.memory)

        self.language = Language(self)
        self.language.add_interpreter(lambda words:
                                      self.interpreter.interpret_ace(' '.join(words)))

        self.condition_handler = ConditionHandler(self)
        self.action_handler = ActionHandler(self)
Example #6
0
    def test_instruction_type(self, output=False):
        agent = Agent(output=output)
        env = Environment()
        memory = Memory(agent)
        vision = Vision(agent, env.display)
        audition = Audition(agent, env.speakers)
        motor = Motor(agent, vision, env)

        def interpreter(words):
            if words[0] == 'read':
                sem = Item(isa='action', type='read', object=words[1])
                pointer = vision.find(isa='pointer')
                if pointer is not None:
                    vision.encode(pointer)
                    sem.set('x', pointer.x).set('y', pointer.y)
                return sem
            elif words[0] == 'done':
                return Item(isa='done')
            else:
                return Item(isa='action', type=words[0], object=words[1])

        language = Language(agent)
        language.add_interpreter(interpreter)

        def executor(action, context):
            if action.type == 'read':
                query = Query(x=action.x, y=action.y)
                context.set(action.object, vision.find_and_encode(query))
            elif action.type == 'type':
                motor.type(context.get(action.object))

        instruction = Instruction(agent, memory, audition, language)
        instruction.add_executor(executor)

        typed = []

        def type_handler(key):
            typed.append(key)

        env.keyboard.add_type_fn(type_handler)

        env.display.add_text(50, 50, 'a')
        pointer = env.display.add(50, 50, 1, 1, 'pointer', 'pointer')

        speech = ['to type', ['read letter', (50, 50)], 'type letter', 'done']

        def thread():
            for line in speech:
                agent.wait(3.0)
                if isinstance(line, str):
                    audition.add(Aural(isa='speech'), line)
                else:
                    audition.add(Aural(isa='speech'), line[0])
                    loc = line[1]
                    pointer.move(loc[0], loc[1])

        agent.run_thread(thread)

        goal = instruction.listen_and_learn()
        self.assertEqual('type', goal)

        context = instruction.execute(goal)
        self.assertEqual('a', context.letter)

        agent.wait_for_all()

        self.assertEqual(['a'], typed)
Example #7
0
 def __init__(self, env):
     """Initializes the agent"""
     super().__init__(output=True)
     self.vision = Vision(self, env.display)  #, eyes=Eyes(self))
     self.motor = Motor(self, self.vision, env)