Example #1
0
    def takeStep(self, myTeam=[], enemyTeam=[], balls=[], obstacles=[]):
        actions = []
        deltaPos = np.array([1, 0, 0])
        avoidMovement = getObstacleAvoidance(obstacles)
        avoidEnemyMovement = getTeamNearestAvoidance(enemyTeam)
        fenceAvoidMovement = getRestrictionField(obstacles[1], 200)
        movement = 1.5*avoidMovement + 2.0 * avoidEnemyMovement + 1.5*fenceAvoidMovement
        deltaRot = getYPRFromVector(movement)
        
        return deltaPos, deltaRot, actions
        

        
Example #2
0
    def takeStep(self, myTeam=[], enemyTeam=[], balls=[], obstacles=[], drawRadius = 20):
        actions = []

        repelDist = 2*myTeam[0].colRadius
        alignDist = 5*myTeam[0].colRadius
        myRadius = myTeam[0].colRadius
        repelParam = 150
        alignParam = 50
        attractParam = 100
        myRadius = myTeam[0].colRadius
        closestEnemy = 800
        repelEnemy = 100
        attractDist = 10*myTeam[0].colRadius

        repelTeamVector = 0
        alignTeamVector = 0
        attractTeamVector = 0
        repelObstacleVector = 0
        repelEnemyVector = 0

        for agent in myTeam:
            if distBetween(agent.position, 0) < repelDist or distBetween(agent.position, 0) > attractDist:   # Repel Team Mate
                repelTeamVector = repelTeamVector - repelParam*agent.position/(1 + pow(distBetween(agent.position, 0) - myRadius - agent.colRadius, 2))
                
            elif distBetween(agent.position, 0) < alignDist: # Align with Team Mate
                 alignTeamVector = alignTeamVector + alignParam*agent.forward/(1 + pow(distBetween(agent.position, 0), 2))

            elif distBetween(agent.position, 0) < attractDist:                                            # Attract toward Team Mate
                attractTeamVector = attractTeamVector + attractParam*agent.position/(1 + pow(distBetween(agent.position, 0), 2))

        for obstacle in obstacles:                           # Repel Obstacle
            if distBetween(obstacle.position, 0) < 1.5*(myRadius + obstacle.radius):
                repelObstacleVector = repelObstacleVector - 10*repelParam*obstacle.position/(1 + pow(distBetween(obstacle.position, 0) - obstacle.radius, 1))

        nearestEnemy = findNearestPredator(enemyTeam)

        if drawRadius < 2*nearestEnemy.drawRadius:
            closestEnemy = 2*closestEnemy
        elif drawRadius < nearestEnemy.drawRadius:
            closestEnemy = 1*closestEnemy
        elif drawRadius > 1.5*nearestEnemy.drawRadius:
            closestEnemy = 0*closestEnemy
        else:
            pass

        repelEnemyVector = repelEnemyVector - closestEnemy*nearestEnemy.position/(1 + pow(distBetween(nearestEnemy.position, 0) -  nearestEnemy.colRadius, 2))

        for enemy in enemyTeam:
            if drawRadius < 2*nearestEnemy.drawRadius:
                repelEnemy = 2*repelEnemy
            elif drawRadius < nearestEnemy.drawRadius:
                repelEnemy = 1*repelEnemy
            elif drawRadius > 1.5*nearestEnemy.drawRadius:
                repelEnemy = 0*repelEnemy
            else:
                pass
            repelEnemyVector = repelEnemyVector - repelEnemy*enemy.position/(1 + pow(distBetween(enemy.position, 0) -  enemy.colRadius, 2))

        movement = repelEnemyVector + repelTeamVector + alignTeamVector + attractTeamVector + repelObstacleVector +5000*getRestrictionField(obstacles[0], 1000)
        deltaPos = np.array([1, 0, 0])
        deltaRot = getYPRFromVector(movement)
        
        return deltaPos, deltaRot, actions