The code runs okay, but the minefield is not surviving for 30 seconds… any help would be appreciated! As you can see, I’ve tried some things and then commented them out when I discovered they didn’t help.
# The goal is to survive for 30 seconds, and keep the mines intact for at least 30 seconds. def chooseStrategy(): enemies = hero.findEnemies() # If you can summon a griffin-rider, return "griffin-rider" if hero.gold >= hero.costOf("griffin-rider"): return "griffin-rider" # If there is a fangrider on your side of the mines, return "fight-back" fangrider = None fangrider = hero.findNearest(hero.findByType("fangrider", hero.findEnemies())) if fangrider and fangrider.pos.x <= 36: return "fight-back" # Otherwise, return "collect-coins" else: return "collect-coins" def commandAttack(): # Command your griffin riders to attack ogres. riders = None riders = hero.findByType("griffin-rider", hero.findFriends()) enemies = hero.findEnemies() if enemies: dist = 9999 nearest = None for enemy in enemies: # Attack if it is not a fangrider if (not (enemy.type == "fangrider")) and hero.distanceTo(enemy) < dist: nearest = enemy dist = hero.distanceTo(enemy) if nearest and riders: for rider in riders: hero.command(rider, "attack", nearest) def pickUpCoin(): # Collect coins """ # Find the "best" coin based on value and distance from hero. value = 0 bestCoin = None coins = hero.findItems() if coins: for coin in coins: if coin.value / hero.distanceTo(coin) > value: value = coin.value bestCoin = coin if bestCoin: hero.move(bestCoin.pos) """ coin = None coin = hero.findNearest(hero.findItems()) if coin: hero.move(coin.pos) def heroAttack(): # Your hero should attack fang riders that cross the minefield. nearest = hero.findNearest(hero.findByType("fangrider", hero.findEnemies())) while nearest.health > 0: if hero.isReady("chain-lightning"): hero.cast("chain-lightning", nearest) else: hero.attack(nearest) """ def commandPeasants(): peasants = None peasants = hero.findByType("peasant", hero.findFriends()) if not peasants: if hero.gold >= hero.costOf("peasant"): hero.summon("peasant") if peasants: for peasant in peasants: pc = None pc = peasantCoin(peasant.pos.x, peasant.pos.y) if pc: hero.command(peasant, "move", pc.pos) def peasantCoin(x1, y1): coins = hero.findItems() if coins: dist = 9999 bestCoin = None for coin in coins: between = distanceBetween(coin.pos.x, coin.pos.y, x1, y1) if between < dist: dist = between bestCoin = coin if bestCoin: return bestCoin else: return False def distanceBetween(x1, y1, x2, y2): deltaX = abs(x1-x2) deltaY = abs(y1-y2) return((deltaX**2)+(deltaY**2)**0.5) """ while True: commandAttack() # commandPeasants() strategy = chooseStrategy() # Call a function, depending on what the current strategy is. if strategy == "fight-back": heroAttack() elif strategy == "griffin-rider": hero.summon("griffin-rider") elif strategy == "collect-coins": pickUpCoin()