Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.72 KB | None | 0 0
  1. """
  2. Read moves from data/moves/moves.asm and report how many moves of each category there are
  3. """
  4.  
  5. with open("data/moves/moves.asm", "r", encoding="utf8") as move_file:
  6.     move_file_lines = move_file.readlines()
  7.  
  8. # {{'ELECTRIC': {'PHYSICAL': 2}, {'SPECIAL': 4}, {'STATUS': 1}}...}
  9. move_analysis_by_type_dict = {}
  10.  
  11. for move_file_line in move_file_lines:
  12.     # Only read move information from moves.asm
  13.     if move_file_line.startswith('\tmove '):
  14.         move_attributes = move_file_line[6:].split(",")
  15.         move_name = move_attributes[0].strip()
  16.         move_type = move_attributes[3].strip()
  17.         move_category = move_attributes[4].strip()
  18.  
  19.         # If dictionary entry for type doesn't exist yet, create one
  20.         dictVal = move_analysis_by_type_dict.get(move_type, -1)
  21.         if dictVal == -1:
  22.             move_analysis_by_type_dict[move_type] = {}
  23.             move_analysis_by_type_dict[move_type]["PHYSICAL"] = 0
  24.             move_analysis_by_type_dict[move_type]["SPECIAL"] = 0
  25.             move_analysis_by_type_dict[move_type]["STATUS"] = 0
  26.             move_analysis_by_type_dict[move_type]["TOTAL"] = 0
  27.  
  28.         # Increment number of moves of move_type that belong to move_category
  29.         move_analysis_by_type_dict[move_type][move_category] += 1
  30.         move_analysis_by_type_dict[move_type]["TOTAL"] += 1
  31.  
  32. # Format and write results to file
  33. with open("move_analysis_results.txt", "w", encoding="utf8") as result_file:
  34.     for key in move_analysis_by_type_dict:
  35.         result_file.write(key + " :\n")
  36.         result_file.write("---------------\n")
  37.         for prop in move_analysis_by_type_dict[key]:
  38.             result_file.write("{:<8} {:<0} {:>3}\n".format(prop, ":", move_analysis_by_type_dict[key][prop]))
  39.         result_file.write("===============\n")
  40.         result_file.write("\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement