private void UsEndCleanup()
 {
     tbxAction.Text = "";
     tbxAction.AppendText("OUR END STEP");
     tbxAction.AppendText("\n");
     tbxAction.AppendText("**************\n");
     foreach (Card c in lbxUsField.Items)
     {
         if (c is Creature)
         {
             ((Creature)c).EndOfTurn();
         }
         else if (c is ArtifactEnchant)
         {
             ((ArtifactEnchant)c).EndOfTurn();
         }
     }
     while (lbxUsHand.Items.Count > 7)
     {
         Card Targ = AI.Target(new TargetEffects.Discard(), AI.getCurrentGameState());
         if (Targ != null)
         {
             Targ.Hand.Remove(Targ);
             Targ.Graveyard.Add(Targ);
             AI.sendDirections(String.Format("Discard {0}", Targ.CName));
         }
     }
 }
        private void btnMore_Click(object sender, EventArgs e)
        {
            switch (currentPhase)
            {
            case GameState.phase.StartGame:
                AI.Mulligan(this.getState());
                break;

            case GameState.phase.UsFirstMain:
                AI.MainPhase1(this.getState());
                break;

            case GameState.phase.UsSecondMain:
                AI.MainPhase2(this.getState());
                break;

            /*case GameState.phase.EnemySecondMain:
             *  AI.EnemyMain2(this.getState());
             *  break;*/
            case GameState.phase.UsDeclareAttackers:
                AI.Attack(this.getState());
                break;

            case GameState.phase.EnemyDeclareDefenders:
                AI.Defend(this.getState());
                break;

            default:
                AI.sendDirections("Move to next phase");
                break;
            }
        }
Ejemplo n.º 3
0
        public static void Mulligan(GameState state)
        {
            int handSize      = state.PlayerHand.Count;
            int landCount     = 0;
            int creatureCount = 0;
            int spellCount    = 0;

            foreach (Card c in state.PlayerHand)
            {
                if (c is Land)
                {
                    ++landCount;
                }
            }
            foreach (Card c in state.PlayerHand)
            {
                if (!(c is Land))
                {
                    if (c.ConvManaCost <= landCount)
                    {
                        ++spellCount;
                        if (c is Creature)
                        {
                            ++creatureCount;
                        }
                    }
                }
            }
            if (handSize > 5)
            {
                if (spellCount >= 2 && landCount >= 2 & creatureCount > 0)
                {
                    AI.sendDirections("Keep Hand");
                }
                else
                {
                    AI.sendDirections(string.Format("Mulligan to {0}", handSize - 1));
                }
            }
            else if (handSize > 3)
            {
                if (creatureCount > 0)
                {
                    AI.sendDirections("Keep Hand");
                }
                else
                {
                    if (handSize > 4)
                    {
                        AI.sendDirections(string.Format("Mulligan to {0}", handSize - 1));
                    }
                    else
                    {
                        AI.sendDirections("Concede Game. Bad hands");
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static void Defend(GameState state)
        {
            getNewState();
            ActiveState = MasterState;
            state       = MasterState;
            LinkedList <Creature> e_blocked  = new LinkedList <Creature>();
            LinkedList <Creature> usblocking = new LinkedList <Creature>();

            state.generateMeta();

            foreach (Creature c in state.Attacking)
            {
                if (c.abilities.Contains <Creature.CreatureAbilities>(Creature.CreatureAbilities.Flying))
                {
                    e_blocked.AddLast(c);
                    usblocking.AddLast(blockDefendFlying(c, usblocking, state));
                }
            }
            foreach (Creature c in state.Attacking)
            {
                if (!c.abilities.Contains <Creature.CreatureAbilities>(Creature.CreatureAbilities.Flying) && !e_blocked.Contains(c))
                {
                    e_blocked.AddLast(c);
                    usblocking.AddLast(blockDefendNonFly(c, usblocking, state));
                }
            }
            LinkedListNode <Creature> enemy = e_blocked.First;
            LinkedListNode <Creature> Us    = usblocking.First;

            for (int i = 0; i < e_blocked.Count; ++i)
            {
                if (Us.Value == null)
                {
                    AI.sendDirections(String.Format("{0} goes unblocked", enemy.Value.CName));
                }
                else
                {
                    AI.sendDirections(String.Format("{0} blocks {1}", Us.Value.CName, enemy.Value.CName));
                }
                enemy = enemy.Next;
                Us    = Us.Next;
            }
        }
Ejemplo n.º 5
0
        public static void Attack(GameState state)
        {
            getNewState();
            state       = MasterState;
            ActiveState = MasterState;
            state.generateMeta();
            if ((state.meta.enemyTotalPow / state.meta.enemyCreatureCount) > (state.meta.totalTough / state.meta.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);

                foreach (Card c in state.PlayerField)
                {
                    if (c is Creature && c != blocker && !(c.Tapped))
                    {
                        AI.sendDirections(String.Format("Attack with {0}", c));
                    }
                }
            }
        }
Ejemplo n.º 6
0
        private static void ManaPayment(Card c, GameState state)
        {
            tbxDirections = tbxReal;
            int[] manaPool  = manaAvailable(state);
            int   forests   = 0;
            int   plains    = 0;
            int   mountains = 0;
            int   Selesnya  = 0;
            int   Treetop   = 0;
            int   sejiri    = 0;

            foreach (Card ca in state.PlayerField)
            {
                if (!ca.Tapped)
                {
                    if (ca is KnightCards.Forest)
                    {
                        forests++;
                    }
                    else if (ca is KnightCards.Plains)
                    {
                        plains++;
                    }
                    else if (ca is DragonCards.Mountain)
                    {
                        mountains++;
                    }
                    else if (ca is KnightCards.Selesnya_Sanctuary)
                    {
                        Selesnya++;
                    }
                    else if (ca is KnightCards.Treetop_Village)
                    {
                        Treetop++;
                    }
                    else if (ca is KnightCards.Sejiri_Steppe)
                    {
                        sejiri++;
                    }
                }
            }
            if ((c.ManaByColor[(int)Card.manaColor.White] > 0 || c.ManaByColor[(int)Card.manaColor.Green] > 0) && Selesnya > 0 && c.ConvManaCost > 1)
            {
                AI.sendDirections("Tap Selesnya Sanctuary for W and G");
                int provide = 2;
                if (c.ManaByColor[(int)Card.manaColor.Green] > 0 && provide > 0)
                {
                    --provide;
                    --c.ManaByColor[(int)Card.manaColor.Green];
                }
                if (c.ManaByColor[(int)Card.manaColor.White] > 0 && provide > 0)
                {
                    --provide;
                    --c.ManaByColor[(int)Card.manaColor.White];
                }
                if (provide > 0)
                {
                    --provide;
                    --c.ManaByColor[(int)Card.manaColor.Colorless];
                }
            }
            while (c.ManaByColor[(int)Card.manaColor.Green] > 0)
            {
                if (Treetop > 0)
                {
                    AI.sendDirections("Tap treetop village for G");
                    Treetop--;
                    c.ManaByColor[(int)Card.manaColor.Green]--;
                }
                else if (forests > 0)
                {
                    AI.sendDirections("Tap Forest for F");
                    forests--;
                    c.ManaByColor[(int)Card.manaColor.Green]--;
                }
            }
            while (c.ManaByColor[(int)Card.manaColor.White] > 0)
            {
                if (sejiri > 0)
                {
                    AI.sendDirections("Tap Sejiri Steppe for W");
                    sejiri--;
                    c.ManaByColor[(int)Card.manaColor.White]--;
                }
                else if (plains > 0)
                {
                    AI.sendDirections("Tap Plains for W");
                    plains--;
                    c.ManaByColor[(int)Card.manaColor.White]--;
                }
            }
            while (c.ManaByColor[(int)Card.manaColor.Red] > 0)
            {
                AI.sendDirections("Tap Mountain for Red");
                mountains--;
                c.ManaByColor[(int)Card.manaColor.Red]--;
            }
            while (c.ManaByColor[(int)Card.manaColor.Colorless] > 0)
            {
                if (c.GetType().FullName.Contains("Knight"))
                {
                    if ((plains + sejiri) > ((forests + Treetop) * 2))
                    {
                        if (sejiri > 0)
                        {
                            AI.sendDirections("Tap Sejiri Steppe for W");
                            sejiri--;
                            c.ManaByColor[(int)Card.manaColor.Colorless]--;
                        }
                        else
                        {
                            AI.sendDirections("Tap Plains for W");
                            plains--;
                            c.ManaByColor[(int)Card.manaColor.Colorless]--;
                        }
                    }
                    else
                    {
                        if (Treetop > 0)
                        {
                            AI.sendDirections("Tap Treetop Village for G");
                            Treetop--;
                            c.ManaByColor[(int)Card.manaColor.Colorless]--;
                        }
                        else
                        {
                            AI.sendDirections("Tap Forest for G");
                            forests--;
                            c.ManaByColor[(int)Card.manaColor.Colorless]--;
                        }
                    }
                }
                else if (c.GetType().FullName.Contains("Dragon"))
                {
                    AI.sendDirections("Tap Mountain for Red");
                    mountains--;
                    c.ManaByColor[(int)Card.manaColor.Colorless]--;
                }
            }
            tbxDirections = tbxFake;
        }
Ejemplo n.º 7
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");
                }
            }
        }