Please help me with this bug

loop:
    flag = self.findFlag()
    enemy = self.findNearestEnemy()
    item = self.findNearestItem()
    if flag:
        # What happens when I find a flag?
        self.pickUpFlag(flag)
        
    elif enemy:
        # What happens when I find an enemy? 
        self.attack(enemy)
        
    elif item:
        # <item %>
        pos = item.pos
        a = pos.x
        b = pos.y
        self.moveXY(a, b)

What is the problem you are seeing?

i can not defeat all my enemies

the life give can not defeat all enemy

and sametime, he looks for item instead of attacking enemy

Try getting more armor; you should be able to do it with somewhere around 400 health on this level.