本文整理汇总了C#中Hand.Add方法的典型用法代码示例。如果您正苦于以下问题:C# Hand.Add方法的具体用法?C# Hand.Add怎么用?C# Hand.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hand
的用法示例。
在下文中一共展示了Hand.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBlackjackIsRaisedWhenHandIsBlackjack
public void TestBlackjackIsRaisedWhenHandIsBlackjack()
{
bool blackjackCalled = false;
Hand hand = new Hand();
hand.Blackjack += () => blackjackCalled = true;
hand.Add(new Card(Rank.Jack, Suit.Diamonds));
hand.Add(new Card(Rank.Ace, Suit.Diamonds));
Assert.IsTrue(blackjackCalled);
}
示例2: TestBustRaisesHandBustEvent
public void TestBustRaisesHandBustEvent()
{
bool bustedCalled = false;
Hand hand = new Hand();
hand.Busted += () => bustedCalled = true;
hand.Add(new Card(Rank.Ten, Suit.Diamonds));
hand.Add(new Card(Rank.Ten, Suit.Diamonds));
Assert.IsFalse(bustedCalled);
hand.Add(new Card(Rank.Ten, Suit.Diamonds));
Assert.IsTrue(bustedCalled);
}
示例3: AddTest
public void AddTest()
{
Hand a = new Hand();
Card c = Card.Joker;
a.Add(c);
Assert.AreEqual(a[0], c);
}
示例4: Test_CheckThreeKindHand_ShouldPass
public void Test_CheckThreeKindHand_ShouldPass()
{
var card1 = new SimpleCard(CardType.Ace, Suit.Clubs);
var card2 = new SimpleCard(CardType.Ace, Suit.Diamonds);
var card3 = new SimpleCard(CardType.Ace, Suit.Hearts);
var card4 = new SimpleCard(CardType.Eight, Suit.Spades);
var card5 = new SimpleCard(CardType.Nine, Suit.Diamonds);
var hand = new Hand();
hand.Add(card1);
hand.Add(card2);
hand.Add(card3);
hand.Add(card4);
hand.Add(card5);
var sortedHand = hand.Sort();
var firstHand = new HandEvaluator(sortedHand);
var result = firstHand.EvaluateHand();
Assert.AreEqual(HandStrength.ThreeKind, result);
}
示例5: btnHandValue_Click
private void btnHandValue_Click(object sender, EventArgs e)
{
int index = lbMain.SelectedIndex;
AIPlayer currentPlayer = (AIPlayer)pokerTable[index];
Stopwatch timer = new Stopwatch();
timer.Start();
Hand hand = new Hand();
hand.Add(new Card(RANK.TWO, SUIT.SPADES));
hand.Add(new Card(RANK.FOUR, SUIT.DIAMONDS));
currentPlayer.CalculateHandValue(playerAmount);
timer.Stop();
pokerTable[index] = currentPlayer;
rtbOutput.Text = currentPlayer.HandValue.ToString() + Environment.NewLine + timer.Elapsed.TotalMilliseconds;
lbMain.Items.Clear();
foreach (Player player in pokerTable)
{
lbMain.Items.Add(player.Name);
}
lbMain.SelectedIndex = index;
}
示例6: Discard_CardInHand_CardOnBottomOfLibrary
public void Discard_CardInHand_CardOnBottomOfLibrary()
{
bool cardDiscardedEventTriggered = false;
GameLibrary lib = new GameLibrary();
SelectableLinkedList<GameCard> cards = new SelectableLinkedList<GameCard>();
for (int i = 0; i < 29; i++)
cards.AddFirst(new MockCard());
lib.Add(cards);
Hand h = new Hand();
cards = new SelectableLinkedList<GameCard>();
cards.AddFirst(new MockCardWithData(42));
h.Add(cards);
Player p = new Player(lib, h, null,null);
p.EventManager = this.EventManager;
this.EventManager.Register(new Trigger<CardDiscardedEvent>(_ => cardDiscardedEventTriggered = true));
Engine.AddActor(lib);
p.Discard(0);
GameCard c = p.Library.TakeCardAt(29);
Assert.IsTrue(cardDiscardedEventTriggered);
Assert.IsTrue(((MockCardWithData)c).data == 42);
}
示例7: getOnePair
public static Hand getOnePair(Hand hand)
{
hand.sortByRank();
Hand onepair = new Hand();
onepair.setValue(2);
for (int i = 0; i <= hand.Count() - 2; i++)
{
if (hand.getCard(i) == hand.getCard(i + 1))
{
onepair.setValue(hand.getCard(i).getRank());
onepair.Add(hand.getCard(i));
onepair.Add(hand.getCard(i + 1));
break;
}
}
return getKickers(hand, onepair);
}
示例8: TestHandPlayableEventIsRaisedWhenTheCardCountIsMoreThanOne
public void TestHandPlayableEventIsRaisedWhenTheCardCountIsMoreThanOne()
{
bool handPlayableCalled = false;
Hand hand = new Hand();
hand.Playable += () => handPlayableCalled = true;
hand.Add(new Card(Rank.Jack, Suit.Diamonds));
hand.Add(new Card(Rank.Two, Suit.Diamonds));
Assert.IsTrue(handPlayableCalled);
}
示例9: getFlush
//use a counter to determine with suit forms a flush
//then get all cards from the suit
public static Hand getFlush(Hand hand)
{
hand.sortByRank();
Hand flush = new Hand();
flush.setValue(6);
int diamondCount = 0, clubCount = 0, heartCount = 0, spadeCount = 0;
for (int i = 0; i < hand.Count(); i++)
{
if ((SUIT)hand.getCard(i).getSuit() == SUIT.DIAMONDS)
diamondCount++;
else if ((SUIT)hand.getCard(i).getSuit() == SUIT.CLUBS)
clubCount++;
else if ((SUIT)hand.getCard(i).getSuit() == SUIT.HEARTS)
heartCount++;
else if ((SUIT)hand.getCard(i).getSuit() == SUIT.SPADES)
spadeCount++;
}
if (diamondCount >= 5)
{
for (int i = 0; i < hand.Count(); i++)
{
if (hand.getCard(i).getSuit() == 1)
{
flush.Add(hand.getCard(i));
flush.setValue(hand.getCard(i).getRank());
}
if (flush.Count() == 5)
break;
}
//return flush;
}
else if (clubCount >= 5)
{
for (int i = 0; i <= hand.Count(); i++)
{
if (hand.getCard(i).getSuit() == 2)
{
flush.Add(hand.getCard(i));
flush.setValue(hand.getCard(i).getRank());
}
if (flush.Count() == 5)
break;
}
//return flush;
}
else if (heartCount >= 5)
{
for (int i = 0; i <= hand.Count(); i++)
{
if (hand.getCard(i).getSuit() == 3)
{
flush.Add(hand.getCard(i));
flush.setValue(hand.getCard(i).getRank());
}
if (flush.Count() == 5)
break;
}
//return flush;
}
else if (spadeCount >= 5)
{
for (int i = 0; i <= hand.Count(); i++)
{
if (hand.getCard(i).getSuit() == 4)
{
flush.Add(hand.getCard(i));
flush.setValue(hand.getCard(i).getRank());
}
if (flush.Count() == 5)
break;
}
//return flush;
}
return flush;
}
示例10: getKickers
//get all remaining cards, if necessary, to form 5 cards
private static Hand getKickers(Hand hand, Hand specialCards)
{
if (specialCards.Count() == 0)
return specialCards;
for (int i = 0; i < specialCards.Count(); i++)
{
hand.Remove(specialCards.getCard(i));
}
for (int i = 0; i < hand.Count();i++)
{
if (specialCards.Count() >= 5)
break;
specialCards.Add(hand.getCard(i));
specialCards.setValue(hand.getCard(i).getRank());
}
return specialCards;
}
示例11: isStraight
//explanation below
public static bool isStraight(Hand hand)
{
hand.sortByRank();
if(hand.getCard(0).getRank()==14)
hand.Add(new Card((int)RANK.ACE,hand.getCard(0).getSuit()));
int straightCount=1;
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++;
//specific condition for 2-A
else if (currentrank == 2 && hand.getCard(i + 1).getRank() == 14)
straightCount++;
//if cards suit differ by more than 1, reset straight to 1
else if (currentrank - hand.getCard(i + 1).getRank() > 1)
straightCount = 1;
//if card suits does not differ, do nothing
}
if (hand.getCard(0).getRank() == 14)
hand.Remove(hand.Count() - 1);
//depending on the straight count, return true or false
if (straightCount == 5)
return true;
return false;
}
示例12: 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;
}
示例13: getThreeOfAKind
public static Hand getThreeOfAKind(Hand hand)
{
hand.sortByRank();
Hand threeofakind = new Hand();
threeofakind.setValue(4);
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.setValue(hand.getCard(i).getRank());
threeofakind.Add(hand.getCard(i));
threeofakind.Add(hand.getCard(i + 1));
threeofakind.Add(hand.getCard(i + 2));
break;
}
}
return getKickers(hand, threeofakind);
}
示例14: TimerNextMove_Tick
//most important method in the game, controls the turns of the players
private void TimerNextMove_Tick(object sender, EventArgs e)
{
timerCount++;
//condition if everyone folds
if (pokerTable.PlayerWon())
{
panelBubble.Hide();
pokerTable.setCurrentIndex(pokerTable.incrementIndexShowdown(pokerTable.getCurrentIndex()));
pokerTable[pokerTable.getCurrentIndex()].CollectMoney(pokerTable.getPot());
lblBanner.Text = pokerTable[pokerTable.getCurrentIndex()].Message;
lblBanner.Show();
TimerNextMove.Stop();
TimerWait3Seconds.Start();
return;
}
//condition to increment player's turn
if (pokerTable.beginNextTurn())
{
pokerTable.setCurrentIndex(pokerTable.incrementIndex(pokerTable.getCurrentIndex()));
lblBanner.Hide();
//condition to pay small/big blind
if (timerCount == 1)
pokerTable.PaySmallBlind();
else if (timerCount == 2)
pokerTable.PayBigBlind();
//condition that the current player is not AI, show labels to player
else if (pokerTable.getCurrentIndex() == 0)
{
initalizeButtons();
TimerNextMove.Stop();
return;
}
//condition for AI
else
{
AIPlayer currentPlayer = (AIPlayer)pokerTable[pokerTable.getCurrentIndex()];
if (difficulty == (int)DIFFICULTY.HARD)
{
Hand holeCards=new Hand();
holeCards.Add(pokerTable[0].getHand()[0]);
holeCards.Add(pokerTable[0].getHand()[1]);
currentPlayer.CalculateHandValueHard(holeCards, new Deck(pokerTable.getDeck()));
}
currentPlayer.MakeADecision(pokerTable.getPot(), pokerTable.decrementIndex(pokerTable.getCurrentIndex()));
pokerTable[pokerTable.getCurrentIndex()] = currentPlayer;
//grey out form if the AI folds
if (currentPlayer.IsFolded())
panelList[pokerTable.getCurrentIndex()].BackgroundImage = Image.FromFile("inactivebutton.png");
}
updateMove();
if (timerCount > 2 && pokerTable.getCurrentIndex() != 0 && difficulty == 1)
{
timerCalculate.Start();
}
}
else
{
//deal community cards
pokerTable.TurnCount = 0;
lblBanner.Show();
panelBubble.Hide();
if (pokerTable[0].getHand().Count() == 2)
{
pokerTable.DealFlop();
lblBanner.Text = "Dealing the Flop";
toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString());
}
else if (pokerTable[0].getHand().Count() == 5)
{
pokerTable.DealTurn();
lblBanner.Text = "Dealing the Turn";
toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString());
}
else if (pokerTable[0].getHand().Count() == 6)
{
pokerTable.DealRiver();
lblBanner.Text = "Dealing the River";
toolTipHint.SetToolTip(panelPlayer, HandCombination.getBestHand(new Hand(pokerTable[0].getHand())).ToString());
}
else if (pokerTable[0].getHand().Count() == 7)
{
//start timer for showdown
lblBanner.Text = "Showdown";
TimerNextMove.Stop();
TimerShowdown.Start();
return;
}
//reset agressor the dealer
int dealerPosition = pokerTable.getDealerPosition();
pokerTable.setCurrentIndex(pokerTable.getDealerPosition());
pokerTable.getPot().AgressorIndex = pokerTable.getDealerPosition();
DrawToScreen();
}
}
示例15: getHighCard
//get highest cards after sorting
public static Hand getHighCard(Hand hand)
{
hand.sortByRank();
Hand highcard = new Hand();
highcard.setValue(1);
highcard.Add(hand.getCard(0));
highcard.setValue(hand.getCard(0).getRank());
return getKickers(hand, highcard);
}