Advertisement
Guest User

Untitled

a guest
Feb 2nd, 2015
193
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import sys
  2. from collections import namedtuple
  3.  
  4. BattleState = namedtuple("BattleState", ["us", "them"])
  5. TeamState = namedtuple("TeamState", ["name", "active", "members"])
  6. MemberState = namedtuple("MemberState", ["name", "id", "attack", "defense", "speed", "hp",
  7.                                          "typeid", "poisonedturns", "otherstats"])
  8.  
  9. def parse_battle_state(state):
  10.     return BattleState(*map(parse_team_state, state.split("#")))
  11.  
  12. def parse_team_state(state):
  13.     na, *members = state.split("|")
  14.     name, active = na.split(":")
  15.     return TeamState(name, int(active), list(map(parse_member_state, members)))
  16.  
  17. def parse_member_state(state):
  18.     name, id_, attack, defense, speed, hp, typeid, poisonedturns, *rest = state.split(":")
  19.     return MemberState(name, int(id_), float(attack), float(defense), float(speed),
  20.                        float(hp), int(typeid), int(poisonedturns), rest)
  21.  
  22. command = sys.argv[1].strip()
  23.  
  24. if command.startswith("T"):
  25.     metapod1 = "Metapod1:0:50:100:80:0:1:11"
  26.     metapod2 = "Metapod2:0:50:100:80:0:1:11"
  27.     metapod3 = "Metapod3:0:50:100:80:0:1:11"
  28.     print("HardenedTrio|{}|{}|{}".format(metapod1, metapod2, metapod3))
  29.  
  30. elif command.startswith("C"):
  31.     battle_state = parse_battle_state(command[2:])
  32.  
  33.     for i,codemon in enumerate(battle_state.us.members):
  34.         if codemon.hp > 0:
  35.             print(i)
  36.             break
  37.  
  38. elif command.startswith("A"):
  39.     battle_state = parse_battle_state(command[2:])
  40.     our_team = battle_state.us
  41.  
  42.     current_codemon = our_team.members[our_team.active]
  43.  
  44.     if current_codemon.hp < 50 and int(current_codemon.otherstats[1]) > 0:
  45.         # Heal up if low
  46.         print(1)
  47.  
  48.     elif int(current_codemon.otherstats[2]) > 0:
  49.         # Harden!
  50.         print(2)
  51.  
  52.     else:
  53.         # Punch!
  54.         print(0)
  55.  
  56. elif command.startswith("B"):
  57.     our_team = parse_team_state(command[2:])
  58.     print("1:1:1")
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement