예제 #1
0
 private static Creature unDoBuffs(TargetEffects.BuffTarget buff, Creature c)
 {
     c.abilities = c.buff.getOriginalAbilities();
     c.buff      = null;
     return(c);
 }
예제 #2
0
        public static void Attack(GameState state)
        {
            getNewState();
            state       = MasterState;
            ActiveState = MasterState;
            int usCreatureCount    = 0;
            int enemyCreatureCount = 0;
            int enemyTotalPower    = 0;
            int totalTough         = 0;

            foreach (Card c in state.EnemyField)
            {
                if (c is Creature && !c.Tapped)
                {
                    enemyCreatureCount++;
                    if ((c as Creature).abilities.Contains <Creature.CreatureAbilities>(Creature.CreatureAbilities.DoubleStrike))
                    {
                        enemyTotalPower += (c as Creature).Power;
                    }
                    enemyTotalPower += (c as Creature).Power;
                }
            }

            foreach (Card c in state.PlayerField)
            {
                if (c is Creature && !c.Tapped && !(c as Creature).SummonSick)
                {
                    usCreatureCount++;

                    if ((c as Creature).abilities.Contains <Creature.CreatureAbilities>(Creature.CreatureAbilities.DoubleStrike))
                    {
                        totalTough -= (c as Creature).Toughness;
                    }
                    totalTough += (c as Creature).Toughness;
                }
            }

            if ((usCreatureCount) == 0)
            {
                AI.sendDirections("Nothing to attack with");
            }
            else if (enemyCreatureCount == 0)
            {
                int atk = 0;
                foreach (Card c in state.PlayerField)
                {
                    if (c is Creature && !c.Tapped)
                    {
                        Creature cr = c as Creature;
                        if (!cr.abilities.Contains <Creature.CreatureAbilities>(Creature.CreatureAbilities.Defender) && !cr.Tapped && !cr.SummonSick)
                        {
                            atk++;
                            AI.sendDirections(String.Format("Attack with {0}", cr.CName));
                        }
                    }
                }
                if (atk == 0)
                {
                    AI.sendDirections("No legal attackers");
                }
            }
            else if ((enemyTotalPower / enemyCreatureCount) > (totalTough / usCreatureCount))
            {
                AI.sendDirections("Don't Attack");
            }
            else
            {
                Creature eBiggest = null;
                foreach (Card c in state.EnemyField)
                {
                    if (c is Creature)
                    {
                        Creature cr = c as Creature;
                        if (eBiggest == null)
                        {
                            eBiggest = cr;
                        }
                        else
                        {
                            if (cr.Power > eBiggest.Power)
                            {
                                eBiggest = cr;
                            }
                        }
                    }
                }
                Creature blocker = findBlockerDuringAttack(eBiggest, state);
                int      atk     = 0;
                foreach (Card c in state.PlayerField)
                {
                    if (c is Creature && c != blocker && !(c.Tapped) && !(c as Creature).abilities.Contains <Creature.CreatureAbilities>(Creature.CreatureAbilities.Defender))
                    {
                        if (!(c as Creature).SummonSick)
                        {
                            atk++;
                            AI.sendDirections(String.Format("Attack with {0}", c));
                        }
                    }
                }
                if (atk == 0)
                {
                    AI.sendDirections("Don't attack, stay on defense");
                }
            }
        }
예제 #3
0
        public static Card Target(TargetEffects.Damage damage, GameState state)
        {
            GameState             bestState   = null;
            LinkedList <Creature> potTargs    = new LinkedList <Creature>();
            LinkedList <Creature> potTargsAtk = new LinkedList <Creature>();
            LinkedList <Creature> potTargsDef = new LinkedList <Creature>();

            if (damage.target == TargetEffects.Damage.dmgTarget.Player || damage.target == TargetEffects.Damage.dmgTarget.Both)
            {
                GameState newState = new GameState(state, null);
                newState.enemyHealth -= damage.DamageAmount;
                state.StateBranches.AddLast(newState);
                newState.enemyHealth += damage.DamageAmount;
            }

            if (damage.target == TargetEffects.Damage.dmgTarget.Creature || damage.target == TargetEffects.Damage.dmgTarget.Both)
            {
                foreach (Card c in state.EnemyField)
                {
                    if (c is Creature)
                    {
                        Creature creat = c as Creature;
                        potTargs.AddLast(creat);
                    }
                }

                if (state.active == GameState.activePlayer.Us)
                {
                    foreach (Card c in state.Defending)
                    {
                        if (c is Creature)
                        {
                            Creature creat = (Creature)c;
                            potTargsDef.AddLast(creat);
                        }
                    }
                }
                else
                {
                    foreach (Card c in state.Attacking)
                    {
                        if (c is Creature)
                        {
                            Creature creat = (Creature)c;
                            potTargsAtk.AddLast(creat);
                        }
                    }
                }
            }
            foreach (Creature creat in potTargs)
            {
                creat.Health -= damage.DamageAmount;//decrease target health
                if (creat.Health <= 0)
                {
                    creat.Graveyard.Add(creat);
                    creat.Field.Remove(creat);
                }
                GameState newState = new GameState(state, creat);//copy the state with the decreased health
                if (creat.Health <= 0)
                {
                    creat.Graveyard.Remove(creat);
                    creat.Field.Add(creat);
                }
                creat.Health += damage.DamageAmount;//return the target's health... we don't wanna mess the original
                state.StateBranches.AddLast(newState);
            }
            foreach (Creature creat in potTargsDef)
            {
                creat.Health -= damage.DamageAmount;//decrease target health
                if (creat.Health <= 0)
                {
                    creat.Graveyard.Add(creat);
                    state.Defending.Remove(creat);
                }
                GameState newState = new GameState(state, creat);//copy the state with the decreased health
                if (creat.Health <= 0)
                {
                    creat.Graveyard.Remove(creat);
                    state.Defending.Add(creat);
                }
                creat.Health += damage.DamageAmount;//return the target's health... we don't wanna mess the original
                state.StateBranches.AddLast(newState);
            }
            foreach (Creature creat in potTargsAtk)
            {
                creat.Health -= damage.DamageAmount;//decrease target health
                if (creat.Health <= 0)
                {
                    creat.Graveyard.Add(creat);
                    state.Attacking.Remove(creat);
                }
                GameState newState = new GameState(state, creat);//copy the state with the decreased health
                if (creat.Health <= 0)
                {
                    creat.Graveyard.Remove(creat);
                    state.Attacking.Add(creat);
                }
                creat.Health += damage.DamageAmount;//return the target's health... we don't wanna mess the original
                state.StateBranches.AddLast(newState);
            }
            bestState = bestStateFinder(state);
            return(bestState.target);
        }