コード例 #1
0
        public void CardCollection_AdditionTest()
        {
            CardCollection left = new CardCollection();

            ColorettoCard card1 = new ColorettoCard(ColorettoCardColors.Blue);
            ColorettoCard card2 = new ColorettoCard(ColorettoCardColors.Brown);
            ColorettoCard card3 = new ColorettoCard(ColorettoCardColors.Gray);

            left = left.Add(card1);
            left = left.Add(card2);
            left = left.Add(card3);

            CardCollection right = new CardCollection();

            card1 = new ColorettoCard(ColorettoCardColors.Blue);
            card2 = new ColorettoCard(ColorettoCardColors.Brown);
            card3 = new ColorettoCard(ColorettoCardColors.Gray);

            right = right.Add(card1);
            right = right.Add(card2);
            right = right.Add(card3);

            CardCollection added = left + right;
            Assert.AreEqual<int>(6, added.Count);
            Assert.AreEqual<int>(9, added.Score);
        }
コード例 #2
0
        /// <summary>
        /// Handles validating the server state. If the round is 6, this handles moving to the next round, giving the defender the win
        /// </summary>
        /// <param name="server">The server to execute on</param>
        public void ValidateState(GameServer server)
        {
            // Todo check won battle

            if (server.GameState.GetValueInt(Names.CURRENT_ROUND) == 6)
            {
                // Get the current round and the discard pile from the state
                int            round   = server.GameState.GetValueInt(Names.CURRENT_ROUND);
                CardCollection discard = server.GameState.GetValueCardCollection(Names.DISCARD);

                // Iterate over over all the previous rounds, as this round has no attacking or defending cards
                for (int index = 0; index < round; index++)
                {
                    // Add the cards to the discard pile
                    discard.Add(server.GameState.GetValueCard(Names.ATTACKING_CARD, index));
                    discard.Add(server.GameState.GetValueCard(Names.DEFENDING_CARD, index));

                    // Remove the cards from the state
                    server.GameState.Set <PlayingCard>(Names.ATTACKING_CARD, index, null);
                    server.GameState.Set <PlayingCard>(Names.DEFENDING_CARD, index, null);
                }

                // Update the discard pile
                server.GameState.Set(Names.DISCARD, discard);

                // Move to the next duel
                Utils.MoveNextDuel(server);
            }
        }
コード例 #3
0
        public void Test_DetermineWinners_FullHouse_TwoWinners()
        {
            Player winner1 = new Player("Winner1", 1000);
            winner1.Cards.Add(new Card(Rank.Two, Suit.Spades));
            winner1.Cards.Add(new Card(Rank.Two, Suit.Hearts));

            Player winner2 = new Player("Winner2", 1000);
            winner2.Cards.Add(new Card(Rank.Two, Suit.Diamonds));
            winner2.Cards.Add(new Card(Rank.Two, Suit.Clubs));

            CardCollection communityCards = new CardCollection();
            communityCards.Add(new Card(Rank.Three, Suit.Hearts));
            communityCards.Add(new Card(Rank.Six, Suit.Clubs));
            communityCards.Add(new Card(Rank.King, Suit.Hearts));
            communityCards.Add(new Card(Rank.King, Suit.Spades));
            communityCards.Add(new Card(Rank.King, Suit.Diamonds));

            HandEvaluator eval = new HandEvaluator();

            Hand hand1 = eval.GetBestHand(winner1.Cards + communityCards);

            Hand hand2 = eval.GetBestHand(winner2.Cards + communityCards);

            Assert.AreEqual(0, HandEvaluator.Compare(hand1, hand2));
        }
コード例 #4
0
        /// <summary>
        /// Handles validating the server state. If the attacker has lost, this handles moving to the next round
        /// </summary>
        /// <param name="server">The server to execute on</param>
        public void ValidateState(GameServer server)
        {
            // Only run this state update if the attacker is forfeiting
            if (server.GameState.GetValueBool(Names.ATTACKER_FORFEIT))
            {
                // Get the current round and the discard pile from the state
                int            round   = server.GameState.GetValueInt(Names.CURRENT_ROUND);
                CardCollection discard = server.GameState.GetValueCardCollection(Names.DISCARD);

                // Iterate over over all the previous rounds, as this round has no attacking or defending cards
                for (int index = 0; index < round; index++)
                {
                    // Add the cards to the discard pile
                    discard.Add(server.GameState.GetValueCard(Names.ATTACKING_CARD, index));
                    discard.Add(server.GameState.GetValueCard(Names.DEFENDING_CARD, index));

                    // Remove the cards from the state
                    server.GameState.Set <PlayingCard>(Names.ATTACKING_CARD, index, null);
                    server.GameState.Set <PlayingCard>(Names.DEFENDING_CARD, index, null);
                }

                // Send the message
                server.SendServerMessage(server.Players[server.GameState.GetValueByte(Names.ATTACKING_PLAYER)].Name + " has forfeited");

                // Update the discard pile
                server.GameState.Set(Names.DISCARD, discard);

                // Move to next match
                Utils.MoveNextDuel(server);
            }
        }
コード例 #5
0
        public void AddTest()
        {
            var cc = new CardCollection();

            cc.Add(new Card("TEST1", "Test1"));
            cc.Add("TEST2", new Card("TEST2", "Test2"));

            // Test add with existing keyword
        }
コード例 #6
0
        public override CardCollection CardStack()
        {
            CardCollection cc = new CardCollection();

            if (_SetAsideCard != null)
            {
                cc.Add(_SetAsideCard);
            }
            cc.Add(this);
            return(cc);
        }
コード例 #7
0
ファイル: Card.cs プロジェクト: bberak/PokerDotNet
        public static CardCollection operator +(Card c1, Card c2)
        {
            CardCollection summCollection = new CardCollection();

            if (c1 != null)
                summCollection.Add(c1);

            if (c2 != null)
                summCollection.Add(c2);

            return summCollection;
        }
コード例 #8
0
        /// <summary>
        /// 动态条件查询卡号
        /// </summary>
        /// <param name="strFields">条件字段</param>
        /// <param name="strValues">条件值</param>
        /// <returns></returns>
        public static CardCollection GetCard(List <QueryElement> list)
        {
            CardCollection coll = new CardCollection();
            StringBuilder  sb   = new StringBuilder();

            sb.Append(" select card.*,a.name as ownerName,b.name as userName from card left join user a on card.ownerId=a.id left join user b on card.userId = b.id where 1=1 ");
            if (list.Count > 0)
            {
                MySqlParameter[] pars = new MySqlParameter[list.Count];
                for (int i = 0; i < list.Count; i++)
                {
                    QueryElement query = list[i];

                    if (query.QueryElementType == MySqlDbType.DateTime)
                    {
                        sb.AppendFormat(" {0} {1} {2} @{3} ", query.QueryLogic, query.Queryname, query.QueryOperation, query.Queryname + i);
                        pars[i] = new MySqlParameter("@" + query.Queryname + i, query.QueryElementType);
                    }
                    else
                    {
                        sb.AppendFormat(" {0} {1} {2} @{3} ", query.QueryLogic, query.Queryname, query.QueryOperation, query.Queryname);
                        pars[i] = new MySqlParameter("@" + query.Queryname, query.QueryElementType);
                    }
                    if (query.QueryOperation.Equals("like"))
                    {
                        pars[i].Value = "%" + query.Queryvalue + "%";
                    }
                    else
                    {
                        pars[i].Value = query.Queryvalue;
                    }
                }
                using (MySqlDataReader reader = MySqlDBHelper.GetReader(sb.ToString(), pars))
                {
                    while (reader.Read())
                    {
                        coll.Add(new CardInfo(reader));
                    }
                }
            }
            else
            {
                using (MySqlDataReader reader = MySqlDBHelper.GetReader(sb.ToString()))
                {
                    while (reader.Read())
                    {
                        coll.Add(new CardInfo(reader));
                    }
                }
            }
            return(coll);
        }
コード例 #9
0
        public Deck(CardValue minValue, CardValue maxValue)
        {
            for (var suit = 0; suit < 4; suit++)
            {
                for (var value = (int)minValue; value < (int)maxValue + 1; value++)
                {
                    Cards.Add(new Card((CardValue)value, (CardSuit)suit));
                }
            }

            Shuffle();
            trumpSuit = Cards.Last().Suit;
        }
コード例 #10
0
		public void TestUpdateLocation( )
		{
			CardCollection coll = new CardCollection( );

			coll.Add( new Card( Suit.Clubs, 10, true, null ) );
			coll.Add( new Card( Suit.Diamonds, 11, true, null ) );
			coll.Add( new Card( Suit.Diamonds, 7, true, null ) );

			coll.UpdateLocation( 10, 7 );

			// This test does in fact rely on the fact that a card
			// will by default initialize its location to 0,0. 
			Assert.AreEqual( coll[ 0 ].Location.X, 10 );
		}
コード例 #11
0
        /// <summary>
        /// Refreshes the logic decks each time there is an action.
        /// </summary>
        private void RefreshLogicDeckFromPanels()
        {
            AIHand.Clear();
            playerHand.Clear();

            foreach (CardBox.CardBox card in pnlComputerCards.Controls)
            {
                AIHand.Add(card.Card);
            }

            foreach (CardBox.CardBox card in pnlPlayerCards.Controls)
            {
                playerHand.Add(card.Card);
            }
        }
コード例 #12
0
ファイル: GotCardsMessage.cs プロジェクト: toadgee/phazex
        public GotCardsMessage(byte [] b, GameRules rules) : base(b)
        {
            Validate(rules);
            Card c     = null;
            int  cards = (int)(msg[1]);

            _cards = new CardCollection(cards);
            int msgctr = 2;

            int id  = 0;
            int col = 0;
            int num = 0;

            for (int ctr = 0; ctr < cards; ctr++)
            {
                id   = (int)msg[msgctr + 3];
                id <<= 8;
                id  += (int)msg[msgctr + 4];

                num = (int)msg[msgctr + 1];
                col = (int)msg[msgctr];

                if (1 == ((int)(msg[msgctr + 2])))
                {
                    c        = new Card(CardNumber.Wild, (CardColor)col, id);
                    c.Number = (CardNumber)num;
                }
                else
                {
                    c = new Card((CardNumber)num, (CardColor)col, id);
                }
                _cards.Add(c);
                msgctr += 5;
            }
        }
コード例 #13
0
        public override void Load(BinaryReader reader, long length)
        {
            Categories.Clear();
            var fileStartPos = reader.BaseStream.Position;

            var numCategories = reader.ReadInt64();

            for (var i = 0; i < numCategories; i++)
            {
                var cardListOffset = reader.ReadInt64();

                var tempOffset = reader.BaseStream.Position;

                reader.BaseStream.Position = fileStartPos + cardListOffset;
                var cardCount      = reader.ReadInt16();
                var cardCollection = new CardCollection();
                for (var j = 0; j < cardCount; j++)
                {
                    cardCollection.Add(reader.ReadInt16());
                }
                Categories.Add(cardCollection);

                reader.BaseStream.Position = tempOffset;
            }
        }
コード例 #14
0
        private CardCollection BuildNineThroughAceOfEachSuit()
        {
            var nineThroughAces = new List <IRank>
            {
                _rankFactory.GetRank(RankEnum.Ace),
                _rankFactory.GetRank(RankEnum.King),
                _rankFactory.GetRank(RankEnum.Queen),
                _rankFactory.GetRank(RankEnum.Jack),
                _rankFactory.GetRank(RankEnum.Ten),
                _rankFactory.GetRank(RankEnum.Nine),
            };

            var suits = new List <ISuit>
            {
                _suitFactory.GetSuit(SuitEnum.Diamonds),
                _suitFactory.GetSuit(SuitEnum.Clubs),
                _suitFactory.GetSuit(SuitEnum.Hearts),
                _suitFactory.GetSuit(SuitEnum.Spades),
            };

            var cardCollection = new CardCollection();

            foreach (var suit in suits)
            {
                foreach (var rank in nineThroughAces)
                {
                    cardCollection.Add(new Card(rank, suit));
                }
            }

            return(cardCollection);
        }
コード例 #15
0
        private void ViewModelCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (syncDisabled)
            {
                return;
            }
            syncDisabled = true;

            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (var card in e.NewItems.OfType <CardViewModel>().Select(v => v.Card).OfType <Card>())
                {
                    cards.Add(card);
                }
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (var card in e.OldItems.OfType <CardViewModel>().Select(v => v.Card).OfType <Card>())
                {
                    cards.Remove(card);
                }
                break;

            case NotifyCollectionChangedAction.Reset:
                cards.Clear();
                break;
            }
            syncDisabled = false;
        }
コード例 #16
0
        private void handleGetTopDiscardMessage(GetTopDiscardMessage m, ServerPlayer p)
        {
            if (!p.MyTurn)
            {
                p.Send(new ErrorMessage("ERROR: It is not your turn to get the top discard!"));
                return; //client sent invalid request!
            }
            if (_discard.ReadTopCard() == null)
            {
                SendAll(new ErrorMessage("Internal server error"));
                return;
            }
            if ((_discard.ReadTopCard().Number == CardNumber.Skip) && (!_firstDiscard))//skip card
            {
                p.Send(new ErrorMessage("ERROR: You asked for a skip card. This is an invalid move, and should have been caught by your client. Upgrade!"));
                return;                 //client sent invalid request
            }

            //remove card from discard
            Card c = _discard.RemoveTopCard();

            p.PickedUpCard = true;
            p.GetHand().Add(c);

            CardCollection cc = new CardCollection(1);

            cc.Add(c);
            p.Send(new GotCardsMessage(cc));
            SendAll(new UpdateDiscardMessage(_discard.ReadTopCard(), p, false));
            SendAll(new GotDiscardMessage(p.PlayerID, c));
            updateClientsStatuses();
        }
コード例 #17
0
        private void handleGetTopDeckCardMessage(GetTopDeckCardMessage m, ServerPlayer p)
        {
            if (!p.MyTurn)
            {
                return;                        //client sent invalid request!
            }
            //remove card from deck
            Card c = _deck.RemoveCard();

            //check to see if top deck card is null!
            if (_deck.IsTopCardNull())
            {
                _deck.ShuffleAndAddUnused(_discard.RemoveAllButTopCard());
            }

            //add to hand of client
            p.PickedUpCard = true;
            p.GetHand().Add(c);
            CardCollection cc = new CardCollection(1);

            cc.Add(c);
            p.Send(new GotCardsMessage(cc));

            //notify the users
            SendAll(new GotDeckCardMessage(p.PlayerID));
            updateClientsStatuses();
        }
コード例 #18
0
        /// <summary>
        /// Handles the card changed packet
        /// </summary>
        /// <param name="inMsg">The message to decode</param>
        private void HandleCardChanged(NetIncomingMessage inMsg)
        {
            bool added    = inMsg.ReadBoolean();
            bool hasValue = inMsg.ReadBoolean();

            inMsg.ReadPadBits();

            if (hasValue)
            {
                CardRank rank = (CardRank)inMsg.ReadByte();
                CardSuit suit = (CardSuit)inMsg.ReadByte();

                PlayingCard card = new PlayingCard(rank, suit)
                {
                    FaceUp = true
                };

                if (added)
                {
                    myHand.Add(card);

                    OnHandCardAdded?.Invoke(this, card);
                }
                else
                {
                    myHand.Discard(card);

                    OnHandCardRemoved?.Invoke(this, card);
                }
            }
        }
コード例 #19
0
        public void CardCollection_AddTest()
        {
            CardCollection target = new CardCollection();

            ColorettoCard card1 = new ColorettoCard(ColorettoCardColors.Blue);
            ColorettoCard card2 = new ColorettoCard(ColorettoCardColors.Brown);
            ColorettoCard card3 = new ColorettoCard(ColorettoCardColors.Gray);

            target = target.Add(card1);
            target = target.Add(card2);
            target = target.Add(card3);

            Assert.AreEqual<ColorettoCard>(card1, target[0]);
            Assert.AreEqual<ColorettoCard>(card2, target[1]);
            Assert.AreEqual<ColorettoCard>(card3, target[2]);
        }
コード例 #20
0
        public void GetEnumeratorShouldReturnAllElementsInCollection()
        {
            var cards = new List <Card>
            {
                new Card(CardSuit.Club, CardType.Ace),
                new Card(CardSuit.Spade, CardType.Ace),
                new Card(CardSuit.Diamond, CardType.Ten),
                new Card(CardSuit.Heart, CardType.Jack),
                new Card(CardSuit.Club, CardType.Nine),
                new Card(CardSuit.Spade, CardType.Nine)
            };

            var collection = new CardCollection();

            foreach (var card in cards)
            {
                collection.Add(card);
            }

            foreach (var card in collection)
            {
                Assert.IsTrue(cards.Contains(card), $"Card {card} not found in collection!");
            }

            // Second enumeration
            var count = 0;

            foreach (var card in collection)
            {
                Assert.IsTrue(cards.Contains(card), $"Card {card} not found in collection!");
                count++;
            }

            Assert.AreEqual(cards.Count, count);
        }
コード例 #21
0
        private void btnExcluirFuncionarios_Click(object sender, EventArgs e)
        {
            try
            {
                InstanciaWatchComm();

                this._watchComm.OpenConnection();

                CardCollection listCartoes = new CardCollection();

                foreach (DataRow dr in dsSDKBioLite.dtFuncionarios)
                {
                    TemplateCollection templateCollection = new TemplateCollection();
                    Template           template           = new Template();

                    Card card = new Card();

                    card.Code = dr["Matricula"].ToString();
                    card.Name = dr["Nome"].ToString();

                    if (!dr["Senha"].ToString().Equals(""))
                    {
                        card.PassWord = Int32.Parse(dr["Senha"].ToString());
                    }

                    if (dr["Supervisor"].ToString().Equals("True"))
                    {
                        card.MasterCard = TypeMasterCard.Master;
                    }

                    foreach (DataRow drTemplate in dsSDKBioLite.dtTemplates)
                    {
                        if (drTemplate["Matricula"].ToString().Equals(card.Code))
                        {
                            template             = new Template();
                            template.DedoDigital = (TypeDedoDigital)Int32.Parse(drTemplate["Dedo"].ToString());
                            template.Digital     = drTemplate["String"].ToString();
                            templateCollection.Add(template);
                        }
                    }

                    card.Template = templateCollection;

                    listCartoes.Add(card);
                }

                this._watchComm.eraseCardListBioLite(listCartoes);

                this._watchComm.CloseConnection();

                ComandoRecepcionadoComSucesso();
            }
            catch (Exception ex)
            {
                this._watchComm.CloseConnection();

                MessageBox.Show(ex.Message, "Erro");
            }
        }
コード例 #22
0
ファイル: GameAction.cs プロジェクト: W3SS/cardstock
 public override void Undo()
 {
     location.Clear();
     foreach (Card c in before.AllCards())
     {
         location.Add(c);
     }
 }
コード例 #23
0
ファイル: GameAction.cs プロジェクト: W3SS/cardstock
 public override void Execute()
 {
     foreach (Card c in location.AllCards())
     {
         before.Add(c);
     }
     cg.SetDeck(deck, location, script);
 }
コード例 #24
0
 public void Played(Card card)
 {
     if (!_CardsPlayed.Contains(card))
     {
         _CardsPlayed.Add(card);
     }
     _CardsResolved.Add(card);
 }
コード例 #25
0
		public void TestAlternatingColors( )
		{
			CardCollection coll = new CardCollection( );

			// An empty one is also alternating:
			Assert.AreEqual( coll.IsAlternatingColors( ), true );
			coll.Add( new Card( Suit.Clubs, 10, true, null ) );

			// So is a collection of only one element:
			Assert.AreEqual( coll.IsAlternatingColors( ), true );

			// Then, add a few cards of alternating colors:
			coll.Add( new Card( Suit.Diamonds, 11, true, null ) );
			coll.Add( new Card( Suit.Clubs, 7, true, null ) );
			coll.Add( new Card( Suit.Diamonds, 11, true, null ) );
			coll.Add( new Card( Suit.Spades, 7, true, null ) );
			coll.Add( new Card( Suit.Hearts, 11, true, null ) );
			coll.Add( new Card( Suit.Clubs, 7, true, null ) );

			// This should hold:
			Assert.AreEqual( coll.IsAlternatingColors( ), true );

			// Finally, remove a card in the middle:

			coll.RemoveAt( 2 );

			// ... which should make it no longer alternating:
			Assert.AreEqual( coll.IsAlternatingColors( ), false );
		}
コード例 #26
0
ファイル: GameAction.cs プロジェクト: W3SS/cardstock
 public override void Execute()
 {
     foreach (Card c in locations.cardList.AllCards())
     {
         unshuffled.Add(c);
     }
     locations.cardList.Shuffle();
     script.WriteToFile("O:" + locations.cardList);
 }
コード例 #27
0
        public void AddCards(List <Card> cards)
        {
            CardCollection _cards = (CardCollection)this.Resources["cards"];

            foreach (var card in cards)
            {
                _cards.Add(card);
            }
        }
コード例 #28
0
        public void CountShouldReturn1WhenOneCardIsAddedAndThenRemoved()
        {
            var collection = new CardCollection();
            var card       = Card.GetCard(CardSuit.Club, CardType.Ace);

            collection.Add(card);
            collection.Remove(card);
            Assert.Empty(collection);
        }
コード例 #29
0
        public void CountShouldReturn1WhenOneCardIsAddedAndThenRemoved()
        {
            var collection = new CardCollection();
            var card       = new Card(CardSuit.Club, CardType.Ace);

            collection.Add(card);
            collection.Remove(card);
            Assert.AreEqual(0, collection.Count);
        }
コード例 #30
0
        /// <summary>
        /// This method disables all cards in the players cards that are lower
        /// than the current AIs attacking card. Also it disables cards that have
        /// not been played yet
        /// </summary>
        private void DisableInvalidCardsInHands()
        {
            if (!playerAttacking)
            {
                // start with all disabled cards
                foreach (CardBox.CardBox cardBox in pnlPlayerCards.Controls)
                {
                    cardBox.Enabled = false;
                }
                // start with empty collection
                cardsPlayedThisTurn.Clear();


                if (pnlActiveCards.Controls.Count > 0)
                {
                    attackingCard = ((CardBox.CardBox)pnlActiveCards.Controls[0]).Card;

                    // add the defended cards to collection
                    foreach (CardBox.CardBox cardBox in pnlDefended.Controls)
                    {
                        // add the defended cards
                        cardsPlayedThisTurn.Add(cardBox.Card);
                    }

                    // enable players cards in the cardsPlayedThisTurn collection
                    foreach (CardBox.CardBox cardBox in pnlPlayerCards.Controls)
                    {
                        // if the collection has this card then enable it in the players hand
                        if (cardsPlayedThisTurn.Contains(cardBox.Card) && cardBox.Card > attackingCard)
                        {
                            cardBox.Enabled = true;
                        }
                    }

                    // enable player cards higher than the current attacking card
                    foreach (CardBox.CardBox cardBox in pnlPlayerCards.Controls)
                    {
                        defendingCard = cardBox.Card;

                        // trump card or higher ranked card in same suit
                        if (defendingCard > attackingCard)
                        {
                            //MessageBox.Show(cardBox.Card + " is greater than " + attackingCard);
                            cardBox.Enabled = true;
                        }
                    }
                }
            }
            else
            {
                foreach (CardBox.CardBox cardBox in pnlPlayerCards.Controls)
                {
                    cardBox.Enabled = true;
                }
            }
        }
コード例 #31
0
ファイル: EnemyDecks.cs プロジェクト: sgastudio/Yugioh
 public static CardCollection CreateEnemyCollection()
 {
     // Create enemy deck collection and return
     CardCollection enemyDeck = new CardCollection();
     foreach (string c in EnemyDeck1)
     {
         enemyDeck.Add(CardData.CreateCardFromName(c));
     }
     return enemyDeck;
 }
コード例 #32
0
ファイル: CardGrouping.cs プロジェクト: W3SS/cardstock
        private CardCollection Clone(CardCollection source)
        {
            var recurseList = new CardCollection(CCType.VIRTUAL);

            foreach (var card in source.AllCards())
            {
                recurseList.Add(card);
            }
            return(recurseList);
        }
コード例 #33
0
 public void Passed(Card card)
 {
     if (!this.IsTurnFinished)
     {
         _CardsPassed.Add(card);
     }
     else
     {
         _CardsPassedAfter.Add(card);
     }
 }
コード例 #34
0
 public void Received(Card card)
 {
     if (!this.IsTurnFinished)
     {
         _CardsReceived.Add(card);
     }
     else
     {
         _CardsReceivedAfter.Add(card);
     }
 }
コード例 #35
0
ファイル: CollectionTest.cs プロジェクト: ALee1303/Hwatu
        public void AddListTest()
        {
            collection = new CardCollection();
            List <Hanafuda> cards = new List <Hanafuda> {
                new Kwang(Month.April), new Kwang(Month.December)
            };

            collection.Add(cards);
            Assert.AreEqual(collection[0], cards[0]);
            Assert.AreEqual(collection[1], cards[1]);
        }
コード例 #36
0
ファイル: CardGrouping.cs プロジェクト: W3SS/cardstock
 private List <CardCollection> RightLook(int idx, int remainingLength)
 {
     if (idx < array.Count() && array[idx].Count > 0)
     {
         List <CardCollection> recurs;
         if (remainingLength != 1)
         {
             recurs = RightLook(idx + 1, remainingLength - 1);
             var ret = new List <CardCollection>();
             foreach (var card in array[idx].AllCards())
             {
                 foreach (var downLine in recurs)
                 {
                     var tempList = new CardCollection(CCType.VIRTUAL);
                     tempList.Add(card);
                     foreach (var innerCard in downLine.AllCards())
                     {
                         tempList.Add(innerCard);
                     }
                     ret.Add(tempList);
                 }
             }
             return(ret);
         }
         else
         {
             var ret = new List <CardCollection>();
             foreach (var card in array[idx].AllCards())
             {
                 var tempList = new CardCollection(CCType.VIRTUAL);
                 tempList.Add(card);
                 ret.Add(tempList);
             }
             return(ret);
         }
     }
     else
     {
         return(new List <CardCollection>());
     }
 }
コード例 #37
0
        public void DefenderCards_Can_Beat_AttackerCards_Without_Trump()
        {
            var attackerCards = new CardCollection <BuraCard>();
            var defenderCards = new CardCollection <BuraCard>();

            attackerCards.Add(new BuraCard(CardSuit.Clubs, CardName.Seven));
            attackerCards.Add(new BuraCard(CardSuit.Clubs, CardName.Queen));
            attackerCards.Add(new BuraCard(CardSuit.Clubs, CardName.Eight));

            defenderCards.Add(new BuraCard(CardSuit.Clubs, CardName.Ace));
            defenderCards.Add(new BuraCard(CardSuit.Clubs, CardName.Ten));
            defenderCards.Add(new BuraCard(CardSuit.Clubs, CardName.Nine));

            var strategy = new BuraDefenseStrategy();

            var tricks = strategy.Execute(attackerCards, defenderCards);

            foreach (var trick in tricks)
            {
                Assert.True(trick.Completed);
            }
        }
コード例 #38
0
ファイル: CardLocReference.cs プロジェクト: W3SS/cardstock
        public void Add(Card c)
        {
            switch (locIdentifier)
            {
            case "top":
                cardList.Add(c);
                break;

            case "bottom":
                cardList.AddBottom(c);
                break;

            case "-1":
                // SHOULD THIS THROW EXCEPTION INSTEAD?
                cardList.Add(c);
                break;

            default:
                cardList.Add(c, Int32.Parse(locIdentifier));
                break;
            }
        }
コード例 #39
0
        internal static CardCollection BitsToCardCollection(int source)
        {
            var result = new CardCollection();

            for (int i = 0; i < 32; i++)
            {
                int card = (1 << i);
                if ((source & card) != 0)
                    result.Add(BitsToCard(card));
            }

            return result;
        }
コード例 #40
0
        public void ContainsShouldReturnTrueForAllCardsAfterAddingThem()
        {
            var collection = new CardCollection();
            foreach (CardSuit cardSuitValue in Enum.GetValues(typeof(CardSuit)))
            {
                foreach (CardType cardTypeValue in Enum.GetValues(typeof(CardType)))
                {
                    var card = new Card(cardSuitValue, cardTypeValue);
                    collection.Add(card);
                }
            }

            foreach (CardSuit cardSuitValue in Enum.GetValues(typeof(CardSuit)))
            {
                foreach (CardType cardTypeValue in Enum.GetValues(typeof(CardType)))
                {
                    var card = new Card(cardSuitValue, cardTypeValue);
                    Assert.IsTrue(collection.Contains(card));
                }
            }
        }
コード例 #41
0
        public void CardCollection_TooManyPiles()
        {
            CardCollection target = new CardCollection();

            ColorettoCard card1 = new ColorettoCard(ColorettoCardColors.Blue);
            ColorettoCard card2 = new ColorettoCard(ColorettoCardColors.Brown);
            ColorettoCard card3 = new ColorettoCard(ColorettoCardColors.Gray);
            ColorettoCard card4 = new ColorettoCard(ColorettoCardColors.Green);
            ColorettoCard card5 = new ColorettoCard(ColorettoCardColors.Orange);

            ColorettoCard wild = new ColorettoCard(ColorettoCardTypes.Wild);

            target = target.Add(card1);
            target = target.Add((ColorettoCard)card1.Clone());
            target = target.Add((ColorettoCard)card1.Clone());
            target = target.Add(wild);

            target = target.Add(card2);
            target = target.Add((ColorettoCard)card2.Clone());
            target = target.Add((ColorettoCard)card2.Clone());

            target = target.Add(card3);
            target = target.Add(card4);

            Assert.AreEqual<int>(16, target.Score);
        }
コード例 #42
0
		protected override ChoiceResult Decide_SecretChamber(Choice choice)
		{
			if (choice.Text == "Choose order of cards to put back on your deck")
			{
				// Order all the cards
				IEnumerable<Card> cardsToReturn = this.FindBestCardsToDiscard(choice.Cards, choice.Cards.Count());

				// Try to save 1 Curse if we can
				if (choice.CardTriggers[0].CardType == Cards.Prosperity.TypeClass.Mountebank)
				{
					cardsToReturn = cardsToReturn.Take(3);
					if (cardsToReturn.ElementAt(0).CardType == Cards.Universal.TypeClass.Curse)
						return new ChoiceResult(new CardCollection(cardsToReturn.Skip(1)));
					if (cardsToReturn.ElementAt(1).CardType == Cards.Universal.TypeClass.Curse)
						return new ChoiceResult(new CardCollection() { cardsToReturn.ElementAt(0), cardsToReturn.ElementAt(2)});
				}
				
				// Try to not put Treasure cards onto our deck, even if that means putting Action cards there
				else if (choice.CardTriggers[0].CardType == Cards.Seaside.TypeClass.PirateShip)
				{
					CardCollection pirateShipCards = new CardCollection(cardsToReturn.Where(c => (c.Category & Category.Treasure) != Category.Treasure));
					if (pirateShipCards.Count < 2)
						pirateShipCards.AddRange(cardsToReturn.Where(c => (c.Category & Category.Treasure) != Category.Treasure).Take(2 - pirateShipCards.Count));
					return new ChoiceResult(pirateShipCards);
				}

				return new ChoiceResult(new CardCollection(cardsToReturn.Take(2)));
			}
			else
			{
				CardCollection scCards = new CardCollection();
				foreach (Card card in choice.Cards)
				{
					if (card.Category == Category.Curse ||
						((card.Category & Category.Victory) == Category.Victory && (card.Category & Category.Treasure) != Category.Treasure) ||
						(card.CardType == Cards.Universal.TypeClass.Copper && this.RealThis.InPlay[Cards.Intrigue.TypeClass.Coppersmith].Count == 0) ||
						(this.RealThis.Actions == 0 && (card.Category & Category.Treasure) != Category.Treasure))
						scCards.Add(card);
				}
				return new ChoiceResult(scCards);
			}
		}
コード例 #43
0
        public void GetEnumeratorShouldReturnAllElementsInCollection()
        {
            var cards = new List<Card>
                            {
                                new Card(CardSuit.Club, CardType.Ace),
                                new Card(CardSuit.Spade, CardType.Ace),
                                new Card(CardSuit.Diamond, CardType.Ten),
                                new Card(CardSuit.Heart, CardType.Jack),
                                new Card(CardSuit.Club, CardType.Nine),
                                new Card(CardSuit.Spade, CardType.Nine)
                            };

            var collection = new CardCollection();
            foreach (var card in cards)
            {
                collection.Add(card);
            }

            foreach (var card in collection)
            {
                Assert.IsTrue(cards.Contains(card), $"Card {card} not found in collection!");
            }

            // Second enumeration
            var count = 0;
            foreach (var card in collection)
            {
                Assert.IsTrue(cards.Contains(card), $"Card {card} not found in collection!");
                count++;
            }

            Assert.AreEqual(cards.Count, count);
        }
コード例 #44
0
		public override CardCollection CardStack()
		{
			CardCollection cc = new CardCollection();
			if (_SetAsideCard != null)
				cc.Add(_SetAsideCard);
			cc.Add(this);
			return cc;
		}
コード例 #45
0
        public void CardCollection_BasicScoreCheck()
        {
            CardCollection target = new CardCollection();

            ColorettoCard card1 = new ColorettoCard(ColorettoCardColors.Blue);
            ColorettoCard card2 = new ColorettoCard(ColorettoCardColors.Brown);
            ColorettoCard card3 = new ColorettoCard(ColorettoCardColors.Gray);

            target = target.Add(card1);
            Assert.AreEqual<int>(1, target.Score);

            target = target.Add(card2);
            Assert.AreEqual<int>(2, target.Score);

            target = target.Add(card3);
            Assert.AreEqual<int>(3, target.Score);

            target = target.Add((ColorettoCard)card1.Clone());
            Assert.AreEqual<int>(5, target.Score);

            target = target.Add((ColorettoCard)card1.Clone());
            Assert.AreEqual<int>(8, target.Score);

            target = target.Add((ColorettoCard)card2.Clone());
            Assert.AreEqual<int>(10, target.Score);
        }
コード例 #46
0
        public void CardCollection_WildCardScores()
        {
            CardCollection target = new CardCollection();

            ColorettoCard card1 = new ColorettoCard(ColorettoCardColors.Blue);
            ColorettoCard card2 = new ColorettoCard(ColorettoCardColors.Brown);
            ColorettoCard card3 = new ColorettoCard(ColorettoCardColors.Gray);

            ColorettoCard wild = new ColorettoCard( ColorettoCardTypes.Wild);

            target = target.Add(card1);
            target = target.Add((ColorettoCard)card1.Clone());
            target = target.Add((ColorettoCard)card1.Clone());
            target = target.Add(wild);

            target = target.Add(card2);
            target = target.Add(card3);

            Assert.AreEqual<int>(12, target.Score);
        }
コード例 #47
0
        /// <summary>
        /// Detects and recognizes cards from source image
        /// </summary>
        /// <param name="source">Source image to be scanned</param>
        /// <returns>Recognized Cards</returns>
        public CardCollection Recognize(Bitmap source, string filePath, int id,
            int minSize, Rectangle suitRect, Rectangle rankRect
            )
        {
            CardCollection collection = new CardCollection();  //Collection that will hold cards
            Bitmap temp = source.Clone() as Bitmap; //Clone image to keep original image

            FiltersSequence seq = new FiltersSequence();
            seq.Add(Grayscale.CommonAlgorithms.BT709);  //First add  grayScaling filter
            seq.Add(new OtsuThreshold()); //Then add binarization(thresholding) filter
            temp = seq.Apply(source); // Apply filters on source image

            //if (!string.IsNullOrEmpty(fileName))
            //{
            //    temp.Save(fileName, ImageFormat.Bmp);
            //}
            //Extract blobs from image whose size width and height larger than 150
            BlobCounter extractor = new BlobCounter();
            extractor.FilterBlobs = true;
            extractor.MinWidth = extractor.MinHeight = minSize;//TODO card size
            //extractor.MaxWidth = extractor.MaxHeight = 70;//TODO card size
            extractor.ProcessImage(temp);

            //Will be used transform(extract) cards on source image
            //QuadrilateralTransformation quadTransformer = new QuadrilateralTransformation();

            foreach (Blob blob in extractor.GetObjectsInformation())
            {
                var cardImg = source.Clone(blob.Rectangle, PixelFormat.DontCare);

                Card card = new Card(cardImg); //Create Card Object

                Bitmap suitBmp = card.GetPart(suitRect);
                char color = ScanColor(suitBmp); //Scan color

                seq.Clear();

                seq.Add(Grayscale.CommonAlgorithms.BT709);
                seq.Add(new OtsuThreshold());
                suitBmp = seq.Apply(suitBmp);

                card.Suit = ScanSuit(suitBmp, color); //Scan suit of face card

                Bitmap rankBmp = card.GetPart(rankRect);
                seq.Clear();

                seq.Add(Grayscale.CommonAlgorithms.BT709);
                seq.Add(new OtsuThreshold());
                rankBmp = seq.Apply(rankBmp);

                //var ext = new BlobsFiltering(0, 0, 40, 40);
                //ext.ApplyInPlace(rankBmp);
                card.Rank = ScanRank(rankBmp); //Scan Rank of non-face card

                //if (card.Rank == Rank.NOT_RECOGNIZED)
                //{
                //    if (!string.IsNullOrEmpty(filePath))
                //    {
                //        while (File.Exists(filePath + id + ".bmp"))
                //            id++;
                //        top.Save(filePath + id + ".bmp", ImageFormat.Bmp);
                //    }
                //}

                if(card.Rank != Rank.NOT_RECOGNIZED && card.Suit != Suit.NOT_RECOGNIZED)
                    collection.Add(card); //Add card to collection
            }

            collection.SortByRank();
            return collection;
        }
コード例 #48
0
		public override void Play(Player player)
		{
			base.Play(player);

			SupplyCollection availableSupplies = new SupplyCollection(player._Game.Table.Supplies.Where(kvp => kvp.Value.Randomizer != null && kvp.Value.Randomizer.GroupMembership != Group.None));
			CardCollection cards = new CardCollection();
			Choice choice = new Choice("Name a card", this, availableSupplies, player, false);
			foreach (Supply supply in player._Game.Table.Supplies.Values.Union(player._Game.Table.SpecialPiles.Values))
			{
				foreach (Type type in supply.CardTypes)
				{
					if (!choice.Supplies.Any(kvp => kvp.Value.CardType == type))
						cards.Add(Card.CreateInstance(type));
				}
			}
			cards.Sort();
			choice.AddCards(cards);

			ChoiceResult result = player.MakeChoice(choice);
			ICard namedCard = null;
			if (result.Supply != null)
				namedCard = result.Supply;
			else
				namedCard = result.Cards[0];

			player._Game.SendMessage(player, this, namedCard);
			if (player.CanDraw)
			{
				player.Draw(DeckLocation.Revealed);
				if (player.Revealed[namedCard.CardType].Count > 0)
				{
					player.AddCardsToHand(DeckLocation.Revealed);
				}
				else
				{
					player.AddCardsToDeck(player.RetrieveCardsFrom(DeckLocation.Revealed), DeckPosition.Top);
				}
			}
		}
コード例 #49
0
ファイル: HandEvaluator.cs プロジェクト: bberak/PokerDotNet
        public bool IsStraight(out CardCollection winningCards)
        {
            checkCardList();

            // Get a copy of the card list
            CardCollection cardList = new CardCollection(_cardList);

            winningCards = new CardCollection();

            // Sort the cards by value
            cardList.Sort();

            // if there is an ace in the deck, it got moved to the end by the sort
            // so we need to insert a new "ace" in the sorted deck (with a value of 1) in the beginning position
            foreach (Card card in cardList)
            {
                if (card.Value == (int)Rank.Ace)
                {
                    cardList.Insert(0, new Card(card.Rank, card.Suit));
                    break;
                }
            }

            int cardsInARow = 1;

            // Check each card and the next one
            for (int i = 0; i < cardList.Count; i++)
            {
                // Add the current card to the winning cards index, just in case it's part of a straight
                winningCards.Add(cardList[i]);

                // If this is the last card, check to see if it is part of a straight
                if (i == cardList.Count - 1)
                {
                    if (cardList[i].IsOneGreaterThan(cardList[i - 1]))
                    {
                        cardsInARow++;
                    }
                    else
                        winningCards.Clear();
                }
                else
                {
                    // If this card is the same as the next one, ignore it
                    if (cardList[i].Value == cardList[i + 1].Value)
                    {
                        // remove the card we just added
                        winningCards.Remove(cardList[i]);
                        continue;
                    }

                    // Check to see if this card is exactly one less than the next card
                    if (cardList[i].IsOneLessThan(cardList[i + 1]))
                    {
                        cardsInARow++;
                    }
                    else
                    {
                        // if we already have a straight (5 cards) stop checking for more straights
                        if (cardsInARow >= 5)
                            break;
                        else
                        {
                            cardsInARow = 1;
                            winningCards.Clear();
                        }
                    }
                }
            }

            // Trim off any excess cards that are not the highest straight, and return true
            // Example: if you have A 2 3 4 5 6, the ace will be cut off and 2 3 4 5 6 will be preserved
            if (winningCards.Count >= 5)
            {
                if (winningCards.Count > 5)
                    winningCards.RemoveRange(0, winningCards.Count - 5);

                return true;
            }

            else
            {
                winningCards = null;
                return false;
            }
        }
コード例 #50
0
ファイル: HandEvaluator.cs プロジェクト: bberak/PokerDotNet
        public bool IsFlush(out CardCollection winningCards)
        {
            checkCardList();

            CardCollection cardList = new CardCollection(_cardList);

            CardCollection clubs = new CardCollection();
            CardCollection diamonds = new CardCollection();
            CardCollection hearts = new CardCollection();
            CardCollection spades = new CardCollection();

            foreach (Card card in cardList)
            {
                switch (card.Suit)
                {
                    case Suit.Clubs:
                        clubs.Add(card);
                        break;
                    case Suit.Diamonds:
                        diamonds.Add(card);
                        break;
                    case Suit.Hearts:
                        hearts.Add(card);
                        break;
                    case Suit.Spades:
                        spades.Add(card);
                        break;
                    default:
                        break;
                }
            }

            if (clubs.Count >= 5)
            {
                winningCards = clubs;
                winningCards.Sort();
                return true;
            }

            if (diamonds.Count >= 5)
            {
                winningCards = diamonds;
                winningCards.Sort();
                return true;
            }

            if (hearts.Count >= 5)
            {
                winningCards = hearts;
                winningCards.Sort();
                return true;
            }

            if (spades.Count >= 5)
            {
                winningCards = spades;
                winningCards.Sort();
                return true;
            }

            winningCards = null;
            return false;
        }
コード例 #51
0
ファイル: HandEvaluator.cs プロジェクト: bberak/PokerDotNet
        public bool CheckHighestPairConfiguration(out Hand hand)
        {
            checkCardList();

            // make a copy
            //List<Card> cardList = new List<Card>(_cardList);
            CardCollection cardList = new CardCollection(_cardList);
            cardList.Sort();

            // this is a list of cards that match the key value
            Dictionary<int, CardCollection> matches = new Dictionary<int, CardCollection>();

            int numPairs = 0;
            int numThrees = 0;
            int numFours = 0;

            // Construct the dictionary
            foreach (Card card in cardList)
            {
                if (matches.ContainsKey(card.Value))
                    matches[card.Value].Add(card);
                else
                    matches.Add(card.Value, new CardCollection(new Card[] { card }));
                    //matches.Add(card.Value, new List<Card>(new Card[] { card }));
            }

            // Determine the number of pairs, threes, and fours
            //foreach (List<Card> cardPairs in matches.Values)
            foreach (CardCollection cardPairs in matches.Values)
            {
                if (cardPairs.Count == 2)
                    numPairs++;

                if (cardPairs.Count == 3)
                    numThrees++;

                if (cardPairs.Count == 4)
                    numFours++;
            }

            //List<Card> resultCards = new List<Card>();
            CardCollection resultCards = new CardCollection();

            // Okay, here comes the real logic
            // One Pair and One Pair Only
            if (numPairs == 1 && numThrees == 0 && numFours == 0)
            {
                // Continue with the assumption that we'll only find one pair
                foreach (int cardValue in matches.Keys)
                {
                    if (matches[cardValue].Count == 2) // this is our pair
                    {
                        resultCards.AddRange(matches[cardValue]);
                        break;
                    }
                }

                // Also add the next highest card
                for (int highCard = cardList.Count - 1; highCard >= 0; highCard--)
                {
                    if (!resultCards.Contains(cardList[highCard]))
                    {
                        // Add the next highest card from the sorted list and break
                        resultCards.Add(cardList[highCard]);
                        break;
                    }
                }

                // Construct the Best Hand for one pair and return true
                //hand = new BestHand(resultCards, HandType.OnePair);
                hand = new Hand(resultCards, Combination.OnePair);
                return true;
            }

            // Two Pair and two pair only
            else if (numPairs >= 2 && numThrees == 0 && numFours == 0)
            {
                int numPairsFound = 0;

                // Continue with the assumption that we'll only find two pairs
                foreach (int cardValue in new Stack<int>(matches.Keys))
                {
                    if (matches[cardValue].Count == 2) // this is our pair
                    {
                        resultCards.AddRange(matches[cardValue]);
                        numPairs++;
                        if (numPairsFound >= 2)
                            break;
                    }
                }

                // Also add the next highest card
                for (int highCard = cardList.Count - 1; highCard >= 0; highCard--)
                {
                    if (!resultCards.Contains(cardList[highCard]))
                    {
                        // Add the next highest card from the sorted list and break
                        resultCards.Add(cardList[highCard]);
                        break;
                    }
                }

                // Construct the Best Hand for one pair and return true
                //hand = new BestHand(resultCards, HandType.TwoPair);
                hand = new Hand(resultCards, Combination.TwoPair);
                return true;
            }

            // Three of a kind only
            else if (numPairs == 0 && numThrees >= 1 && numFours == 0)
            {
                foreach (int cardValue in new Stack<int>(matches.Keys))
                {
                    if (matches[cardValue].Count == 3) // this is our highest 3
                    {
                        resultCards.AddRange(matches[cardValue]);
                        break;
                    }
                }

                // Also add the next highest card
                for (int highCard = cardList.Count - 1; highCard >= 0; highCard--)
                {
                    if (!resultCards.Contains(cardList[highCard]))
                    {
                        // Add the next highest card from the sorted list and break
                        resultCards.Add(cardList[highCard]);
                        break;
                    }
                }

                // Construct the Best Hand for one pair and return true
                //hand = new BestHand(resultCards, HandType.ThreeOfAKind);
                hand = new Hand(resultCards, Combination.ThreeOfAKind);
                return true;
            }

            // four of a kind only
            else if (numPairs <= 1 && numThrees <= 1 && numFours == 1)
            {
                foreach (int cardValue in new Stack<int>(matches.Keys))
                {
                    if (matches[cardValue].Count == 4) // this is the 4
                    {
                        resultCards.AddRange(matches[cardValue]);
                        break;
                    }
                }

                // Also add the next highest card
                for (int highCard = cardList.Count - 1; highCard >= 0; highCard--)
                {
                    if (!resultCards.Contains(cardList[highCard]))
                    {
                        resultCards.Add(cardList[highCard]);
                        break;
                    }
                }

                // Construct the Best Hand for one pair and return true
                //hand = new BestHand(resultCards, HandType.FourOfAKind);
                hand = new Hand(resultCards, Combination.FourOfAKind);
                return true;
            }

            // Full house only
            else if (numPairs >= 1 && numThrees == 1 && numFours == 0)
            {
                foreach (int cardValue in new Stack<int>(matches.Keys))
                {
                    if (matches[cardValue].Count == 3) // this is the 3 in the full house
                        resultCards.AddRange(matches[cardValue]);

                    if (matches[cardValue].Count == 2) // this is the 2
                        resultCards.AddRange(matches[cardValue]);

                    if (resultCards.Count >= 5)
                        break;
                }

                // Construct the Best Hand for one pair and return true
                //hand = new BestHand(resultCards, HandType.FullHouse);
                hand = new Hand(resultCards, Combination.FullHouse);
                return true;
            }

            else
            {
                // Just return the high card
                //List<Card> highCard = new List<Card>();
                CardCollection highCard = new CardCollection();
                highCard.Add(cardList[cardList.Count - 1]);
                //hand = new BestHand(highCard, HandType.HighCard);
                hand = new Hand(highCard, Combination.HighCard);
                return false;
            }
        }
コード例 #52
0
        public void CardCollection_UnEqualityTest()
        {
            CardCollection left = new CardCollection();

            ColorettoCard card1 = new ColorettoCard(ColorettoCardColors.Blue);
            ColorettoCard card2 = new ColorettoCard(ColorettoCardColors.Brown);
            ColorettoCard card3 = new ColorettoCard(ColorettoCardColors.Gray);

            left = left.Add(card1);
            left = left.Add(card2);
            left = left.Add(card3);

            CardCollection right = new CardCollection();

            card1 = new ColorettoCard(ColorettoCardColors.Blue);
            card2 = new ColorettoCard(ColorettoCardColors.Blue);
            card3 = new ColorettoCard(ColorettoCardColors.Gray);

            right = right.Add(card1);
            right = right.Add(card2);
            right = right.Add(card3);

            bool areEqual = left == right;
            Assert.IsFalse(areEqual);
        }
コード例 #53
0
        public void CountShouldReturnCorrectValueAfterAddingAllCards()
        {
            var collection = new CardCollection();
            foreach (CardSuit cardSuitValue in Enum.GetValues(typeof(CardSuit)))
            {
                foreach (CardType cardTypeValue in Enum.GetValues(typeof(CardType)))
                {
                    var card = new Card(cardSuitValue, cardTypeValue);
                    collection.Add(card);
                }
            }

            Assert.AreEqual(24, collection.Count);
        }
コード例 #54
0
		public override void Setup(Game game, Supply supply)
		{
			base.Setup(game, supply);

			CardCollection cards = new CardCollection();
			for (int i = 0; i < 10; i++)
			{
				cards.Add(new AbandonedMine());
				cards.Add(new RuinedLibrary());
				cards.Add(new RuinedMarket());
				cards.Add(new RuinedVillage());
				cards.Add(new Survivors());
			}

			Utilities.Shuffler.Shuffle<Card>(cards);

			supply.AddTo(cards.Take(10 * (game.Players.Count - 1)));
		}
コード例 #55
0
 public void CountShouldReturn1WhenOneCardIsAddedAndThenRemoved()
 {
     var collection = new CardCollection();
     var card = new Card(CardSuit.Club, CardType.Ace);
     collection.Add(card);
     collection.Remove(card);
     Assert.AreEqual(0, collection.Count);
 }
コード例 #56
0
		private void CardEffects(Player player)
		{
			// Perform attack on every player
			IEnumerator<Player> enumerator = player._Game.GetPlayersStartingWithEnumerator(player);
			enumerator.MoveNext();
			CardCollection trashed = new CardCollection();
			while (enumerator.MoveNext())
			{
				Player attackee = enumerator.Current;
				// Skip if the attack is blocked (Moat, Lighthouse, etc.)
				// The on-buy Attack can't be blocked, so make sure the player is in the dictionary first
				if (this.IsAttackBlocked.ContainsKey(attackee) && this.IsAttackBlocked[attackee])
					continue;

				attackee.Draw(2, DeckLocation.Revealed);

				Boolean gainCopper = false;
				if (attackee.Revealed[Cards.Category.Treasure].Count == 0)
					gainCopper = true;

				CardCollection treasuresSilverGold = attackee.Revealed[c => c.CardType == Universal.TypeClass.Silver || c.CardType == Universal.TypeClass.Gold];

				Choice choice = new Choice(String.Format("Choose a Treasure card of {0} to trash", attackee), this, treasuresSilverGold, attackee);
				ChoiceResult result = player.MakeChoice(choice);
				if (result.Cards.Count > 0)
				{
					Card trashCard = attackee.RetrieveCardFrom(DeckLocation.Revealed, result.Cards[0]);
					attackee.Trash(trashCard);
					trashed.Add(trashCard);
				}

				attackee.DiscardRevealed();

				if (gainCopper)
					attackee.Gain(player._Game.Table.Copper);
			}

			// Gain all trashed Silver & Golds
			foreach (Card card in trashed)
				player.Gain(player._Game.Table.Trash, card);
		}
コード例 #57
0
		public override void Play(Player player)
		{
			base.Play(player);

			SupplyCollection availableSupplies = new SupplyCollection(player._Game.Table.Supplies.Where(kvp => kvp.Value.Randomizer != null && kvp.Value.Randomizer.GroupMembership != Group.None));
			CardCollection cards = new CardCollection();
			Choice choice = new Choice("Name a card", this, availableSupplies, player, false);
			foreach (Supply supply in player._Game.Table.Supplies.Values.Union(player._Game.Table.SpecialPiles.Values))
			{
				foreach (Type type in supply.CardTypes)
				{
					if (!choice.Supplies.Any(kvp => kvp.Value.CardType == type))
						cards.Add(Card.CreateInstance(type));
				}
			}
			choice.AddCards(cards);

			ChoiceResult result = player.MakeChoice(choice);
			ICard namedCard = null;
			if (result.Supply != null)
				namedCard = result.Supply;
			else
				namedCard = result.Cards[0];

			player._Game.SendMessage(player, this, namedCard);

			Card foundCard = null;
			player.BeginDrawing();
			while (player.CanDraw)
			{
				player.Draw(DeckLocation.Revealed);
				Card lastRevealed = player.Revealed.Last();
				if ((lastRevealed.Category & Cards.Category.Victory) == Cards.Category.Victory &&
					namedCard.Name != lastRevealed.Name)
				{
					foundCard = lastRevealed;
					break;
				}
			}
			player.EndDrawing();

			if (foundCard != null)
				foundCard = player.RetrieveCardFrom(DeckLocation.Revealed, foundCard);

			player.DiscardRevealed();

			if (foundCard != null)
			{
				player.Trash(foundCard);

				Cost trashedCardCost = player._Game.ComputeCost(foundCard);
				SupplyCollection gainableSupplies = player._Game.Table.Supplies.FindAll(supply => supply.CanGain() && (supply.Category & Cards.Category.Victory) == Cards.Category.Victory && supply.CurrentCost <= (trashedCardCost + new Coin(3)));
				Choice choiceGain = new Choice("Gain a Victory card", this, gainableSupplies, player, false);
				ChoiceResult resultGain = player.MakeChoice(choiceGain);
				if (resultGain.Supply != null)
					player.Gain(resultGain.Supply);
			}
		}
コード例 #58
0
		public override void Setup(Game game, Supply supply)
		{
			base.Setup(game, supply);

			supply.Empty();

			CardCollection cards = new CardCollection();
			cards.Add(new DameAnna());
			cards.Add(new DameJosephine());
			cards.Add(new DameMolly());
			cards.Add(new DameNatalie());
			cards.Add(new DameSylvia());
			cards.Add(new SirBailey());
			cards.Add(new SirDestry());
			cards.Add(new SirMartin());
			cards.Add(new SirMichael());
			cards.Add(new SirVander());

			Utilities.Shuffler.Shuffle<Card>(cards);

			supply.AddTo(cards);
		}
コード例 #59
0
		private CardCollection GetSelectableCards(CleaningUpEventArgs e)
		{
			CardCollection allInPlayCards = new CardCollection();
			allInPlayCards.AddRange(e.CardsMovements.Where(cm =>
				((cm.Card.Category & Cards.Category.Action) == Cards.Category.Action) &&
				cm.CurrentLocation == DeckLocation.InPlay &&
				(cm.Destination == DeckLocation.SetAside || cm.Destination == DeckLocation.Discard)).Select(cm => cm.Card));

			// This is used to separate the In Play from the Set Aside for the Choice.MakeChoice call
			allInPlayCards.Add(new Universal.Dummy());

			allInPlayCards.AddRange(e.CardsMovements.Where(cm =>
				((cm.Card.Category & Cards.Category.Action) == Cards.Category.Action) &&
				cm.CurrentLocation == DeckLocation.SetAside &&
				cm.Destination == DeckLocation.Discard).Select(cm => cm.Card));

			if (allInPlayCards.FirstOrDefault() is Universal.Dummy)
				allInPlayCards.RemoveAt(0);
			if (allInPlayCards.LastOrDefault() is Universal.Dummy)
				allInPlayCards.RemoveAt(allInPlayCards.Count - 1);

			return allInPlayCards;
		}
コード例 #60
0
ファイル: Base.cs プロジェクト: micahpaul/dominion_net_multi
		public override void Play(Player player)
		{
			base.Play(player);

			// Perform attack on every player
			IEnumerator<Player> enumerator = player._Game.GetPlayersStartingWithEnumerator(player);
			enumerator.MoveNext();
			CardCollection trashed = new CardCollection();
			while (enumerator.MoveNext())
			{
				Player attackee = enumerator.Current;
				// Skip if the attack is blocked (Moat, Lighthouse, etc.)
				if (this.IsAttackBlocked[attackee])
					continue;

				attackee.Draw(2, DeckLocation.Revealed);

				CardCollection treasures = attackee.Revealed[Category.Treasure];

				Choice choice = new Choice(String.Format("Choose a Treasure card of {0} to trash", attackee), this, treasures, attackee);
				ChoiceResult result = player.MakeChoice(choice);
				if (result.Cards.Count > 0)
				{
					Card trashCard = attackee.RetrieveCardFrom(DeckLocation.Revealed, result.Cards[0]);
					attackee.Trash(trashCard);
					trashed.Add(trashCard);
				}

				attackee.DiscardRevealed();
			}

			Choice keepCards = new Choice("Choose which cards you'd like to gain from being trashed.", this, trashed, player, true, 0, trashed.Count);
			ChoiceResult keptCards = player.MakeChoice(keepCards);
			foreach (Card card in keptCards.Cards)
				player.Gain(player._Game.Table.Trash, card);
		}