Exemplo n.º 1
0
		public static void Configure()
		{
			Server.Utility.PushColor( ConsoleColor.White );

			Card[] testHand = new Card[7]
		    {
		        new Card( CardSuit.Clubs, CardValue.Two ),
		        new Card( CardSuit.Diamonds, CardValue.Two ),
		        new Card( CardSuit.Hearts, CardValue.Three ),
		        new Card( CardSuit.Spades, CardValue.Three ),
		        new Card( CardSuit.Diamonds, CardValue.Three ),
		        new Card( CardSuit.Hearts, CardValue.Seven ),
		        new Card( CardSuit.Spades, CardValue.King )
		    };
			CardValue highCard;

			Console.WriteLine( "\n===== hand eval result: {0} [high card={1}]\n", HandEvaluator.EvaluateHand( testHand, out highCard ), highCard );

			#region old tests
			CardDeck deck = new CardDeck( DeckSize.One );
			Console.WriteLine( "\n===== single deck contents:\n{0}\n", deck.PrintContents() );

			Card c = new Card( CardSuit.Diamonds, CardValue.Ten );
			Console.WriteLine( "\n===== Ten of Diamonds: {0} | {1}\n", c.ToSimpleString(), c.ToString() );

			PokerHand hand1 = new PokerHand( 5 );
			PokerHand hand2 = new PokerHand( 5 );
			deck.DealCards( new PokerHand[] { hand1, hand2 }, 6 );

			Console.WriteLine( "\n===== hand1: {0}", hand1.ToString() );
			Console.WriteLine( "===== hand2: {0}", hand2.ToString() );
			Console.WriteLine( "\n===== new deck contents:\n{0}\n", deck.PrintContents() );

			hand1.ReturnToDeck();
			hand2.ReturnToDeck();

			Stopwatch sw = new Stopwatch();
			byte shuffleAmt = byte.MaxValue;
			Console.WriteLine( "===== hands returned to deck...shuffling {0} times", shuffleAmt );
			sw.Start();
			deck.ShuffleDeck( shuffleAmt );
			sw.Stop();
			Console.WriteLine( "===== deck shuffled, time taken: {0} milliseconds | {1} seconds", sw.ElapsedMilliseconds, (sw.ElapsedMilliseconds / 1000) );
			Console.WriteLine( "\n===== deck contents:\n{0}\n", deck.PrintContents() );
			Console.WriteLine( "===== deck length={0}", deck.deck.Count );

			PokerHand pkh = new PokerHand( 7 );
			deck.DealCards( new PokerHand[] { pkh }, 7 );
			Console.WriteLine( "\n===== unsorted: {0}", pkh.ToString() );
			Array.Sort<Card>( pkh.Cards );
			Console.WriteLine( "===== sorted: {0}", pkh.ToString() );
			#endregion

			Server.Utility.PopColor();
		}
Exemplo n.º 2
0
		/// <summary>
		/// Deals a specified amount of cards to each <code>PokerHand</code>
		/// </summary>
		/// <param name="playerHands">array of players' <code>PokerHand</code>s</param>
		/// <param name="dealAmt">amount to deal to each <code>PokerHand</code></param>
		public virtual void DealCards( PokerHand[] playerHands, byte dealAmt )
		{
			Card card;
			List<Card> recycleCards = new List<Card>();

			for( byte i = 0; i < dealAmt; i++ )
			{
				for( byte j = 0; j < (byte)playerHands.Length; j++ )
				{
					card = DrawOne();

					if( card == null )
						break;

					if( playerHands[j].GiveCard( card ) )
						playerHands[j].FromDeck = this;
					else
						recycleCards.Add( card );
				}
			}

			recycleCards.Reverse();
			recycleCards.ForEach(
				delegate( Card c )
				{
					deck.Push( c );
				} );
			recycleCards.Clear();
		}