Advertisement
Nenogzar

MOBA_challenger.py

May 14th, 2024
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.07 KB | None | 0 0
  1. def adding_players(new_player, all_players_dict):
  2.     player, position_type, skill = [item if item[0].isalpha() else int(item) for item in new_player.split(" -> ")]
  3.     all_players_dict[player] = all_players_dict.get(player, {'roles': {}})
  4.     all_players_dict[player]['roles'][position_type] = all_players_dict[player]['roles'].get(position_type, skill)
  5.     if position_type in all_players_dict[player]['roles'] and all_players_dict[player]['roles'][position_type] < skill:
  6.         all_players_dict[player]['roles'][position_type] = skill
  7.     return all_players_dict
  8.  
  9.  
  10. def player_vs_player(both_players, all_players_dict):
  11.     first_player, second_player = both_players.split(" vs ")
  12.     if first_player and second_player in all_players_dict:
  13.         for first_player_roles in all_players_dict[first_player]['roles']:
  14.             if first_player_roles in all_players_dict[second_player]['roles']:
  15.                 total_points_first_player = sum(all_players_dict[first_player]['roles'].values())
  16.                 total_points_second_player = sum(all_players_dict[second_player]['roles'].values())
  17.                 if total_points_first_player > total_points_second_player:
  18.                     all_players_dict.pop(second_player)
  19.                     break
  20.                 elif total_points_second_player > total_points_first_player:
  21.                     all_players_dict.pop(first_player)
  22.                     break
  23.     return all_players_dict
  24.  
  25.  
  26. def show_result(dict_to_sort):
  27.     for player, total_points in sorted(dict_to_sort.items(), key=lambda item: (-sum(item[1]['roles'].values()), item[0])):
  28.         print(f"{player}: {sum(total_points['roles'].values())} skill")
  29.         for role, points in sorted(total_points['roles'].items(), key=lambda item: (-item[1], item[0])):
  30.             print(f"- {role} <::> {points}")
  31.  
  32.  
  33. players = {}
  34. command = input()
  35. while command != "Season end":
  36.     if "->" in command:
  37.         players = adding_players(command, players)
  38.     elif "vs" in command:
  39.         players = player_vs_player(command, players)
  40.     command = input()
  41. show_result(players)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement