예제 #1
0
 def __init__(self, team, position, rotation, brain, turnRate, colRadius,
              drawRadius):
     self.position = position.astype(float)  #numpy array [x, y ,z]
     self.rotation = rotation.astype(
         float)  #numpy array [yaw, pitch, roll] (in degrees)
     self.colRadius = colRadius  #float size of collision sphere
     self.drawRadius = drawRadius  #float size of sphere to be drawn
     self.team = team  #provide team 'A' or team 'B'
     self.forward = dot(array([1, 0, 0]), rotMatrixFromYPR(
         rotation))  #unit vector in forward direction of agent
     self.right = dot(array([0, 1, 0]), rotMatrixFromYPR(
         rotation))  #unit vector in right direction of agent
     self.up = cross(self.forward,
                     self.right)  #unit vector pointing upwards
     self.maxMove = double(
         1.0)  #max distance the agent can move in each frame
     self.turnRate = turnRate
     self.maxRot = array(
         [turnRate, turnRate,
          turnRate])  #max YPR in degrees the agent can rotate in each frame
     self.brain = brain
     self.uid = id(self)  #unique identifier
     self.isStunned = False
     self.lastStunned = float(-1)  #Last time agent was stunned
     self.stunDuration = float(-1)  #Duration for which I am stunned
     self.stunRange = 15
예제 #2
0
파일: Agent.py 프로젝트: arihantb2/Projects
 def rotateAgent(self, rotation):
     #clamping
     if not self.isStunned:
         rotation = clampRotation(rotation, self.maxRot)
         self.rotation += rotation
         self.forward = normalize(dot(array([1, 0, 0]), rotMatrixFromYPR(self.rotation)))    
         self.right = normalize(dot(array([0, 1, 0]), rotMatrixFromYPR(self.rotation)))      
         self.up = normalize(cross(self.forward, self.right))
예제 #3
0
 def rotateAgent(self, rotation):
     #clamping
     if not self.isStunned:
         rotation = clampRotation(rotation, self.maxRot)
         self.rotation += rotation
         self.forward = normalize(
             dot(array([1, 0, 0]), rotMatrixFromYPR(self.rotation)))
         self.right = normalize(
             dot(array([0, 1, 0]), rotMatrixFromYPR(self.rotation)))
         self.up = normalize(cross(self.forward, self.right))
예제 #4
0
 def getEgoCentricOf(self, otherObject):
     otherPosition = otherObject.position
     rotMat = rotMatrixFromYPR(self.rotation)
     rotMatInverse = inv(rotMat)
     posVector = otherPosition - self.position
     egoCentric = dot(posVector, rotMatInverse)
     return egoCentric
예제 #5
0
파일: Agent.py 프로젝트: arihantb2/Projects
 def getEgoCentricOf(self, otherObject):
     otherPosition = otherObject.position;
     rotMat = rotMatrixFromYPR(self.rotation)
     rotMatInverse = inv(rotMat)
     posVector = otherPosition - self.position
     egoCentric = dot(posVector, rotMatInverse)
     return egoCentric
예제 #6
0
파일: Agent.py 프로젝트: arihantb2/Projects
 def moveAgent(self, world):
     myTeam, enemyTeam, balls, obstacles = self.buildEgoCentricRepresentationOfWorld(world)
     deltaPos, deltaRot, actions = self.brain.takeStep(myTeam, enemyTeam, balls, obstacles)
     #handle movements
     if not self.isStunned:
         #check if agent is within required area
         if distBetween(self.position, array([0, 0, 0])) < self.maxDistance:
             self.rotateAgent(deltaRot)
             self.translateAgent(deltaPos)
         
     #handle actions
     if not self.isStunned:
         for action in actions:
             #handle stun action
             if action.__class__.__name__ == 'Stun':
                 for agent in world.agents:
                     if agent.getUID() == action.agentUID:
                         if distBetween(self.position, agent.position) < self.stunRange:
                             agent.stun(action.duration)
             #handle kick action
             if action.__class__.__name__ == 'Kick':
                 for ball in world.balls:
                     if ball.getUID() == action.ballUID:
                         if distBetween(self.position, ball.position) < 20:
                             globalDirection = dot(action.direction, rotMatrixFromYPR(self.rotation))
                             ball.kick(globalDirection, action.intensity)
     #Unstun Self
     if self.isStunned:
         if not (self.lastStunned == -1 and self.stunDuration == -1):
             if SimTime.time - self.lastStunned > float(self.stunDuration):
                 self.isStunned = False
                 self.lastStunned = -1
                 self.stunDuration = -1
예제 #7
0
파일: Agent.py 프로젝트: arihantb2/Projects
 def __init__(self, team, position, rotation, brain, turnRate, colRadius, drawRadius):
     self.position = position.astype(float)        #numpy array [x, y ,z]
     self.rotation = rotation.astype(float)        #numpy array [yaw, pitch, roll] (in degrees)
     self.colRadius = colRadius      #float size of collision sphere
     self.drawRadius = drawRadius    #float size of sphere to be drawn
     self.team = team                #provide team 'A' or team 'B'
     self.forward = dot(array([1, 0, 0]), rotMatrixFromYPR(rotation))    #unit vector in forward direction of agent
     self.right = dot(array([0, 1, 0]), rotMatrixFromYPR(rotation))      #unit vector in right direction of agent
     self.up = cross(self.forward, self.right)       #unit vector pointing upwards
     self.maxMove = double(1.0)             #max distance the agent can move in each frame
     self.turnRate = turnRate
     self.maxRot = array([turnRate, turnRate, turnRate])           #max YPR in degrees the agent can rotate in each frame
     self.brain = brain
     self.uid = id(self)            #unique identifier
     self.isStunned = False
     self.lastStunned = float(-1)          #Last time agent was stunned
     self.stunDuration = float(-1)         #Duration for which I am stunned
     self.stunRange = 15
예제 #8
0
파일: Agent.py 프로젝트: arihantb2/Projects
    def __init__(self, team, position, rotation, brain, turnRate, maxMove, colRadius, drawRadius, maturity, death, kids):
        
        self.position = position.astype(float)        #numpy array [x, y ,z]
        self.rotation = rotation.astype(float)        #numpy array [yaw, pitch, roll] (in degrees)
        
        self.colRadius = colRadius/float(2)      #float size of collision sphere
        self.drawRadius = drawRadius/float(2)    #float size of sphere to be drawn
        self.maxcolRadius = colRadius
        self.maxdrawRadius = drawRadius
        
        self.team = team                #provide team 'A' or team 'B'
        self.forward = dot(array([1, 0, 0]), rotMatrixFromYPR(rotation))    #unit vector in forward direction of agent
        self.right = dot(array([0, 1, 0]), rotMatrixFromYPR(rotation))      #unit vector in right direction of agent
        self.up = cross(self.forward, self.right)       #unit vector pointing upwards
        
        self.maxMove = float(maxMove)/1.5                          #max distance the agent can move in each frame
        self.turnRate = float(turnRate)/1.5
        self.maxMaxMove = float(maxMove)
        self.maxTurn = float(turnRate)
        self.maxRot = array([turnRate, turnRate, turnRate])           #max YPR in degrees the agent can rotate in each frame
        
        self.brain = brain
        self.uid = id(self)            #unique identifier
        
        self.isStunned = False
        self.lastStunned = float(-1)          #Last time agent was stunned
        self.stunDuration = float(-1)         #Duration for which I am stunned
        self.isDead = False
        self.stunRange = float(colRadius)
        self.killed = 0
        
        self.alive = float(0)
        self.maturity = maturity
        self.death = death
        self.reproduced = float(0)
        self.drawTime = 12

        self.kids = kids
예제 #9
0
    def moveAgent(self, world):
        myTeam, enemyTeam, balls, obstacles = self.buildEgoCentricRepresentationOfWorld(
            world)
        deltaPos, deltaRot, actions = self.brain.takeStep(
            myTeam, enemyTeam, balls, obstacles)
        #handle movements
        if not self.isStunned:
            #check if agent is within required area
            if distBetween(self.position, array([0, 0, 0])) < self.maxDistance:
                self.rotateAgent(deltaRot)
                self.translateAgent(deltaPos)

        #handle actions
        if not self.isStunned:
            for action in actions:
                #handle stun action
                if action.__class__.__name__ == 'Stun':
                    for agent in world.agents:
                        if agent.getUID() == action.agentUID:
                            if distBetween(self.position,
                                           agent.position) < self.stunRange:
                                agent.stun(action.duration)
                #handle kick action
                if action.__class__.__name__ == 'Kick':
                    for ball in world.balls:
                        if ball.getUID() == action.ballUID:
                            if distBetween(self.position, ball.position) < 20:
                                globalDirection = dot(
                                    action.direction,
                                    rotMatrixFromYPR(self.rotation))
                                ball.kick(globalDirection, action.intensity)
        #Unstun Self
        if self.isStunned:
            if not (self.lastStunned == -1 and self.stunDuration == -1):
                if SimTime.time - self.lastStunned > float(self.stunDuration):
                    self.isStunned = False
                    self.lastStunned = -1
                    self.stunDuration = -1
예제 #10
0
 def translateAgent(self, direction):
     #clamp the direction by normalizing
     if not self.isStunned:
         globaldirection = dot(direction, rotMatrixFromYPR(self.rotation))
         globaldirection = normalize(globaldirection) * self.maxMove
         self.position = self.position + globaldirection
예제 #11
0
파일: Agent.py 프로젝트: arihantb2/Projects
 def translateAgent(self, direction):
     #clamp the direction by normalizing
     if not self.isStunned:
         globaldirection = dot(direction, rotMatrixFromYPR(self.rotation))
         globaldirection = normalize(globaldirection) * self.maxMove
         self.position =self.position + globaldirection