Exemplo n.º 1
0
    def test_behaviour(self):
        class TestBehaviour(OneShotBehaviour):
            async def run(self):
                msg = Message(
                    to="cservice@localhost")  # Instantiate the message
                msg.set_metadata(
                    "performative",
                    "register")  # Set the "inform" FIPA performative
                msg.body = "Hello"  # Set the message content
                await self.send(msg)

                msg = Message(to="cservice@localhost")
                msg.set_metadata("performative", "get")
                msg.body = "Hello"
                await self.send(msg)
                res = await self.receive(timeout=10000)

                msg = Message(to="cservice@localhost")
                msg.set_metadata("performative", "deregister_service")
                msg.body = "Hello"
                await self.send(msg)

        service = CService()
        service.start()

        agent = CJGomasAgent('sender@localhost')
        agent.start()

        behav = TestBehaviour()
        agent.add_behaviour(behav)

        while not behav.done():
            time.sleep(1)
        service.stop()
        agent.stop()
Exemplo n.º 2
0
    def test_setup(self):
        class TestBehaviour(OneShotBehaviour):
            async def run(self):
                res = await self.receive(timeout=10000)
                msg = Message(to="objective1@localhost")
                msg.set_metadata("performative", "inform")
                msg.body = "Hello"
                await self.send(msg)

        agent = CJGomasAgent('cmanager@localhost')
        agent.start()

        behav = TestBehaviour()
        agent.add_behaviour(behav)

        pack = CObjPack("objective1@localhost")

        pack.start()

        while not behav.done():
            time.sleep(1)

        agent.stop()

        pack.stop()
Exemplo n.º 3
0
    def start(self):

        CJGomasAgent.start(self)
        if self.m_eType != self.PACK_OBJPACK:
            dOffset = 10.0  # OJO
            self.m_Position.x += random.random() * dOffset
            self.m_Position.z += random.random() * dOffset

        self.add_behaviour(self.CreatePackBehaviour())

        t = Template()
        t.set_metadata("performative", "pack")
        self.add_behaviour(self.PackTakenResponderBehaviour(), t)
Exemplo n.º 4
0
    def start(self, auto_register=True):
        CJGomasAgent.start(self, auto_register)

        self.m_iHealth = 100
        self.m_iProtection = 25
        self.m_iStamina = 100
        self.m_iPower = 100
        self.m_iAmmo = 100

        # Send a welcome message, and wait for the beginning of match
        self.add_behaviour(self.CreateBasicTroopBehaviour())

        t = Template()
        t.set_metadata("performative", "init")
        self.add_behaviour(self.InitResponderBehaviour(), t)
Exemplo n.º 5
0
 def test_add_service(self):
     agent = CJGomasAgent("agent@localhost", "agent", 0)
     agent.start()
     agent.stop()
Exemplo n.º 6
0
    def start(self, auto_register=True):
        class InitBehaviour(OneShotBehaviour):
            async def run(self):
                print("Manager (Expected Agents): " + str(self.agent.MAX_TOTAL_AGENTS))

                for i in range(1, self.agent.MAX_TOTAL_AGENTS + 1):
                    msg = await self.receive(timeout=100000)
                    if msg:
                        sContent = msg.body
                        tokens = sContent.lower().split()

                        sName = None
                        eType = None
                        eTeam = None

                        for token in tokens:
                            if token == "name:":
                                sName = tokens[tokens.index(token) + 1]
                            elif token == "type:":
                                eType = int(tokens[tokens.index(token) + 1])
                            elif token == "team:":
                                eTeam = int(tokens[tokens.index(token) + 1])

                        self.agent.m_AgentList[sName] = CMicroAgent()

                        self.agent.m_AgentList[sName].m_JID = sName
                        self.agent.m_AgentList[sName].m_eType = eType
                        self.agent.m_AgentList[sName].m_eTeam = eTeam

                        print("Manager: [" + sName + "] is Ready!")
                        self.agent.m_iNumberOfAgents += 1

                print("Manager (Accepted Agents): " + str(self.agent.m_iNumberOfAgents))
                for agent in self.agent.m_AgentList.values():
                    msg = Message()
                    msg.set_metadata("performative", "init")
                    msg.to = agent.m_JID
                    msg.body = " MAP: " + self.agent.m_sMapName + " FIGHT!!"
                    await self.send(msg)
                    print("Manager: Sending notification to fight to: " + agent.m_JID)

                await self.agent.InformObjectives(self)
                self.agent.m_lMatchInit = time.time()

        print("JGOMAS v. 0.1.4 (c) GTI-IA 2005 - 2007 (DSIC / UPV)")
        CJGomasAgent.start(self, auto_register=auto_register)

        self.m_GameStatistic = CGameStatistic()

        # Manager notify its services in a different way
        self.cservice = CService(self.service_jid)
        self.cservice.start()



        self.register_service("management")

        self.m_DinObjectList = dict()
        self.m_REServer = CServer(self.m_sMapName)
        self.m_REServer.start()

        self.m_Map = CTerrainMap()
        self.m_Map.LoadMap(self.m_sMapName, self.m_CConfig)

        self.CreateObjectives()  # We need to do this when online

        #// Behaviour to refresh all render engines connected
        self.Launch_RenderEngine_InformBehaviour()

        # Behaviour to listen to data (position, health?, an so on) from troop agents
        self.Launch_DataFromTroop_ListenerBehaviour()

        # Behaviour to handle Sight messages
        self.Launch_Sight_ResponderBehaviour()

        # Behaviour to handle Shot messages
        self.Launch_Shot_ResponderBehaviour()

        # Behaviour to attend the petitions for register services
        self.Launch_ServiceRegister_ResponderBehaviour()

        # Behaviour to handle Pack Management: Creation and Destruction
        self.Launch_PackManagement_ResponderBehaviour()

        # Behaviour to inform all agents that game has finished by time
        self.Launch_GameTimeout_InformBehaviour()

        template = Template()
        template.set_metadata("performative", "init")
        self.add_behaviour(InitBehaviour(), template)