Example #1
0
 void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
 {
     turn.AddBuys(1);
     turn.AddTreasure(1);
     turn.AddActions(1);
     turn.AddCards(1);
 }
Example #2
0
        void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
        {
            Copper copper = sidedata as Copper;
            if (copper == null)
                throw new Exception("Moneylender needs a copper");

            player.TrashCard(copper);
            turn.AddTreasure(3);
        }
Example #3
0
 void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
 {
     IEnumerable<ICard> cards = (IEnumerable<ICard>)sidedata;
     int count = 0;
     foreach (ICard card in cards)
     {
         if (Object.ReferenceEquals(card, this))
             throw new Exception("Attempted to discard the Cellar card that was being played");
         player.DiscardFromHand(card);
         ++count;
     }
     player.Draw(count);
 }
Example #4
0
        void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
        {
            Enum newCardType = (Enum)sidedata;

            ICard newCard = game.DrawCard(newCardType);
            if (newCard == null)
                throw new Exception("Selected target type is not available");

            if (newCard.Cost > 4)
                throw new Exception("Target card is too expensive for Workshop");

            player.AddDiscard(newCard);
        }
Example #5
0
 void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
 {
     IEnumerable<ICard> cards = (IEnumerable<ICard>)sidedata;
     int count = 0;
     foreach (ICard card in cards)
     {
         if (Object.ReferenceEquals(card, this))
             throw new Exception("Attempted to trash the Chapel card that was being played");
         if (count == 4)
             throw new Exception("Attempted to trash more than 4 cards permitted by Chapel");
         player.TrashCard(card);
         ++count;
     }
 }
Example #6
0
        void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
        {
            RemodelData upgradeData = (RemodelData)sidedata;
            ICard origCard = (ICard)upgradeData.Card;

            ICard newCard = game.DrawCard(upgradeData.TargetType);
            if (newCard == null)
                throw new Exception("Selected target type is not available");

            if ((origCard.Cost + 2) < newCard.Cost)
                throw new Exception("Target card is too expensive to remodel");

            game.TrashCard(origCard);
            player.AddDiscard(newCard);
        }
Example #7
0
        void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
        {
            MineData upgradeData = (MineData)sidedata;
            ICard origCard = (ICard)upgradeData.Card;

            if ((origCard.Type & CardType.Treasure) != CardType.Treasure)
                throw new Exception("Mine attempted on a non-treasure card");

            ICard newCard = game.DrawCard(upgradeData.TargetType);
            if (newCard == null)
                throw new Exception("Selected target type is not available for Mine");

            if ((origCard.Cost + 3) < newCard.Cost)
                throw new Exception("Target card is too expensive to mine into");

            player.TrashCard(origCard);
            player.AddToHand(newCard);
        }
Example #8
0
        void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
        {
            turn.AddTreasure(2);

            foreach (KeyValuePair<IAI, Player> opponent in game.Players)
            {
                if (object.ReferenceEquals(opponent.Value, player))
                    continue;

                // FIXME: should have a better way of handling reaction cards that puts
                // the reaction in the reaction card, not the attack card
                bool safe = false;
                foreach (ICard card in opponent.Value.Hand)
                {
                    if (card is Moat)
                    {
                        safe = true;
                        break;
                    }
                }
                if (safe)
                    continue;

                int expectedDiscards = opponent.Value.Hand.Count() - 3;
                if (expectedDiscards != 0)
                {
                    IEnumerable<ICard> discards = opponent.Key.ChooseExternalDiscard(opponent.Value, opponent.Value.Hand.Count() - 3);
                    int count = 0;
                    foreach (ICard card in discards)
                    {
                        opponent.Value.DiscardFromHand(card);
                        ++count;
                    }
                    if (count != expectedDiscards)
                        throw new Exception("ChooseExternalDiscard did not choose correct card count");
                }
            }
        }
Example #9
0
 void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
 {
     turn.AddTreasure(2);
     if ((bool)sidedata)
         player.PlaceDeckInDiscard();
 }
Example #10
0
 void IActionCard.Play(Dominion.Engine.Game game, Player player, Turn turn, object sidedata)
 {
     player.Draw(3);
 }
Example #11
0
        public int RunGame()
        {
            CreateBaseStacks();
            foreach (KeyValuePair<IAI, Player> kvp in players)
                kvp.Value.Deal();

            while (!GameIsOver())
            {
                foreach (KeyValuePair<IAI, Player> kvp in players)
                {
                    Turn turn = new Turn(this, kvp.Value);

                    turn.ActionPhase();
                    kvp.Key.ActionPhase(this, turn, kvp.Value);

                    turn.BuyPhase();
                    kvp.Key.BuyPhase(this, turn, kvp.Value);

                    kvp.Value.DoCleanup();

                    if (GameIsOver())
                        break;
                }
            }

            int[] vps = new int[players.Count];
            int maxvp = 0;
            for (int i = 0; i < players.Count; i++)
            {
                vps[i] = players[i].Value.CountVictoryPoints();
                maxvp = Math.Max(vps[i], maxvp);
            }

            int pc = 0;
            int winnerIdx = 0;
            for (int i = 0; i < players.Count; i++)
            {
                if (vps[i] == maxvp)
                {
                    ++pc;
                    winnerIdx = i;
                }
            }

            if (pc == 1)
            {
                // outright winner based upon victory points
                return winnerIdx;
            }

            int minturns = int.MaxValue;
            for (int i = 0; i < players.Count; i++)
                minturns = Math.Min(players[i].Value.Turns, minturns);
            pc = 0;
            winnerIdx = 0;
            for (int i = 0; i < players.Count; i++)
            {
                if (players[i].Value.Turns == minturns && vps[i] == maxvp)
                {
                    ++pc;
                    winnerIdx = i;
                }
            }
            if (pc == 1)
            {
                // outright winner based upon tied vp & fewest turns
                return winnerIdx;
            }

            // tied game
            return -1;
        }