Advertisement
Guest User

Untitled

a guest
Jun 18th, 2019
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.17 KB | None | 0 0
  1. #!/usr/bin/env python3
  2. import copy
  3. class Kick:
  4.     def __init__(self):
  5.         self.cooldown_duration=2
  6.         self.cooldown=0
  7.         self.duration=1
  8.         self.damage=10
  9.     def action(self,user,target):
  10.         target.health-=self.damage*user.get_power()
  11.         self.cooldown=self.cooldown_duration
  12.         user.step(self.duration)
  13.         target.step(self.duration)
  14. class Punch:
  15.     def __init__(self):
  16.         self.cooldown_duration=1
  17.         self.cooldown=0
  18.         self.duration=1
  19.         self.damage=3
  20.     def action(self,user,target):
  21.         target.health-=self.damage*user.get_power()
  22.         self.cooldown=self.cooldown_duration
  23.         user.step(self.duration)
  24.         target.step(self.duration)
  25.  
  26. class Curse:
  27.     def __init__(self):
  28.         self.cooldown_duration=1
  29.         self.cooldown=0
  30.         self.duration=1
  31.     class CurseDebuff:
  32.         def __init__(self):
  33.             self.duration=10
  34.             self.damage=2
  35.         def action(self,target,duration):
  36.             self.duration-=duration
  37.             target.health-=self.damage*duration
  38.     def action(self,user,target):
  39.         target.debuffs['curse']=Curse.CurseDebuff()
  40.         self.cooldown=self.cooldown_duration
  41.         user.step(self.duration)
  42.         target.step(self.duration)
  43.  
  44. class User:
  45.     def __init__(self):
  46.         self.skills={'kick':Kick(),'punch':Punch(),'curse':Curse()}
  47.         self.buffs={}
  48.         self.age=0
  49.         self.power=1
  50.     def step(self,duration):
  51.         for name, skill in self.skills.items():
  52.             skill.cooldown=max(0,skill.cooldown-duration)
  53.         for name, buff in self.buffs.items():
  54.             buff.action(self,duration)
  55.         self.buffs={name:buff for name, buff in self.buffs.items() if buff.duration>0}
  56.         self.age+=duration
  57.     def get_power(self):
  58.         power=self.power
  59.         for buff in self.buffs:
  60.             power*=buff.power
  61.         return power
  62.  
  63. class Target:
  64.     def __init__(self):
  65.         self.health=100
  66.         self.debuffs={}
  67.         self.age=0
  68.     def step(self,duration):
  69.         for name, debuff in self.debuffs.items():
  70.             debuff.action(self,duration)
  71.         self.debuffs={name:debuff for name, debuff in self.debuffs.items() if debuff.duration>0}
  72.         self.age+=duration
  73.  
  74. class World:
  75.     def __init__(self):
  76.         self.path=[]
  77.         self.user=User()
  78.         self.target=Target()
  79.     def step(self,action):
  80.         self.user.skills[action].action(self.user,self.target)
  81.         self.path.append(action)
  82.  
  83. optimal_damage=10
  84. search_list=[World()]
  85. heuristic=lambda world: world.target.health/optimal_damage+world.target.age
  86. iterations=0
  87. while search_list[0].target.health>0:
  88.     for name, skill in search_list[0].user.skills.items():
  89.         if skill.cooldown <= 0:
  90.             skill_world=copy.deepcopy(search_list[0])
  91.             skill_world.step(name)
  92.             search_list.append(skill_world)
  93.     search_list = search_list[1:]
  94.     search_list=sorted(search_list,key=heuristic)
  95.     iterations+=1
  96.     #for world in search_list:
  97.         #print(str(heuristic(world))+':'+str(world.path))
  98.     #input()
  99. print('iterations:'+str(iterations))
  100. print(search_list[0].path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement