Ejemplo n.º 1
0
	def next_step(self, things,t):
		try:
			if self.lider == None:
				self.lider = getPerrito(things)
		except:
			pass
		if self.life > self.vida :
			if self.next_move == 'move':
				action = self.next_move
				target = tuple(random.choice(emptyPlace(self,things)))
				self.next_move = 'heal'
			elif self.next_move == 'heal':
				action = self.next_move
				target = self
				self.vida = self.life
				self.next_move = 'move'
			else:
				self.next_move = 'move'
		else:
			target = sort_by_distance(self.lider.position,adyacent_positions(self))[0]
			if (things.get(target) is None):
				action = 'move'
				self.lidermove = target
				# self.status = 'Perrito'
			else:
				# self.status = 'Perrito'
				if not isinstance(things.get(target), Player):
					action = 'attack'
					target = things.get(target)
		self.vida = self.life
		if action:
			return action, target
Ejemplo n.º 2
0
    def build(self):
        # print "goal", self.goal
        # print "size", self.size
        if isinstance(self.goal, list):
            for g in self.goal:
                self.map[g[0]][g[1]] = 0
        else:
            self.map[self.goal[0]][self.goal[1]] = 0
        count = 0
        while True:
            changed = False
            for y in range(self.size[1]):
                for x in range(self.size[0]):
                    thing = self.things.get((x, y), None)

                    if thing is not None:
                        if isinstance(thing, Wall) or isinstance(thing, Box):
                            self.map[x][y] = float("+inf")
                            continue
                    v = self.map[x][y]

                    if v is None:
                        for p in utils.adyacent_positions((x, y)):
                            cv = self[p]

                            if cv == count:
                                self.map[x][y] = cv + 1
                                changed = True

            if not changed:
                break

            count += 1
Ejemplo n.º 3
0
    def next_step(self, things, t):
        zombies = [thing for thing in things.values()
                   if isinstance(thing, Zombie)]

        if zombies:
            target = closest(self, zombies)
            if distance(self, target) > self.weapon.max_range:
                best_move = closest(target, adyacent_positions(self))
                obstacle = things.get(best_move)
                if obstacle:
                    if isinstance(obstacle, Player):
                        # zombie not in range. Player blocking path. Heal it.
                        return 'heal', obstacle
                    else:
                        # zombie not in range. Obstacle in front. Shoot it.
                        self.status = u'shooting obstacle to chase target'
                        return 'attack', obstacle
                else:
                    # zombie not in range. Not obstacle. Move.
                    self.status = u'chasing target'
                    return 'move', best_move
            else:
                # zombie in range. Shoot it.
                self.status = u'shooting target'
                return 'attack', target
        else:
            # no zombies. Heal.
            self.status = u'no targets, healing'
            return 'heal', self
Ejemplo n.º 4
0
    def alive_players_together(self):
        '''Are the alive players together (close to each other)?'''
        alive_players = self.get_alive_players()
        players_by_pos = dict((player.position, player)
                              for player in alive_players)
        together = set()
        pending = [alive_players[0], ]

        while pending:
            player = pending.pop()
            together.add(player)

            neighbors = [players_by_pos[position]
                         for position in adyacent_positions(player)
                         if position in players_by_pos]

            for neighbor in neighbors:
                if neighbor not in together:
                    pending.append(neighbor)

        return len(together) == len(alive_players)
Ejemplo n.º 5
0
    def next_step(self, things, t):
        '''Zombies attack if in range, else move in direction of players.'''
        action = None

        # possible targets for movement and attack
        humans = [thing for thing in things.values()
                  if isinstance(thing, Player)]
        positions = possible_moves(self.position, things)

        if humans:
            # targets available
            target = closest(self, humans)

            if distance(self.position, target.position) < self.weapon.max_range:
                # target in range, attack
                action = 'attack', target
            else:
                # target not in range, _try_ to move
                if positions:
                    # move
                    best_position = closest(target, positions)
                    action = 'move', best_position
                else:
                    # if blocked by obstacles, try to break them
                    adyacents = sort_by_distance(target,
                                                 adyacent_positions(self))
                    for position in adyacents:
                        thing = things.get(position)
                        if isinstance(thing, (Box, Wall)):
                            return 'attack', thing
        else:
            # no targets, just wander around
            if positions:
                action = 'move', random.choice(positions)

        return action
Ejemplo n.º 6
0
 def adyacent(one, two):
     ps = utils.adyacent_positions(one)
     if two.position in ps:
         return True
     return False