private List <CardData> GetSingle(List <CardData> gameHand, bool useStrongest = false) { List <CardData> sortedHand = playerCards.SortBySuits(useStrongest); sortedHand = sortedHand.SortByRank(useStrongest); int count = sortedHand.Count; if (useStrongest) { if (gameHand == null || HandEvaluator.CompareValue(sortedHand[0], gameHand[0])) { return(new List <CardData> { sortedHand[0] }); } } for (int i = 0; i < count; i++) { if (gameHand == null || HandEvaluator.CompareValue(sortedHand[i], gameHand[0])) { return(new List <CardData> { sortedHand[i] }); } } return(null); }
public List <CardData> GetFullHouse(List <CardData> gameHand) { var groupedList = playerCards.GroupBy(c => c.rank).Select(group => new { key = group.Key, list = group.ToList() }); groupedList = groupedList.OrderBy(g => g.key); List <List <CardData> > pairs = new List <List <CardData> >(); List <List <CardData> > triples = new List <List <CardData> >(); foreach (var group in groupedList) { List <CardData> sortedList = new List <CardData>(group.list); sortedList = sortedList.SortBySuits(); if (sortedList.Count >= 2) { var pair = new List <CardData>(); for (int i = 0; i < 2; i++) { pair.Add(sortedList[i]); } pairs.Add(pair); } if (sortedList.Count >= 3) { var triple = new List <CardData>(); for (int i = 0; i < 3; i++) { triple.Add(sortedList[i]); } triples.Add(triple); } } List <CardData> tempHand = new List <CardData>(); if (pairs.Count > 0 && triples.Count > 0) { for (int i = 0; i < triples.Count; i++) { for (int j = 0; j < pairs.Count; j++) { if (triples[i][0].rank != pairs[j][0].rank) { tempHand = new List <CardData>(triples[i].Union(pairs[j])); if (HandEvaluator.CompareMiddle(tempHand, gameHand)) { return(tempHand); } } tempHand.Clear(); } } } return(null); }
public void TestTripsKickerEvaluation() { HandEvaluation first = HandEvaluator.Evaluate(Board.Parse("Qd7d9dQcQs8sJc")); HandEvaluation second = HandEvaluator.Evaluate(Board.Parse("Qd7d9dQcQsKc6s")); Assert.That(second > first); }
private static PlayerGameType RecognitionPlayerGameType(GetActionContext context) { var handStrength = HandEvaluator.Evaluate(context.FirstCard, context.SecondCard, context.CommunityCards); if (CheckFoldGameHands.Contains(handStrength)) { return(PlayerGameType.CheckFold); } if (BluffGameHands.Contains(handStrength)) { return(PlayerGameType.Bluff); } if (SmallValueGameHands.Contains(handStrength)) { return(PlayerGameType.SmallValue); } if (MaxValueGameHands.Contains(handStrength)) { return(PlayerGameType.MaxValue); } if (CheckCallSmallGameHands.Contains(handStrength)) { return(PlayerGameType.CheckCallSmall); } throw new System.ArgumentException("PlayerGameType Error !!"); }
/// <summary> /// The entry point of the program. /// </summary> private static void Main() { try { IHandEvaluator handEvaluator = new HandEvaluator(); ICard[] cards = new ICard[] { new Card(CardRank.Queen, CardSuit.Hearts), new Card(CardRank.Queen, CardSuit.Spades), new Card(CardRank.Ten, CardSuit.Hearts), new Card(CardRank.Queen, CardSuit.Diamonds), new Card(CardRank.Queen, CardSuit.Clubs) }; IHand hand = new Hand(cards); Console.WriteLine(handEvaluator.GetCategory(hand) == HandCategory.FourOfAKind); IHand handFromString = new Hand("7♠ 5♣ 4♦ 3♦ 2♣"); Console.WriteLine(handFromString); } catch (ArgumentException aex) { Console.WriteLine(aex.Message); } }
private List <CardData> GetSingle(List <CardData> gameHand, bool playStrong = false) { List <CardData> sortedHand = hand.cardDatas.ToDynList().SortBySuits(playStrong); sortedHand = sortedHand.SortByRank(playStrong); int count = sortedHand.Count; if (playStrong) { if (gameHand == null || HandEvaluator.CompareValue(sortedHand[0], gameHand[0])) { return(new List <CardData> { sortedHand[0] }); } } for (int i = 0; i < count; i++) { if (gameHand == null || HandEvaluator.CompareValue(sortedHand[i], gameHand[0])) { return(new List <CardData> { sortedHand[i] }); } } return(null); }
public void TestPairKickerEvaluation() { HandEvaluation first = HandEvaluator.Evaluate(Board.Parse("4d4s3h5c2s8sJc")); HandEvaluation second = HandEvaluator.Evaluate(Board.Parse("4d4s3h5c2sKc6s")); Assert.That(second > first); }
public override void ExecuteCommand(IChatChannel channel, StreamCommand command) { long userid = playermodule.GetPlayer(command.Service, command.User).UserID; HoldemGame game = casino.GetGame(userid); if (game == null) { SendMessage(channel, command.User, "You have no active holdem game. Use !holdem to start a new game."); return; } casino.RemoveGame(userid); RPGMessageBuilder message = messagemodule.Create().User(userid).Text(" folds the hand. "); HandEvaluation dealerevaluation = HandEvaluator.Evaluate(game.Board + game.DealerHand); HandEvaluation playerevaluation = HandEvaluator.Evaluate(game.Board + game.PlayerHand); if (dealerevaluation < playerevaluation || dealerevaluation.Rank < HandRank.Pair || (dealerevaluation.Rank == HandRank.Pair && dealerevaluation.HighCard < CardRank.Four)) { message.ShopKeeper().Text(" laughs and shows "); foreach (Card card in game.DealerHand) { message.Image(cardimages.GetCardUrl(card), $"{card} "); } message.Text("while grabbing ").Gold(game.Pot); } else { message.ShopKeeper().Text(" gladly rakes in ").Gold(game.Pot); } message.Send(); }
public void WhenICompareTheHands() { var evaluator = new HandEvaluator(); var comparer = new PokerHandsComparer(evaluator, "Black", "White", _blackhand, _whiteHand); _actualResult = comparer.CompareHands(); }
public void OnePairShouldWinAgainstHighCard() { var hand1 = new PokerHand(new List <ICard>() { new PlayingCard(6, "Club"), new PlayingCard(1, "Heart"), new PlayingCard(5, "Club"), new PlayingCard(7, "Club"), new PlayingCard(9, "Club"), }); var hand2 = new PokerHand(new List <ICard>() { new PlayingCard(1, "Club"), new PlayingCard(1, "Heart"), new PlayingCard(5, "Club"), new PlayingCard(7, "Club"), new PlayingCard(9, "Club"), }); var handList = new List <IHand>() { hand1, hand2 }; var handEvaluator = new HandEvaluator(); handEvaluator.Evaluate(handList); var winnerSelector = new WinnerSelector(); winnerSelector.SelectWinner(handList); Assert.IsTrue(hand2.IsWinner); }
public static int RateCards(IEnumerable<Card> cards) { var evaluator = new HandEvaluator(); var strength = (int)evaluator.GetBestHand(cards).RankType; return strength; }
public void HighCardTest() { Card highCard = new Card(Rank.Two, Suit.Clubs); highCard = HandEvaluator.HighCard(aceOfDiamondHighCard); Assert.AreEqual((new Card(Rank.Ace, Suit.Diamonds)).Rank, highCard.Rank); }
public static int RateCards(IEnumerable <Card> cards) { var evaluator = new HandEvaluator(); var strength = (int)evaluator.GetBestHand(cards).RankType; return(strength); }
//TODO: Convert this block to tests. //public void TestHandEvaluation() //{ // Console.WriteLine("In Test Hand Evaluation\n\n"); // HandEvaluator HE = new HandEvaluator(); // var testHands = MakeSevenRandomTestHands(); // byte isFlush; // foreach (var th in testHands) // { // Console.WriteLine("\nNext Hand:"); // foreach (var c in th.SevCards) // Console.WriteLine("{0}: {1}", c.SuitValue, c.FaceValue); // isFlush = HE.IsFlush(th); // Console.WriteLine("Straight strength: {0}", HE.IsStraight(th)); // Console.WriteLine("Is flush?: {0}", isFlush); // Console.WriteLine("Straight flush strength: {0}", // String.Join(" ", HE.GetStraightFlush(th, isFlush))); // Console.WriteLine("Flush strength: {0}", // String.Join(" ", HE.GetFlushStrength(th, isFlush))); // Console.WriteLine("Group based hand strength: {0}", // String.Join(" ", HE.GetMatchStrength(th))); // Console.WriteLine("Total Strength: {0}", // String.Join(" ",HE.GetStrength(th))); // } //} public void TestShowdown() { Console.WriteLine("In Test Showdown\n"); HandEvaluator HE = new HandEvaluator(); HandForEval[] testHands = MakeRandomTestHands(); for (int i = 0; i < testHands.Length - 1; i += 2) { Console.WriteLine("Next Showdown"); Card c1, c2; for (int j = 0; j < 7; j++) { c1 = testHands[i].SevCards[j]; c2 = testHands[i + 1].SevCards[j]; Console.WriteLine("{0}: {1}\t {2}: {3}", c1.SuitValue, c1.FaceValue, c2.SuitValue, c2.FaceValue); } Console.WriteLine("Showdown Winner: {0}", testHands[i].CompareTo(testHands[i + 1])); Console.WriteLine("A Hand Strength: {0}", String.Join(" ", testHands[i].HandStrength)); Console.WriteLine("B Hand Strength: {0}", String.Join(" ", testHands[i + 1].HandStrength)); } }
public void TestBug2() { eval = new HandEvaluator(buggedCombo3.ToArray()); Console.WriteLine(eval.Evaluate()); eval = new HandEvaluator(buggedCombo4.ToArray()); Console.WriteLine(eval.Evaluate()); }
private List <CardData> GetFiver(List <CardData> gameHand) { HandType handType = HandEvaluator.EvaluateHand(gameHand); if (handType < HandType.Straight) { return(null); } if (handType == HandType.Straight) { return(GetStraight(gameHand) ?? GetFlush(gameHand) ?? GetFullHouse(gameHand) ?? GetFourKind(gameHand) ?? GetStraightFlush(gameHand)); } else if (handType == HandType.Flush) { return(GetFlush(gameHand) ?? GetFullHouse(gameHand) ?? GetFourKind(gameHand) ?? GetStraightFlush(gameHand)); } else if (handType == HandType.FullHouse) { return(GetFullHouse(gameHand) ?? GetFourKind(gameHand) ?? GetStraightFlush(gameHand)); } else if (handType == HandType.FourOfAKind) { return(GetFourKind(gameHand) ?? GetStraightFlush(gameHand)); } else if (handType == HandType.StraightFlush) { return(GetStraightFlush(gameHand)); } return(null); }
public void GetRankTypeShouldWorkCorrectly(ICollection <Card> playerCards, HandRankType expectedHandRankType, ICollection <CardType> expectedBestHandCards) { IHandEvaluator handEvaluator = new HandEvaluator(); var bestHand = handEvaluator.GetBestHand(playerCards.Shuffle().ToList()); Assert.Equal(expectedHandRankType, bestHand.RankType); CollectionsAssert.SameElements(expectedBestHandCards, bestHand.Cards); }
private bool WinningHand_Over_LosingHand(string expectedToWinString, string expectedToLoseString) { var expectedToWinCards = Card.ParseMultiple(expectedToWinString); var expectedToLoseCards = Card.ParseMultiple(expectedToLoseString); var handEvaluatorWinner = HandEvaluator.GetWinningCards(new Card[][] { expectedToWinCards, expectedToLoseCards }); return(Enumerable.SequenceEqual(handEvaluatorWinner, expectedToWinCards)); }
public List <CardData> GetStraightFlush(List <CardData> gameHand) { //TODO: Strongest List <CardData> sortedHand = hand.cardDatas.ToList().SortByRank(); var groupedList = sortedHand.GroupBy(c => c.suit).Select(group => new { key = group.Key, list = group.ToList() }).OrderBy(g => g.key); foreach (var group in groupedList) { if (group.list.Count >= 5) { List <CardData> tempHand = new List <CardData>(); int w = 0; while (w < group.list.Count - 5) { int invalidIndex = 0; if (tempHand.Count == 0) { tempHand.Add(group.list[w]); for (int i = 1; i < 5; i++) { if (tempHand[tempHand.Count - 1].rank != group.list[w + i].rank - 1) { invalidIndex = w + i; break; } tempHand.Add(group.list[w + i]); } } if (invalidIndex > 0) { w = invalidIndex; continue; } if (tempHand.IsStraightFlush()) { if (gameHand == null || HandEvaluator.CompareHand(tempHand, gameHand)) { return(tempHand); } } tempHand.Clear(); w++; } } } return(null); }
public List <CardData> GetFlush(List <CardData> gameHand) { var groupedList = hand.cardDatas.GroupBy(c => c.suit).Select(group => new { key = group.Key, list = group.ToList() }); groupedList = groupedList.OrderBy(g => g.key); foreach (var group in groupedList) { if (group.list.Count >= 5) { if (group.list.Count > 5) //more than 5 of the same suit { List <CardData> sortedList = group.list.SortBySuits(); List <CardData> tempHand = new List <CardData>(); for (int i = 0; i < 5; i++) { tempHand.Add(sortedList[i]); } if (gameHand == null || HandEvaluator.CompareFlush(tempHand, gameHand)) //if weakest flush wins against hand { return(tempHand); } else if (gameHand.IsFlush() && gameHand[0].suit == group.list[0].suit) //check if game hand is also flush of the same suit { int w = 5; while (w < sortedList.Count) { Debug.Log("w: " + w); tempHand[4] = sortedList[w]; //change flush head if (gameHand == null || HandEvaluator.CompareFlush(tempHand, gameHand)) { return(tempHand); } w++; } } } else //exactly 5 { Debug.Log("exactly 5"); if (gameHand == null || HandEvaluator.CompareFlush(group.list, gameHand)) { return(group.list); } } } } return(null); }
static void Main(string[] args) { CustomLogger.InitializeLogger("C:/logs/pokerLogs.txt"); var handEvaluator = new HandEvaluator(); var poker = new Poker.PokerGame.Poker(new StaticBlindsController(10)); poker.AddPlayer(new Player(new ConsolePlayerController(), new Wallet(15000)) { Name = "Benas" }); poker.AddPlayer(new Player(new AlwaysCallPlayerController(), new Wallet(10000)) { Name = "Benas2" }); poker.OnChange(() => Update(poker, handEvaluator)); poker.Start(() => false); }
public void TestInvalidCardCountException() { var holeCards = new List <Card>(); holeCards.Add(new Card(CardSuit.Clubs, CardValue.Two)); var board = new List <Card>(); board.Add(new Card(CardSuit.Diamonds, CardValue.Seven)); var evaluator = new HandEvaluator(holeCards, board); var rank = evaluator.GetHandRank(); }
private void Awake() { if (instance != null && instance != this) { Destroy(this.gameObject); } else { instance = this; } }
public void FindFlush() { var evaluator = new HandEvaluator(); var hand = evaluator.Evaluate( new Card(Rank.FIVE, Suit.SPADES), new Card(Rank.EIGHT, Suit.SPADES), new Card(Rank.THREE, Suit.SPADES), new Card(Rank.KING, Suit.CLUBS), new Card(Rank.SEVEN, Suit.SPADES), new Card(Rank.DEUCE, Suit.SPADES)); Assert.AreEqual(PokerHand.FLUSH, hand); }
public void TestPrimeMagic2() { Card card1 = new Card(Value.Ace, Suit.Spades); Card card2 = new Card(Value.Ace, Suit.Hearts); Card card3 = new Card(Value.King, Suit.Hearts); Card card4 = new Card(Value.Ace, Suit.Diamonds); Card card5 = new Card(Value.Ace, Suit.Clubs); Hand hand = new Hand { card1, card2, card3, card4, card5 }; Assert.AreEqual(104553157, HandEvaluator.PrimeMagic(hand)); }
public void TestPrimeMagic1() { Card card1 = new Card(Value.Two, Suit.Clubs); Card card2 = new Card(Value.Two, Suit.Spades); Card card3 = new Card(Value.Two, Suit.Hearts); Card card4 = new Card(Value.Two, Suit.Diamonds); Card card5 = new Card(Value.Three, Suit.Hearts); Hand hand = new Hand { card1, card2, card3, card4, card5 }; Assert.AreEqual(48, HandEvaluator.PrimeMagic(hand)); }
public void TestShift2() { Card card1 = new Card(Value.Ace, Suit.Hearts); Card card2 = new Card(Value.King, Suit.Hearts); Card card3 = new Card(Value.Queen, Suit.Hearts); Card card4 = new Card(Value.Jack, Suit.Diamonds); Card card5 = new Card(Value.Nine, Suit.Hearts); Hand hand = new Hand { card1, card2, card3, card4, card5 }; Assert.AreEqual(7808, HandEvaluator.Shift(hand)); }
public void TestShift1() { Card card1 = new Card(Value.Two, Suit.Hearts); Card card2 = new Card(Value.Three, Suit.Hearts); Card card3 = new Card(Value.Four, Suit.Hearts); Card card4 = new Card(Value.Five, Suit.Diamonds); Card card5 = new Card(Value.Six, Suit.Hearts); Hand hand = new Hand { card1, card2, card3, card4, card5 }; Assert.AreEqual(31, HandEvaluator.Shift(hand)); }
public void TestStraightOrHighHand2() { Card card1 = new Card(Value.Seven, Suit.Hearts); Card card2 = new Card(Value.Five, Suit.Hearts); Card card3 = new Card(Value.Four, Suit.Hearts); Card card4 = new Card(Value.Three, Suit.Diamonds); Card card5 = new Card(Value.Two, Suit.Hearts); Hand hand = new Hand { card1, card2, card3, card4, card5 }; Assert.AreEqual(true, HandEvaluator.StraightOrHighHand(hand)); }
public void TestFlush2() { Card card1 = new Card(Value.Ace, Suit.Hearts); Card card2 = new Card(Value.King, Suit.Hearts); Card card3 = new Card(Value.Queen, Suit.Hearts); Card card4 = new Card(Value.Jack, Suit.Diamonds); Card card5 = new Card(Value.Ten, Suit.Hearts); Hand hand = new Hand { card1, card2, card3, card4, card5 }; Assert.AreEqual(false, HandEvaluator.Flush(hand)); }
public void TestEvaluate1() { Card card1 = new Card(Value.Two, Suit.Hearts); Card card2 = new Card(Value.Three, Suit.Hearts); Card card3 = new Card(Value.Four, Suit.Hearts); Card card4 = new Card(Value.Five, Suit.Hearts); Card card5 = new Card(Value.Six, Suit.Hearts); Hand hand = new Hand { card1, card2, card3, card4, card5 }; Assert.AreEqual(9, HandEvaluator.Evaluate(hand).Rank); }
public void TestStraightOrHighHand4() { Card card1 = new Card(Value.King, Suit.Diamonds); Card card2 = new Card(Value.Ten, Suit.Hearts); Card card3 = new Card(Value.Jack, Suit.Hearts); Card card4 = new Card(Value.Queen, Suit.Diamonds); Card card5 = new Card(Value.King, Suit.Hearts); Hand hand = new Hand { card1, card2, card3, card4, card5 }; Assert.AreEqual(false, HandEvaluator.StraightOrHighHand(hand)); }
/// <summary> /// Claculates current CardValuation type based on players cards and community cards /// </summary> /// <param name="firstCard">first cards</param> /// <param name="secondCard">second card</param> /// <param name="comunityCards">Comunity cards</param> /// <returns>the Card Valuation Type</returns> public static CardValuationType Flop(Card firstCard, Card secondCard, IEnumerable<Card> comunityCards) { var handEvaluator = new HandEvaluator(); var cards = new List<Card>(); cards.AddRange(comunityCards); var playerCards = new List<Card>(); playerCards.Add(firstCard); playerCards.Add(secondCard); var percentageValuation = new PercentageValuation(); var percentage = percentageValuation.CalculatePercentage(playerCards, cards); cards.Add(firstCard); cards.Add(secondCard); var bestHand = handEvaluator.GetBestHand(cards); if (bestHand.RankType >= Logic.HandRankType.FourOfAKind) { return CardValuationType.PlayItAllIn; } if (bestHand.RankType >= Logic.HandRankType.ThreeOfAKind) { return CardValuationType.Recommended; } if (percentage < 25) { return CardValuationType.Unplayable; } if (percentage < 45) { return CardValuationType.Risky; } if (percentage < 85) { return CardValuationType.Recommended; } return CardValuationType.StronglyRecommended; }
public void Test_CheckFullHouseHand_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.Nine, 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.FullHouse, result); }
public void Test_CheckStraightHand_ShouldPass() { var card1 = new SimpleCard(CardType.Two, Suit.Clubs); var card2 = new SimpleCard(CardType.Three, Suit.Diamonds); var card3 = new SimpleCard(CardType.Four, Suit.Hearts); var card4 = new SimpleCard(CardType.Five, Suit.Spades); var card5 = new SimpleCard(CardType.Six, Suit.Spades); 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.Straight, result); }
public static CardValuationType Turn(Card firstCard, Card secondCard, IEnumerable<Card> comunityCards) { var handEvaluator = new HandEvaluator(); var cards = new List<Card>(); cards.AddRange(comunityCards); var playerCards = new List<Card>(); playerCards.Add(firstCard); playerCards.Add(secondCard); //var bestHand = handEvaluator.GetBestHand(cards); var outsValuation = new GameOutsValuation(); var outsResult = outsValuation.CalculateOuts(playerCards, cards); cards.Add(firstCard); cards.Add(secondCard); var bestHand = handEvaluator.GetBestHand(cards); if (bestHand.RankType >= Logic.HandRankType.FourOfAKind) { return CardValuationType.PlayItAllIn; } if (outsResult < 25) { return CardValuationType.Unplayable; } if (outsResult < 45) { return CardValuationType.Risky; } if (outsResult < 85) { return CardValuationType.Recommended; } return CardValuationType.StronglyRecommended; }
public void Test_CheckHighCardHand_ShouldPass() { var card1 = new SimpleCard(CardType.Three, Suit.Clubs); var card2 = new SimpleCard(CardType.Two, Suit.Diamonds); var card3 = new SimpleCard(CardType.Seven, Suit.Hearts); var card4 = new SimpleCard(CardType.Five, 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); firstHand.EvaluateHand(); bool highCard = firstHand.HandValue.HighCard.Equals((int)card5.Type); Assert.IsTrue(highCard); }
/// <summary> /// Claculates current CardValuation type based on players cards and community cards /// </summary> /// <param name="firstCard">first cards</param> /// <param name="secondCard">second card</param> /// <param name="comunityCards">Comunity cards</param> /// <returns>the Card Valuation Type</returns> public static CardValuationType River(Card firstCard, Card secondCard, IEnumerable<Card> comunityCards) { var handEvaluator = new HandEvaluator(); var cards = new List<Card>(); cards.AddRange(comunityCards); cards.Add(firstCard); cards.Add(secondCard); var bestHand = handEvaluator.GetBestHand(cards); if (bestHand.RankType <= Logic.HandRankType.Pair) { return CardValuationType.Unplayable; } if (bestHand.RankType <= Logic.HandRankType.TwoPairs) { return CardValuationType.Risky; } if (bestHand.RankType > Logic.HandRankType.TwoPairs && bestHand.RankType <= Logic.HandRankType.Straight) { return CardValuationType.Recommended; } if (bestHand.RankType > Logic.HandRankType.Flush) { return CardValuationType.StronglyRecommended; } return CardValuationType.StronglyRecommended; }
static void Update(Poker.PokerGame.Poker poker, HandEvaluator handEvaluator) { var table = poker.GetData(); System.Console.Clear(); var hand = handEvaluator.EvaluateCards(Enumerable.Concat(table.ActivePlayer.Cards, table.DealerCards).ToList()); System.Console.WriteLine(@"Turn: {0}", table.ActivePlayer.Name); System.Console.Write(@"Your best hand: {0} ", hand.Rank); foreach (var card in hand.HandCards) { System.Console.Write(@"{0} ", ShortStringCard(card)); } System.Console.WriteLine(); System.Console.WriteLine(@" -----------------------------------"); System.Console.WriteLine(@" / \"); System.Console.WriteLine(@" / \"); System.Console.WriteLine(@" / {0,-14} \", table.DealerCards.Count >= 1 ? table.DealerCards[0].ToString() : new string('?', 14)); System.Console.WriteLine(@" / {0,-14} \", table.DealerCards.Count >= 2 ? table.DealerCards[1].ToString() : new string('?', 14)); System.Console.WriteLine(@"| {0,-14} |", table.DealerCards.Count >= 3 ? table.DealerCards[2].ToString() : new string('?', 14)); System.Console.WriteLine(@"| {0,-14} |", table.DealerCards.Count >= 4 ? table.DealerCards[3].ToString() : new string('?', 14)); System.Console.WriteLine(@"| {0,-14} |", table.DealerCards.Count >= 5 ? table.DealerCards[4].ToString() : new string('?', 14)); System.Console.WriteLine(@"| ${0,-6} |", table.Pot); System.Console.WriteLine(@"| |"); System.Console.WriteLine(@" \ /"); System.Console.WriteLine(@" \ /"); System.Console.Write(@" \ "); foreach (var player in table.Players) { var bet = table.Bets.FirstOrDefault(x => x.Player == player); System.Console.Write("${0,-11}", bet == null ? 0 : bet.Amount); } System.Console.WriteLine(@" /"); System.Console.Write(@" \ "); foreach (var player in table.Players) { var firstCard = player.Cards.Count >= 1 ? string.Format("{0} ", ShortStringCard(player.Cards[0])) : string.Format("{0} ", "?"); var secondCard = player.Cards.Count >= 2 ? string.Format("{0}", ShortStringCard(player.Cards[1])) : string.Format("{0}", "?", ""); System.Console.Write("{0,-11}", firstCard + " " + secondCard); } System.Console.WriteLine(" /"); System.Console.WriteLine(@" -----------------------------------"); System.Console.Write(@" "); foreach (var player in table.Players) { System.Console.Write("{0,-13}", player.Name); } System.Console.WriteLine(""); System.Console.Write(@" "); foreach (var player in table.Players) { System.Console.Write("${0,-12}", player.Wallet.Money); } System.Console.WriteLine(@" "); System.Console.WriteLine(@" Fold, Call, Raise, Check"); }
public static void TestInitializeHandEvaluator(TestContext testContext) { handEvaluator = new HandEvaluator(); Assert.IsNotNull(handEvaluator, "handEvaluator should not be null!"); }
protected void SetSuccessor(HandEvaluator successor) { this.Successor = successor; }
public double CalculateOuts(IEnumerable<Card> playerCards, IEnumerable<Card> cards) { var deck = new List<Card>(); for (int i = 0; i <= 3; i++) { for (int j = 2; j <= 14; j++) { deck.Add(new Card((CardSuit)i, (CardType)j)); } } List<Card[]> pairsCombos = new List<Card[]>(); for (int i = 0; i < deck.Count; i++) { for (int j = 0; j < deck.Count; j++) { if (i != j) { pairsCombos.Add(new Card[2] { deck[i], deck[j] }); } } } HashSet<Card> board = new HashSet<Card>(cards); var handEvaluator = new HandEvaluator(); var myPlayerCards = new HashSet<Card>(); foreach (var card in playerCards) { myPlayerCards.Add(card); } foreach (var card in board) { myPlayerCards.Add(card); } var handEvaluatorExtended = new HandEvaluatorExtension(); var bestHandFromBoard = handEvaluatorExtended.GetBestHandForFlop(board); var playerBestHand = handEvaluator.GetBestHand(myPlayerCards); if (playerBestHand.RankType <= bestHandFromBoard.RankType && (cards.ToList().Count() == 3)) { return 21; } if (cards.Count() == 4 && cards.Any()) { var bestHandFromBoardOnTurn = handEvaluatorExtended.GetBestHandForTurn(board); if (playerBestHand.RankType <= bestHandFromBoardOnTurn.RankType) { return 21; } } long wins = 0, ties = 0, loses = 0, count = 0; // Iterate through all possible opponent hole cards // This is one because it is very slow otherwise. // I have tested it and there is not much of a difference for (var i = 0; i < 1; i++) { var otherHand = new HashSet<Card>(); foreach (var pairsCombo in pairsCombos) { foreach (var card in pairsCombo) { otherHand.Add(card); } foreach (var card in board) { otherHand.Add(card); } if (otherHand.Count < 5) { continue; } var otherBestHand = handEvaluator.GetBestHand(otherHand); if (playerBestHand.RankType > otherBestHand.RankType) { wins++; } else if (playerBestHand.RankType == otherBestHand.RankType) { ties++; } else { loses++; } count++; otherHand.Clear(); } } var percent = (((double)wins) + ((double)ties) / 2.0) / ((double)count) * 100.0; return percent; }
/// <summary> /// Calculates percesentage for the currant hand in the game; /// </summary> /// <param name="playerCards">The Turing player cards</param> /// <param name="cards">Community cards</param> /// <returns>Percentage for game development in Turing's favour</returns> public double CalculatePercentage(IEnumerable<Card> playerCards, IEnumerable<Card> cards) { var deck = new List<Card>(); for (int i = 0; i <= 3; i++) { for (int j = 2; j <= 14; j++) { deck.Add(new Card((CardSuit)i, (CardType)j)); } } List<Card[]> pairsCombos = new List<Card[]>(); for (int i = 0; i < deck.Count; i++) { for (int j = 0; j < deck.Count; j++) { if (i != j) { pairsCombos.Add(new Card[2] { deck[i], deck[j] }); } } } HashSet<Card> board = new HashSet<Card>(cards); var handEvaluator = new HandEvaluator(); var myPlayerCards = new HashSet<Card>(); foreach (var card in playerCards) { myPlayerCards.Add(card); } foreach (var card in board) { myPlayerCards.Add(card); } var playerBestHand = handEvaluator.GetBestHand(myPlayerCards); long wins = 0, ties = 0, loses = 0, count = 0; for (var i = 0; i < 1; i++) { var otherHand = new HashSet<Card>(); foreach (var pairsCombo in pairsCombos) { foreach (var card in pairsCombo) { otherHand.Add(card); } foreach (var card in board) { otherHand.Add(card); } if (otherHand.Count < 5) { continue; } var otherBestHand = handEvaluator.GetBestHand(otherHand); if (playerBestHand.RankType > otherBestHand.RankType) { wins++; } else if (playerBestHand.RankType == otherBestHand.RankType) { ties++; } else { loses++; } count++; otherHand.Clear(); } } var percent = (((double)wins) + (((double)ties) / 2.0)) / ((double)count) * 100.0; return percent; }