/// <summary>
        /// Zagrywa karte wyliczona przez algorytm.
        /// </summary>
        /// <param name="playerPossibleMoves">Wszystkie mozliwe ruchy gracza.</param>
        /// <param name="playerTrick">Kupka na ktora gracz zagrywa karte.</param>
        /// <param name="usedCards">Reka w ktorej przechowywane sa zagrane karty gracza.</param>
        /// <returns>Zagrana karta.</returns>
        private Card PlayCardChosenAlgorithm(Deck playerPossibleMoves, DeckShape playerTrick, Hand usedCards, AlgorithmTypes chosenAlg)
        {
            //tutaj jest wybor algorytmu - akurat teraz jest losowa karta z gory
            //var card = playerPossibleMoves.RandomCard;
            var card = ChooseAlgorithm(playerPossibleMoves, currentTrick.Count, currentTrick, chosenAlg);

            //zagraj karte zwrocona przez algorytm
            Card playedCard = new Card(card.Rank, card.Suit, playerPossibleMoves);

            PlayCard(playerPossibleMoves, playerTrick.Deck, card);

            //wylaczyc zeby dzialalo jeszcze szybciej
            //ExtraFunctions.WaitTime(10);

            usedCards.AddPlayed(playedCard);
            usedCards.SortLow();
            return(playedCard);
        }
        private void GameShape_CardDrag(CardShape cardShape, DeckShape oldDeckShape, DeckShape newDeckShape)
        {
            // check for lead suit renege

            if (((newDeckShape.Deck.TopCard == null) && (cardShape.Card.Number == 1)) ||
                ((newDeckShape.Deck.TopCard != null) && (cardShape.Card.Suit == newDeckShape.Deck.TopCard.Suit) && (cardShape.Card.Number - 1 == newDeckShape.Deck.TopCard.Number)))
            {
                //Move card to stack
                cardShape.Card.Deck = newDeckShape.Deck;

                //Flip the first remaining card in the old deck
                if (oldDeckShape.Deck.TopCard != null)
                {
                    oldDeckShape.Deck.TopCard.Visible    = true;
                    oldDeckShape.Deck.TopCard.Enabled    = true;
                    oldDeckShape.Deck.TopCard.IsDragable = true;
                }
            }
        }
        public void NewGame()
        {
            rowDecks = new List<Deck>();
            stackDecks = new List<Deck>();

            gameShape.Game = new Game();

            //Dealer
            dealer = new Deck(1, 13, gameShape.Game);
            dealer.Shuffle(5);
            dealer.FlipAllCards();
            dealer.EnableAllCards(false);
            dealer.MakeAllCardsDragable(false);
            dealer.Enabled = false;
            Dealer.Deck = dealer;
            gameShape.DeckShapes.Add(Dealer);
            Dealer.DeckMouseLeftButtonDown += new MouseButtonEventHandler(Dealer_DeckMouseLeftButtonDown);

            //Ground
            ground = new Deck(gameShape.Game);
            Ground.Deck = ground;
            Ground.UpdateCardShapes();
            gameShape.DeckShapes.Add(Ground);

            //Row Decks
            for (int i = 0; i < 7; i++)
            {
                Deck deck = new Deck(gameShape.Game);
                rowDecks.Add(deck);

                DeckShape deckShape = new DeckShape();
                gameShape.DeckShapes.Add(deckShape);
                deckShape.CardSpacerY = 20;
                deckShape.MaxCardsSpace = 10;
                deckShape.Deck = deck;

                this.LayoutRoot.Children.Add(deckShape);
                Canvas.SetLeft(deckShape, 25 + (i * 85));
                Canvas.SetTop(deckShape, 150);

                dealer.Draw(deck, i + 1);

                deck.TopCard.Visible = true;
                deck.TopCard.Enabled = true;
                deck.TopCard.IsDragable = true;
            }

            //Stack Decks
            for (int i = 0; i < 4; i++)
            {
                Deck deck = new Deck(gameShape.Game);
                stackDecks.Add(deck);

                DeckShape deckShape = new DeckShape();
                gameShape.DeckShapes.Add(deckShape);
                deckShape.CardSpacerY = 1;
                deckShape.MaxCardsSpace = 10;
                deckShape.Deck = deck;

                this.LayoutRoot.Children.Add(deckShape);
                Canvas.SetLeft(deckShape, 280 + (i * 85));
                Canvas.SetTop(deckShape, 24);
            }

            dealer.TopCard.Enabled = true;
            dealer.TopCard.IsDragable = false;
        }
        protected void gameShape_CardDrag(CardShape cardShape, DeckShape oldDeckShape, DeckShape newDeckShape)
        {
            if (oldDeckShape.Deck != newDeckShape.Deck)
            {
                //To Row Decks
                if (rowDecks.Contains(newDeckShape.Deck))
                {
                    //Color/Rank Rules
                    if (((newDeckShape.Deck.TopCard != null) && (cardShape.Card.Color != newDeckShape.Deck.TopCard.Color) && (cardShape.Card.Number + 1 == newDeckShape.Deck.TopCard.Number)) ||
                        ((newDeckShape.Deck.TopCard == null) && (cardShape.Card.Rank == CardRank.King)))
                    {
                        //Move the current card with all cards after it to the new deck
                        for (int i = oldDeckShape.Deck.Cards.IndexOf(cardShape.Card); i < oldDeckShape.Deck.Cards.Count; i++)
                        {
                            oldDeckShape.Deck.Cards[i].Deck = newDeckShape.Deck;
                            i--;
                        }

                        //Flip the first remaining card in the old deck
                        if (oldDeckShape.Deck.TopCard != null)
                        {
                            oldDeckShape.Deck.TopCard.Visible = true;
                            oldDeckShape.Deck.TopCard.Enabled = true;
                            oldDeckShape.Deck.TopCard.IsDragable = true;
                        }
                    }
                }

                //To Stack Decks
                if (stackDecks.Contains(newDeckShape.Deck))
                {
                    //Must be dragging one card only
                    if (oldDeckShape.Deck.Cards.IndexOf(cardShape.Card) == oldDeckShape.Deck.Cards.Count - 1)
                    {
                        if (((newDeckShape.Deck.TopCard == null) && (cardShape.Card.Number == 1)) ||
                            ((newDeckShape.Deck.TopCard != null) && (cardShape.Card.Suit == newDeckShape.Deck.TopCard.Suit) && (cardShape.Card.Number - 1 == newDeckShape.Deck.TopCard.Number)))
                        {
                            //Move card to stack
                            cardShape.Card.Deck = newDeckShape.Deck;

                            //Flip the first remaining card in the old deck
                            if (oldDeckShape.Deck.TopCard != null)
                            {
                                oldDeckShape.Deck.TopCard.Visible = true;
                                oldDeckShape.Deck.TopCard.Enabled = true;
                                oldDeckShape.Deck.TopCard.IsDragable = true;
                            }

                            //Check for winning condition
                            bool win = true;
                            for (int i = 0; i < 4; i++)
                            {
                                if ((stackDecks[i].TopCard == null) || (stackDecks[i].TopCard.Rank != CardRank.King))
                                    win = false;
                            }

                            if (win)
                            {
                                DoWinAnimation();
                            }
                        }
                    }
                }
            }
        }