本文整理汇总了C#中Hand.Clear方法的典型用法代码示例。如果您正苦于以下问题:C# Hand.Clear方法的具体用法?C# Hand.Clear怎么用?C# Hand.Clear使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hand
的用法示例。
在下文中一共展示了Hand.Clear方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getBestHandEfficiently
//get best class without running isRoyalFlush, since straightflush covers the royal flush
public static Hand getBestHandEfficiently(Hand hand)
{
if (hand.Count() < 5)
{
hand.Clear();
return hand;
}
if (isStraightFlush(hand))
return getStraightFlush(hand);
if (isFourOfAKind(hand))
return getFourOfAKind(hand);
if (isFullHouse(hand))
return getFullHouse(hand);
if (isFlush(hand))
return getFlush(hand);
if (isStraight(hand))
return getStraight(hand);
if (isThreeOfAKind(hand))
return getThreeOfAKind(hand);
if (isTwoPair(hand))
return getTwoPair(hand);
if (isOnePair(hand))
return getOnePair(hand);
return getHighCard(hand);
}
示例2: Hand_AddCard_Test
public void Hand_AddCard_Test()
{
// Arrange
var hand = new Hand();
// Act & Assert
hand.AddCard(new Card(Rank.Ace, Suite.Club));
Assert.AreEqual(10, hand.SoftValue);
Assert.AreEqual(10, hand.TotalValue);
hand.AddCard(new Card(Rank.Two, Suite.Club));
Assert.AreEqual(12, hand.SoftValue);
Assert.AreEqual(12, hand.TotalValue);
hand.AddCard(new Card(Rank.Ace, Suite.Club));
Assert.AreEqual(22, hand.SoftValue);
Assert.AreEqual(13, hand.TotalValue);
hand.AddCard(new Card(Rank.Eight, Suite.Club));
Assert.AreEqual(30, hand.SoftValue);
Assert.AreEqual(21, hand.TotalValue);
hand.Clear();
Assert.AreEqual(0, hand.Cards.Count);
Assert.AreEqual(0, hand.SoftValue);
Assert.AreEqual(0, hand.TotalValue);
}
示例3: TestClearResetsAceCount
public void TestClearResetsAceCount()
{
Hand hand = new Hand
{
new Card(Rank.Ace, Suit.Hearts),
new Card(Rank.Ace, Suit.Hearts),
new Card(Rank.Ten, Suit.Hearts)
};
hand.Clear();
Assert.AreEqual(0, hand.AceCount);
}
示例4: getTwoPair
public static Hand getTwoPair(Hand hand)
{
hand.sortByRank();
Hand twopair = new Hand();
twopair.setValue(3);
int pairCount = 0;
for (int i = 0; i <= hand.Count() - 2; i++)
{
if (hand.getCard(i) == hand.getCard(i + 1))
{
twopair.setValue(hand.getCard(i).getRank());
twopair.Add(hand.getCard(i));
twopair.Add(hand.getCard(i+1));
pairCount++;
if (pairCount == 2)
break;
i++; //the pair has already been checked, i must be incremented an additional time to avoid using a card in this pair again. This prevents the program from identifying 3 of a kind as 2 pairs.
}
}
if (pairCount == 2)
return getKickers(hand,twopair);
else
twopair.Clear();
return twopair;
}
示例5: getStraightFlush
//get straight flush using two pointer variable and taking care of all cases
public static Hand getStraightFlush(Hand hand)
{
hand.sortByRank();
Hand straightflush = new Hand();
straightflush.setValue(9);
if (hand.getCard(0).getRank() == 14)
hand.Add(new Card((int)RANK.ACE, hand.getCard(0).getSuit()));
//int straightflushCount = 1;
straightflush.Add(hand.getCard(0));
int ptr1=0, ptr2=1;
while (ptr1 < hand.Count() - 2 || ptr2 < hand.Count())
{
if (straightflush.Count() >= 5)
break;
int rank1=hand.getCard(ptr1).getRank(), rank2=hand.getCard(ptr2).getRank();
int suit1=hand.getCard(ptr1).getSuit(), suit2=hand.getCard(ptr2).getSuit();
if (rank1 - rank2 == 1 && suit1 == suit2)
{
straightflush.Add(hand.getCard(ptr2));
ptr1 = ptr2;
ptr2++;
}
else if(rank1==2&&rank2==14&&suit1==suit2)
{
straightflush.Add(hand.getCard(ptr2));
ptr1 = ptr2;
ptr2++;
}
else
{
if (rank1 - rank2 <= 1)
ptr2++;
else
{
straightflush.Clear();
straightflush.setValue(9);
ptr1++;
ptr2=ptr1+1;
straightflush.Add(hand.getCard(ptr1));
}
}
}
if (hand.getCard(0).getRank() == 14)
hand.Remove(hand.Count() - 1);
straightflush.setValue(straightflush.getCard(0).getRank());
if (straightflush.Count() < 5)
straightflush.Clear();
return straightflush;
}
示例6: getStraight
//explaination below, same as isStraight except return cards
public static Hand getStraight(Hand hand)
{
hand.sortByRank();
Hand straight = new Hand();
straight.setValue(5);
if (hand.getCard(0).getRank() == 14)
hand.Add(new Card((int)RANK.ACE, hand.getCard(0).getSuit()));
int straightCount = 1;
straight.Add(hand.getCard(0));
for (int i = 0; i <= hand.Count() - 2; i++)
{
//if 5 cards are found to be straights, break out of the loop
if (straightCount == 5)
break;
int currentrank = hand.getCard(i).getRank();
//if cards suit differ by 1, increment straight
if (currentrank - hand.getCard(i + 1).getRank() == 1)
{
straightCount++;
straight.Add(hand.getCard(i+1));
}
//specific condition for 2-A
else if (currentrank == 2 && hand.getCard(i + 1).getRank() == 14)
{
straightCount++;
straight.Add(hand.getCard(i+1));
}
//if cards suit differ by more than 1, reset straight to 1
else if (currentrank - hand.getCard(i + 1).getRank() > 1)
{
straightCount = 1;
straight.Clear();
straight.setValue(5);
straight.Add(hand.getCard(i+1));
}
//if card suits does not differ, do nothing
}
//depending on the straight count, return true or false
if (hand.getCard(0).getRank() == 14)
hand.Remove(hand.Count() - 1);
if (straightCount != 5)
straight.Clear();
straight.setValue(straight.getCard(0).getRank());
return straight;
}
示例7: getRoyalFlush
//get royal flush using recursion
public static Hand getRoyalFlush(Hand hand)
{
hand.sortByRank();
Hand straightflush = new Hand(HandCombination.getStraightFlush(hand));
straightflush.setValue(10);
if (straightflush.getCard(0).getRank() == 14)
return straightflush;
else
{
straightflush.Clear();
return straightflush;
}
}
示例8: getFullHouse
public static Hand getFullHouse(Hand hand)
{
hand.sortByRank();
Hand fullhouse = new Hand();
fullhouse.setValue(7);
bool threeofakind = false, pair = false;
int threeofakindRank = 0;
for (int i = 0; i <= hand.Count() - 3; i++)
{
if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i) == hand.getCard(i + 2))
{
threeofakind = true;
threeofakindRank = hand.getCard(i).getRank();
fullhouse.Add(hand.getCard(i));
fullhouse.Add(hand.getCard(i + 1));
fullhouse.Add(hand.getCard(i + 2));
fullhouse.setValue(hand.getCard(i).getRank());
break;
}
}
for (int i = 0; i <= hand.Count() - 2; i++)
{
if (hand.getCard(i) == hand.getCard(i + 1) && hand.getCard(i).getRank() != threeofakindRank)
{
pair = true;
fullhouse.Add(hand.getCard(i));
fullhouse.Add(hand.getCard(i + 1));
fullhouse.setValue(hand.getCard(i).getRank());
break;
}
}
if (threeofakind == true && pair == true)
return fullhouse;
else
{
fullhouse.Clear();
return fullhouse;
}
}
示例9: CalculateHandValue
//using the monte carlo method, calculate a hand value for the AI's current hand
//this can be very hard on the computer's memory and processor and can result in lag time
public void CalculateHandValue(int count)
{
double score = 0;
PlayerList playerList = new PlayerList();
for (int i = 0; i < count - 1; i++)
{
playerList.Add(new Player());
}
Hand bestHand = new Hand();
int bestHandCount = 1;
Deck deck = new Deck();
Hand knownCommunityCards = new Hand();
Hand remainingCommunityCards = new Hand();
Hand myHoleCards = new Hand();
//remove known cards from deck
for (int i = 0; i < myHand.Count(); i++)
{
deck.Remove(myHand[i]);
}
//add known community cards
for (int i = 2; i < myHand.Count(); i++)
{
knownCommunityCards.Add(myHand[i]);
}
myHoleCards.Add(this.getHand()[0]);
myHoleCards.Add(this.getHand()[1]);
//loop 100 times
for (int i = 0; i < 100; i++)
{
//reset players and shuffle deck
for (int j = 0; j < playerList.Count; j++)
{
playerList[j].isbusted = false;
playerList[j].getHand().Clear();
}
myHand.Clear();
remainingCommunityCards.Clear();
deck.Shuffle();
//generate remaining community cards
if (knownCommunityCards.Count() < 5)
{
remainingCommunityCards.Add(deck.Deal());
if (knownCommunityCards.Count() < 4)
{
remainingCommunityCards.Add(deck.Deal());
if (knownCommunityCards.Count() < 3)
{
remainingCommunityCards.Add(deck.Deal());
remainingCommunityCards.Add(deck.Deal());
remainingCommunityCards.Add(deck.Deal());
}
}
}
//add hole/community cards to the AI
this.AddToHand(knownCommunityCards);
this.AddToHand(remainingCommunityCards);
this.AddToHand(myHoleCards);
//add hole/community cards to other players
for (int j = 0; j < playerList.Count; j++)
{
playerList[j].AddToHand(knownCommunityCards);
if (remainingCommunityCards.Count() != 0)
playerList[j].AddToHand(remainingCommunityCards);
playerList[j].AddToHand(deck.Deal());
playerList[j].AddToHand(deck.Deal());
//if player is dealt hole cards of less than 5-5, and no pocket pairs the player drops out
if (playerList[j].getHand()[playerList[j].getHand().Count() - 1].getRank() + playerList[j].getHand()[playerList[j].getHand().Count() - 2].getRank() <= 10 && playerList[j].getHand()[playerList[j].getHand().Count() - 1].getRank() != playerList[j].getHand()[playerList[j].getHand().Count() - 2].getRank())
{
playerList[j].isbusted = true;
}
}
//add cards back to deck
for (int j = 0; j < remainingCommunityCards.Count(); j++)
{
deck.Add(remainingCommunityCards[j]);
}
for (int j = 0; j < playerList.Count; j++)
{
deck.Add(playerList[j].getHand()[playerList[j].getHand().Count() - 1]);
deck.Add(playerList[j].getHand()[playerList[j].getHand().Count() - 2]);
}
//compare hands
bestHandCount = 1;
playerList.Add(this);
bestHand = playerList[0].getHand();
for (int j = 0; j <playerList.Count-1; j++)
{
if (playerList[j].isbusted)
continue;
if (HandCombination.getBestHandEfficiently(new Hand(playerList[j+1].getHand())) > HandCombination.getBestHandEfficiently(new Hand(playerList[j].getHand())))
{
bestHandCount = 1;
bestHand = playerList[j+1].getHand();
}
else if (HandCombination.getBestHandEfficiently(new Hand(playerList[j+1].getHand())) == HandCombination.getBestHandEfficiently(new Hand(playerList[j].getHand())))
bestHandCount++;
}
//.........这里部分代码省略.........