def run_away(player_1, player_2, factor, action_number, inverse): tweet = Tweet() candidates = [x for x in player_1.location.connection_list if not x.destroyed] if len(candidates) == 0: return False new_location = random.choice(candidates) if inverse: there_was_infection, infected_or_was_infected_by = who_infected_who(player_1, new_location.players) move_player(player_1, new_location) tweet.place = player_2.location tweet.place_2 = player_1.location else: there_was_infection, infected_or_was_infected_by = who_infected_who(player_1, new_location.players) move_player(player_2, new_location) tweet.place = player_1.location tweet.place_2 = player_2.location tweet.type = TweetType.somebody_escaped tweet.player = player_1 tweet.player_2 = player_2 tweet.factor = factor tweet.action_number = action_number tweet.inverse = inverse if there_was_infection: tweet.there_was_infection = True tweet.infected_or_was_infected_by = infected_or_was_infected_by if are_friends(player_1, player_2): unfriend(player_1, player_2) tweet.unfriend = True write_tweet(tweet) return True
def kill(player_1, player_2, place, factor, action_number, inverse): killer = player_1 killed = player_2 if inverse: killer = player_2 killed = player_1 killer.kills = killer.kills + 1 best_killer_item = killer.get_best_item() best_killed_item = killed.get_best_item() tweet = Tweet() tweet.type = TweetType.somebody_killed tweet.place = place tweet.player = player_1 tweet.player_2 = player_2 tweet.factor = factor tweet.action_number = action_number tweet.inverse = inverse tweet.item = killer.get_best_item() if best_killed_item is not None and len(killer.item_list) == 2 and ( best_killer_item.power < best_killed_item.power): # Steal item and throw away killer.previous_power = killer.get_power() killed.previous_power = killed.get_power() killer.item_list = [best_killer_item, best_killed_item] killed.item_list.pop(killed.item_list.index(best_killed_item)) old_item = killer.get_worst_item() killer.location.items.append(old_item) old_item.thrown_away_by = killer tweet.old_item = old_item tweet.new_item = best_killed_item elif best_killed_item is not None and len(killer.item_list) < 2: # Steal item killer.previous_power = killer.get_power() killed.previous_power = killed.get_power() if best_killer_item is not None: killer.item_list = [best_killer_item, best_killed_item] else: killer.item_list = [best_killed_item] killed.item_list.pop(killed.item_list.index(best_killed_item)) tweet.new_item = best_killed_item place = killed.location place.players.pop(place.players.index(killed)) killed.is_alive = False write_tweet(tweet) kill_player(killed) killer.previous_power = None killed.previous_power = None if config.general.match_type == MatchType.districts: destroy_tweet = destroy_district_if_needed(killed.district) if destroy_tweet is not None: write_tweet(destroy_tweet) return True
def initialize_tributes(): global player_list if config.general.redistribute_tributes: # Initialize and distribute the tributes per district free_tributes = [x for x in player_list if x.district is None] tributes_per_district = round(len(player_list) / len(place_list)) random.shuffle(place_list) enough_tributes_list = [x for x in place_list if len(x.tributes) >= tributes_per_district] not_enough_tributes_list = [x for x in place_list if len(x.tributes) < tributes_per_district] # Districts with enough tributes for j, enough_tributes_district in enumerate(enough_tributes_list): exported_tributes = [] index = len(enough_tributes_district.tributes) - tributes_per_district while index > 0: excess_tribute = random.choice(enough_tributes_district.tributes) free_tributes.append(excess_tribute) exported_tributes.append(excess_tribute) enough_tributes_district.tributes.remove(excess_tribute) index = index - 1 tweet = Tweet() tweet.type = TweetType.introduce_players tweet.place = enough_tributes_district tweet.player_list = enough_tributes_district.tributes tweet.player_list_2 = exported_tributes introduction_tweet_list.append(tweet) # Districts with not enough tributes index = tributes_per_district while index > 0: for j, not_enough_tributes_district in enumerate(not_enough_tributes_list): if len(not_enough_tributes_district.tributes) < tributes_per_district and len(free_tributes) > 0: chosen_tribute = random.choice(free_tributes) free_tributes.remove(chosen_tribute) chosen_tribute.location = not_enough_tributes_district not_enough_tributes_district.tributes.append(chosen_tribute) index = index - 1 for j, not_enough_tributes_district in enumerate(not_enough_tributes_list): imported_tributes = [x for x in not_enough_tributes_district.tributes if (x.district is None or x.district.name != not_enough_tributes_district.name)] local_tributes = [x for x in not_enough_tributes_district.tributes if x.district is not None and x.district.name == not_enough_tributes_district.name] for j, imported in enumerate(imported_tributes): imported.district = not_enough_tributes_district tweet = Tweet() tweet.type = TweetType.introduce_players tweet.place = not_enough_tributes_district tweet.player_list = local_tributes tweet.player_list_2 = imported_tributes tweet.inverse = True introduction_tweet_list.append(tweet) else: random.shuffle(place_list) district_list = [x for x in place_list if len(x.tributes) > 0] for i, district in enumerate(district_list): tweet = Tweet() tweet.type = TweetType.introduce_players tweet.place = district tweet.player_list = district.tributes introduction_tweet_list.append(tweet) # Friends list for j, place in enumerate(place_list): for k, tribute in enumerate(place.tributes): tribute.district = place tribute.location = place place.players.append(tribute) tribute.friend_list = tribute.friend_list + [x for x in place.tributes if x.get_name() != tribute.get_name()]