本文整理汇总了C#中Hand.ToShortString方法的典型用法代码示例。如果您正苦于以下问题:C# Hand.ToShortString方法的具体用法?C# Hand.ToShortString怎么用?C# Hand.ToShortString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hand
的用法示例。
在下文中一共展示了Hand.ToShortString方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PlayRound
/// <summary>
/// Advance the game by one round, querying all entities for their actions until their hand is complete
/// before playing the dealer's hand
/// </summary>
/// <returns>Should another round be played after this one?</returns>
public bool PlayRound()
{
//OutputLine(5, "");
//If the shoe is running low or not created yet, create it
if (m_shoe == null || m_shoe.CardsLeft < 25)
{
OutputLine(2, "Under 15 cards left in the shoe. Creating a new shoe.");
OutputLine(5, "");
m_shoe = new Shoe(m_deckCount, m_countMethod);
}
//Clear all hands
m_hands = new List<Hand>();
//Take bets from players
foreach (Entity e in m_entities)
{
int bet = 0;
//If the entity isn't a dealer, get their bet
if (!(e is DealerEntity))
{
bet = e.GetBet(m_shoe.Count);
OutputLine(1, "{0} bets {1}. The count is {2}", e.Name, bet, m_shoe.Count);
e.Balance -= bet;
}
//Deal the entity a hand
Hand hand = new Hand(e, m_shoe.DealNextCard(), m_shoe.DealNextCard(), bet);
m_hands.Add(hand);
OutputLine(1, "{0} receives {1} and {2}", e.Name, hand.Cards[0].ToShortString(), hand.Cards[1].ToShortString());
}
//Find the dealers hand
Hand dealerHand = m_hands.First(hand => hand.Owner is DealerEntity);
//Declare the dealer's hole card
OutputLine(1, "{0}'s hole card is {1}", m_dealer.Name, dealerHand.Cards[0].ToShortString());
//Now evaluate each hand in the game
for (int i = 0; i < m_hands.Count; i++)
{
Hand currentHand = m_hands[i];
//Output who's turn it is to act and what their hand is
OutputLine(1, "{0}'s turn to act on {1}...", currentHand.Owner.Name, currentHand.ToShortString());
//Keep getting the hand owner's chosen action until their hand is complete
//No enforcement of game rules is done here! It's up to the entities to play nicely :)
while (true)
{
TurnAction action = currentHand.Owner.TakeTurn(currentHand.Cards, dealerHand.Cards[0]);
if (action == TurnAction.Stick)
{
//If they stuck, output their final hand and end their turn
OutputLine(1, "{0} sticks with {1}", currentHand.Owner.Name, currentHand.ToShortString());
break;
}
else if (action == TurnAction.Hit)
{
//If they hit, add a card on to their hand
Card hitCard = m_shoe.DealNextCard();
currentHand.Cards.Add(hitCard);
OutputLine(1, "{0} hits and receives a {1}. New hand is {2}", currentHand.Owner.Name, hitCard.ToShortString(), currentHand.ToShortString());
}
else if (action == TurnAction.Split)
{
//If the entity wishes to split their hand, create them a new hand with one card from their current hand + a new one
Hand newHand = new Hand(currentHand.Owner, currentHand.Cards[1], m_shoe.DealNextCard(), currentHand.Bet);
//Make them pay for the hand
currentHand.Owner.Balance -= currentHand.Bet;
//Flag both of these hands as having been split
newHand.IsSplit = true;
currentHand.IsSplit = true;
//Add the new hand in to take its turn after the current hand
m_hands.Insert(i + 1, newHand);
//Replace the card that was split out from this hand with a new card
currentHand.Cards[1] = m_shoe.DealNextCard();
//Output what their hand is now
OutputLine(1, "{0} splits. Current hand is now{1}", currentHand.Owner.Name, currentHand.ToShortString());
}
else if (action == TurnAction.Double)
{
//If the entity wishes to double down, find out how much they want to double down for and bill them for it
int doubleBet = currentHand.Owner.GetDoubleDownBet(currentHand.Cards, m_shoe.Count);
currentHand.Bet += doubleBet;
currentHand.Owner.Balance -= doubleBet;
//.........这里部分代码省略.........