private static void CountHandValues(uint handVal) { HandValue.Kind handType = HandValue.GetKind(handVal); _uniqHandValues[(int)handType].Add(handVal); // Count total as well _uniqHandValues[(int)HandValue.Kind._Count].Add(handVal); }
//Constructor public HandEvaluatorService(Player currentPlayer) { this.CurrentPlayer = currentPlayer; _cards = new Card[5]; _cards = currentPlayer.PlayerHand; _handValue = new HandValue(); }
public HandEvalutor(GameObject[] sortedHand) { heartsSum = 0; diamondSum = 0; clubSum = 0; spadesSum = 0; cards = new GameObject[5]; Cards = sortedHand; handValue = new HandValue( ); }
public void TestMethod1() { List <Player> players = new List <Player>(); players.Add(new Player("Joe", StringToCards("3H,6H,8H,JH,KH"))); players.Add(new Player("Jen", StringToCards("3C,3D,3S,8C,10H"))); players.Add(new Player("Bob", StringToCards("2H,5C,7S,10C,AC"))); Player expected = new Player(); expected.PlayerName = "Joe"; expected.Hand = StringToCards("3H,6H,8H,JH,KH"); var handValue = new HandValue(); handValue.pokerHand = PokerHands.Flush; handValue.value = 531247; }
public void PlayPoker() { deck.NewDeck(); deck.Shuffle(); List <Card> playerHand = new List <Card>(); List <Card> dealerHand = new List <Card>(); int count = 0; while (count < 3) { Card newCard = deck.TakeCard(); playerHand.Add(newCard); count++; } count = 0; while (count < 3) { Card newCard = deck.TakeCard(); dealerHand.Add(newCard); count++; } io.DisplayMessage($"the player has:"); foreach (Card c in playerHand) { io.DisplayMessage($"{c.CardNumber} of {c.Suit}"); } io.DisplayMessage($"\nthe dealer has:"); foreach (Card c in dealerHand) { io.DisplayMessage($"{c.CardNumber} of {c.Suit}"); } HandValue playerHandValue = CheckForValue(playerHand, io); HandValue dealerHandValue = CheckForValue(dealerHand, io); io.DisplayMessage($"\nPlayer has a {playerHandValue}"); io.DisplayMessage($"Dealer has a {dealerHandValue}"); }
public Evaluator(Card[] sortedHand) { heartsSum = 0; diamondSum = 0; clubSum = 0; spadesSum = 0; cards = new Card[7]; Cards = sortedHand; handValue = new HandValue(); if ((int)cards[0].MyValue > (int)cards[1].MyValue) { handValue.HighCard = (int)cards[0].MyValue; handValue.SecondHighCard = (int)cards[1].MyValue; } else if ((int)cards[1].MyValue > (int)cards[0].MyValue) { handValue.HighCard = (int)cards[1].MyValue; handValue.SecondHighCard = (int)cards[0].MyValue; } }
public HandValue DetermineHandValue(List<uint> cards) { var handValue = new HandValue(); int? keepAceTillLast = null; if (cards.Count() == 2 && cards.Distinct().Count() == 1 && !NotValidSplitValues.Contains(cards.First())) { handValue.IsSplit = true; } foreach (var value in cards) { if (value == 1 && keepAceTillLast == null) { keepAceTillLast = 1; continue; } if (value >= 10) { handValue.Value += 10; } else { handValue.Value += value; } } if (keepAceTillLast != null) { if (handValue.Value + 11 <= 21) { if (handValue.Value + 11 == 12 && handValue.IsSplit) handValue.IsSoft = false; else handValue.IsSoft = true; handValue.Value += 11; } else { handValue.Value += 1; } } return handValue; }
public static HandValue EvaluateCards(List <Card> cards) { HandValue result = new HandValue(); List <Card> m_pairs = new List <Card>(); List <Card> m_threes = new List <Card>(); List <Card> m_fours = new List <Card>(); int index = 0; // Only check for n of a kind while (index < cards.Count - 1) { Card c = cards[index]; int sameCount = 1; for (int i = index + 1; i < cards.Count; ++i) { if (cards[i].m_value == c.m_value) { ++sameCount; } } if (sameCount > 1) { ref List <Card> cardList = ref m_pairs; if (sameCount == 3) { cardList = ref m_threes; } else if (sameCount == 4) { cardList = ref m_fours; } cardList.AddRange(cards.Where(card => card.m_value == c.m_value)); cards.RemoveAll(card => card.m_value == c.m_value); } ++index; }
private void StraightCards(List <Card> cards) { var hands = new List <List <Card> >(); if (cards.Count() >= 5) { hands.Add(cards.Take(5).ToList()); } if (cards.Count() >= 6) { hands.Add(cards.Skip(1).Take(5).ToList()); var tmpCards = cards.Take(4).ToList(); tmpCards.AddRange(cards.Skip(5).Take(1)); hands.Add(tmpCards.ToList()); } if (cards.Count() == 7) { hands.Add(cards.Skip(2).Take(5).ToList()); var tmpCards = cards.Take(4).ToList(); tmpCards.AddRange(cards.Skip(6).Take(1)); hands.Add(tmpCards.ToList()); var tmpCards1 = cards.Skip(1).Take(4).ToList(); tmpCards1.AddRange(cards.Skip(6).Take(1)); hands.Add(tmpCards1.ToList()); } foreach (var hand in hands) { if (HandValue.Equals(Hands.RoyalStraightFlush)) { break; } IsStraight(hand); } }
/// <summary> /// Runs the algorythm of showdown of poker game. /// </summary> protected void Showdown() { foreach (Card card in _table) { _player1.Hand.Add(card); _player2.Hand.Add(card); } DrawCards.DisplayCards(_player1.Hand, 1); Console.SetCursorPosition(0, 14); Console.WriteLine("COMPUTER'S HAND"); DrawCards.DisplayCards(_player2.Hand, 2); // processing the hands HandValue p1Hand = _firstChecker.CheckCombination(_player1.Hand); HandValue p2Hand = _firstChecker.CheckCombination(_player2.Hand); DisplayBanks(); Console.SetCursorPosition(0, 36); if (p1Hand > p2Hand) { Console.WriteLine("Player1 wins"); Console.WriteLine("Player1 Combination: {0}", p1Hand.Combination); Console.WriteLine("Player2 Combination: {0}", p2Hand.Combination); _player1.WinBank(_bank); } else { Console.WriteLine("Player2 wins"); Console.WriteLine("Player1 Combination: {0}", p1Hand.Combination); Console.WriteLine("Player2 Combination: {0}", p2Hand.Combination); _player2.WinBank(_bank); } _bank = 0; DisplayBanks(); }
public Hand(HandValue t) { this.type = t; this.top_five = null; }
string GetFeatureValue(InputDevice device, InputFeatureUsage featureUsage) { switch (featureUsage.type.ToString()) { case "System.Boolean": bool boolValue; if (device.TryGetFeatureValue(featureUsage.As <bool>(), out boolValue)) { return(boolValue.ToString()); } break; case "System.UInt32": uint uintValue; if (device.TryGetFeatureValue(featureUsage.As <uint>(), out uintValue)) { return(uintValue.ToString()); } break; case "System.Single": float floatValue; if (device.TryGetFeatureValue(featureUsage.As <float>(), out floatValue)) { return(floatValue.ToString()); } break; case "UnityEngine.Vector2": Vector2 Vector2Value; if (device.TryGetFeatureValue(featureUsage.As <Vector2>(), out Vector2Value)) { return(Vector2Value.ToString()); } break; case "UnityEngine.Vector3": Vector3 Vector3Value; if (device.TryGetFeatureValue(featureUsage.As <Vector3>(), out Vector3Value)) { return(Vector3Value.ToString()); } break; case "UnityEngine.Quaternion": Quaternion QuaternionValue; if (device.TryGetFeatureValue(featureUsage.As <Quaternion>(), out QuaternionValue)) { return(QuaternionValue.ToString()); } break; case "UnityEngine.XR.Hand": Hand HandValue; if (device.TryGetFeatureValue(featureUsage.As <Hand>(), out HandValue)) { return(HandValue.ToString()); } break; case "UnityEngine.XR.Bone": Bone BoneValue; if (device.TryGetFeatureValue(featureUsage.As <Bone>(), out BoneValue)) { Vector3 bonePosition; Quaternion boneRotation; if (BoneValue.TryGetPosition(out bonePosition) && BoneValue.TryGetRotation(out boneRotation)) { return(string.Format("{0}, {1}", bonePosition.ToString(), boneRotation.ToString())); } } break; case "UnityEngine.XR.Eyes": Eyes EyesValue; if (device.TryGetFeatureValue(featureUsage.As <Eyes>(), out EyesValue)) { Vector3 fixation, left, right; float leftOpen, rightOpen; if (EyesValue.TryGetFixationPoint(out fixation) && EyesValue.TryGetLeftEyePosition(out left) && EyesValue.TryGetRightEyePosition(out right) && EyesValue.TryGetLeftEyeOpenAmount(out leftOpen) && EyesValue.TryGetRightEyeOpenAmount(out rightOpen)) { return(string.Format("{0}, {1}, {2}, {3}, {4}", fixation.ToString(), left.ToString(), right.ToString(), leftOpen, rightOpen)); } } break; } return(""); }
string GetFeatureValue(InputDevice device, InputFeatureUsage featureUsage) { switch (featureUsage.type.ToString()) { case "System.Boolean": bool boolValue; if (device.TryGetFeatureValue(featureUsage.As <bool>(), out boolValue)) { return(boolValue.ToString()); } break; case "System.UInt32": uint uintValue; if (device.TryGetFeatureValue(featureUsage.As <uint>(), out uintValue)) { return(uintValue.ToString()); } break; case "System.Single": float floatValue; if (device.TryGetFeatureValue(featureUsage.As <float>(), out floatValue)) { return(floatValue.ToString()); } break; case "UnityEngine.Vector2": Vector2 Vector2Value; if (device.TryGetFeatureValue(featureUsage.As <Vector2>(), out Vector2Value)) { return(Vector2Value.ToString()); } break; case "UnityEngine.Vector3": Vector3 Vector3Value; if (device.TryGetFeatureValue(featureUsage.As <Vector3>(), out Vector3Value)) { return(Vector3Value.ToString()); } break; case "UnityEngine.Quaternion": Quaternion QuaternionValue; if (device.TryGetFeatureValue(featureUsage.As <Quaternion>(), out QuaternionValue)) { return(QuaternionValue.ToString()); } break; case "UnityEngine.XR.Hand": Hand HandValue; if (device.TryGetFeatureValue(featureUsage.As <Hand>(), out HandValue)) { return(HandValue.ToString()); } break; case "UnityEngine.XR.Bone": Bone BoneValue; if (device.TryGetFeatureValue(featureUsage.As <Bone>(), out BoneValue)) { return(BoneValue.ToString()); } break; case "UnityEngine.XR.Eyes": Eyes EyesValue; if (device.TryGetFeatureValue(featureUsage.As <Eyes>(), out EyesValue)) { return(EyesValue.ToString()); } break; } return(""); }
public void Count(UInt32 handVal) { HandValue.Kind handType = HandValue.GetKind(handVal); _handTypesCount[(int)handType]++; _handTypesCount[(int)HandValue.Kind._Count]++; // Total. }
public int CompareTo(Seat other) { return(HandValue.CompareTo(other.HandValue)); }
public void Test_ValueToString() { CardSet m; UInt32 value; string text; m = StdDeck.Descriptor.GetCardSet("2s 3h 6c Ah 9d Kd Js"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("High Card: Ah Kd Js 9d 6c", text); m = StdDeck.Descriptor.GetCardSet("7s 6h 7c Ah 9d Qd Jd"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("Pair: 7c 7s Ah Qd Jd", text); m = StdDeck.Descriptor.GetCardSet("7s 6h 7c Ah 9d Qd Ad"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("2 Pair: Ad Ah 7c 7s Qd", text); m = StdDeck.Descriptor.GetCardSet("2s 6h 7c Ah 2d Qd 2c"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("3 of a Kind: 2c 2d 2s Ah Qd", text); m = StdDeck.Descriptor.GetCardSet("2s 6h 3c 5h 4d 8d 2c"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("Straight: 6h 5h 4d 3c 2c", text); m = StdDeck.Descriptor.GetCardSet("2s Ah 3c 5h 4d 8d 2c"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("Straight: 5h 4d 3c 2c Ah", text); m = StdDeck.Descriptor.GetCardSet("2s 6s Qs 4h 8s 8d 7s"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("Flush: Qs 8s 7s 6s 2s", text); m = StdDeck.Descriptor.GetCardSet("2s 6h 7c Ah 2d Qd 2c"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("3 of a Kind: 2c 2d 2s Ah Qd", text); m = StdDeck.Descriptor.GetCardSet("2s 6h 7c 6c 2d Qd 2c"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("Full House: 2c 2d 2s 6c 6h", text); m = StdDeck.Descriptor.GetCardSet("2s 6h 7c Ah 2d 2h 2c"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("4 of a Kind: 2c 2d 2h 2s Ah", text); m = StdDeck.Descriptor.GetCardSet("As 5s 9s 7s 8s 6s Qc"); value = CardSetEvaluator.Evaluate(ref m); text = HandValue.ValueToString(m, value); Assert.AreEqual("Straight Flush: 9s 8s 7s 6s 5s", text); }
public Hand(HandValue t, Card[] five) { this.type = t; this.top_five = five; }
public (List <Card> Cards, Hands HandValue, Suits Suit) EvaluateHand(List <Card> cards) { HandValue = Hands.Nothing; Suit = 0; BestCards.Clear(); if (cards.Count() >= 2) { #region Sort the cards cards.Sort(); #endregion #region Royal Straight Flush & Straight Flush & Straight StraightCards(cards); if (HandValue.Equals(Hands.RoyalStraightFlush) || HandValue.Equals(Hands.StraightFlush)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Four of a kind IsFourOfAKind(cards); if (HandValue.Equals(Hands.FourOfAKind)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Full House IsFullHouse(cards); if (HandValue.Equals(Hands.FullHouse)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Flush FlushCards(cards); if (HandValue.Equals(Hands.Flush)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Straight if (HandValue.Equals(Hands.Straight)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Three of a Kind IsThreeOfAKind(cards); if (HandValue.Equals(Hands.ThreeOfAKind)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Two Pair IsTwoPair(cards); if (HandValue.Equals(Hands.TwoPair)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region Pair IsPair(cards); if (HandValue.Equals(Hands.Pair)) { return(Cards : BestCards, HandValue : HandValue, Suit : Suit); } #endregion #region High Card HighCard(cards); #endregion } return(Cards : BestCards, HandValue : HandValue, Suit : Suit); }
public static string FindBestHandValue(string inputLine) { string[] splits = inputLine.Split(' '); //validate the length of the input lines and number of card codes if (inputLine.Length != 29 || splits.Length != 10) { throw new InvalidInputException("Invalid input line: " + inputLine); } else { ParseResult parseResult; string handString; string deckString; try { int halfLength = inputLine.Length / 2; //get the card codes representing the hand handString = inputLine.Substring(0, halfLength); //get the card codes representing the deck deckString = inputLine.Remove(0, halfLength + 1); //parse the card codes and create corresponding Hand and Deck objects parseResult = InputParser.Parse(handString, deckString); } catch (InvalidInputException ex) { //this exception is thrown by our own classes to indicate an invalid input throw new InvalidInputException(ex.Message + inputLine); } catch { //any other unknown exception that may occur during input parsing throw new InvalidInputException("Invalid input line: " + inputLine); } //this will be used to enumarate all possible (32) card combinations int enumerator = 0; //this is the temporary value of enumerator used in the loop int temp; Hand hand; Deck deck; //represents the best hand value HandValue result = HandValue.highest_card; HandValue current; //in this loop we enumerate and try all possible hands //to do this we use the binary representation of the numbers from 0 to 31 //00000 means no card is replaced (no card drawn from the deck) //00001 means first card of the hand is replaced //10001 means first and last cards of the hand is replaced and so on. while (enumerator < 32) { temp = enumerator; hand = new Hand(parseResult.Hand); deck = new Deck(parseResult.Deck); for (int i = 0; i < 5; i++) { //determine if the current card will be replaced //if the last bit is 1, then the card in the current index is replaced if ((temp & 1) == 1) { hand.ReplaceCard(i, deck.GetNext()); } //we are done with this bit, so drop it temp = temp >> 1; } //calculate the hand value current = hand.GetHandValue(); if (current > result) { result = current; } //if it is a straight flush, no need to check other possible hands if (result == HandValue.straight_flush) { break; } //advance to the next hand enumerator++; } return("Hand: " + handString + " Deck:" + deckString + " Best hand: " + result.ToString()); } }