コード例 #1
0
ファイル: movement.py プロジェクト: olrunsrc/fc-public
    def reachable_nav_point(self):
        #print "reachable_nav_point?"

        # setup location tuple
        if not self.agent.Bot.botinfo.has_key("Location"):
            # if we don't know where we are, treat it as (0,0,0) as that will just mean we go to the nav point even if we're close by
            (SX, SY, SZ) = (0, 0, 0)
        else:
            (SX, SY, SZ) = utilityfns.location_string_to_tuple(
                self.agent.Bot.botinfo["Location"])

        print str(SX) + str(SY) + str(SZ)

        # is there already a navpoint we're aiming for?
        DistanceTolerance = 30  # how near we must be to be thought of as at the nav point
        if self.PosInfo.ChosenNavPoint != None:
            #print "  One already chosen.  DistanceTolerance is", DistanceTolerance
            (NX, NY, NZ) = self.PosInfo.ChosenNavPoint
            if utilityfns.find_distance((NX, NY),
                                        (SX, SY)) > DistanceTolerance:
                #print "    Distance Tolerance check passed (i.e. far away enough)"
                return 1
            else:
                self.PosInfo.VisitedNavPoints.append(
                    (NX, NY, NZ))  # set this NP as visited
                self.PosInfo.ChosenNavPoint = None  # the visited check override isn't used here, instead just clear it

        # now look at the list of navpoints the bot can see
        if self.agent.Bot.nav_points == None or len(
                self.agent.Bot.nav_points) == 0:
            print "  no nav points"
            return 0
        else:
            #print "  else -- work through nav points"
            # nav_points is a list of tuples.  Each tuple contains an ID and a dictionary of attributes as defined in the API
            # Search for reachable nav points
            PossibleNPs = self.get_reachable_nav_points(
                self.agent.Bot.nav_points.items(), DistanceTolerance,
                (SX, SY, SZ))

            # now work through this list of NavPoints until we find once that we haven't been to
            # or the one we've been to least often
            if len(PossibleNPs) == 0:
                print "    No PossibleNPs"
                return 0  # nothing found
            else:
                self.PosInfo.ChosenNavPoint = self.get_least_often_visited_navpoint(
                    PossibleNPs)
                print "    Possible NP, returning 1"
                return 1
コード例 #2
0
ファイル: movement.py プロジェクト: olrunsrc/fc-public
    def at_own_base(self):
        if not self.agent.Bot.botinfo.has_key("Location"):
            return 0
        LocTuple = utilityfns.location_string_to_tuple(
            self.agent.Bot.botinfo["Location"])

        if self.PosInfo.OwnBasePos == None:
            return 0
        else:
            (SX, SY, SZ) = LocTuple
            (HX, HY,
             HZ) = utilityfns.location_string_to_tuple(self.PosInfo.OwnBasePos)
            if utilityfns.find_distance(
                (HX, HY), (SX, SY)
            ) < 10:  # this distance may need adjusting in future (we may also wish to consider the Z axis)
                return 1
            else:
                return 0
コード例 #3
0
 def close_to_player(self):
     #print "Checking to see if close to player..."
     # If we are really close to the first player
     closeness = 50
     players = self.agent.Bot.view_players.values()
     
     if len(players) > 0:
         id = players[0]["Id"]
         loc = players[0]["Location"]
         (px, py, pz) = re.split(',', loc)
         (sx, sy, sz) = re.split(',', self.agent.Bot.botinfo["Location"])
         dis = utilityfns.find_distance((float(px),float(py)), (float(sx),float(sy)))
         # print dis
         if dis < closeness:
             return 1
         else:
             return 0
     else:
         return 0
コード例 #4
0
ファイル: movement.py プロジェクト: olrunsrc/fc-public
    def at_enemy_base(self):
        #print "in at_enemy_base sense"
        if not self.agent.Bot.botinfo.has_key("Location"):
            return 0
        LocTuple = utilityfns.location_string_to_tuple(
            self.agent.Bot.botinfo["Location"])

        if self.PosInfo.EnemyBasePos == None:
            return 0
        else:
            (SX, SY, SZ) = LocTuple
            (EX, EY, EZ) = utilityfns.location_string_to_tuple(
                self.PosInfo.EnemyBasePos)
            if utilityfns.find_distance(
                (SX, SY), (EX, EY)
            ) < 100:  # this distance may need adjusting in future (we may also wish to consider the Z axis)
                return 1
            else:
                return 0
コード例 #5
0
ファイル: movement.py プロジェクト: olrunsrc/fc-public
    def to_known_location(self, Location, DistanceTolerance):
        if len(Location) == 0:
            return 1  # even though we failed, we return 1 so that it doesn't tail the list
        # to first point in current list, if we're not already there
        Location0 = Location[0]
        (HX, HY, HZ) = utilityfns.location_string_to_tuple(Location0)
        (SX, SY, SZ) = utilityfns.location_string_to_tuple(
            self.agent.Bot.botinfo["Location"])
        if utilityfns.find_distance((HX, HY), (SX, SY)) > DistanceTolerance:
            print "DistanceTolerance check passed"

            print "About to send RUNTO to",
            print Location0
            print "Current location",
            print self.agent.Bot.botinfo["Location"]

            self.send_runto_or_strafe_to_location(Location0, 0)
            # was
            #if not utilityfns.is_previous_message(self.agent.Bot, ("RUNTO", {"Location" : PathLoc})):
            #    self.agent.Bot.send_message("RUNTO", {"Location" : PathLoc})
            #    print "Running to " + PathLoc
            return 1
        else:
            return 0
コード例 #6
0
 def calculate_velocity(self, v):
     (vx, vy, vz) = re.split(',', v)
     vx = float(vx)
     vy = float(vy)
     return utilityfns.find_distance((0, 0), (vx, vy))
コード例 #7
0
ファイル: movement.py プロジェクト: olrunsrc/fc-public
class Movement(Behaviour):
    def __init__(self, agent):
        Behaviour.__init__(
            self, agent, ("walk_to_nav_point", "to_enemy_flag", "to_own_base",
                          "to_own_flag", "to_enemy_base", "inch",
                          "runto_medical_kit", "runto_weapon"),
            ("at_enemy_base", "at_own_base", "know_enemy_base_pos",
             "know_own_base_pos", "reachable_nav_point",
             "enemy_flag_reachable", "our_flag_reachable", "see_enemy",
             "see_reachable_medical_kit", "see_reachable_weapon",
             "too_close_for_path"))
        self.PosInfo = PositionsInfo()
        # set up useful constants
        self.PathHomeID = "PathHome"
        self.ReachPathHomeID = "ReachPathHome"
        self.PathToEnemyBaseID = "PathThere"
        self.ReachPathToEnemyBaseID = "ReachPathThere"

    # === SENSES ===

    def at_enemy_base(self):
        #print "in at_enemy_base sense"
        if not self.agent.Bot.botinfo.has_key("Location"):
            return 0
        LocTuple = utilityfns.location_string_to_tuple(
            self.agent.Bot.botinfo["Location"])

        if self.PosInfo.EnemyBasePos == None:
            return 0
        else:
            (SX, SY, SZ) = LocTuple
            (EX, EY, EZ) = utilityfns.location_string_to_tuple(
                self.PosInfo.EnemyBasePos)
            if utilityfns.find_distance(
                (SX, SY), (EX, EY)
            ) < 100:  # this distance may need adjusting in future (we may also wish to consider the Z axis)
                return 1
            else:
                return 0

    # returns 1 if we're near enough to our own base
    def at_own_base(self):
        if not self.agent.Bot.botinfo.has_key("Location"):
            return 0
        LocTuple = utilityfns.location_string_to_tuple(
            self.agent.Bot.botinfo["Location"])

        if self.PosInfo.OwnBasePos == None:
            return 0
        else:
            (SX, SY, SZ) = LocTuple
            (HX, HY,
             HZ) = utilityfns.location_string_to_tuple(self.PosInfo.OwnBasePos)
            if utilityfns.find_distance(
                (HX, HY), (SX, SY)
            ) < 10:  # this distance may need adjusting in future (we may also wish to consider the Z axis)
                return 1
            else:
                return 0

    # returns 1 if we have a location for the enemy base
    def know_enemy_base_pos(self):
        #print "in know_enemy_base_pos sense"
        if self.PosInfo.EnemyBasePos == None:
            return 0
        else:
            return 1

    # returns 1 if we have a location for our own base
    def know_own_base_pos(self):
        if self.PosInfo.OwnBasePos == None:
            return 0
        else:
            return 1

    # returns 1 if there's a reachable nav point in the bot's list which we're not already at
    def reachable_nav_point(self):
        #print "reachable_nav_point?"

        # setup location tuple
        if not self.agent.Bot.botinfo.has_key("Location"):
            # if we don't know where we are, treat it as (0,0,0) as that will just mean we go to the nav point even if we're close by
            (SX, SY, SZ) = (0, 0, 0)
        else:
            (SX, SY, SZ) = utilityfns.location_string_to_tuple(
                self.agent.Bot.botinfo["Location"])

        print str(SX) + str(SY) + str(SZ)

        # is there already a navpoint we're aiming for?
        DistanceTolerance = 30  # how near we must be to be thought of as at the nav point
        if self.PosInfo.ChosenNavPoint != None:
            #print "  One already chosen.  DistanceTolerance is", DistanceTolerance
            (NX, NY, NZ) = self.PosInfo.ChosenNavPoint
            if utilityfns.find_distance((NX, NY),
                                        (SX, SY)) > DistanceTolerance:
                #print "    Distance Tolerance check passed (i.e. far away enough)"
                return 1
            else:
                self.PosInfo.VisitedNavPoints.append(
                    (NX, NY, NZ))  # set this NP as visited
                self.PosInfo.ChosenNavPoint = None  # the visited check override isn't used here, instead just clear it

        # now look at the list of navpoints the bot can see
        if self.agent.Bot.nav_points == None or len(
                self.agent.Bot.nav_points) == 0:
            print "  no nav points"
            return 0
        else:
            #print "  else -- work through nav points"
            # nav_points is a list of tuples.  Each tuple contains an ID and a dictionary of attributes as defined in the API
            # Search for reachable nav points
            PossibleNPs = self.get_reachable_nav_points(
                self.agent.Bot.nav_points.items(), DistanceTolerance,
                (SX, SY, SZ))

            # now work through this list of NavPoints until we find once that we haven't been to
            # or the one we've been to least often
            if len(PossibleNPs) == 0:
                print "    No PossibleNPs"
                return 0  # nothing found
            else:
                self.PosInfo.ChosenNavPoint = self.get_least_often_visited_navpoint(
                    PossibleNPs)
                print "    Possible NP, returning 1"
                return 1

    def get_least_often_visited_navpoint(self, PossibleNPs):
        CurrentMin = self.PosInfo.VisitedNavPoints.count(PossibleNPs[0])
        CurrentMinNP = PossibleNPs[0]
        for CurrentNPTuple in PossibleNPs:
            CurrentCount = self.PosInfo.VisitedNavPoints.count(CurrentNPTuple)
            if CurrentCount < CurrentMinNP:
                CurrentMin = CurrentCount
                CurrentMinNP = CurrentNPTuple
        return CurrentMinNP

    # also performs a distance tolerance check, (SX, SY, SZ) is position of player
    def get_reachable_nav_points(self, NPList, DistanceTolerance, (SX, SY,
                                                                   SZ)):
        PossibleNPs = []
        for CurrentNP in NPList:
            #print type(CurrentNP)
            #print " is the type\n"
            #print type(CurrentNP[1])
            #print " is the type of its 2nd element\n"
            (NX, NY, NZ) = utilityfns.location_string_to_tuple(
                (CurrentNP[1])["Location"])
            if CurrentNP[1]["Reachable"] == "True" and utilityfns.find_distance(
                (NX, NY), (SX, SY)) > DistanceTolerance:
                PossibleNPs.append((NX, NY, NZ))
        return PossibleNPs