Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import copy
- class Kick:
- def __init__(self):
- self.cooldown_duration=2
- self.cooldown=0
- self.duration=1
- self.damage=10
- def action(self,user,target):
- target.health-=self.damage*user.get_power()
- self.cooldown=self.cooldown_duration
- user.step(self.duration)
- target.step(self.duration)
- class Punch:
- def __init__(self):
- self.cooldown_duration=1
- self.cooldown=0
- self.duration=1
- self.damage=3
- def action(self,user,target):
- target.health-=self.damage*user.get_power()
- self.cooldown=self.cooldown_duration
- user.step(self.duration)
- target.step(self.duration)
- class Curse:
- def __init__(self):
- self.cooldown_duration=1
- self.cooldown=0
- self.duration=1
- class CurseDebuff:
- def __init__(self):
- self.duration=10
- self.damage=2
- def action(self,target,duration):
- self.duration-=duration
- target.health-=self.damage*duration
- def action(self,user,target):
- target.debuffs['curse']=Curse.CurseDebuff()
- self.cooldown=self.cooldown_duration
- user.step(self.duration)
- target.step(self.duration)
- class User:
- def __init__(self):
- self.skills={'kick':Kick(),'punch':Punch(),'curse':Curse()}
- self.buffs={}
- self.age=0
- self.power=1
- def step(self,duration):
- for name, skill in self.skills.items():
- skill.cooldown=max(0,skill.cooldown-duration)
- for name, buff in self.buffs.items():
- buff.action(self,duration)
- self.buffs={name:buff for name, buff in self.buffs.items() if buff.duration>0}
- self.age+=duration
- def get_power(self):
- power=self.power
- for buff in self.buffs:
- power*=buff.power
- return power
- class Target:
- def __init__(self):
- self.health=100
- self.debuffs={}
- self.age=0
- def step(self,duration):
- for name, debuff in self.debuffs.items():
- debuff.action(self,duration)
- self.debuffs={name:debuff for name, debuff in self.debuffs.items() if debuff.duration>0}
- self.age+=duration
- class World:
- def __init__(self):
- self.path=[]
- self.user=User()
- self.target=Target()
- def step(self,action):
- self.user.skills[action].action(self.user,self.target)
- self.path.append(action)
- optimal_damage=10
- search_list=[World()]
- heuristic=lambda world: world.target.health/optimal_damage+world.target.age
- iterations=0
- while search_list[0].target.health>0:
- for name, skill in search_list[0].user.skills.items():
- if skill.cooldown <= 0:
- skill_world=copy.deepcopy(search_list[0])
- skill_world.step(name)
- search_list.append(skill_world)
- search_list = search_list[1:]
- search_list=sorted(search_list,key=heuristic)
- iterations+=1
- #for world in search_list:
- #print(str(heuristic(world))+':'+str(world.path))
- #input()
- print('iterations:'+str(iterations))
- print(search_list[0].path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement