use of Minions.Minion in project cardgame1 by joey101937.
the class ThrasherMinion method onTurnEnd.
@Override
public void onTurnEnd() {
if (isFrozen || isSilenced) {
// do not attack if frozen
isFrozen = false;
return;
}
Sticker s = new Sticker(SpriteHandler.bloodMedium, this, AI.AI.speed / 2);
Main.wait(AI.AI.speed / 2);
int roll = (int) (Math.random() * (owner.opponent.minions.numOccupants() + 1));
if (roll >= owner.opponent.minions.numOccupants()) {
owner.opponent.takeDamage(attack);
return;
}
Minion target = owner.opponent.minions.getOccupants().get(roll);
this.refresh();
this.attack(target);
Main.wait(AI.AI.speed / 2);
}
use of Minions.Minion in project cardgame1 by joey101937.
the class AI method getValueOfCard.
/**
* gets the value that playing a card represents
* @param c card to evaluate
* @return the value playing the card presents
*/
public static int getValueOfCard(Card c) {
Board.getMainBoard().tick();
Hero enemy;
if (c.getOwner() == Board.topHero) {
enemy = Board.botHero;
} else {
enemy = Board.topHero;
}
int value = 0;
switch(c.cardPurpose) {
case VanillaMinion:
value = c.summon.attack + c.summon.health + c.intrinsicValue;
if (c.cost < c.getOwner().minions.numOccupants()) {
// small minions are penalized for taking a board slot
value -= c.cost - c.getOwner().minions.numOccupants();
}
// if there is no place to summon the minion, it has 0 value.
if (c.getOwner().minions.isFull())
return 0;
if (isVulnerable(c.summon)) {
value = c.summon.attack + c.intrinsicValue;
}
return value;
case BattlecryMinionDamage:
// if there is no place to summon the minion, it has 0 value.
if (c.getOwner().minions.isFull())
return 0;
Minion target = AI.getBestTarget(new SimulatedMinion(c.spellDamage, 0, c.getOwner()));
// System.out.println("best target for " + c + " is " + target);
if (target != null)
value += getWorth(target) - AI.getWorthAfterDamage(target, c.spellDamage);
else
// there are no minions to use it on so this is the value of using the damage on the opponent's hero
value += c.spellDamage / 2;
if (isVulnerable(c.summon)) {
value += c.summon.attack;
} else {
value += c.summon.attack + c.summon.maxHealth;
}
return value + c.intrinsicValue;
case BattlecryMinionHeal:
// if there is no place to summon the minion, it has 0 value.
if (c.getOwner().minions.isFull())
return 0;
for (Minion m : c.getOwner().minions.getStorage()) {
if (m == null)
continue;
if (isVulnerable(m)) {
if (!isVulnerable(new SimulatedMinion(m.attack, m.health + c.spellDamage, c.getOwner()))) {
// if we can save a minion
if (getWorth(m) > value) {
// the value of the card becomes teh value of the minion saved. use the value of the most important minion we can save
value = getWorth(m);
}
}
}
}
if (value == 0)
value = c.spellDamage;
value += getWorth(c.summon);
return value + c.intrinsicValue;
case AOEDamage:
value = 0;
for (Minion m : c.getOwner().opponent.minions.getOccupants()) {
if (m.health <= c.spellDamage)
value += getWorth(m) + 1;
else
value += c.spellDamage;
}
return value + c.intrinsicValue;
case DirectDamage:
value = 0;
Minion optimalTarget = null;
if (c.spellDamage == 0)
return -1;
if (c.getOwner() == Board.topHero) {
for (Minion m : Board.botHero.minions.getStorage()) {
if (m == null)
continue;
int thisValue = getWorth(m) - AI.getWorthAfterDamage(m, c.spellDamage);
if (thisValue > value) {
value = thisValue;
optimalTarget = m;
}
}
} else {
for (Minion m : Board.topHero.minions.getStorage()) {
if (m == null)
continue;
int thisValue = getWorth(m) - AI.getWorthAfterDamage(m, c.spellDamage);
if (thisValue > value) {
value = thisValue;
optimalTarget = m;
}
}
}
// System.out.println("best target for " + c + " is " + optimalTarget);
return value + c.intrinsicValue;
case Debuff:
if (c.getOwner() == Board.botHero) {
if (Board.topHero.minions.numOccupants() == 0)
return -1;
if (AI.canFavorablyTrade(AI.getBiggestThreatOf(Board.topHero))) {
if (!canFavorablyTrade(new SimulatedMinion(getBiggestThreatOf(Board.topHero).attack - c.spellDamage, getBiggestThreatOf(Board.topHero).health, c.getOwner()))) {
// if the enemy's biggest threat can no longer trade up
value += 1;
}
if (!AI.isVulnerable(getBiggestThreatOf(Board.topHero))) {
if (isVulnerable(new SimulatedMinion(getBiggestThreatOf(Board.topHero).attack - c.spellDamage, getBiggestThreatOf(Board.topHero).health, c.getOwner()))) {
// if the enemy's biggest threat is now vulnerable
value += 1;
}
}
}
if (getWorth(getBiggestThreatOf(Board.topHero)) > c.spellDamage) {
value += getBiggestThreatOf(Board.topHero).health;
} else {
value += c.spellDamage;
}
} else {
if (Board.botHero.minions.numOccupants() == 0)
return -1;
if (AI.canFavorablyTrade(AI.getBiggestThreatOf(Board.botHero))) {
if (!canFavorablyTrade(new SimulatedMinion(getBiggestThreatOf(Board.botHero).attack - c.spellDamage, getBiggestThreatOf(Board.botHero).health, c.getOwner()))) {
// if the enemy's biggest threat can no longer trade up
value += 1;
}
if (!AI.isVulnerable(getBiggestThreatOf(Board.botHero))) {
if (isVulnerable(new SimulatedMinion(getBiggestThreatOf(Board.botHero).attack - c.spellDamage, getBiggestThreatOf(Board.botHero).health, c.getOwner()))) {
// if the enemy's biggest threat is now vulnerable
value += 1;
}
}
}
if (getWorth(getBiggestThreatOf(Board.botHero)) > c.spellDamage) {
value += getBiggestThreatOf(Board.botHero).health;
} else {
value += c.spellDamage;
}
}
return value + c.intrinsicValue;
case AOEHeal:
for (Minion m : c.getOwner().minions.getStorage()) {
if (m == null)
continue;
int missingHealth = (m.maxHealth - m.health);
if (missingHealth > c.spellDamage) {
value += c.spellDamage;
} else {
value += missingHealth;
}
}
return value + c.intrinsicValue;
case DirectHeal:
// TODO: Analyze hero hp for potential hero heal
for (Minion m : c.getOwner().minions.getStorage()) {
if (m == null)
continue;
if (isVulnerable(m)) {
if (!isVulnerable(new SimulatedMinion(m.attack, m.health + c.spellDamage, c.getOwner()))) {
// if we can save a minion
if (getWorth(m) > value) {
// the value of the card becomes teh value of the minion saved. use the value of the most important minion we can save
value = getWorth(m);
}
}
}
}
if (value == 0) {
value = c.spellDamage;
}
if (AI.isHeroVulnerable(c.getOwner())) {
int damagePotential = 0;
for (Minion m : enemy.minions.getStorage()) {
if (m == null)
continue;
damagePotential += m.attack;
}
// if this heal would take the hero out of lethal range, its worth alot
if (damagePotential < c.getOwner().health + c.spellDamage)
return 30;
}
return value + c.intrinsicValue;
case Buff:
for (Minion m : c.getOwner().minions.getStorage()) {
if (!canFavorablyTrade(m)) {
if (canFavorablyTrade(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner))) {
value += AI.getTradeValue(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner), AI.getBestTarget(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner)));
}
}
}
if (value == 0)
value = c.spellDamage - 1;
return value;
case BattleCryMinionBuff:
for (Minion m : c.getOwner().minions.getStorage()) {
if (!canFavorablyTrade(m)) {
if (canFavorablyTrade(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner))) {
value += AI.getTradeValue(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner), AI.getBestTarget(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner)));
}
}
}
if (value == 0)
value = c.spellDamage - 1;
value += AI.getWorth(c.summon);
return value + c.intrinsicValue;
case ChargeMinion:
if (c.getOwner().minions.isFull())
return 0;
if (getBestTarget(c.summon) == null)
return getWorth(c.summon);
value += getTradeValue(new SimulatedMinion(c.summon), getBestTarget(new SimulatedMinion(c.summon))) + AI.getWorthAfterCombat(c.summon, getBestTarget(c.summon));
// System.out.println("best target for " + c + " is " + getBestTarget(new SimulatedMinion(c.summon)));
if (value < 1)
return getWorth(c.summon);
return value + c.intrinsicValue;
case BattlecryMinionDraw:
if (c.getOwner().minions.isFull())
return 0;
value = getWorth(c.summon) + c.intrinsicValue;
// number of cards we can draw.
int numDrawable = Hero.maxHandSize - c.getOwner().hand.size();
if (// reduce value if it will cause overdraw
c.spellDamage > numDrawable)
// reduce value if it will cause overdraw
value -= (c.spellDamage - numDrawable) * 2;
else
value += (numDrawable - c.spellDamage);
return value;
case Draw:
value = c.intrinsicValue;
// number of cards we can draw.
int amountDrawable = Hero.maxHandSize - c.getOwner().hand.size() + 1;
if (// reduce value if it will cause overdraw
c.spellDamage > amountDrawable)
// reduce value if it will cause overdraw
value -= (c.spellDamage - amountDrawable) * 2;
else
value += (amountDrawable - c.spellDamage);
return value;
case Special:
value = c.getValue();
return value + c.intrinsicValue;
case Trap:
for (Trap t : c.getOwner().traps.getOccupants()) {
if (t.name.equals(c.name)) {
return 0;
}
}
value = c.getValue();
return value + c.intrinsicValue;
}
System.out.println("error finding value for " + c);
return value + c.intrinsicValue;
}
use of Minions.Minion in project cardgame1 by joey101937.
the class AI method getWorth.
/**
* calculates the worth of a minion for purposes of making plays
* @param m minion to evaluate
* @return how much a minion is worth, higher is better
*/
public static int getWorth(Minion m) {
int sumStats = m.health + m.attack;
sumStats += m.intrinsicValue;
// low attack is slightly worse than high atk
if (m.attack < m.health)
sumStats--;
if (m.health <= 0) {
// worthless if dead
return 0;
}
if (m.owner.minions.isFull()) {
for (Minion min : m.owner.minions.getStorage()) {
if (m == null)
continue;
if (sumStats > min.attack + min.health) {
return sumStats;
}
}
// this is the smallest minion on a full field
for (Card c : m.owner.hand) {
if (c.canAfford() && c.cardType == CardType.Minion && (c.summon.attack + c.summon.health + c.intrinsicValue) > sumStats) {
// the minion is taking a slot that a largert minion should have
return 0;
}
}
}
return sumStats;
}
use of Minions.Minion in project cardgame1 by joey101937.
the class AI method getBestTarget.
/**
* returns the best target for the given minion
* @param attacker
* @return
*/
public static Minion getBestTarget(Minion attacker) {
int bestValue = -99;
Minion bestTarget = null;
if (attacker.owner == Board.topHero) {
for (Minion m : Board.botHero.minions.getStorage()) {
if (m == null)
continue;
if (getTradeValue(attacker, m) > bestValue) {
bestValue = getTradeValue(attacker, m);
bestTarget = m;
}
}
} else {
for (Minion m : Board.topHero.minions.getStorage()) {
if (m == null)
continue;
if (getTradeValue(attacker, m) > bestValue) {
bestValue = getTradeValue(attacker, m);
bestTarget = m;
}
}
}
return bestTarget;
}
use of Minions.Minion in project cardgame1 by joey101937.
the class AI method playCard.
/**
* plays card with minion target
* @param c
* @param target
*/
public static void playCard(Card c) {
Board.getMainBoard().tick();
System.out.println("casting " + c);
if (!c.canAfford()) {
System.out.println("cannot play " + c + "; cannot afford");
return;
}
Hero enemy = null;
if (c.getOwner() == Board.topHero) {
enemy = Board.botHero;
} else {
enemy = Board.topHero;
}
int value = 0;
switch(c.cardPurpose) {
case VanillaMinion:
case ChargeMinion:
case AOEDamage:
case AOEHeal:
case BattlecryMinionDraw:
case Trap:
case Draw:
c.cast(null);
break;
case BattlecryMinionDamage:
Minion bestTarget = AI.getBestTarget(new SimulatedMinion(c.spellDamage, 1, c.getOwner()));
if (bestTarget != null) {
System.out.println("casting " + c + "on " + bestTarget);
c.cast(bestTarget);
} else {
c.castOnHero(enemy);
}
break;
case BattlecryMinionHeal:
value = -999;
Minion bestHealTarget = null;
for (Minion m : c.getOwner().minions.getStorage()) {
if (m == null)
continue;
if (isVulnerable(m)) {
if (!isVulnerable(new SimulatedMinion(m.attack, m.health + c.spellDamage, c.getOwner()))) {
// if we can save a minion
if (getWorth(m) > value) {
// the value of the card becomes teh value of the minion saved. use the value of the most important minion we can save
value = getWorth(m);
bestHealTarget = m;
}
}
}
}
if (bestHealTarget != null)
c.cast(bestHealTarget);
else
c.castOnHero(c.getOwner());
break;
case BattleCryMinionBuff:
value = 0;
Minion BestFit = null;
for (Minion m : c.getOwner().minions.getStorage()) {
if (!AI.canFavorablyTrade(m)) {
if (canFavorablyTrade(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner))) {
if (AI.getTradeValue(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner), AI.getBestTarget(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner))) > value) {
value = AI.getTradeValue(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner), AI.getBestTarget(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner)));
BestFit = m;
}
}
}
if (BestFit != null) {
c.cast(BestFit);
} else {
if (c.getOwner().minions.numOccupants() > 0) {
c.cast(AI.getBiggestThreatOf(c.getOwner()));
}
}
}
break;
case DirectDamage:
if (enemy.health <= c.spellDamage) {
c.castOnHero(enemy);
break;
}
Minion target = AI.getBestTarget(new SimulatedMinion(c.spellDamage, 0, c.getOwner()));
if (target != null) {
System.out.println("casting " + c + "on " + target);
c.cast(target);
break;
} else {
c.castOnHero(enemy);
System.out.println("no minion target for " + c);
break;
}
case Debuff:
// TODO
break;
case DirectHeal:
if (isHeroVulnerable(c.getOwner())) {
c.castOnHero(c.getOwner());
break;
} else {
Minion potential = null;
int valGained = 0;
for (Minion m : c.getOwner().minions.getStorage()) {
if (m == null)
continue;
if (isVulnerable(m)) {
if (!isVulnerable(new SimulatedMinion(m.attack, m.health + c.spellDamage, m.owner))) {
if (getWorth(m) > valGained) {
valGained = getWorth(m);
potential = m;
}
}
}
}
if (valGained != 0) {
c.cast(potential);
break;
}
if (AI.getBiggestThreatOf(c.getOwner()) != null) {
c.cast(getBiggestThreatOf(c.getOwner()));
break;
} else {
c.castOnHero(c.getOwner());
break;
}
}
case Buff:
int best = 0;
Minion buffTarget = null;
for (Minion m : c.getOwner().minions.getStorage()) {
if (m == null)
continue;
if (!canTradeUp(m)) {
if (canTradeUp(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner))) {
if (m.attack + c.spellDamage > best) {
best = m.attack + c.spellDamage;
buffTarget = m;
}
}
}
}
if (buffTarget != null) {
c.cast(buffTarget);
break;
}
for (Minion m : c.getOwner().minions.getStorage()) {
if (m == null)
continue;
if (!canFavorablyTrade(m)) {
if (canFavorablyTrade(new SimulatedMinion(m.attack + c.spellDamage, m.health, m.owner))) {
if (getWorth(m) > best) {
best = getWorth(m);
buffTarget = m;
}
}
}
}
if (buffTarget != null) {
c.cast(buffTarget);
break;
}
if (c.getOwner().minions.numOccupants() > 0) {
c.cast(getBiggestThreatOf(c.getOwner()));
break;
} else {
System.out.println("No target for " + c);
}
break;
case Special:
if (!c.isTargeted) {
c.cast(null);
} else {
c.smartCast();
return;
}
break;
}
}
Aggregations