• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python rg.loc_types函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中rg.loc_types函数的典型用法代码示例。如果您正苦于以下问题:Python loc_types函数的具体用法?Python loc_types怎么用?Python loc_types使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了loc_types函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: act

    def act(self, game):

        # wyznaczamy zbiory różnych pól na planszy
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
        zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}
        druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
        wrogowie = set(game.robots) - druzyna
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna
        bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna

        def mindist(bots, loc):
            return min(bots, key=lambda x: rg.dist(x, loc))

        ruch = ['guard']

        if self.location in wejscia:
            if bezpieczne:
                ruch = ['move',  mindist(bezpieczne, rg.CENTER_POINT)]

        if self.location == rg.CENTER_POINT:
            ruch = ['guard']

        if sasiednie_wrogowie:
            if 9*len(sasiednie_wrogowie) < self.hp:
                ruch = ['attack', sasiednie_wrogowie.pop()]

        if sasiednie_wrogowie2:
            ruch = ['attack', sasiednie_wrogowie2.pop()]

        return ruch
开发者ID:astefaniuk,项目名称:linetc,代码行数:33,代码来源:robot10.py


示例2: score_orientation

        def score_orientation(loc):
            self.orientation_score = 0

            #Terrain types
            self._loc_type = rg.loc_types(loc)
            if 'spawn' in self._loc_type:
                self.orientation_score += spawn
                if 'spawn' in rg.loc_types(base_bot):
                    self.orientation_score += spawn_move

            # Distance to center
            self.dist_to_center = round(rg.dist(loc, gravity_center))
            if self.dist_to_center <= inner_circle:
                self.dist_to_center = 0
            self.orientation_score += - self.dist_to_center

            #Distance to friends
            self.dist_to_closest_friend = 0
            for loc2 in friends:
                self._ref_dist = 16
                self.dist_to_closest_friend = 16
                self.dist_to_closest_friend = rg.dist(loc, loc2)
                if self.dist_to_closest_friend < self._ref_dist:
                    self._ref_dist = self.dist_to_closest_friend
            self.orientation_score += round(self.dist_to_closest_friend)
            return self.orientation_score
开发者ID:Lacra17,项目名称:robotgame-bots,代码行数:26,代码来源:chasintheTrane.py


示例3: act

 def act(self, game):
   robots = game['robots']
   locs = rg.locs_around(self.location, filter_out=('invalid', 'obstacle'))
   
   enemies = [loc for loc in locs if loc in robots and robots[loc]['player_id'] != self.player_id]
   if enemies: ## attack weakest
       loc = sorted(enemies, key=lambda x: robots[x]['hp'])[0]
       return ['attack', loc]
   
   ## so no enemy nearby, walk around randomly but prefer non-spawn points
   
   ## filter out my own occupied spots
   locs = [loc for loc in locs if loc not in robots]
   
   ## empty non spawn points?
   non_spawn = [loc for loc in locs if 'spawn' not in rg.loc_types(loc)]
   if non_spawn:
       loc = random.choice(non_spawn)
       return ['move', loc]
       
   spawn = [loc for loc in locs if 'spawn' in rg.loc_types(loc)]
   if spawn:
       loc = random.choice(spawn)
       return ['move', loc]
       
   ## no more options
   return ['guard']
开发者ID:gwillem,项目名称:robotgame,代码行数:27,代码来源:random_aggressive.py


示例4: __init__

	def __init__(self, robot, game):

		self.robot = robot
		self.game = game
		self.current_loc_types = rg.loc_types(robot.location)

		self.unobstructed_locs = []
		self.normal_unobstructed_locs = []
		self.safe_locs = []

		self.immediate_friends = []
		self.immediate_enemies = []
		
		valid_and_wall_locs = rg.locs_around(robot.location, filter_out='invalid')

		self.valid_locs = []
		for vwloc in valid_and_wall_locs:
			if not 'obstacle' in rg.loc_types(vwloc):
 				self.unobstructed_locs.append(vwloc)
 				self.valid_locs.append(vwloc)
 			elif vwloc in self.game.robots:
 				# valid locs INCLUDES robots
 				self.valid_locs.append(vwloc)
 
		self.immediate_enemies = self.enemies_around(self.robot.location, self.robot.player_id)
		self.immediate_friends = self.friends_around(self.robot.location, self.robot.player_id, self.robot.location)

 		for unobloc in self.unobstructed_locs:
 			if not 'spawn' in rg.loc_types(unobloc):
 				self.normal_unobstructed_locs.append(unobloc)

 			if not self.enemies_around(unobloc, robot.player_id):
				self.safe_locs.append(unobloc)
开发者ID:AlexSincennes,项目名称:robotgame-stance-bot,代码行数:33,代码来源:stance-bot.py


示例5: act

 def act(self, game):
     # get a list of all my allies
     allies = [bot for bot in game['robots'].values() if bot.player_id == self.player_id]
     # process movement alone
     movements = {}
     attacks = {}
     
     for bot in allies:
         movements[bot.location] = request_move(bot, game, allies)
     # remove collisions
     for loc, choice in movements.items():
         # check for environment collisions
         if 'obstacle' in rg.loc_types(choice) or 'invalid' in rg.loc_types(choice):
             del movements[loc]
             continue
         occupant = game['robots'].get(choice)
         # check for vacancy
         if occupant != None:
             del movements[loc]
             # check for enemy
             if occupant.player_id != self.player_id:
                 attacks[loc] = occupant.location
     # enact MY decision
     if self.location in movements:
         return ['move', movements[self.location]]
     elif self.location in attacks:
         return ['attack', attacks[self.location]]
     # neither move nor attack. if I will die in 1 turn and there are nearby enemies, suicide
     elif self.hp <= 18 and True in [loc in game['robots'] and game['robots'][loc].player_id != self.player_id for loc in rg.locs_around(self.location)]:
         return ['suicide']
     else:
         return ['guard']
开发者ID:wrongu,项目名称:robotgame,代码行数:32,代码来源:clusterbot2.py


示例6: act

    def act(self, game):

        global runda_numer, wybrane_pola
        if game.turn != runda_numer:
            runda_numer = game.turn
            wybrane_pola = set()

        # jeżeli się ruszamy, zapisujemy docelowe pole
        def ruszaj(loc):
            wybrane_pola.add(loc)
            return ['move', loc]

        # jeżeli stoimy, zapisujemy zajmowane miejsce
        def stoj(act, loc=None):
            wybrane_pola.add(self.location)
            return [act, loc]

        # wyznaczamy zbiory różnych pól na planszy
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
        zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}
        druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
        wrogowie = set(game.robots) - druzyna
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna
        # bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna
        bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - \
                     wejscia - druzyna - wybrane_pola

        def mindist(bots, loc):
            return min(bots, key=lambda x: rg.dist(x, loc))

        def minhp(bots):
            return min(bots, key=lambda x: game.robots[x].hp)

        if wrogowie:
            najblizszy_wrog = mindist(wrogowie,self.location)
        else:
            najblizszy_wrog = rg.CENTER_POINT

        ruch = ['guard']

        if self.location in wejscia:
            if bezpieczne:
                ruch = ['move',  mindist(bezpieczne, rg.CENTER_POINT)]
        elif sasiednie_wrogowie:
            if 9*len(sasiednie_wrogowie) < self.hp:
                ruch = stoj('attack',minhp(sasiednie_wrogowie.pop()))
            elif bezpieczne:
                ruch = ruszaj(mindist(bezpieczne, rg.CENTER_POINT))
            else:
                ruch = stoj('suicide')
        elif sasiednie_wrogowie2 and self.location not in wybrane_pola:
            ruch = ['attack', sasiednie_wrogowie2.pop()]
        elif bezpieczne:
            ruch = ruszaj(mindist(bezpieczne, najblizszy_wrog))


        return ruch
开发者ID:astefaniuk,项目名称:linetc,代码行数:60,代码来源:robot24.py


示例7: escape_spawn_trap_move

    def escape_spawn_trap_move(self, game):
        if 'spawn' in rg.loc_types(self.location):
            locs = [x for x in rg.locs_around(self.location) if
                    self.is_empty_loc(game, x)]
            free_locs = [x for x in locs if 'spawn' not in rg.loc_types(x)]
            safe_locs = [x for x in locs if self.is_safe_from_attacks(game, x)]
            safe_and_free_locs = [x for x in free_locs if x in safe_locs]

            # Try moving away first, even if may get hit.
            if len(safe_and_free_locs) > 0:
                return ['move', random.choice(safe_and_free_locs)]
            elif len(safe_locs) > 0:
                return ['move', random.choice(safe_locs)]
            elif len(free_locs) > 0:
                return ['move', random.choice(free_locs)]
            elif len(locs) > 0:
                return ['move', random.choice(locs)]
            # No where to move.
            else:
                # Todo: for friendlies, can tell them to gtfo out lol.
                # Todo: find a route, instead of just moving back n forth lol

                # Gonna die anyways, explode and cause some damage!
                # Enemies likely to guard. Some may move but hard to tell.
                if self.is_spawn_reset(game):
                    return ['suicide']
                # Else, go to some other behaviour
                return False
开发者ID:rui-lin,项目名称:robot-game,代码行数:28,代码来源:alpha.py


示例8: act

    def act(self, game):
        
        # wszystkie pola
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        # punkty wejścia
        wejscia = {poz for poz in wszystkie if 'spawn' in rg.loc_types(poz)}
        # pola zablokowane
        zablokowane = {poz for poz in wszystkie if 'obstacle' in rg.loc_types(poz)}
        # pola zajęte przez nasze roboty
        przyjaciele = {poz for poz in game.robots if game.robots[poz].player_id == self.player_id}
        # pola zajęte przez wrogów
        wrogowie = set(game.robots) - przyjaciele
        # pola sąsiednie
        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        # pola sąsiednie zajęte przez wrogów
        wrogowie_obok = sasiednie & wrogowie

        # działanie domyślne:
        ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]

        # jeżeli jesteś w punkcie wejścia, opuść go
        if self.location in wejscia:
            ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]

        # jeżeli jesteś w środku, broń się
        if self.location == rg.CENTER_POINT:
            ruch = ['guard']

        # jeżeli obok są przeciwnicy, atakuj
        if wrogowie_obok:
            ruch = ['attack', wrogowie_obok.pop()]

        return ruch
开发者ID:EdwardBetts,项目名称:python101,代码行数:33,代码来源:rgkod05b.py


示例9: act

    def act(self, game):

        # zbiory pól na planszy

        # wszystkie pola
        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}

        # punkty wejścia (spawn)
        wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}

        # pola zablokowane (obstacle)
        zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}

        # pola zajęte przez nasze roboty
        druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}

        # pola zajęte przez wrogów
        wrogowie = set(game.robots) - druzyna

        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna

        bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna

        print wejscia
        # domyślne działanie robota: ruch do środka
        ruch = ['move', rg.toward(self.location, rg.CENTER_POINT)]

        return ruch
开发者ID:astefaniuk,项目名称:linetc,代码行数:30,代码来源:zbiory.py


示例10: act

 def act(self, game):
     self.game = game
     enemy_location = self.closest_adjacent_enemy()
     if 'spawn' in rg.loc_types(self.location):
         destinations = rg.locs_around(self.location, filter_out=('invalid','obstacle','spawn'))
         if destinations:
             # print("Robot {0}: In a spawn. Moving to {1}".format(str(self.location), str(destination)))
             return self.move(destinations[0])
         else:
             return self.guard()
     elif enemy_location:
         # print("Robot {0}:Trying to attack. Location:{1}".format(str(self.location), str(enemy_location)))
         return self.attack(enemy_location)
     else:
         enemies = []
         for loc, robot in game.robots.items():
             if robot.player_id != self.player_id:
                 enemies.append(loc)
         enemies.sort()
         if rg.toward(self.location, enemies[0]) == self.location:
             # print("Robot {0}:Don't want to collide; guarding.".format(self.location))
             return self.guard()
         else:
             destination = rg.toward(self.location, enemies[0])
             # print("Robot {0}: Not in position; moving to {1}.".format(self.location, destination))
             if 'spawn' not in rg.loc_types(destination):
                 return self.move(rg.toward(self.location, enemies[0]))
             else:
                 return self.move(rg.toward(self.location, rg.CENTER_POINT))
开发者ID:joeletizia,项目名称:robots,代码行数:29,代码来源:luke_strat.py


示例11: check_walkable

 def check_walkable(self, loc, game):
     # if True in [(loc in game['robots']), ('obstacle' in rg.loc_types(loc)), ('invalid' in rg.loc_types(loc))]:
     if True in [('obstacle' in rg.loc_types(loc)), ('invalid' in rg.loc_types(loc))]:
         return False
     # if it's a spawning turn
     # if 'spawn' in rg.loc_types(loc) and game['turn'] % 10 == 1:
     #     return False
     return True
开发者ID:hayksaakian,项目名称:robotgamebot,代码行数:8,代码来源:kamikaze.py


示例12: init_obstacles

 def init_obstacles():
     self.obstacles = np.ones((19, 19)) * np.nan
     for i in range(19):
         for j in range(19):
             if 'invalid' in rg.loc_types((i, j)) or 'obstacle' in rg.loc_types((i, j)):
                 self.obstacles[i, j] = np.inf
     for _, bot in game.get('robots').items():
         self.obstacles[tuple(bot["location"])] = enemy_cell if bot["player_id"] != self.player_id else friendly_cell
开发者ID:T-Mac,项目名称:robotgame-bots,代码行数:8,代码来源:Stalinsbeard.py


示例13: check_walkable

def check_walkable(loc, game=None):
    if not set(rg.loc_types(loc)).isdisjoint(set(['invalid', 'obstacle'])):
        return False
    if game and loc in game['robots']:
        return False
    if game and game['turn'] % 10 == 0 and 'spawn' in rg.loc_types(loc):
        return False
    return True
开发者ID:hayksaakian,项目名称:robotgamebot,代码行数:8,代码来源:bolt.py


示例14: act

    def act(self, game):
        if "spawn" in rg.loc_types(self.location):
            s = sanitize(['move', rg.toward(self.location, rg.CENTER_POINT)])
            return s

        adjacent_enemies = []
        for loc, bot in game.get('robots').items():
            if bot.get('player_id') != self.player_id:
                if rg.dist(loc, self.location) <= 1:
                    allies = 0
                    #Find out how many allies are around this enemy
                    for nloc, nbot in game.get('robots').items():
                        if bot.get("player_id") == self.player_id and rg.dist(loc, nloc) <=1:
                            allies = allies + 1
                    adjacent_enemies.append([loc, bot, allies])
            else:
                if "spawn" in rg.loc_types(bot.get("location")): #The friendly wants to get out of spawn, make way for it
                    r = Robot.move(self, game)
                    if r and rg.toward(bot.get("location"), rg.CENTER_POINT) == r[1]:
                            return sanitize(['move', rg.toward(self.location, rg.CENTER_POINT)])
        if adjacent_enemies and self.hp >= CRITICAL_HP:
            if len(adjacent_enemies) * ATTACK_DAMAGE > self.hp: # They can kill me! lets flee!
                return sanitize(self.flee(game))
            adjacent_enemies.sort(key= lambda x: (x[2], x[1].get("hp")))
            return sanitize(['attack', adjacent_enemies[0][0]])
        elif adjacent_enemies and self.hp < CRITICAL_HP:
            return sanitize(self.flee(game))
        else:
            r = Robot.move(self, game)

            if not r:
                return ["guard"]
            
            #Check if allied damaged bots will move to our destination, and if so, let them
            move = True
            for loc, bot in game.get('robots').items():
                if bot.get("player_id") == self.player_id and not bot.location == self.location:
                    if rg.dist(loc, r[1]) <= 1:
                        if Robot.get_destination(bot, game) == r[1]: #our destination matches, let them come
                            if bot.get("hp") < CRITICAL_HP:
                                return ["guard"]
                            else: # Figure out who should be given highest movement priority (based on which one is furthest from middle, or who has lowest hp in tiebreaker)
                                prio = rg.dist(self.location, rg.CENTER_POINT)
                                prio_o = rg.dist(bot.location, rg.CENTER_POINT)

                                if prio == prio_o: #Tie
                                    if self.hp >= bot.hp:
                                        move = True
                                    else:
                                        move = False
                                elif prio > prio_o:
                                    move = True
                                else:
                                    move = False
            if not move:
                return ["guard"]
            else:
                return sanitize(r) or ["guard"]
开发者ID:Lacra17,项目名称:robotgame-bots,代码行数:58,代码来源:Sunguard.py


示例15: act

    def act(self, game):
        # Update the class variables if this is a new turn. 
        if game.turn != self.currentTurn:
            # If this is the very first turn, print out some info.
            if game.turn == 1:
                print "The rally point is: {0}".format(self.rallyPoint);

            self.updateVariables(game);
            self.currentTurn = game.turn;
            print "New Turn! " + str(self.currentTurn) + " Friends: " + str(self.numberOfFriends) + " Foes: " + str(self.numberOfFoes);

        # First order of business, if this bot is on a spawn point, we need to get him out of there. 
        if 'spawn' in rg.loc_types(self.location):
            # Try to move toward the rally point.
            moveToPoint = rg.toward(self.location, self.rallyPoint);
            if 'normal' in rg.loc_types(moveToPoint):
                return ['move', moveToPoint];
            else:
                # Can't move towards the rally point. See where we can move. 
                adjacentLocations = rg.locs_around(self.location);
                for loc in adjacentLocations:
                    if 'normal' in rg.loc_types(loc):
                        return ['move', loc];

                # If we got here, we can't move off the spawn point. Let's try to do some damage if we have a nearby enemy. 
                for loc in adjacentLocations:
                    if loc in game.robots:
                        if game.robots[loc].player_id != self.player_id:
                            return self.attackOrSuicide(loc, game.robots[loc]);

                # If we are here, nothing else we can do, but guard. We must be blocked by our guys. Hopefully they will get out of the way.
                return ['guard'];


        # Now some strategy. 
        if self.numberOfFoes > self.numberOfFriends:
            # We have less bots than the enemy. Let's play it safe until the numbers are back in our favor.
            
            # Head to the rally point if possible. Fight if someone gets in the way, but be passive otherwise. 
            if (self.location == self.rallyPoint):
                return ['guard'];

            moveToPoint = rg.toward(self.location, self.rallyPoint);
            if 'normal' in rg.loc_types(moveToPoint):
                return ['move', moveToPoint];
            else:
                # We can't move. Attack if we can.
                for loc in adjacentLocations:
                    if loc in game.robots:
                        if game.robots[loc].player_id != self.player_id:
                            return self.attackOrSuicide(loc, game.robots[loc]);

            # Guard if we can't move.                     
            return ['guard'];
        
        else:
            # We have the numbers advantage. Start hunting. 
            return ['guard'];
开发者ID:pneisen,项目名称:robot-game-experiments,代码行数:58,代码来源:scrubby04.py


示例16: act

	def act(self, game):
		nearest = self.nearestEnemy(game)
		print rg.loc_types(nearest)
		if rg.dist(self.location, nearest) <= 1:
			return ['attack', nearest]
		elif ('obstacle' not in rg.loc_types(nearest) or 'spawn' not in rg.loc_types(nearest)):
			return ['move', rg.toward(self.location, nearest)]
		else:
			return ['guard']
开发者ID:ChrisAnn,项目名称:robotgame,代码行数:9,代码来源:simple.py


示例17: entireBoard

 def entireBoard(self):
     board = []
     lmin = 0
     lmax = 18
     for x in range(lmin, lmax + 1):
         for y in range(lmin, lmax + 1):
             loc = (x,y)
             if 'normal' in rg.loc_types(loc) or 'spawn' in rg.loc_types(loc):
                 board.append((x,y))
     return board
         
开发者ID:dmhacker,项目名称:rg-bots,代码行数:10,代码来源:Marquis.py


示例18: move

    def move(bot, game):
        x, y = bot.location
        RIGHT, UP, LEFT, DOWN = (1, 0), (0, -1), (-1, 0), (0, 1)
        prio = ()
        result = False

        if rg.locs_around(tuple(bot.location), filter_out=('invalid', 'obstacle', 'normal')): #We are out of order
            return False
        
        if x <= 9 and y > 9: #lower left quadrant; moving right and down priority
            if bot.hp >= CRITICAL_HP:
                prio = (DOWN, RIGHT, UP, LEFT)
            else:
                prio = (LEFT, UP, RIGHT, DOWN)
        elif x > 9 and y >= 9: #lower right; right and up
            if bot.hp >= CRITICAL_HP:
                prio = (RIGHT, UP, LEFT, DOWN)
            else:
                prio = (DOWN, LEFT, UP, RIGHT)
        elif x > 9 and y <= 9: #upper right; up and left
            if bot.hp >= CRITICAL_HP:
                prio = (UP, LEFT, DOWN, RIGHT)
            else:
                prio = (RIGHT, DOWN, LEFT, UP)
        elif x <= 9 and y <= 9: #upper left; left and down
            if bot.hp >= CRITICAL_HP:
                prio = (LEFT, DOWN, RIGHT, UP)
            else:
                prio = (UP, RIGHT, DOWN, LEFT)
        else:
            prio = (UP,)

        for d in prio:
            dest = (x + d[0], y + d[1])
            occupied = False
            for loc, nbot in game.get('robots').items():
                if bot.hp >= CRITICAL_HP and nbot.hp < CRITICAL_HP and nbot.get("location") == dest:
                    continue
            if occupied: #if it is occupied by an ally, check for a less prioritized move, but if not, try moving anyway
                result = ["move", dest]
                continue
            elif "spawn" in rg.loc_types(dest) or "invalid" in rg.loc_types(dest):
                continue
            elif bot.hp < CRITICAL_HP:
                x2 = dest[0] + d[0]
                y2 = dest[1] + d[1] # Also check the tile after, so we go in the second row instead
                if "spawn" in rg.loc_types((x2,y2)):
                    continue
                else:
                    result = ["move", dest]
            else:
                result = ["move", dest]
                break
        return result
开发者ID:Lacra17,项目名称:robotgame-bots,代码行数:54,代码来源:Sunguard.py


示例19: act

    def act(self, game):
        global runda_numer, wybrane_ruchy
        if game.turn != runda_numer:
            runda_numer = game.turn
            wybrane_ruchy = set()

        def ruszaj(loc):
            wybrane_ruchy.add(loc)
            return ['move', loc]

        def stoj(act, loc=None):
            wybrane_ruchy.add(self.location)
            return [act, loc]

        wszystkie = {(x, y) for x in xrange(19) for y in xrange(19)}
        wejscia = {loc for loc in wszystkie if 'spawn' in rg.loc_types(loc)}
        zablokowane = {loc for loc in wszystkie if 'obstacle' in rg.loc_types(loc)}
        druzyna = {loc for loc in game.robots if game.robots[loc].player_id == self.player_id}
        wrogowie = set(game.robots)-druzyna

        sasiednie = set(rg.locs_around(self.location)) - zablokowane
        sasiednie_wrogowie = sasiednie & wrogowie
        sasiednie_wrogowie2 = {loc for loc in sasiednie if (set(rg.locs_around(loc)) & wrogowie)} - druzyna
        bezpieczne = sasiednie - sasiednie_wrogowie - sasiednie_wrogowie2 - wejscia - druzyna - wybrane_ruchy

        def mindist(bots, loc):
            return min(bots, key=lambda x: rg.dist(x, loc))

        if wrogowie:
            najblizszy_wrog = mindist(wrogowie,self.location)
        else:
            najblizszy_wrog = rg.CENTER_POINT

        # akcja domyślna, którą nadpiszemy, jak znajdziemy coś lepszego
        ruch = ['guard']

        if self.location in wejscia:
            if bezpieczne:
                ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
        elif sasiednie_wrogowie:
            if 9*len(sasiednie_wrogowie) >= self.hp:
                if bezpieczne:
                    ruch = ['move', mindist(bezpieczne, rg.CENTER_POINT)]
            else:
                ruch = ['attack', sasiednie_wrogowie.pop()]
        elif sasiednie_wrogowie2 and self.location not in wybrane_ruchy:
            #ruch = ['attack', sasiednie_wrogowie2.pop()]
            if sasiednie_wrogowie:
                ruch = stoj('attack',sasiednie_wrogowie.pop())
        elif bezpieczne:
            #ruch = ['move', mindist(bezpieczne, najblizszy_wrog)]
            ruch = ruszaj(mindist(bezpieczne, najblizszy_wrog))
        return ruch
开发者ID:astefaniuk,项目名称:linetc,代码行数:53,代码来源:robot_ext.py


示例20: can_move

def can_move(loc, game, spawnok=False):
    """
    Returns True if loc is an unoccupied, normal location

    :param loc: Proposed location
    :param game: Current game data
    :param spawnok: Is it OK to move to a spawn zone location?
    """
    # In GitHub version of rgkit, rg.loc_types(loc) returns a set, and website
    # version it returns a list. Cast as set. Website uses Python < 2.7, so no
    # set literals
    if spawnok:
        return set(rg.loc_types(loc)) | set(['spawn']) == set(['normal', 'spawn']) and loc not in game['robots']
    return set(rg.loc_types(loc)) == set(['normal']) and loc not in game['robots']
开发者ID:kaapstorm,项目名称:robotgamebots,代码行数:14,代码来源:abstract_robot.py



注:本文中的rg.loc_types函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python rg.locs_around函数代码示例发布时间:2022-05-26
下一篇:
Python rg.dist函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap