Hello once again!
I have been running into issues using arrays and loops to prioritize enemies on a couple different levels…mainly Clash of Clones and the Trials. The following is a brief snippet of the method I have been using (this is based on the loops in the “preferential treatment” level. But BELIEVE ME, I have tried this many, many ways.
I just erased my entire code and started from scratch for the third or fourth time, so i will update as I progress…but as it stands, this is a snippet of what i am using, and my hero stands there doing nothing:
while True: enemies = hero.findEnemies() healthThresh = hero.health < hero.maxHealth / 2 if healthThresh: heal(self) enemyIndex = 0 while enemyIndex < len(enemies): enemy = enemies[enemyIndex] if enemy.type == "thrower": # I want to prioritize enemies by type while enemy.health > 0: # i.e. throwers first, then the clone, then everyone else lightning(enemy) # these functions are defined previously and work fine, don't worry about these hero.attack(enemy) enemyIndex += 1
I have basically just been trying to find an efficient method/algorithm for prioritizing enemies, but I keep hitting a wall. As I said, i will update with more code as I write something a little more elegant, but a shove in the right direction would not be unwelcome.