The Agrippa Defense Python. Please Help

Hi,

I need help with the Agrippa Defense. This is Python. Here is my code.

     loop:
    enemy = self.findNearestEnemy()
    
    if enemy:
        a = self.distanceTo(enemy)
        self.isReady("cleave")
        b = self.isReady("cleave")
    
        # Find the distance to the enemy with distanceTo.
        self.distanceTo(enemy)
    
        # If the distance is less than 5 meters...
        if a < 5: 
            if b:
                self.cleave(enemy)
    
            # ... if "cleave" is ready, cleave!
            if b:
    
                self.attack(enemy)
                # ... else, just attack.

i can’t figure out what I am doing wrong! I’ll appreciate your help. Thanks! :smile:

Notice that you’re setting “b” to be the result of whether cleave is ready. Then, later on, you see whether there is an enemy within 5 units. If there is, you check whether cleave is ready, if so - you cleave. Then, you check if cleave is ready, if so - you attack. You need to go check the second “if b” to be either “if not b” or “else:”

2 Likes

OHHHHHHH! thx a lot. i got it. :smile:

loop:
    enemy = self.findNearestEnemy()
    
    if enemy:
        a = self.distanceTo(enemy)
        if a < 5: 
            self.isReady("cleave")
            self.cleave(enemy)
        else:
                self.attack(enemy)

2 errors:

  1. You check if cleave is ready, but you don’t do anything with the result.
  2. Your self.attack(enemy) is too indented.
loop:
    enemy = self.findNearestEnemy()
    
    if enemy:
        a = self.distanceTo(enemy)
        if a < 5 and self.isReady("cleave"):    #Both must be true
            self.cleave(enemy)
        else:
            self.attack(enemy)                  #Only 4 spaces relative to else
1 Like

Thank you very much!