Fix for computer AI with creatures which sacrifice at eot.
by mtgrares
Moderators: timmermac, Blacksmith, KrazyTheFox, Agetian, friarsol, CCGHQ Admins
Fix for computer AI with creatures which sacrifice at eot.
by jpb » 13 Jan 2009, 05:12
There are some times when the AI will not attack with creatures it must sacrifice at the end of the turn. This more often than not doesn't make sense. Here is the fix so that the computer will always attack with creatures that must be sacrificed at the end of the turn. First add the following to Card.java
- Code: Select all
private boolean sacrificeAtEOT = false;
//...
public boolean getSacrificeAtEOT() {
return sacrificeAtEOT;
}
public void setSacrificeAtEOT(boolean sacrificeAtEOT) {
this.sacrificeAtEOT = sacrificeAtEOT;
}
- Code: Select all
public Combat getAttackers()
{
Combat combat = new Combat();
if(doAssault() /*|| (blockers.size() == 1 && 1 < attackers.size())*/)
{
for(int i = 0; i < attackers.size(); i++)
combat.addAttacker(attackers.get(i));
}
else
{
Card bigDef;
Card bigAtt;
int nNotAttacking = 0;
//so the biggest creature will usually attack
//I think this works, not sure, may have to change it
//sortNonFlyingFirst has to be done first, because it reverses everything
CardListUtil.sortNonFlyingFirst(attackers);
CardListUtil.sortAttackLowFirst(attackers);
/*
//if under 7 life, always don't attack with smallest creature
if(AllZone.Computer_Life.getLife() < 7 && 2 < attackers.size())
{
nNotAttacking++;
attackers.remove(0);
}
*/
for(int i = 0; i < attackers.size(); i++)
{
//try to make the computer a little unpredictable
//do not attack 9% of the time
//always attack if 3 creatures are not already attacking
if(MyRandom.percentTrue(9) && nNotAttacking < 3 && !blockers.isEmpty())
{
nNotAttacking++;
continue;
}
bigAtt = getBiggestAttack(attackers.get(i));
bigDef = getBiggestDefense(attackers.get(i));
//if attacker can destroy biggest blocker or
//biggest blocker cannot destroy attacker
if(CombatUtil.canDestroyAttacker(bigDef, attackers.get(i)) /*||
(! CombatUtil.canDestroyAttacker(attackers.get(i), bigAtt))*/){
combat.addAttacker(attackers.get(i));
}
else if(attackers.get(i).getSacrificeAtEOT()){
combat.addAttacker(attackers.get(i));
}
else{
nNotAttacking++;
}
}
}//getAttackers()
- Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Groundbreaker") || cardName.equals("Ball Lightning") ||
cardName.equals("Blistering Firecat") || cardName.equals("Spark Elemental"))
{
final SpellAbility spell = new Ability(card, "0")
{
public void resolve()
{
if(AllZone.GameAction.isCardInPlay(card))
AllZone.GameAction.sacrifice(card);
}
};
spell.setStackDescription("Sacrifice " +card);
final Command destroy = new Command()
{
public void execute()
{
if(AllZone.GameAction.isCardInPlay(card))
AllZone.Stack.add(spell);
}
};
Command intoPlay = new Command()
{
public void execute()
{
AllZone.EndOfTurn.addAt(destroy);
}
};
card.setComesIntoPlay(intoPlay);
card.setSacrificeAtEOT(true);
}//*************** END ************ END **************************
- Code: Select all
//*************** START *********** START **************************
if(cardName.equals("Feral Lightning"))
{
SpellAbility spell = new Spell(card)
{
public boolean canPlayAI()
{
return AllZone.Phase.getPhase().equals(Constant.Phase.Main1);
}
public void resolve()
{
final Card[] token = new Card[3];
final Command atEOT = new Command()
{
public void execute()
{
//destroy tokens at end of turn
for(int i = 0; i < token.length; i++)
if(AllZone.GameAction.isCardInPlay(token[i]))
AllZone.GameAction.destroy(token[i]);
}
};
AllZone.EndOfTurn.addAt(atEOT);
for(int i = 0; i < token.length; i++)
token[i] = makeToken();
}//resolve()
Card makeToken()
{
Card c = new Card();
c.setOwner(card.getController());
c.setController(card.getController());
c.setManaCost("R");
c.setToken(true);
c.addType("Creature");
c.addType("Elemental");
c.setAttack(3);
c.setDefense(1);
c.addKeyword("Haste");
c.setSacrificeAtEOT(true);
PlayerZone play = AllZone.getZone(Constant.Zone.Play, card.getController());
play.add(c);
return c;
}//makeToken()
};//SpellAbility
card.clearSpellAbility();
card.addSpellAbility(spell);
}//*************** END ************ END **************************
- jpb
- Posts: 132
- Joined: 05 Sep 2008, 13:12
- Has thanked: 0 time
- Been thanked: 0 time
1 post
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 17 guests