use of Traps.Trap 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 Traps.Trap in project cardgame1 by joey101937.
the class Board method tick.
public void tick() {
this.visHandler.tick();
InputHandler.tick();
// tick cards
ArrayList<Card> doneC = new ArrayList<>();
while (true) {
try {
for (Card c : topHero.hand) {
if (c != null && !doneC.contains(c)) {
c.tick();
doneC.add(c);
}
}
for (Card c : botHero.hand) {
if (c != null && !doneC.contains(c)) {
c.tick();
doneC.add(c);
}
}
break;
} catch (ConcurrentModificationException cme) {
System.out.println("caught concurrent modication in main tick, cards");
cme.printStackTrace();
}
}
// tick minions
ArrayList<Minion> doneM = new ArrayList<>();
while (true) {
try {
for (Minion m : topHero.minions.getOccupants()) {
if (m != null && !doneC.contains(m)) {
m.tick();
doneM.add(m);
}
}
for (Minion m : botHero.minions.getOccupants()) {
if (m != null && !doneC.contains(m)) {
m.tick();
doneM.add(m);
}
}
break;
} catch (ConcurrentModificationException cme) {
System.out.println("CME caught in main tick, minions");
}
}
// tick traps
ArrayList<Trap> doneT = new ArrayList<>();
while (true) {
try {
for (Trap t : topHero.traps.getOccupants()) {
if (t != null && !doneC.contains(t)) {
t.tick();
doneT.add(t);
}
}
for (Trap t : botHero.traps.getOccupants()) {
if (t != null && !doneC.contains(t)) {
t.tick();
doneT.add(t);
}
}
break;
} catch (ConcurrentModificationException cme) {
System.out.println("CME caught in main tick, traps");
}
}
}
Aggregations