Ejemplo n.º 1
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)
Ejemplo n.º 2
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()
Ejemplo n.º 3
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()
Ejemplo 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)
Ejemplo n.º 5
0
    def __init__(self,
                 name,
                 passwd="secret",
                 manager_jid="cmanager@localhost",
                 x=0,
                 z=0,
                 team=0):

        CJGomasAgent.__init__(self, name, passwd, team)
        self.m_eType = self.PACK_NONE
        self.m_Manager = manager_jid

        self.m_Position = Vector3D()
        self.m_Position.x = (x * 8)
        self.m_Position.y = 0
        self.m_Position.z = (z * 8)

        self.m_eTeam = team
Ejemplo n.º 6
0
    def __init__(self,
                 name="cmanager@localhost",
                 passwd="secret",
                 players=10,
                 fps=0.033,
                 match_time=380,
                 path=None,
                 mapname="map_01",
                 service_jid="cservice@localhost"):

        CJGomasAgent.__init__(self, name, passwd, service_jid=service_jid)
        self.MAX_TOTAL_AGENTS = players
        self.m_iFPS = fps
        self.m_lMatchTime = match_time
        self.m_sMapName = str(mapname)
        self.m_CConfig = CConfig()
        if path is not None:
            self.m_CConfig.setDataPath(path)
        self.m_iNumberOfAgents = 0
        self.m_AgentList = {}
        self.m_lMatchInit = 0
        self.m_domain = name.split('@')[1]
        self.ObjectiveAgent = None
        self.cservice = None
Ejemplo n.º 7
0
 def test_add_service(self):
     agent = CJGomasAgent("agent@localhost", "agent", 0)
     agent.start()
     agent.stop()
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
 def take_down(self):
     self.ObjectiveAgent.stop()
     CJGomasAgent.take_down(self)
Ejemplo n.º 10
0
    def __init__(self,
                 jid,
                 passwd,
                 team=TEAM_NONE,
                 manager_jid="cmanager@localhost",
                 service_jid="cservice@localhost"):

        # Task List Lock
        self.m_TaskListLock = threading.Lock()

        self.m_ServiceType = []

        # Variable used to store the AID of Manager
        self.m_Manager = manager_jid
        self.m_Service = service_jid

        # List of prepared to execut tasks
        self.m_TaskList = {}

        # Variable used to point the current task in execution
        self.m_CurrentTask = None

        # Variable indicating if this agent is carrying the objective pack (flag)
        self.m_bObjectiveCarried = False

        # Array of default values of priorities for each task
        self.m_TaskPriority = {}

        # Array of points used in patrolling task
        self.m_ControlPoints = []

        # Current position in array m_ControlPoints
        self.m_iControlPointsIndex = 0

        # Array of points used in walking (a calculated) path task
        self.m_AStarPath = []

        # Current position in array m_AStarPath
        self.m_iAStarPathIndex = 0

        # List of objects in the agent's Field Of Vision
        self.m_FOVObjects = []

        # Current aimed enemy
        self.m_AimedAgent = None  # CSight

        self.m_eClass = 0
        self.m_iHealth = 0
        self.m_iProtection = 0
        self.m_iStamina = 0
        self.m_iPower = 0
        self.m_iAmmo = 0

        # Variable indicating if agent is fighting at this moment
        self.m_bFighting = False

        # Variable indicating if agent is escaping at this moment
        self.m_bEscaping = False

        # Current position, direction, and so on...
        self.m_Movement = None  # CMobile

        self.m_iSoldiersCount = 0
        self.m_iMedicsCount = 0
        self.m_iEngineersCount = 0
        self.m_iFieldOpsCount = 0
        self.m_iTeamCount = 0

        # Limits of some variables (to trigger some events)
        self.m_Threshold = CThreshold()  # CThreshold

        # Current Map
        self.m_Map = None  # CTerrainMap

        self.m_FSM = None  # FSMBehaviour

        CJGomasAgent.__init__(self, jid, passwd, team=team)