how to check if player not using a shield-mages might

@enPointe77 The question has nothing to do with existing code.

ProfMonkey07–
Possible duplicate of here.

You listed four conditions:

  1. Do I have enough mana for a shield?
    Check hero.earth > 3
  2. Does the opponent have enough mana for a ball?
    Check opponent.fire > 15 where opponent = hero.getEnemyHero()
  3. Do I have a current shield?
    Check truthiness of hero.getActiveShield()
  4. What type is my current shield?
    Check shield.mana where shield = hero.getActiveShield()

Sample solution, in Python, that solves a similar problem to yours. All the same concepts are here.

# Summons shields to block potential enemy ball spells
# Code is untested

opponent = hero.getEnemyHero()

ball_cost = hero.getSpellData("fire-ball").cost
shield_cost = hero.getSpellData("fire-shield").cost

elements = ["fire", "earth", "water"]
affinities = {
  "fire":  {"weak": "water", "strong": "earth"},
  "water": {"weak": "earth", "strong": "fire" },
  "earth": {"weak": "fire",  "strong": "water"},
}

while True:
  # Condition 3, do nothing if I have an active shield
  shield = hero.getActiveShield()
  if shield: continue

  # This is where you would use Condition 4 if you wish
  #   Rather than doing nothing regardless of the shield's type,
  #   you could replace your shield if it is of the incorrect type
  # `shield.mana` is one of `elements`

  for element in elements:
    shield_element = affinities[element].weak
    # Condition 2, if the enemy is able to cast a ball
    #   and Condition 1, if I can afford a shield to counter it
    if opponent[element] > ball_cost and hero[shield_element] > shield_cost:
      hero.cast(shield_element + "-shield")
2 Likes