Shuffle() public method

public Shuffle ( ) : void
return void
Beispiel #1
0
        public void Deck_Shuffle_Test()
        {
            // Arrange
            var position = 0;
            var newPosition = 0;
            var deck = new Deck();
            var positions = deck.Cards.ToDictionary(c => c, c => position++);

            // Act
            deck.Shuffle();

            foreach (var card in deck.Cards)
            {
                Console.WriteLine(card);
            }

            var positionChangeCount = deck.Cards.Select(c => positions[c] == newPosition++ ? 0 : 1).Sum();

            // Assert
            Assert.IsTrue(positionChangeCount > 52 * .9);
            Assert.AreEqual(52, deck.Cards.Count);
            Assert.AreEqual(52, deck.Cards.Distinct().Count());
            Assert.AreEqual(52, deck.Cards.Select(c => c.ToString()).Distinct().Count());
            Assert.AreEqual(52, deck.Cards.Select(c => c.GetHashCode()).Distinct().Count());
        }
Beispiel #2
0
        public void WhenADeckIsShuffled_TheCardsAreNotInExactlyTheSameOrderAsBefore()
        {
            var deck = new Deck();
            var expectedCardString = string.Empty;

            // Add Cards to Deck
            for (var i = 1; i <= 9; i++)
            {
                var card = deck.Push(new Cards.Number(i, CardColour.Blue));
                expectedCardString += string.Format("{0}{1}", card.Colour, card.Value);
            }

            // Shuffle the Deck
            deck.Shuffle();

            // Remove Cards from Deck
            var cards = new List<ICard>();
            while (deck.NumberOfCardsInDeck > 0)
            {
                cards.Add(deck.Pop());
            }

            // Build Compare Strings in reverse order because the Deck is a Stack (LIFO).  (I understand due to the way shuffling occurs that in theory the decks could be identical in some universe)
            var actualCardString = string.Empty;
            for (var i = cards.Count - 1; i >= 0; i--)
            {
                actualCardString += string.Format("{0}{1}", cards[i].Colour, cards[i].Value);
            }

            Assert.AreNotEqual(actualCardString, expectedCardString);
        }
Beispiel #3
0
        public void Shuffle_atDifferentTimes_produceDifferentOrders()
        {
            // arrange:
            SerialNumber number = new SerialNumber();
            IDeck deck = new Deck(number);
            DateTime time = DateTime.Now;

            // act:
            deck.Shuffle(time);
            Card[] afterFirstShuffle = deck.ToArray();
            deck.Shuffle(time + new TimeSpan(100)); // just to be sure :-D
            Card[] afterSecondShuffle = deck.ToArray();

            // assert:
            Assert.IsFalse(afterFirstShuffle.SequenceEqual(afterSecondShuffle));
        }
Beispiel #4
0
    void Awake()
    {
        Deck deck1 = new Deck();
        deck1.Shuffle();
        Card card1 = deck1.TakeCard();
        Card[] hand1 = new Card[5];
        hand1Size = hand1.Length;  // atribui o numero de cartas na mao

        for (i = 0; i < hand1.Length; i++)
        {
            hand1[i] = deck1.TakeCard();
        }

        //hand1[] = deck1.TakeCards(3);

        //IEnumerable < Card > = deck1.TakeCards();
        //Card mao1[] = deck1.TakeCards();

        //Debug.Log( card1.Suit.ToString() + card1.CardNumber.ToString() );
        for (i = 0; i < hand1.Length; i++)
        {
            Debug.Log(hand1[i].Suit.ToString() + hand1[i].CardNumber.ToString());
        }

        Debug.Log("tamanho da mao: " + hand1Size);
    }
Beispiel #5
0
        static void Main(string[] args)
        {
            Deck deck1 = new Deck();
            Deck deck2 = new Deck();

            int step = 0;
            bool flag = false;
            while (!flag)
            {
                deck2.Shuffle();
                for (int j = 0; j < 52; j++)
                {
                    if (deck1[j].ShortName == deck2[j].ShortName) flag = true;
                }
                step++;
            }

            for (int j = 0; j < 52; j++)
            {
                Console.WriteLine(String.Format("{0} \t{2}\t {1}", deck1[j].ShortName, deck2[j].ShortName, (deck1[j].ShortName == deck2[j].ShortName)?"-----":"     "));
            }
            Console.WriteLine(step);

            Console.ReadLine();
        }
Beispiel #6
0
        public void Deck_Should_Be_Without_Duplicates_After_Shuffle()
        {
            var deck = new Deck();
            var shuffledDeck = deck.Shuffle(deck.DeckBuilder());

            Assert.IsTrue(deck.IsDeckValid(shuffledDeck));
        }
 public static void TestDeck()
 {
     Console.ForegroundColor = ConsoleColor.Cyan;
     var d = new Deck();
     d.Shuffle();
     for (var i = 0; i < 52; i += 4)
         Console.WriteLine($"{i + 1}: {d.Pop()}   {i + 2}: {d.Pop()}   {i + 3}: {d.Pop()}   {i + 4}: {d.Pop()}");
 }
Beispiel #8
0
 public void testDeck()
 {
     Deck testDeck = new Deck();
     testDeck.CreateDeck();
     testDeck.DrawCard();
     testDeck.Shuffle();
     Assert.IsNotNull(testDeck);
 }
Beispiel #9
0
 public Game()
 {
     Deck = new Deck();
     Deck.Shuffle();
     Finished = false;
     Moves = 0;
     Round = 1;
 }
Beispiel #10
0
        public void Deck_Shuffle_VerifyNotInOrder()
        {
            // Arrange
            var deck = new Deck();

            // Act
            deck.Shuffle();
        }
        public void Shuffle_ShouldShuffleSuccessfully()
        {
            var shuffleMock = OpositeOrderShufflerMock();
            var initCards = RandomStandartCards();
            var deck = new Deck<StandartCard>(shuffleMock.Object, initCards);

            deck.Shuffle();

            shuffleMock.Verify(x => x.Shuffle(It.IsAny<List<StandartCard>>()));
        }
Beispiel #12
0
        public void Shuffle_withTheSameTimeOnTheSameDeck_isIdempotent()
        {
            // arrange:
            SerialNumber number = new SerialNumber();
            IDeck deck = new Deck(number);
            DateTime time = DateTime.Now;

            // act:
            deck.Shuffle(time);
            Card[] afterFirstShuffle = deck.ToArray();
            deck.Shuffle(time);
            Card[] afterSecondShuffle = deck.ToArray();

            // assert:
            for(int i = 0; i < deck.Count(); ++i)
            {
                Assert.AreSame(afterFirstShuffle[i], afterSecondShuffle[i]);
            }
        }
        public void RunManyMaxAverageDecisions()
        {
            var decision = new MaxAverageDecision();
            var deck = new Deck();

            foreach (var index in Enumerable.Range(0, 1000))
            {
                deck.Shuffle();
                decision.DetermineCardsToThrow(deck.Take(6));
            }
        }
Beispiel #14
0
 public Game(Player Master, List<Player> Learners, Random Random)
 {
     _Random = Random;
     _Deck = new Deck();
     _Deck.Shuffle(_Random);
     _Return = new Deck(true);
     _Master = Master;
     _Learners = Learners;
     _MasterHand = new Hand(10, _Deck);
     foreach(Player L in _Learners) _LearnerHands.Add(new Hand(10, _Deck));
     _DownCard = _Deck.Draw();
 }
 public string PopHand()
 {
     if (!(CanPopHand))
     {
         deck = new Deck();
         deck.Shuffle();
     }
     string[] cards = { Pop(), Pop(), Pop(), Pop(), Pop() };
     var s = new StringBuilder();
     for (int i = 0; i < 5; i++)
         s.Append(cards[i].ToString() + (i < 4 ? ", " : ""));
     return s.ToString();
 }
Beispiel #16
0
 public void TestSort()
 {
     var trials = 100; // Arbitrary number
     var newDeck = new Deck();
     var deck = new Deck();
     for (int i = 0; i < trials; i++)
     {
         deck.Shuffle();
         Assert.AreNotEqual(newDeck, deck);
         deck.Sort();
         Assert.AreEqual<Deck>(newDeck, deck);
     }
 }
Beispiel #17
0
        /// <summary> 
        /// A single hand of Blackjack
        /// </summary> 
        /// <param name="args">command-line args</param> 
        static void Main(string[] args)
        {
            //Declare variables for and create a deck of cards and blackjack hands for the dealer and the player

            Deck deck = new Deck();
            BlackjackHand dealerHand = new BlackjackHand("Dealer");
            BlackjackHand playerHand = new BlackjackHand("Player");

            //Print a “welcome” message to the user telling them that the program will play a single hand of Blackjack

            Console.WriteLine("You will play a single hand of Blackjack.");

            // Shuffle the deck of cards

            deck.Shuffle();

            //Deal 2 cards to the player and dealer
            dealerHand.AddCard(deck.TakeTopCard());
            playerHand.AddCard(deck.TakeTopCard());

            //Show all the player’s cards

            playerHand.ShowAllCards();

            //Show the dealer’s first card

            dealerHand.ShowFirstCard();

            //Print both the player’s hand and the dealer’s hand

            playerHand.Print();
            dealerHand.Print();

            //Let the player hit if they want to

            playerHand.HitOrNot(deck);

            //Show all the dealer’s cards

            dealerHand.ShowAllCards();

            //Print both the player’s hand and the dealer’s hand

            playerHand.Print();
            dealerHand.Print();

            //Print the scores for both hands

            Console.WriteLine("Player's score: " + playerHand.Score + ".");
            Console.WriteLine("Dealer's score: " + dealerHand.Score + ".");
        }
Beispiel #18
0
    static void Main(string[] args)
    {
        // Create new instances of classes
            Deck deck = new Deck();

            Player[] players = new Player[2];
            players[0] = new Player("Player 1");
            players[1] = new Player("Player 2");

            deck.Shuffle(); // Shuffle the deck

        //for (int i = 0; i < 5;i++) // Deal 5 cards to each player
        //{
        //    players[0].addCardToHand(deck.dealCard());
        //    players[1].addCardToHand(deck.dealCard());

        //}
        players[0].addCardToHand(new Card(Suit.Spades, Value.Eight));
        players[0].addCardToHand(new Card(Suit.Spades, Value.Nine));
        players[0].addCardToHand(new Card(Suit.Spades, Value.Ten));
        players[0].addCardToHand(new Card(Suit.Spades, Value.Knight));
        players[0].addCardToHand(new Card(Suit.Spades, Value.Queen));
        players[1].addCardToHand(new Card(Suit.Clubs, Value.Seven));
        players[1].addCardToHand(new Card(Suit.Clubs, Value.Eight));
        players[1].addCardToHand(new Card(Suit.Clubs, Value.Nine));
        players[1].addCardToHand(new Card(Suit.Clubs, Value.Ten));
        players[1].addCardToHand(new Card(Suit.Clubs, Value.Knight));

        players[0].sortHand();
            players[1].sortHand();

            // Print Test info to console
            players[0].printPlayerInfo();
            players[0].printPlayerHand();
            Console.WriteLine();

            players[1].printPlayerInfo();
            players[1].printPlayerHand();

        Console.WriteLine();
        //    Console.WriteLine(players[0].getPokerHand().pokerHand + " in " + players[0].getPokerHand().rank1 + " and " + players[0].getPokerHand().rank2);
        //Console.WriteLine(players[1].getPokerHand().pokerHand + " in " + players[1].getPokerHand().rank1 + " and " + players[1].getPokerHand().rank2);

        List<Poker.PokerHandValue> _pHand = new List<Poker.PokerHandValue>{ Poker.getPokerHand(players[0].Hand), Poker.getPokerHand(players[1].Hand) };

        Console.WriteLine("{0} Hand: {1}", players[0].Name, _pHand[0].pokerHand);
        Console.WriteLine("{0} Hand: {1}", players[1].Name, _pHand[1].pokerHand);
        int highindex = Poker.ComparePokerHand(_pHand);
        Console.WriteLine("{0} has highest hand: {1} and wins.",players[highindex].Name,_pHand[highindex].pokerHand);
        Console.ReadKey(); // Wait for keypress
    }
Beispiel #19
0
        public void Decks_with_different_seed_does_not_generate_equal_decks()
        {
            // Arrange.
            var seed = Environment.TickCount;
            var sut = new Deck();
            var other = new Deck();

            // Act.
            sut.Shuffle(seed);
            other.Shuffle(seed + 1);

            // Assert.
            Assert.That(sut.Equals(other), Is.False);
        }
Beispiel #20
0
        public void Shuffle_withTheSameTimeOnDifferentDecks_produceDifferentOrders()
        {
            // arrange:
            IDeck firstDeck = new Deck(new SerialNumber());
            IDeck secondDeck = new Deck(new SerialNumber());
            DateTime time = DateTime.Now;

            // act:
            firstDeck.Shuffle(time);
            secondDeck.Shuffle(time);

            // assert:
            Assert.IsFalse(firstDeck.SequenceEqual(secondDeck));
        }
Beispiel #21
0
        public void Decks_with_same_seed_generate_equal_decks()
        {
            // Arrange.
            var seed = Environment.TickCount;
            var sut = new Deck();
            var other = new Deck();

            // Act.
            sut.Shuffle(seed);
            other.Shuffle(seed);

            // Assert.
            Assert.That(sut.Equals(other), Is.True);
        }
Beispiel #22
0
 public void TestShuffle()
 {
     var trials = 100; // Arbitrary number
     var decksSeen = new List<Deck>();
     var deck = new Deck();
     for (int i = 0; i < trials; i++)
     {
         decksSeen.Add(new Deck(deck));
         deck.Shuffle();
         foreach (var seen in decksSeen)
         {
             Assert.AreNotEqual(seen, deck);
         }
     }
 }
Beispiel #23
0
        public void GetEnumerator_afterAShuffle_dontChangeTheCardsOrderOnHisOwn()
        {
            // arrange:
            SerialNumber number = new SerialNumber();
            IDeck deck = new Deck(number);
            DateTime time = DateTime.Now;

            // act:
            deck.Shuffle(time);
            Card[] firstRead = deck.ToArray();
            Thread.Sleep(1000); // just to be sure :-)
            Card[] secondRead = deck.ToArray();

            // assert:
            Assert.IsTrue(firstRead.SequenceEqual(secondRead));
        }
        /// <summary>
        /// Let you play a hand of Blackjack
        /// </summary>
        /// <param name="args">command-line args</param>
        static void Main(string[] args)
        {
            //create deck and two hands
            Deck deck = new Deck();
            BlackjackHand dealerHand = new BlackjackHand("Dealer");
            BlackjackHand playerHand = new BlackjackHand("Player");

            //print welcome message
            Console.WriteLine("Welcome friend!");
            Console.WriteLine("You are now going to play a single hand of Blackjack\n");

            //shuffle the deck
            deck.Shuffle();

            //deal two cards for player
            playerHand.AddCard(deck.TakeTopCard());
            playerHand.AddCard(deck.TakeTopCard());

            //deal two cards for dealer
            dealerHand.AddCard(deck.TakeTopCard());
            dealerHand.AddCard(deck.TakeTopCard());

            //make all player's cards face up
            playerHand.ShowAllCards();

            //make first dealer's card face up
            dealerHand.ShowFirstCard();

            //print both hands
            playerHand.Print();
            dealerHand.Print();

            //ask player if he wants to "hit"
            playerHand.HitOrNot(deck);

            //make all dealer's card face up
            dealerHand.ShowAllCards();

            //print both hands
            playerHand.Print();
            dealerHand.Print();

            //print scores
            Console.WriteLine("Player score: {0}", playerHand.Score);
            Console.WriteLine("Dealer score: {0}", dealerHand.Score);
        }
Beispiel #25
0
        static void Main()
        {
            _player1 = new Player();
            _player2 = new Player();
            _deck = Deck.GetDeck();

            do
            {
                PlayRound(_player1, _player2);

                Console.Write("Press enter for another round. Type 'exit' to quit: ");
                var input = Console.ReadLine();
                if (input == "exit")
                {
                    break;
                }

                _deck.Shuffle();
            } 
            while (true);
        }
        /// <summary>Main Program</summary>
        public static void Main(string[] args)
        {
            // create puzzle
            Puzzle puzzle = new Puzzle(7);

            // create Deck
            Deck deck = new Deck();
            IEnumerable<PlayingCard> shuffledDeck = deck.Shuffle();

            // add cards to puzzle
            foreach (PlayingCard card in shuffledDeck.Take<PlayingCard>(7)) {
                puzzle.Add(card);
            }

            // lets show the puzzle, compuute the best hand, and show that
            Console.WriteLine("Puzzle cards: " + puzzle.ToString());

            PokerHand bestHand = puzzle.GetBestHandPossible();

            Console.WriteLine("Best hand: " + bestHand.ToString() );
            Console.WriteLine("Score: " + bestHand.ScoreHand() );
        }
Beispiel #27
0
        public void DrawHands_draws_the_top_cards_from_the_stack()
        {
            // Arrange.
            var seed = Environment.TickCount;
            var sut = new Deck();
            var controlDeck = new Deck();
            sut.Shuffle(seed);
            controlDeck.Shuffle(seed);

            // Act.
            var hands = sut.DrawHands(2);
            var controlHands = hands.Select(hand => hand.Select(card => controlDeck.Draw())).ToList();

            // Assert.
            for (int i = 0; i < hands.Count; i++)
            {
                var hand = hands[i];
                var controlHand = controlHands[i];
                ActualValueDelegate<bool> test = () => hand.SequenceEqual(controlHand);
                Assert.That(test, Is.True);
            }
        }
Beispiel #28
0
 private void CreateGameDeck()
 {
     GameDeck = new Deck();
     GameDeck.Shuffle();
 }
Beispiel #29
0
        /// <summary>
        /// Blackjack game in console
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Declare varables for and create a deck of cards and blackjack hands for the dealer and the player
            Deck          deck0      = new Deck();
            BlackjackHand playerHand = new BlackjackHand("Player");
            BlackjackHand dealerHand = new BlackjackHand("Dealer");

            //Print a “welcome” message to the user telling them that the program will play a single hand of Blackjack
            Console.WriteLine("Welcome to Blackjack game (Single hand version)\n");

            //Shuffle the deck of cards
            deck0.Shuffle();

            //Deal 2 cards to the player and dealer
            playerHand.AddCard(deck0.TakeTopCard());
            dealerHand.AddCard(deck0.TakeTopCard());
            playerHand.AddCard(deck0.TakeTopCard());
            dealerHand.AddCard(deck0.TakeTopCard());

            // Make all the player’s cards face up (you need to see what you have!); there's a method for this in the BlackjackHand class
            playerHand.ShowAllCards();

            //Make the dealer’s first card face up (the second card is the dealer’s “hole” card); there's a method for this in the BlackjackHand class
            dealerHand.ShowFirstCard();

            //Print both the player’s hand and the dealer’s hand
            playerHand.Print();
            dealerHand.Print();

            //Let the player hit if they want to
            playerHand.HitOrNot(deck0);

            //(ignore this) experimental code - looping invalid input (I only realised there's a HitOrNot meathod for this after wasting the time)
            ConsoleKeyInfo key;
            int            i = 1;

            while (i == 1)
            {
                i--;
                if (key.Key == ConsoleKey.Enter)
                {
                    Console.Write("\nDo you want to hit? (y/n):");
                    key = Console.ReadKey();
                    i++;
                }
                else
                {
                    if (key.Key == ConsoleKey.Y)
                    {
                        Console.WriteLine("\nyes");
                    }
                    else if (key.Key == ConsoleKey.N)
                    {
                        Console.WriteLine("\nno");
                    }
                    else
                    {
                        Console.Write("\nDo you want to hit? (y/n):");
                        key = Console.ReadKey();
                        i++;
                    }
                }
            }

            //Make all the dealer’s cards face up; there's a method for this in the BlackjackHand class
            dealerHand.ShowAllCards();

            //Print both the player’s hand and the dealer’s hand
            playerHand.Print();
            dealerHand.Print();

            //Print the scores for both hands
            Console.WriteLine("Your score is:" + playerHand.Score);
            Console.WriteLine("The dealer's score is:" + dealerHand.Score);

            //(Ignore this) Calculate who won
            if (playerHand.Score == 21)
            {
                Console.WriteLine("Blackjack! You won!");
            }
            else if (playerHand.Score > 21 || playerHand.Score < dealerHand.Score)
            {
                Console.WriteLine("You lost!");
            }
            else if (playerHand.Score == dealerHand.Score)
            {
                Console.WriteLine("Push!");
            }
            else
            {
                Console.WriteLine("You won!");
            }
        }
        /// <summary>
        /// Console application that plays Blackjack
        /// </summary>
        /// <param name="args">command-line args</param>

        static void Main(string[] args)
        {
            // Create a deck of cards
            Deck deck = new Deck();

            // Create blackjack hands for the dealer and the player
            BlackjackHand playerHand = new BlackjackHand("Player");
            BlackjackHand dealerHand = new BlackjackHand("Dealer");

            // Print a “welcome” message to the user
            Console.WriteLine("Welcome player. The program will play a single hand of Blackjack.");
            Console.WriteLine();

            // Shuffle the deck of cards
            deck.Shuffle();

            // Deal 2 cards to the player and dealer
            // Otherwise
            // Card card; // Create a card
            // card = deck.TakeTopCard();
            // playerHand.AddCard(card);
            // card = deck.TakeTopCard();
            // playerHand.AddCard(card);
            // card = deck.TakeTopCard();
            // dealerHand.AddCard(card);
            // card = deck.TakeTopCard();
            // dealerHand.AddCard(card);
            playerHand.AddCard(deck.TakeTopCard());
            dealerHand.AddCard(deck.TakeTopCard());
            playerHand.AddCard(deck.TakeTopCard());
            dealerHand.AddCard(deck.TakeTopCard());

            // Make all the player’s cards face up
            playerHand.ShowAllCards();

            //Make the dealer’s first card face up
            dealerHand.ShowFirstCard();

            // Print both the player’s hand and the dealer’s hand
            playerHand.Print();
            dealerHand.Print();

            // Let the player hit if they want to
            // Otherwhise
            // Console.Write("Hit or stand? (h or s): ");
            // char answer = Console.ReadLine()[0];
            // Console.WriteLine();
            //
            // if (answer == 'h')
            // {
            //     card = deck.TakeTopCard();
            //     playerHand.AddCard(card);
            //     playerHand.ShowAllCards();
            // }
            playerHand.HitOrNot(deck);

            // Make all the dealer’s cards face up
            dealerHand.ShowAllCards();

            // Print both the player’s hand and the dealer’s hand
            playerHand.Print();
            dealerHand.Print();

            // Print the scores for both hands
            // Otherwhise
            // int playerScore = playerHand.Score;
            // Console.WriteLine("The player score is: " + playerScore);
            // int dealerScore = dealerHand.Score;
            // Console.WriteLine("The dealer score is: " + dealerScore);
            Console.WriteLine("The player score is: " + playerHand.Score);
            Console.WriteLine("The dealer score is: " + dealerHand.Score);
            Console.WriteLine();

            Console.ReadKey();
        }
Beispiel #31
0
        public async Task StartGame()
        {
            deck.Shuffle();
            //TODO remove test case
            if (Players.Count == 3)
            {
                deck.RemoveReduntant();
            }
            else if (Players.Count != 2)
            {
                return;
            }

            int deckCount = deck.cards.Count;

            foreach (ClientHandler cl in Players)
            {
                for (int i = 0; i < deckCount / Players.Count; i++)
                {
                    cl.PlayerStats.Hand.Add(deck.Deal());
                }
            }

            try
            {
                await UpdateCards(UpdateContent.Hand);

                //TODO zmienić kolejność przekazywania kart po ukończeniu rozgrywki
                for (int i = 0; i < Players.Count; i++)
                {
                    Message response = await Players[i].SendData(new Message(MessageType.PassOn, null));
                    //Players[i].PlayerStats.Hand = Players[i].PlayerStats.Hand.Except(response.CardsRequested).ToList();

                    foreach (Card c in response.CardsRequested)
                    {
                        for (int j = 0; j < Players[i].PlayerStats.Hand.Count; j++)
                        {
                            if (c.Equals(Players[i].PlayerStats.Hand[j]))
                            {
                                Players[i].PlayerStats.Hand.Remove(Players[i].PlayerStats.Hand[j]);
                            }
                        }
                    }

                    int index = 0;

                    if (i + 1 <= Players.Count - 1)
                    {
                        index = i + 1;
                        Players[index].PlayerStats.Hand.AddRange(response.CardsRequested);
                    }
                    else
                    {
                        index = Players.Count - (i + 1);
                        Players[index].PlayerStats.Hand.AddRange(response.CardsRequested);
                    }

                    await Players[i].SendData(new Message(MessageType.ShowCards, null, Players[i].PlayerStats.Hand.ToArray()), false);
                }
                //TODO REFACTOR
                await UpdateCards(UpdateContent.Hand);

                await PlayFirstRound();

                int x = 0;
                while (!isEnd)
                {
                    x++;
                    // Test log
                    Console.WriteLine($"New round: {x}");
                    //
                    await PlayRound();

                    ClientHandler winner = CheckIfOver();

                    if (winner != null)
                    {
                        isEnd = true;
                        await winner.SendData(new Message(MessageType.Win, null, null), false);
                    }
                }

                Console.WriteLine("KONIEC GRY!");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
Beispiel #32
0
        static void Main(string[] args)
        {
            // Declare variables that we want in scope for this entire method.
            Deck   myDeck    = new Deck();
            string userInput = "";
            bool   isFlush   = false;
            int    firstCard = 0;

            // Track how many decks we use.
            int deckNumber = 0;

            // Set the hand to a number that will trigger a shuffle on the first iteration of
            // the outer loop.
            int hand = 99;

            // Keep shuffling until the user enters "Q" or "q" to quit.
            do
            {
                // Keep making 5-card draws until the current deck is exhausted. Once a deck is
                // is exhausted, reset the hand counter and shuffle the deck.
                if (hand >= 10)
                {
                    hand = 1;
                    deckNumber++;
                    WriteLine($"Drawing from deck number {deckNumber}...");
                    myDeck.Shuffle();
                }
                else
                {
                    hand++;
                }


                // Store the index to the first card in the current hand. This can be used
                // later to display the cards in this hand.
                firstCard = (hand - 1) * 5;

                // Initialize the flag for a flush to true, since we will assume this hand
                // is a flush until we turn over the first card that proves otherwise.
                isFlush = true;

                // Store the suit of the first card in the hand. This is the suit we need to
                // match to get a flush.
                Suit currentSuit = myDeck.GetCard(firstCard).suit;
                //Write(myDeck.GetCard(firstCard).ToString());

                // Check the rest of the cards in the hand.
                for (int i = 1; i < 5; i++)
                {
                    //Write(", " + myDeck.GetCard(firstCard + i).ToString());

                    // As soon as we find a card that doesn't match the suit, we need to clear
                    // the flag, and we can stop checking this hand.
                    if (myDeck.GetCard(firstCard + i).suit != currentSuit)
                    {
                        isFlush = false;
                        break;
                    }
                }

                Write($"Hand {hand}: ");
                if (isFlush)
                {
                    // We got a flush! Display the hand, and wait for the user to press a key.
                    // Then exit the outer loop, ending the program.
                    WriteLine("Flush!");
                    for (int i = 0; i < 5; i++)
                    {
                        WriteLine(myDeck.GetCard(firstCard + i).ToString());
                    }
                    ReadKey();
                    break;
                }
                else
                {
                    // No flush for this hand. On the last hand of the deck, prompt the user to
                    // allow the opportunity to quit.
                    WriteLine("No flush");
                    if (hand == 10)
                    {
                        userInput = ReadLine();
                    }
                }

                // Check if the user wants to [Q]uit before the next pass.
            } while (userInput.ToLower() != "q");
        }
Beispiel #33
0
        public static void PlaygetCard()
        {
            paper.Shuffle();
            Card play1 = paper.Dealer();

            playhand[arrayCount] = play1;
            arrayCount++;
            if (play1.getFaceValue() == Card.FACEVALUE.ace)
            {
                if ((playerhand + 11) > 21)
                {
                    playerhand += 1;
                    Console.WriteLine("you got an ace but it has to be one not to bust");
                }
                else
                {
                    playerhand += 11;
                    Console.WriteLine("you got an ace, since you wont bust, its value is 11");
                }
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.two)
            {
                playerhand += 2;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.three)
            {
                playerhand += 3;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.four)
            {
                playerhand += 4;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.five)
            {
                playerhand += 5;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.six)
            {
                playerhand += 6;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.seven)
            {
                playerhand += 7;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.eight)
            {
                playerhand += 8;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.nine)
            {
                playerhand += 9;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.ten)
            {
                playerhand += 10;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.jack)
            {
                playerhand += 10;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.queen)
            {
                playerhand += 10;
            }
            else if (play1.getFaceValue() == Card.FACEVALUE.king)
            {
                playerhand += 10;
            }
        }
        public override void AI()
        {
            //QwertyMethods.ServerClientCheck(timer);
            if (Main.expertMode)
            {
                timeBetweenAttacks = 60;
            }
            Player player = Main.player[npc.target];

            npc.chaseable = false;
            if (chargeTime > 0)
            {
                npc.chaseable = true;
            }
            else
            {
                for (int i = 0; i < Main.player.Length; i++)
                {
                    if ((Main.player[i].active && (QwertysRandomContent.LocalCursor[i] - npc.Center).Length() < 180) || (Main.player[i].Center - npc.Center).Length() < playerviewRadius)
                    {
                        npc.chaseable = true;
                        break;
                    }
                }
            }
            npc.TargetClosest(false);
            pupilDirection      = (player.Center - npc.Center).ToRotation();
            pulseCounter       += (float)Math.PI / 30;
            npc.scale           = 1f + .05f * (float)Math.Sin(pulseCounter);
            pupilStareOutAmount = (player.Center - npc.Center).Length() / 300f;
            if (pupilStareOutAmount > 1f)
            {
                pupilStareOutAmount = 1f;
            }
            blinkCounter--;
            if (blinkCounter < 0)
            {
                if (blinkCounter % 10 == 0)
                {
                    if (frame == 7)
                    {
                        blinkCounter = Main.rand.Next(180, 240);
                    }
                    else
                    {
                        frame++;
                    }
                }
            }
            else
            {
                frame = 0;
            }
            if (!player.active || player.dead)
            {
                npc.TargetClosest(false);
                player = Main.player[npc.target];
                if (!player.active || player.dead)
                {
                    canDespawn   = true;
                    npc.velocity = new Vector2(0f, 10f);
                    if (npc.timeLeft > 10)
                    {
                        npc.timeLeft = 10;
                    }
                    return;
                }
            }
            else
            {
                canDespawn = false;
                if ((cloak == null || cloak.type != mod.ProjectileType("Cloak") || !cloak.active) && Main.netMode != 1)
                {
                    cloak = Main.projectile[cloakID = Projectile.NewProjectile(npc.Center, Vector2.Zero, mod.ProjectileType("Cloak"), 0, 0, Main.myPlayer, npc.whoAmI)];
                }
                if (attacks.Count > 0)
                {
                    if (!rage && (float)npc.life / (float)npc.lifeMax < .2f)
                    {
                        rage = true;
                        attacks.Clear();
                    }
                    timer++;
                    if (timer > timeBetweenAttacks + startAttacksDelay + forecastTime)
                    {
                        switch ((int)attacks[0].X)
                        {
                        case 0:
                            if (Main.netMode != 1)
                            {
                                for (int t = 0; t < 4; t++)
                                {
                                    float      r      = attacks[0].Y + t * (float)Math.PI / 2;
                                    Projectile turret = Main.projectile[Projectile.NewProjectile(player.Center + QwertyMethods.PolarVector(orbitDistance, r), Vector2.Zero, mod.ProjectileType("Cannon"), Main.expertMode ? 22 : 35, 0f, Main.myPlayer)];
                                    turret.rotation  = r + (float)Math.PI;
                                    turret.netUpdate = true;
                                }
                            }
                            break;

                        case 1:
                            chargeTime   = 60;
                            npc.Center   = player.Center + QwertyMethods.PolarVector(-600, attacks[0].Y);
                            npc.velocity = QwertyMethods.PolarVector(20, attacks[0].Y);
                            Main.PlaySound(mod.GetLegacySoundSlot(SoundType.Custom, "Sounds/SoundEffects/Warp"), npc.Center);
                            break;

                        case 2:
                            if (Main.netMode != 1)
                            {
                                Projectile catalyst = Main.projectile[Projectile.NewProjectile(player.Center, Vector2.Zero, mod.ProjectileType("BloodforceCatalyst"), Main.expertMode ? 20 : 34, 0f, Main.myPlayer)];
                                catalyst.rotation  = attacks[0].Y - (float)Math.PI / 4;
                                catalyst.netUpdate = true;
                            }

                            break;

                        case 3:
                            if (Main.netMode != 1)
                            {
                                Projectile tripwire = Main.projectile[Projectile.NewProjectile(player.Center + QwertyMethods.PolarVector(300, attacks[0].Y), Vector2.Zero, mod.ProjectileType("Tripwire"), Main.expertMode ? 30 : 45, 0f, Main.myPlayer)];
                                tripwire.rotation  = attacks[0].Y + (float)Math.PI / 2;
                                tripwire.timeLeft  = timeBetweenAttacks * attacks.Count + 60;
                                tripwire.netUpdate = true;
                            }

                            break;
                        }
                        attacks.RemoveAt(0);
                        timer = startAttacksDelay + forecastTime;
                    }
                    else if (timer > startAttacksDelay + forecastTime)
                    {
                    }
                    else if (timer < forecastTime)
                    {
                    }
                }
                else
                {
                    timer = -retreatTime;
                    if (Main.netMode != 1)
                    {
                        float ratio = (float)npc.life / (float)npc.lifeMax;
                        if (ratio > .9f)
                        {
                            attacks.Add(new Vector2(0, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(0, randomRotation()));
                        }
                        else if (ratio > .8f)
                        {
                            attacks.Add(new Vector2(0, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(2, randomRotation()));
                            attacks.Shuffle();
                        }
                        else if (ratio > .7f)
                        {
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(2, randomRotation()));
                            attacks.Add(new Vector2(2, randomRotation()));
                            attacks.Shuffle();
                        }
                        else if (ratio > .6f)
                        {
                            attacks.Add(new Vector2(3, randomRotation()));
                            attacks.Add(new Vector2(3, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                        }
                        else if (ratio > .5f)
                        {
                            attacks.Add(new Vector2(2, randomRotation()));
                            attacks.Add(new Vector2(0, randomRotation()));
                            attacks.Add(new Vector2(0, randomRotation()));
                            attacks.Add(new Vector2(0, randomRotation()));
                            attacks.Add(new Vector2(0, randomRotation()));
                            attacks.Shuffle();
                            attacks.Insert(0, new Vector2(3, randomRotation()));
                        }
                        else if (ratio > .4f)
                        {
                            attacks.Add(new Vector2(3, randomRotation()));
                            attacks.Add(new Vector2(3, randomRotation()));
                            attacks.Add(new Vector2(2, randomRotation()));
                            attacks.Add(new Vector2(2, randomRotation()));
                            attacks.Add(new Vector2(2, randomRotation()));
                        }
                        else if (ratio > .3f)
                        {
                            attacks.Add(new Vector2(2, randomRotation()));
                            attacks.Add(new Vector2(2, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(3, randomRotation()));
                            attacks.Shuffle();
                            attacks.Insert(0, new Vector2(3, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                        }
                        else if (ratio > .2f)
                        {
                            attacks.Add(new Vector2(3, randomRotation()));
                            attacks.Add(new Vector2(3, randomRotation()));
                            attacks.Add(new Vector2(3, randomRotation()));
                            attacks.Add(new Vector2(2, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                            attacks.Add(new Vector2(1, randomRotation()));
                        }
                        else if (ratio > .1f)
                        {
                            for (int i = 0; i < 12; i++)
                            {
                                attacks.Add(new Vector2(2, randomRotation()));
                            }
                        }
                        else
                        {
                            attacks.Add(new Vector2(3, randomRotation()));
                            attacks.Add(new Vector2(3, randomRotation()));
                            for (int i = 0; i < 10; i++)
                            {
                                attacks.Add(new Vector2(2, randomRotation()));
                            }
                        }
                        forecastTime  = foreCastTimePerAttack * attacks.Count + BoxDrawTime;
                        npc.netUpdate = true;
                    }
                }
                if (playerviewRadius > 80 && timer > forecastTime)
                {
                    playerviewRadius -= 10;
                }
                else if (playerviewRadius < 1200 && timer < forecastTime && timer > -120)
                {
                    playerviewRadius += 10;
                }

                if (Main.netMode != 1)
                {
                    cloak.ai[1]    = playerviewRadius;
                    cloak.timeLeft = 2;
                }



                if (playerviewRadius > 500)
                {
                    orbitDistance        = 1200;
                    retreatApproachSpeed = 8f;
                }
                else
                {
                    retreatApproachSpeed = 4f;
                    orbitDistance        = 500;
                }
                npc.ai[3] = 0;
                if (chargeTime > 0)
                {
                    chargeTime--;
                    if (chargeTime > 45)
                    {
                        npc.ai[3] = (60 - chargeTime) * 7;
                    }
                    else if (chargeTime > 30)
                    {
                        npc.ai[3] = 210 - (60 - chargeTime) * 7;
                    }
                }
                else
                {
                    chargeTime   = 0;
                    npc.velocity = QwertyMethods.PolarVector(orbitalVelocity, (player.Center - npc.Center).ToRotation() + (float)Math.PI / 2);
                    if (Main.netMode != 1 && Main.rand.Next(200) == 0)
                    {
                        orbitalVelocity *= -1;
                        npc.netUpdate    = true;
                    }
                    if ((player.Center - npc.Center).Length() < orbitDistance - 50)
                    {
                        npc.velocity += QwertyMethods.PolarVector(-retreatApproachSpeed, (player.Center - npc.Center).ToRotation());
                    }
                    else if ((player.Center - npc.Center).Length() > orbitDistance + 50)
                    {
                        npc.velocity += QwertyMethods.PolarVector(retreatApproachSpeed, (player.Center - npc.Center).ToRotation());
                    }
                }
            }
        }
Beispiel #35
0
 public BaccaratService(Random rand)
 {
     _deck = new Deck(45, rand, 1, 0);
     _deck.Shuffle();
 }
Beispiel #36
0
 public void Deal()
 {
     Deck = new Deck();
     Deck.Shuffle();
     _dealCardsService.Deal(Players, Deck);
 }
Beispiel #37
0
        /** Runs the unit test. */
        public override void RunTests()
        {
            Debug.Write("Testing the BlackjackPlayer class\n" + CardGame.ConsoleLine ('*') + "\n" +
                "Creating player1 and printing ToString ()...\n");

            var player1 = new BlackjackPlayer("Player 1", 10);

            Debug.Write(player1.ToString() + "\n\n" +
                "Attempting to take away more points than the user has...\n\n");

            player1.RemovePoints(100);

            Debug.Assert(player1.NumPoints == 10, "Error! The computer took away more points than player1 had!");

            var Deck = new Deck();
            Deck.Shuffle();

            Debug.Write("Dealing hand and testing int Compare (Hand) function...\n\n");

            var player2 = new BlackjackPlayer("Player 2", 999999999);

            player1.Hand.AddCard(Deck.DrawCard(10, 3));
            player1.Hand.AddCard(Deck.DrawCard(1, 4));

            player2.Hand.AddCard(Deck.DrawCard(10, 3));
            player2.Hand.AddCard(Deck.DrawCard(5, 4));

            Debug.Write("Comparing 10 plus ace to 10 plus 5\n");

            Debug.Assert(player1.Hand.Compare(player2.Hand) > 1, "Error ! player1 had 21!");

            player1.Hand.Clear();
            player2.Hand.Clear();

            player1.Hand.AddCard(Deck.DrawCard(13, 3));
            player1.Hand.AddCard(Deck.DrawCard(7, 4));

            player2.Hand.AddCard(Deck.DrawCard(7, 3));
            player2.Hand.AddCard(Deck.DrawCard(4, 4));

            Debug.Assert(player1.HandWins(player2), "Error ! player1 had a hiter point total!");

            Debug.Write("\n\nDone testing the BlackjackPlayer class.\n\n\n");
        }
Beispiel #38
0
 /// <summary>
 /// Shuffle game.
 /// </summary>
 private void Shuffle()
 {
     _cardDeck.Shuffle();
 }
Beispiel #39
0
 public void StartTurn()
 {
     // Shuffle the deck and pick 5 new cards
     deck.Shuffle();
     deck.DrawCards(5);
 }
Beispiel #40
0
    //Recives event to play card, updating deck on all clients
    public void HandlePhotonEvents(EventData photonEvent)
    {
        byte eventCode = photonEvent.Code;

        switch (eventCode)
        {
        case 1:
            //------Playing Cards
        {
            if (view.IsMine)
            {
                //Stores the number of each trick card where the number matters
                byte[] cards = (byte[])photonEvent.CustomData;

                //A count of each trick card played
                //Aces = index[0] 2s = index[2] | 8s = index[2] | Jacks = index[3] | Black Queens = index[4] | Kings of Hearts = index[5]
                byte[] trickCards = new byte[6];

                #region Trick Card reading
                //Get a count of each trick card in the cards played
                foreach (byte id in cards)
                {
                    Card card = deck.FindCard(id);
                    switch (card.GetValue())
                    {
                    //Ace
                    case 1:
                        trickCards[0]++;
                        break;

                    //Twos
                    case 2:
                        trickCards[1]++;
                        break;

                    //Eights
                    case 8:
                        turnHandler.PlayerUseTurn();
                        trickCards[2]++;
                        break;

                    //Jacks
                    case 11:
                        turnHandler.ReverseOrder();
                        trickCards[3]++;
                        break;

                    //Black Queens
                    case 12:
                        if (card.GetCardId() == 102)
                        {
                            lights.DiscoMode();
                        }
                        break;

                    //King of Hearts
                    case 13:
                        if (card.GetSuit() == 1)
                        {
                            trickCards[5]++;
                        }
                        break;
                    }
                }

                twoCount  += trickCards[1];
                kingCount += trickCards[5];

                //Let player set ace value
                if (trickCards[0] > 0 && turnHandler.GetCurrentPlayer() == view.ViewID)
                {
                    playerHud.aceSelectionArea.GetComponent <CanvasGroup>().alpha = 1;
                }

                //Only use turn if jacks havn't reversed the order
                if (trickCards[3] % 2 == 0 || trickCards[3] == 0)
                {
                    turnHandler.PlayerUseTurn();
                }
                #endregion

                deck.PlayCard(cards);
                playerHud.topCardPrompt.GetComponent <Image>().sprite = deck.GetPlayDeckTopCard().GetCardSprite();
            }
        }
        break;

        case 2:
            //------Game Start
        {
            if (view.IsMine)
            {
                //Shuffles all players decks using the same seed, meaning all players will have the same randomization
                byte seed = (byte)photonEvent.CustomData;
                deck.Shuffle(seed);
                deck.PlayFirstCard();

                //Enables all UI buttons on game start
                playerHud.drawCardsButton.interactable = true;
                playerHud.sortCardsButton.interactable = true;
                playerHud.believeButton.interactable   = true;
                playerHud.lastCardButton.interactable  = true;
                gameStartButton.gameObject.SetActive(false);

                //Adds all the current players to the turn handler to be sorted through
                turnHandler.AddPlayers();
            }
        }
        break;

        case 3:
            //------Drawing Cards
        {
            if (view.IsMine)
            {
                if ((int)photonEvent.CustomData != view.ViewID)
                {
                    Card card = deck.DrawCard();
                }

                if ((int)photonEvent.CustomData == turnHandler.GetCurrentPlayer())
                {
                    turnHandler.PlayerUseTurn();
                }
            }
        }
        break;

        case 4:
            //------Game Start Card Dealing
        {
            int eventViewID = (int)photonEvent.CustomData;
            if (eventViewID == view.ViewID && view.IsMine)
            {
                DrawMultipleCards(5);
                DealStartCardsLoop();
            }
        }
        break;

        case 5:
            //------Game Start Card Loop
        {
            DealStartCards();
        }
        break;

        case 6:
            //------Set trick cards to be used
        {
            twoCount  = 0;
            kingCount = 0;
        }
        break;

        case 7:
            //------Update game log
        {
            if (view.IsMine)
            {
                string text = (string)photonEvent.CustomData;
                playerHud.SendChatboxMessage(text);
            }
        }
        break;

        case 8:
            //------Handle Game Over
        {
            if (view.IsMine)
            {
                string[] message = (string[])photonEvent.CustomData;

                playerHud.gameObject.SetActive(false);

                GameObject winnerScreen = GameObject.Find("WinnerScreen");
                winnerScreen.GetComponent <CanvasGroup>().alpha = 1;
                string gameOverMessage;

                //If someone won...
                if (message[1] == "Winner")
                {
                    //If they were also first winner, display flawless message
                    if (firstWinner == message[0])
                    {
                        gameOverMessage = winnerScreen.GetComponentInChildren <Text>().text = message[0] + "\n is flawless!";
                    }
                    //Else just display winner message
                    else
                    {
                        gameOverMessage = winnerScreen.GetComponentInChildren <Text>().text = message[0] + "\n is the winner!";
                    }
                }

                //If the deck ran out of cards...
                else
                {
                    gameOverMessage = winnerScreen.GetComponentInChildren <Text>().text = message[0] + "\n ruined the game...";
                }

                //Print the winner, time and game log to file
                string path = "GameLog.txt";

                StreamWriter writer = new StreamWriter(path, true);
                writer.WriteLine(DateTime.Now.ToString());
                writer.WriteLine(playerHud.chatBoxText.GetComponent <Text>().text);
                writer.WriteLine(gameOverMessage);
                writer.WriteLine("----------------------------<  Game End  >----------------------------");
                writer.Close();

                //Move back to the main menu
                StartCoroutine("ChangeScene");
            }
        }
        break;

        case 9:
            //------Set first winner
        {
            firstWinner = (string)photonEvent.CustomData;
        }
        break;

        case 10:
            //Blind play / belief button
        {
            if (view.IsMine)
            {
                Card card = deck.DrawCard();
            }
        }
        break;

        case 11:
            //Handle Black queen
        {
        }
        break;

        case 12:
            //Recieving your cards from a black queen target
        {
            short[] data = (short[])photonEvent.CustomData;
            if (data[0] == view.ViewID)
            {
                for (int i = 1; i < data.Length; i++)
                {
                    Card temp = deck.FindCard((byte)data[i]);
                    myCards.Add(temp.GetCardId(), temp);
                }
            }
        }
        break;
        }
    }
Beispiel #41
0
        static void Main(string[] args)
        {
            //// Get a new deck and shuffle it.
            //Deck myDeck = new Deck();
            //myDeck.Shuffle();

            //// Read all the cards in the deck.
            //for (int i = 0; i < 52; i++)
            //{
            //    Card tempCard = myDeck.GetCard(i);
            //    Write(tempCard.ToString());

            //    // After all but the last card, add a comma to separate it from the next card.
            //    if (i != 51)
            //        Write(", ");
            //    else
            //        WriteLine();
            //}

            WriteLine("Test 1");
            Deck deck1 = new Deck();
            Deck deck2 = (Deck)deck1.Clone();

            // First show that both decks start out the same.
            WriteLine($"The first card in the original deck is: {deck1.GetCard(0)}");
            WriteLine($"The first card in the cloned deck is: {deck2.GetCard(0)}");

            // Shuffle the first deck, then show that changes to it do not affect the cloned deck.
            deck1.Shuffle();
            WriteLine("Original deck shuffled.");
            WriteLine($"The first card in the original deck is: {deck1.GetCard(0)}");
            WriteLine($"The first card in the cloned deck is: {deck2.GetCard(0)}");

            WriteLine("\nTest 2");
            Card.isAceHigh = true;
            WriteLine("Aces are high.");

            Card.useTrumps = true;
            Card.trump     = Suit.Club;
            WriteLine("Clubs are trumps.");

            Card card1, card2, card3, card4, card5;

            card1 = new Card(Suit.Club, Rank.Five);
            card2 = new Card(Suit.Club, Rank.Five);
            card3 = new Card(Suit.Club, Rank.Ace);
            card4 = new Card(Suit.Heart, Rank.Ten);
            card5 = new Card(Suit.Diamond, Rank.Ace);

            // Test the operator overloads by comparing various pairs of cards.
            WriteLine($"{card1.ToString()} == {card2.ToString()} ? {card1 == card2}");
            WriteLine($"{card1.ToString()} != {card3.ToString()} ? {card1 != card3}");
            WriteLine($"{card1.ToString()}.Equals({card4.ToString()}) ? " +
                      $" { card1.Equals(card4)}");
            WriteLine($"Card.Equals({card3.ToString()}, {card4.ToString()}) ? " +
                      $" { Card.Equals(card3, card4)}");
            WriteLine($"{card1.ToString()} > {card2.ToString()} ? {card1 > card2}");
            WriteLine($"{card1.ToString()} <= {card3.ToString()} ? {card1 <= card3}");
            WriteLine($"{card1.ToString()} > {card4.ToString()} ? {card1 > card4}");
            WriteLine($"{card4.ToString()} > {card1.ToString()} ? {card4 > card1}");
            WriteLine($"{card5.ToString()} > {card4.ToString()} ? {card5 > card4}");
            WriteLine($"{card4.ToString()} > {card5.ToString()} ? {card4 > card5}");

            ReadKey();
        }
Beispiel #42
0
    public void NewGame(/*default is 2v2*/)
    {
        TurnCounter = 0;
        PhaseCounter = PHASE.DRAW;

        TableBoard = new Board(4);

        TableDeck = new Deck(2);
        TableDeck.Shuffle();

        Players = new List<Player>();
        //needs dynamic logic for player number and team number
        Players.Add(new Player("Player One", 1));
        Players.Add(new Player("Player Two", 2));
        Players.Add(new Player("Player Three", 1));
        Players.Add(new Player("Player Four", 2));

        Deal();

        //print players cards to test
        /*foreach(Player _player in Players){
            Debug.Log("" + _player.Name);
            foreach(Card _card in _player.Hand){
                Debug.Log(_card.FaceValue());
            }
        }*/
    }
Beispiel #43
0
        public override IEnumerator Enter()
        {
            yield return(base.Enter());

            //Ensure no cards are animating
            if (GameManager.AnimateGame)
            {
                foreach (Card card in owner.Memory.GetData <Deck>("GameDeck"))
                {
                    while (card.animating)
                    {
                        yield return(null);
                    }
                }
            }

            //Advance the Dealer
            owner.Memory.SetData("Dealer", (owner.Memory.GetData <int>("Dealer") == 3) ? 0 : owner.Memory.GetData <int>("Dealer") + 1);

            //Set active player to right of the dealer.
            owner.Memory.SetData("ActivePlayer", (owner.Memory.GetData <int>("Dealer") == 3) ? 0 : owner.Memory.GetData <int>("Dealer") + 1);

            owner.Memory.SetData("Plays", new List <Card>());
            owner.Memory.SetData("PlaysMap", new Dictionary <Card, int>());

            owner.Memory.SetData("Player0Tricks", 0);
            owner.Memory.SetData("Player1Tricks", 0);
            owner.Memory.SetData("Player2Tricks", 0);
            owner.Memory.SetData("Player3Tricks", 0);

            PointSpread testingPointSpread;

            if (GameManager.RunGenetics)
            {
                int[] array = null;
                yield return(GameManager.GeneticHandler.GetSpread((int[] inn) => { array = inn; }));

                testingPointSpread = new PointSpread(array);
            }
            else
            {
                testingPointSpread = GameManager.DefaultPointSpread;
            }
            //if (GameManager.RunGenetics) Debug.LogWarning("Trial of: " + testingPointSpread);
            owner.Memory.SetData("Player0PointSpread", testingPointSpread);
            owner.Memory.SetData("Player1PointSpread", GameManager.DefaultPointSpread);
            owner.Memory.SetData("Player2PointSpread", testingPointSpread);
            owner.Memory.SetData("Player3PointSpread", GameManager.DefaultPointSpread);



            owner.Memory.GetData <TrumpSelector>("TrumpSelector").aloneToggle.isOn = false;

            owner.Memory.SetData <bool>("Alone", false);
            //Remove trump if this is not our first round.
            owner.Memory.RemoveData <Card.Suit>("Trump");


            Deck playingDeck = owner.Memory.GetData <Deck>("GameDeck");

            playingDeck.basePosition = Vector3.Lerp(Vector3.zero, owner.Memory.GetData <Player>("Player" + owner.Memory.GetData <int>("Dealer")).gameObject.transform.position, 0.55f);

            if (GameManager.AnimateGame)
            {
                //Reorient the deck to the dealer
                yield return(playingDeck.Orient("Player" + owner.Memory.GetData <int>("Dealer"), owner));
            }

            //Shuffle the deck
            playingDeck.Shuffle();


            //Deal to each player
            int[] dealSequence = new int[] { 3, 2, 3, 2,
                                             2, 3, 2, 3 };
            int player = owner.Memory.GetData <int>("ActivePlayer");

            for (int i = 0; i < dealSequence.Length; i++)
            {
                //Mark the player as playing this round
                owner.Memory.GetData <Player>("Player" + player).playingRound = true;
                yield return(GameManager.cardAnimator.Deal("Player" + player, "GameDeck", dealSequence[i], GameManager.AnimateGame, owner));

                player++;
                if (player > 3)
                {
                    player = 0;
                }
            }

            Card revealedCard = owner.Memory.GetData <Deck>("GameDeck").Draw(1)[0];

            owner.Memory.SetData("RevealedCardFromKittie", revealedCard);
            owner.Memory.SetData <List <Card> >("KnownCards", new List <Card>(new Card[] { revealedCard }));
            revealedCard.SetOrdering(1);
            yield return(GameManager.cardAnimator.Flip(revealedCard, GameManager.AnimateGame));

            owner.Transition <DetermineTrump>();
        }
Beispiel #44
0
 public void ShuffleDrawDeck()       //Randomize the draw deck
 {
     drawDeck.Shuffle();
 }
Beispiel #45
0
        public void StartGame(Deck deck)
        {
            Deck = deck;
            Deck.Shuffle();
            CurrentCard = Deck.Deal();
            PreviewCard = Deck.Deal();

            Elapsed = 0;
            Progress = 1;
            IsPlaying = true;
            StartedAt = DateTime.Now;
            _dispatcher.PublishMessage(MessageType.StartGame);
        }
Beispiel #46
0
 //--デッキをシャッフルする
 public void Shuffle( )
 {
     _deck.Shuffle( );
 }
Beispiel #47
0
 private void ResetDeck(Deck deck)
 {
     deck.Fill();
     deck.Shuffle(false);
 }
Beispiel #48
0
    // Start is called before the first frame update
    void Start()
    {
        CardLibrary cardlib = new CardLibrary();


        test_poke = cardlib.Mewtwo_promo();               //new Pokemon("Mewtwo", "PR003", 'p', 70, 2, 'p', 'n', 0);
        Pokemon test_enemy_poke = cardlib.Mewtwo_promo(); //new Pokemon("Mewtwo", "PR003", 'p', 70, 2, 'p', 'n', 0);

        p1_active_pkmn = test_poke;
        p1_active_pkmn._energy.Add(new Energy());
        p1_active_pkmn._energy.Add(new Energy());
        p1_active_pkmn._energy.Add(new Energy());
        p2_active_pkmn = test_enemy_poke;
        test_attack    = new Attack("Psyburn", "2p1c", 40);

        p1_deck = new Deck();
        p1_deck.Populate();
        p1_deck.Shuffle();
        p1_hand    = new List <Card>();
        p1_discard = new List <Card>();
        p1_prizes  = new List <Card>();
        p1_bench   = new List <Pokemon>();

        p2_deck = new Deck();
        p2_deck.Populate();
        p2_deck.Shuffle();
        p2_hand    = new List <Card>();
        p2_discard = new List <Card>();
        p2_prizes  = new List <Card>();
        p2_bench   = new List <Pokemon>();

        p1_hand_display = new List <GameObject>();

        //random basic from deck to active

        for (int i = 0; i < 6; i++)
        {
            p1_hand.Add(p1_deck.Draw());
        }
        for (int i = 0; i < 6; i++)
        {
            p1_prizes.Add(p1_deck.Draw());
        }

        for (int i = 0; i < 6; i++)
        {
            p2_hand.Add(p2_deck.Draw());
        }
        for (int i = 0; i < 6; i++)
        {
            p2_prizes.Add(p2_deck.Draw());
        }


        DrawScreen();


        //print(player_hand[0]);


        //card_preview.GetComponent<CardPreview>().ChangeSprite(player_hand[cursor]._id);
    }
Beispiel #49
0
    };                                                           //Storing card index to swap card.
    #endregion
    void Start()
    {
        int index = 0;

        //makes each card
        foreach (Sprite sprite in cardImages)
        {
            Card c = new Card();
            c.sprite = sprite;
            #region HandleSuit
            if (sprite.name.Contains("Clubs"))
            {
                c.suit = eSuit.Clubs;
            }
            else if (sprite.name.Contains("Diamonds"))
            {
                c.suit = eSuit.Diamonds;
            }
            else if (sprite.name.Contains("Hearts"))
            {
                c.suit = eSuit.Hearts;
            }
            else
            {
                c.suit = eSuit.Spades;
            }
            #endregion
            #region HandleValue
            if (sprite.name.EndsWith("A"))
            {
                c.value = 1;
            }
            else if (sprite.name.EndsWith("2"))
            {
                c.value = 2;
            }
            else if (sprite.name.EndsWith("3"))
            {
                c.value = 3;
            }
            else if (sprite.name.EndsWith("4"))
            {
                c.value = 4;
            }
            else if (sprite.name.EndsWith("5"))
            {
                c.value = 5;
            }
            else if (sprite.name.EndsWith("6"))
            {
                c.value = 6;
            }
            else if (sprite.name.EndsWith("7"))
            {
                c.value = 7;
            }
            else if (sprite.name.EndsWith("8"))
            {
                c.value = 8;
            }
            else if (sprite.name.EndsWith("9"))
            {
                c.value = 9;
            }
            else if (sprite.name.EndsWith("0"))
            {
                c.value = 10;
            }
            else if (sprite.name.EndsWith("J"))
            {
                c.value = 11;
            }
            else if (sprite.name.EndsWith("Q"))
            {
                c.value = 12;
            }
            else if (sprite.name.EndsWith("K"))
            {
                c.value = 13;
            }
            #endregion
            deck.deck[index] = c;
            index++;
        }
        deck.Shuffle();
        DrawCards(5);
    }
 void Start()
 {
     deck = GetComponent <Deck>();                // Получить компонент Deck.cs
     deck.InitDeck(deckXML.text);                 // Создаем стартовую колоду из deckXML.xml
     Deck.Shuffle(ref deck.table, ref deck.well); // Стартовую колоду раскладываем на стол, 4 карты в колодец
 }
Beispiel #51
0
        static void Main(string[] args)
        {
            Deck deck = new Deck();

            deck.Shuffle();
            Cards hand  = new Cards();
            bool  match = false;

            for (int i = 0; i < 1000; i++)
            {
                hand  = deck.DrawFive(false);
                match = Deck.IsFlush(hand);
                WriteLine(string.Join(", ", hand.Select(c => c._Suit)));

                if (match)
                {
                    //hand.ForEach(c => Write($"{c.suit} "));
                    WriteLine("Flush!!!!!!!!!!!!!!!");
                    break;
                }
            }

            if (!match)
            {
                WriteLine("No Flush.");
            }
            ReadKey();


            //Book answer:
            //while (true)
            //{
            //    Deck playDeck = new Deck();
            //    playDeck.Shuffle();
            //    bool isFlush = false;
            //    int flushHandIndex = 0;
            //    for (int hand = 0; hand < 10; hand++)
            //    {
            //        isFlush = true;
            //        Suit flushSuit = playDeck.GetCard(hand * 5).suit;
            //        for (int card = 1; card < 5; card++)
            //        {
            //            if (playDeck.GetCard(hand * 5 + card).suit != flushSuit)
            //            {
            //                isFlush = false;
            //            }
            //        }
            //        if (isFlush)
            //        {
            //            flushHandIndex = hand * 5;
            //            break;
            //        }
            //    }
            //    if (isFlush)
            //    {
            //        WriteLine("Flush!!!");
            //        for (int card = 0; card < 5; card++)
            //        {
            //            WriteLine(playDeck.GetCard(flushHandIndex + card));
            //        }
            //    }
            //    else
            //    {
            //        WriteLine("No Flush.");
            //    }
            //    ReadKey();

            //}
        }
Beispiel #52
0
        public override void SpecialUpdate()
        {
            health = 0;
            for (int i = 0; i < guns.Count; i++)
            {
                if (!Miasma.gameEntities.Contains(guns[i]))
                {
                    guns.RemoveAt(i);
                }
            }
            foreach (AndromedaGunBase gun in guns)
            {
                health += gun.health;
            }
            for (int e = 0; e < gunPairs.Count; e++)
            {
                if (!gunPairs[e].IsActive())
                {
                    gunPairs.RemoveAt(e);
                }
            }
            if (Miasma.hard)
            {
                flyTimer++;
                if (flyTimer > 120)
                {
                    flyTo    = Vector2.UnitX * Miasma.random.Next(-80, 81);
                    flyTimer = 0;
                }
            }
            if ((Vector2.Zero - Position).Length() < flyInSpeed || lockIn)
            {
                if ((flyTo - Position).Length() < flyInSpeed)
                {
                    Velocity = Vector2.Zero;
                    Position = flyTo;
                }
                else
                {
                    Velocity = Functions.PolarVector(flyInSpeed, Functions.ToRotation(flyTo - Position));
                }
                lockIn = true;


                if (guns.Count > 1)
                {
                    if (gunPairs.Count == 0 || (gunSlots[0] != null && gunSlots[0].team == 1) || (gunSlots[1] != null && gunSlots[1].team == 1))
                    {
                        for (int i = 0; i < 2; i++)
                        {
                            if (gunSlots[i] == null || !gunSlots[i].active)
                            {
                                guns.Shuffle();
                                gunSlots[i]        = (gunSlots[i == 0 ? 1 : 0] != null && gunSlots[i == 0 ? 1 : 0] == guns[0]) ? guns[1] : guns[0];
                                gunSlots[i].active = true;
                                switch (i)
                                {
                                case 0:
                                    gunSlots[i].SetRelativeX(Miasma.leftSide + 104);
                                    break;

                                case 1:
                                    gunSlots[i].SetRelativeX(Miasma.rightSide - 104);
                                    break;
                                }
                                gunSlots[i].Position.Y = Position.Y;
                            }
                        }
                    }
                    else
                    {
                        if ((gunSlots[0] == null || !gunSlots[0].active) && (gunSlots[1] == null || !gunSlots[1].active))
                        {
                            gunSlots = gunPairs.Draw(1)[0].GetGuns();
                            for (int i = 0; i < 2; i++)
                            {
                                gunSlots[i].active = true;
                                switch (i)
                                {
                                case 0:
                                    gunSlots[i].SetRelativeX(Miasma.leftSide + 104);
                                    break;

                                case 1:
                                    gunSlots[i].SetRelativeX(Miasma.rightSide - 104);
                                    break;
                                }
                                gunSlots[i].Position.Y = Position.Y;
                            }
                        }
                    }
                }
                else if (guns.Count > 0)
                {
                    if (guns[0] == null || !guns[0].active)
                    {
                        guns[0].active     = true;
                        guns[0].Position.Y = Position.Y;
                        switch (Miasma.random.Next(2))
                        {
                        case 0:
                            guns[0].SetRelativeX(Miasma.leftSide + 104);
                            break;

                        case 1:
                            guns[0].SetRelativeX(Miasma.rightSide - 104);
                            break;
                        }
                    }
                }
            }
            else
            {
                Velocity = Functions.PolarVector(flyInSpeed, Functions.ToRotation(Vector2.Zero - Position));
            }
        }