public MatchingGameViewModel(CardDeck selectedDeck, bool isMatchingGame, int[] cardsOrder, bool[] cardsUseDuplicate, bool[] cardsIsMatched, bool[] cardsIsSelected)
            : this(selectedDeck, isMatchingGame, false)
        {
            // add card pair according to original cards order
            for (int i = 0; i < cardsOrder.Length; ++i)
            {
                CardPair cardPair = selectedDeck.Collection[cardsOrder[i]];
                if (cardsUseDuplicate[i])
                {
                    cardPair = cardPair.Duplicate();
                }

                cardPair.IsMatchingGame = isMatchingGame;
                cardPair.IsMatched      = cardsIsMatched[i];
                cardPair.IsLoaded       = true;
                //cardPair.IsSelected = cardsIsSelected[i];
                cardPair.SelectionChanged += new EventHandler(card_SelectionChanged);

                CardPairs.Add(cardPair);
            }

            SetRowsAndColumns();

            Matches = cardsIsMatched.Count(isMatched => isMatched) / 2;
        }
        public void Best_Empty_AreEqual()
        {
            var pairs = CardPairs.Create(Cards.Empty);

            var act = pairs.Best;
            var exp = 0;

            Assert.AreEqual(exp, act);
        }
        public void Second_56KK_AreEqual()
        {
            var cards = Cards.Parse("[5c,6c,Kh,Kc]");
            var pairs = CardPairs.Create(cards);

            var act = pairs.Second;
            var exp = 13;

            Assert.AreEqual(exp, act);
        }
        public void Best_56KQ_AreEqual()
        {
            var cards = Cards.Parse("[5c,6c,Kh,Qc]");
            var pairs = CardPairs.Create(cards);

            var act = pairs.Best;
            var exp = 13;

            Assert.AreEqual(exp, act);
        }
示例#5
0
        public GameAction Action(GameState state)
        {
            var pairs = CardPairs.Create(state.Own.Hand);

            // We have to (Small Blind), and a creapy hand.
            if (state.AmountToCall != 0 && state.Table.Count == 0)
            {
                if (pairs.Max < 2 && state.Own.Hand.Best.Height < 11)
                {
                    return(GameAction.Fold);
                }
                return(GameAction.Call);
            }
            // If we need to call, we call.
            if (state.AmountToCall != 0)
            {
                return(GameAction.Call);
            }
            // we check.
            return(GameAction.Check);
        }
        private void ShuffleCards()
        {
            SetRowsAndColumns();

#if !SILVERLIGHT
            Taskbar.UpdateTaskBarStatus(0, SelectedDeck.Count / 2);
#endif

            List <CardPair> cardpairs = Randomize <CardPair>(SelectedDeck.Collection.ToList()).Take(_countTotal / 2).ToList();

            foreach (CardPair card in CardPairs)
            {
                card.SelectionChanged -= new EventHandler(card_SelectionChanged);
            }

            CardPairs.Clear();

            Matches = 0;

            SlowCollectionAdd(cardpairs);
        }
        private void SlowCollectionAdd(List <CardPair> cardpairs)
        {
            List <CardPair> temp = new List <CardPair>();


            foreach (CardPair cpair in cardpairs)
            {
                cpair.IsSelected = false;

                CardPair dup = cpair.Duplicate();

                if (IsMatchingGame)
                {
                    dup.IsMatchingGame   = true;
                    cpair.IsMatchingGame = true;
                }
                else
                {
                    dup.IsMatchingGame   = false;
                    cpair.IsMatchingGame = false;
                }

                cpair.IsLoaded  = false;
                dup.IsLoaded    = false;
                cpair.IsMatched = false;
                dup.IsMatched   = false;

                temp.Add(cpair);
                temp.Add(dup);
            }

            cardpairs = Randomize <CardPair>(temp);
            List <int> indexCollection = new List <int>(); int i = 0;

            foreach (CardPair cp in cardpairs)
            {
                CardPairs.Add(cp);
                cp.SelectionChanged += new EventHandler(card_SelectionChanged);
                indexCollection.Add(i++);
            }

            //Randomize the IndexCollection
            indexCollection = Randomize <int>(indexCollection);

            DispatcherTimer _timer = new DispatcherTimer();

            _timer.Interval = TimeSpan.FromMilliseconds(MainViewModel.CardLoadingDelay); //Just waiting to Sync any animation in the View

            _timer.Tick += new EventHandler(delegate(object s, EventArgs ev)
            {
                int index = indexCollection.Count - 1;

                if (index == -1)
                {
                    _timer.Stop();
                }
                else
                {
                    CardPairs[indexCollection[index]].IsLoaded = true;
                    indexCollection.RemoveAt(index);
                }
            });

            _timer.Start();
        }