def next_step(self, things,t): 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 = getClosestZombie(self,things) if (canAttack(self,target)): action = 'attack' else: action = 'move' target = closest(target,possible_moves(self,things)) try: name = target.name except: name = target self.status = str(action)#, str(name)#, self.weapon.max_range self.vida = self.life if action: return action, target
def next_step(self, things, t): 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 = getClosestZombie(self, things) if (canAttack(self, target)): action = 'attack' else: action = 'move' target = closest(target, possible_moves(self, things)) try: name = target.name except: name = target self.status = str(action) #, str(name)#, self.weapon.max_range self.vida = self.life if action: return action, target
def next_step(self, things): '''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: by_distance = lambda position: distance(target.position, position) best_position = sorted(positions, key=by_distance)[0] action = 'move', best_position else: # no targets, just wander around if positions: action = 'move', random.choice(positions) return action
def get_next_move(self, player, things): if self.start_t is None: self.start_t = S.tick result = None g = self.map current = g[player.position] winner = None if player.life < 70 and random.random() < 0.3: result = ('heal', player) #elif player.life < 40: # result = ('heal', player) else: #print "evaluating", self, self.position moves = utils.possible_moves(player, things) random.shuffle(moves) for pos in moves: #print pos, g[pos], current if g[pos] < current: winner = pos if winner: result = ('move', winner) else: target = closest( player, [x for x in things.values() if isinstance(x, Zombie)]) if target is not None: if utils.distance(target, player) <= player.weapon.max_range: result = ('attack', target) # if result is None: # if random.random() < 0.25: # moves = utils.possible_moves(self, things) # if moves: # pos = random.choice(moves) # result = ('move', pos) if result is None: result = ('heal', player) if result[0] in ('attack', 'move'): S.last_action = S.tick if S.tick - S.last_action > self.wait: S.next_strategy = self.next_strategy S.last_action = S.tick if S.tick - self.start_t > self.timeout: S.next_strategy = self.next_strategy S.last_action = S.tick return result
def get_next_move(self, player, things): if self.start_t is None: self.start_t = S.tick result = None g = self.map current = g[player.position] winner = None if player.life < 70 and random.random() < 0.3: result = ('heal', player) #elif player.life < 40: # result = ('heal', player) else: #print "evaluating", self, self.position moves = utils.possible_moves(player, things) random.shuffle(moves) for pos in moves: #print pos, g[pos], current if g[pos] < current: winner = pos if winner: result = ('move', winner) else: target = closest(player, [x for x in things.values() if isinstance(x, Zombie)]) if target is not None: if utils.distance(target, player) <= player.weapon.max_range: result = ('attack', target) # if result is None: # if random.random() < 0.25: # moves = utils.possible_moves(self, things) # if moves: # pos = random.choice(moves) # result = ('move', pos) if result is None: result = ('heal', player) if result[0] in ('attack', 'move'): S.last_action = S.tick if S.tick - S.last_action > self.wait: S.next_strategy = self.next_strategy S.last_action = S.tick if S.tick - self.start_t > self.timeout: S.next_strategy = self.next_strategy S.last_action = S.tick return result
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 adjacent = sort_by_distance(target, adjacent_positions(self)) for position in adjacent: 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
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
def emptyPlace(self,things): return possible_moves(self,things)
def next_step(self, things, t): self.status = u"wii wi wiii" moves = possible_moves(self, things) if moves: return "move", random.choice(moves)
def emptyPlace(self, things): return possible_moves(self, things)
def next_step(self, things, t): self.status = u'wii wi wiii' moves = possible_moves(self, things) if moves: return 'move', random.choice(moves)
def get_next_move(self, player, things): if self.start_tick is None: self.start_tick = S.tick if self.map is None: self.map = GoalDistanceMap(self.goal, things) result = None done = False g = self.map current = g[player.position] winner = None if player.life < 70 and random.random() < 0.3: result = ('heal', player) elif player.life < 50: result = ('heal', player) else: #print "evaluating", self, self.position moves = utils.possible_moves(player, things) random.shuffle(moves) for pos in moves: #print pos, g[pos], current if g[pos] < current: winner = pos if winner: result = ('move', winner) else: target = closest(player, [x for x in things.values() if isinstance(x, Zombie)]) if target is not None: if utils.distance(target, player) <= player.weapon.max_range: result = ('attack', target) # target = closest(player, [x for x in things.values() if isinstance(x, Zombie)]) # if target is not None: # if utils.distance(target, player) <= 1.5: # result = ('attack', target) # if result is not None: # moves = utils.possible_moves(player, things) # random.shuffle(moves) # for pos in moves: # #print pos, g[pos], current # if g[pos] < current: # winner = pos # if winner: # result = ('move', winner) # else: # target = closest(player, [x for x in things.values() if isinstance(x, Zombie)]) # if target is not None: # if utils.distance(target, player) <= player.weapon.max_range: # result = ('attack', target) # if result is None: # if random.random() < 0.25: # moves = utils.possible_moves(self, things) # if moves: # pos = random.choice(moves) # result = ('move', pos) if result is None: result = ('heal', player) if result[0] in ('attack', 'move'): S.last_action = S.tick if S.tick - S.last_action > self.wait: done = True S.last_action = S.tick if S.tick - self.start_tick > self.timeout: done = True return result, done, "Rush(%s)" % (self.goal,)
def next_step(self, things, t): # action = random.choice(('move', 'attack', 'heal')) if self.life <= self.MAX_LIFE * .4: #max_heal_threshold(self): self.status = "I'm dieing!" return 'heal', self zombies = [thing for thing in things.values() if isinstance(thing, Zombie)] closest_zombie = closest(self, zombies) players = [thing for thing in things.values() if isinstance(thing, Player)] other_players = set(players) - set([self]) zombie_locations = [position for position, thing in things if isinstance(thing, Zombie)] moves = possible_moves(self, things) if moves and len([1 for move in moves if move in zombie_locations]) == 3: assert len(moves) == 1 self.status = "I'm surrounded!" return 'move', moves[0] #if closest_zombie and len(list(filter(lambda z: distance(self, z) <= 3, zombies))) > 5: # self.status = "I'm surrounded!" # return 'attack', closest_zombie if other_players and closest_zombie and len(list(filter(lambda z: distance(self, z) <= closest_zombie.weapon.max_range, zombies))) > 1: avgx = int(sum(player.position[0] for player in other_players) / len(other_players)) avgy = int(sum(player.position[0] for player in other_players) / len(other_players)) moves = astar(self.position, (avgx, avgy), closed=set(things.keys()) - set([(avgx, avgy)]), goal_met=distance_goal_fn(core.HEALING_RANGE)) if moves: self.status = 'This is a little overwhelming' return 'move', moves[0] players.sort(key=lambda x: x.life) if closest_zombie: moves_left_predicted = distance(self, closest_zombie) - closest_zombie.weapon.max_range #self.weapon.max_range else: moves_left_predicted = 9999 if moves_left_predicted - 1 > 0: if not closest_zombie: players_to_heal = players else: players_to_heal = list(filter(lambda p: (distance(self, p) - core.HEALING_RANGE) < moves_left_predicted, players)) if players_to_heal: player_to_heal = players_to_heal[0] if player_to_heal.life <= max_heal_threshold(self): self.status = 'healing ' + player_to_heal.name if distance(self, player_to_heal) < core.HEALING_RANGE: return 'heal', player_to_heal else: moves = astar(self.position, player_to_heal.position, closed=things.keys(), goal_met=distance_goal_fn(core.HEALING_RANGE)) if moves: return 'move', moves[0] else: self.status = "Healing (can't reach " + player_to_heal.name + ')' return 'heal', self else: if self.life < min_heal_threshold(self): self.status = "Nobody makes me bleed my own blood!" return 'heal', self else: self.status = "If it bleeds, we can kill it..." if closest_zombie and distance(self, closest_zombie) <= self.weapon.max_range: return 'attack', closest_zombie else: if closest_zombie: moves = astar(self.position, closest_zombie.position, closed=things.keys(), goal_met=distance_goal_fn(self.weapon.max_range)) else: moves = [] if moves: return 'move', moves[0] else: self.status = "Healing (can't attack)" return 'heal', self else: if self.life < min_heal_threshold(self): self.status = "Nobody makes me bleed my own blood!" return 'heal', self else: self.status = "WE'RE INVINCIBLE!" if closest_zombie and distance(self, closest_zombie) <= self.weapon.max_range: return 'attack', closest_zombie else: if closest_zombie: moves = astar(self.position, closest_zombie.position, closed=things.keys(), goal_met=distance_goal_fn(self.weapon.max_range)) else: moves = [] if moves: return 'move', moves[0] else: self.status = "Healing (can't attack)" return 'heal', self else: self.status = "DIE!" return 'attack', closest_zombie
def get_next_move(self, player, things): if self.start_tick is None: self.start_tick = S.tick if self.map is None: self.map = GoalDistanceMap(self.goal, things) result = None done = False g = self.map current = g[player.position] winner = None if player.life < 70 and random.random() < 0.3: result = ('heal', player) elif player.life < 50: result = ('heal', player) else: #print "evaluating", self, self.position moves = utils.possible_moves(player, things) random.shuffle(moves) for pos in moves: #print pos, g[pos], current if g[pos] < current: winner = pos if winner: result = ('move', winner) else: target = closest( player, [x for x in things.values() if isinstance(x, Zombie)]) if target is not None: if utils.distance(target, player) <= player.weapon.max_range: result = ('attack', target) # target = closest(player, [x for x in things.values() if isinstance(x, Zombie)]) # if target is not None: # if utils.distance(target, player) <= 1.5: # result = ('attack', target) # if result is not None: # moves = utils.possible_moves(player, things) # random.shuffle(moves) # for pos in moves: # #print pos, g[pos], current # if g[pos] < current: # winner = pos # if winner: # result = ('move', winner) # else: # target = closest(player, [x for x in things.values() if isinstance(x, Zombie)]) # if target is not None: # if utils.distance(target, player) <= player.weapon.max_range: # result = ('attack', target) # if result is None: # if random.random() < 0.25: # moves = utils.possible_moves(self, things) # if moves: # pos = random.choice(moves) # result = ('move', pos) if result is None: result = ('heal', player) if result[0] in ('attack', 'move'): S.last_action = S.tick if S.tick - S.last_action > self.wait: done = True S.last_action = S.tick if S.tick - self.start_tick > self.timeout: done = True return result, done, "Rush(%s)" % (self.goal, )