Пример #1
0
 def add_self_memory_node(self):
     """Adds agent node into its own memory"""
     # how/when to, memory is initialized before physical interfaces...
     try:
         p = self.get_player()
     except:  # this is for test/test_agent
         return
     PlayerNode.create(self.memory, p, memid=self.memory.self_memid)
Пример #2
0
 def get_incoming_chats(self):
     all_chats = []
     speaker_name = "dashboard"
     if self.dashboard_chat is not None:
         if not self.memory.get_player_by_name(speaker_name):
             PlayerNode.create(
                 self.memory,
                 to_player_struct((None, None, None), None, None, None, speaker_name),
             )
         all_chats.append(self.dashboard_chat)
         self.dashboard_chat = None
     return all_chats
Пример #3
0
 def get_incoming_chats(self):
     c = self.chat_count
     for raw_chatstr in self.world.chat_log[c:]:
         match = re.search("^<([^>]+)> (.*)", raw_chatstr)
         speaker_name = match.group(1)
         if not self.memory.get_player_by_name(speaker_name):
             # FIXME! name used as eid
             PlayerNode.create(
                 self.memory,
                 to_player_struct((None, None, None), None, None, speaker_name, speaker_name),
             )
     self.chat_count = len(self.world.chat_log)
     return self.world.chat_log[c:].copy()
 def update_other_players(self, player_list: List, force=False):
     # input is a list of player_structs from agent
     for p in player_list:
         mem = self.memory.get_player_by_eid(p.entityId)
         if mem is None:
             memid = PlayerNode.create(self.memory, p)
         else:
             memid = mem.memid
         cmd = (
             "UPDATE ReferenceObjects SET eid=?, name=?, x=?,  y=?, z=?, pitch=?, yaw=? WHERE "
         )
         cmd = cmd + "uuid=?"
         self.memory._db_write(cmd, p.entityId, p.name, p.pos.x, p.pos.y,
                               p.pos.z, p.look.pitch, p.look.yaw, memid)
         loc = capped_line_of_sight(self.agent, p)
         loc[1] += 1
         memids = self.memory._db_read_one(
             'SELECT uuid FROM ReferenceObjects WHERE ref_type="attention" AND type_name=?',
             p.entityId,
         )
         if memids:
             self.memory._db_write(
                 "UPDATE ReferenceObjects SET x=?, y=?, z=? WHERE uuid=?",
                 loc[0],
                 loc[1],
                 loc[2],
                 memids[0],
             )
         else:
             AttentionNode.create(self.memory, loc, attender=p.entityId)
Пример #5
0
 def update_other_players(self, player_list: List):
     # input is a list of player_structs from agent
     for p in player_list:
         mem = self.get_player_by_eid(p.entityId)
         if mem is None:
             memid = PlayerNode.create(self, p)
         else:
             memid = mem.memid
         PlayerNode.update(self, p, memid)
 def update_other_players(self, player_list: List):
     # input is a list of player_structs from agent
     for p in player_list:
         mem = self.memory.get_player_by_eid(p.entityId)
         if mem is None:
             memid = PlayerNode.create(self.memory, p)
         else:
             memid = mem.memid
         cmd = "UPDATE Players SET eid=?, name=?, x=?,  y=?, z=?, pitch=?, yaw=? WHERE "
         cmd = cmd + "uuid=?"
         self.memory._db_write(cmd, p.entityId, p.name, p.pos.x, p.pos.y,
                               p.pos.z, p.look.pitch, p.look.yaw, memid)
Пример #7
0
    def perceive(self):
        bots = self.agent.world.get_bots()
        for bot in bots:
            #            print(f"[Perception INFO]: Perceived bot [{bot.name}] in the world, update in memory]")
            bot_node = self.agent.memory.get_player_by_eid(bot.entityId)
            if bot_node is None:
                memid = PlayerNode.create(self.agent.memory, bot)
                bot_node = PlayerNode(self.agent.memory, memid)
                self.agent.memory.tag(memid, "bot")
            bot_node.update(self.agent.memory, bot, bot_node.memid)
            print(
                f"[Memory INFO]: update bot [{bot.name}] position: ({bot.pos.x}, {bot.pos.y}, {bot.pos.z})"
            )

        bot_memids = self.agent.memory.get_memids_by_tag("bot")
        bots_in_world = [b.entityId for b in bots]
        for memid in bot_memids:
            bot_eid = self.agent.memory.get_mem_by_id(memid).eid
            if bot_eid not in bots_in_world:
                self.agent.memory.forget(memid)
                print(f"[Memory INFO]: delete bot [{bot_eid}] from memory")
Пример #8
0
    def test_triggers(self):
        joe_memid = PlayerNode.create(
            self.memory, Player(10, "joe", Pos(1, 0, 1), Look(0, 0)))
        joe_tag_memid = self.memory.tag(joe_memid, "joe")
        jane_memid = PlayerNode.create(
            self.memory, Player(11, "jane", Pos(-1, 0, 1), Look(0, 0)))

        joe_mems = self.memory.basic_search({
            "base_exact": {
                "name": "joe"
            },
            "triples": []
        })
        jane_mems = self.memory.basic_search({
            "base_exact": {
                "name": "jane"
            },
            "triples": []
        })
        assert len(joe_mems) == 1
        assert len(jane_mems) == 1

        joe_mems_from_tag = self.memory.basic_search({
            "base_exact": {},
            "triples": [{
                "obj_text": "joe",
                "pred_text": "has_tag"
            }]
        })
        jane_mems_from_tag = self.memory.basic_search({
            "base_exact": {},
            "triples": [{
                "obj_text": "jane",
                "pred_text": "has_tag"
            }]
        })
        assert len(joe_mems_from_tag) == 1
        assert len(jane_mems_from_tag) == 0

        self.time.add_tick()
        brother_of_memid = self.memory.add_triple(subj=joe_memid,
                                                  pred_text="brother_of",
                                                  obj=jane_memid)
        sister_of_memid = self.memory.add_triple(subj=jane_memid,
                                                 pred_text="sister_of",
                                                 obj=joe_memid)

        triples = self.memory.get_triples(subj=jane_memid,
                                          pred_text="sister_of")
        assert len(triples) == 1

        self.time.add_tick()
        self.memory.db_write("UPDATE ReferenceObjects SET x=? WHERE uuid=?", 2,
                             joe_memid)
        cmd = "SELECT updated_time FROM Memories WHERE uuid=?"
        joe_t = self.memory._db_read(cmd, joe_memid)[0][0]
        jane_t = self.memory._db_read(cmd, jane_memid)[0][0]
        assert joe_t == 2
        assert jane_t == 0

        self.memory.forget(joe_memid)
        triples = self.memory.get_triples(subj=jane_memid,
                                          pred_text="sister_of")
        assert len(triples) == 0