Exemplo n.º 1
0
class FireMove(Move):
    
    def execute(self, entity, enemy):
        damage = (entity.fire_strength - enemy.fire_strength) / 4
        if(damage <= 0): #if damage is very weak, pick random damage
            damage = randrange(1, 10)
        else:
            damage = randrange(1, damage) #take random from damage
        print "Damage: " + str(damage)
        enemy.health -= damage
    
    def get_desirability(self, entity, enemy):
        self.fuzzy.fuzzify("firestrength", entity.fire_strength - enemy.fire_strength)
        self.last_desirability = self.fuzzy.deFuzzify("desirability", DefuzzifyType.MAX_AV)
        return self.last_desirability
    
    def init_fuzzy(self):
        self.fuzzy = FuzzyModule()
        firestrength = self.fuzzy.createFLV("firestrength")
        fire_weak = firestrength.addLeftShoulderSet("move_weak", -100, 20, 40)
        fire_ok = firestrength.addTriangularSet("move_ok", 20, 40, 75)
        fire_great = firestrength.addRightShoulderSet("move_great", 40, 75, 100)
        
        desirability = self.fuzzy.createFLV("desirability")
        very_desirable = desirability.addRightShoulderSet("very_desirable", 50, 75, 100)
        desirable = desirability.addTriangularSet("desirable", 25, 50, 75)
        undesirable = desirability.addLeftShoulderSet("undesirable", 0, 25, 50)
        
        self.fuzzy.addRule(fire_weak, undesirable)
        self.fuzzy.addRule(fire_ok, desirable)
        self.fuzzy.addRule(fire_great, very_desirable)
        
    def get_name(self):
        return "Fire move"
Exemplo n.º 2
0
 def init_fuzzy(self):
     self.fuzzy = FuzzyModule()
     
     weakenwaterstrength = self.fuzzy.createFLV("waterresistance")
     weaken_water_poor = weakenwaterstrength.addLeftShoulderSet("move_water_poor", 0, 22, 44)
     weaken_water_ok = weakenwaterstrength.addTriangularSet("move_water_ok", 22, 44, 77)
     weaken_water_great = weakenwaterstrength.addRightShoulderSet("move_water_great", 44, 77, 100)
     
     enemyhealth = self.fuzzy.createFLV("enemyhealth")
     health_poor = enemyhealth.addLeftShoulderSet("health_poor", 0, 40, 50)
     health_ok = enemyhealth.addTriangularSet("health_ok", 40, 50, 75)
     health_great = enemyhealth.addRightShoulderSet("health_ok", 50, 75, 100)
     
     desirability = self.fuzzy.createFLV("desirability")
     very_desirable = desirability.addRightShoulderSet("very_desirable", 50, 75, 100)
     desirable = desirability.addTriangularSet("desirable", 25, 50, 75)
     undesirable = desirability.addLeftShoulderSet("undesirable", 0, 25, 50)
     
     self.fuzzy.addRule(FuzzyAnd(weaken_water_poor, health_poor), FuzzyVery(undesirable))
     self.fuzzy.addRule(FuzzyAnd(weaken_water_poor, health_ok), FuzzyFairly(undesirable))
     self.fuzzy.addRule(FuzzyAnd(weaken_water_poor, health_great), FuzzyFairly(undesirable))
     
     
     self.fuzzy.addRule(FuzzyAnd(weaken_water_ok, health_poor), FuzzyFairly(undesirable))
     self.fuzzy.addRule(FuzzyAnd(weaken_water_ok, health_ok), undesirable)
     self.fuzzy.addRule(FuzzyAnd(weaken_water_ok, health_great), desirable)
     
     self.fuzzy.addRule(FuzzyAnd(weaken_water_great, health_poor), desirable)
     self.fuzzy.addRule(FuzzyAnd(weaken_water_great, health_ok), FuzzyFairly(desirable))
     self.fuzzy.addRule(FuzzyAnd(weaken_water_great, health_great), FuzzyVery(desirable))
Exemplo n.º 3
0
 def init_fuzzy(self):
     self.fuzzy = FuzzyModule()
     firestrength = self.fuzzy.createFLV("firestrength")
     fire_weak = firestrength.addLeftShoulderSet("move_weak", -100, 20, 40)
     fire_ok = firestrength.addTriangularSet("move_ok", 20, 40, 75)
     fire_great = firestrength.addRightShoulderSet("move_great", 40, 75, 100)
     
     desirability = self.fuzzy.createFLV("desirability")
     very_desirable = desirability.addRightShoulderSet("very_desirable", 50, 75, 100)
     desirable = desirability.addTriangularSet("desirable", 25, 50, 75)
     undesirable = desirability.addLeftShoulderSet("undesirable", 0, 25, 50)
     
     self.fuzzy.addRule(fire_weak, undesirable)
     self.fuzzy.addRule(fire_ok, desirable)
     self.fuzzy.addRule(fire_great, very_desirable)
Exemplo n.º 4
0
class WaterWeaken(Move):
    
    def execute(self, entity, enemy):
        enemy.set_water_strength(enemy.get_water_strength() - randrange(5, 15))
    
    def get_desirability(self, entity, enemy):
        self.fuzzy.fuzzify("waterresistance", enemy.water_strength)
        self.fuzzy.fuzzify("enemyhealth", enemy.health)
        self.last_desirability = self.fuzzy.deFuzzify("desirability", DefuzzifyType.MAX_AV)
        return self.last_desirability
    
    def init_fuzzy(self):
        self.fuzzy = FuzzyModule()
        
        weakenwaterstrength = self.fuzzy.createFLV("waterresistance")
        weaken_water_poor = weakenwaterstrength.addLeftShoulderSet("move_water_poor", 0, 22, 44)
        weaken_water_ok = weakenwaterstrength.addTriangularSet("move_water_ok", 22, 44, 77)
        weaken_water_great = weakenwaterstrength.addRightShoulderSet("move_water_great", 44, 77, 100)
        
        enemyhealth = self.fuzzy.createFLV("enemyhealth")
        health_poor = enemyhealth.addLeftShoulderSet("health_poor", 0, 40, 50)
        health_ok = enemyhealth.addTriangularSet("health_ok", 40, 50, 75)
        health_great = enemyhealth.addRightShoulderSet("health_ok", 50, 75, 100)
        
        desirability = self.fuzzy.createFLV("desirability")
        very_desirable = desirability.addRightShoulderSet("very_desirable", 50, 75, 100)
        desirable = desirability.addTriangularSet("desirable", 25, 50, 75)
        undesirable = desirability.addLeftShoulderSet("undesirable", 0, 25, 50)
        
        self.fuzzy.addRule(FuzzyAnd(weaken_water_poor, health_poor), FuzzyVery(undesirable))
        self.fuzzy.addRule(FuzzyAnd(weaken_water_poor, health_ok), FuzzyFairly(undesirable))
        self.fuzzy.addRule(FuzzyAnd(weaken_water_poor, health_great), FuzzyFairly(undesirable))
        
        
        self.fuzzy.addRule(FuzzyAnd(weaken_water_ok, health_poor), FuzzyFairly(undesirable))
        self.fuzzy.addRule(FuzzyAnd(weaken_water_ok, health_ok), undesirable)
        self.fuzzy.addRule(FuzzyAnd(weaken_water_ok, health_great), desirable)
        
        self.fuzzy.addRule(FuzzyAnd(weaken_water_great, health_poor), desirable)
        self.fuzzy.addRule(FuzzyAnd(weaken_water_great, health_ok), FuzzyFairly(desirable))
        self.fuzzy.addRule(FuzzyAnd(weaken_water_great, health_great), FuzzyVery(desirable))
        
    def get_name(self):
        return "Water weaken"