public BaseRankedHand GetHighestMadeRankedHand() { highestMadeRankedHand = new HandStraightFlush(_cards); if (highestMadeRankedHand.IsMade()) { return(highestMadeRankedHand); } highestMadeRankedHand = new HandFourOfAKind(_cards); if (highestMadeRankedHand.IsMade()) { return(highestMadeRankedHand); } // SEVEN-UP // Modified for Seven-Up. Flush beats Full House. highestMadeRankedHand = new HandFlush(_cards); if (highestMadeRankedHand.IsMade()) { return(highestMadeRankedHand); } highestMadeRankedHand = new HandFullHouse(_cards); if (highestMadeRankedHand.IsMade()) { return(highestMadeRankedHand); } highestMadeRankedHand = new HandStraight(_cards); if (highestMadeRankedHand.IsMade()) { return(highestMadeRankedHand); } highestMadeRankedHand = new HandThreeOfAKind(_cards); if (highestMadeRankedHand.IsMade()) { return(highestMadeRankedHand); } highestMadeRankedHand = new HandTwoPair(_cards); if (highestMadeRankedHand.IsMade()) { return(highestMadeRankedHand); } highestMadeRankedHand = new HandOnePair(_cards); if (highestMadeRankedHand.IsMade()) { return(highestMadeRankedHand); } highestMadeRankedHand = new HandHighCard(_cards); return(highestMadeRankedHand); }
/// <summary> /// /// </summary> /// <param name="pOpponentHand"></param> /// <returns> /// -1 if this Hand wins /// 1 if pOpponentHand wins /// </returns> public int CompareSameRankHand(BaseRankedHand pOpponentHand) { int tHand1; int tHand2; // Primary Made tHand1 = GetMadeNumericRank(); tHand2 = pOpponentHand.GetMadeNumericRank(); if (tHand1 > tHand2) { return(-1); } else if (tHand1 < tHand2) { return(1); } // Secondary Made tHand1 = GetMade2NumericRank(); tHand2 = pOpponentHand.GetMade2NumericRank(); if (tHand1 > tHand2) { return(-1); } else if (tHand1 < tHand2) { return(1); } // Kickers for (int i = 0; i < 4; i++) { tHand1 = GetNextKickerValue(); tHand2 = pOpponentHand.GetNextKickerValue(); if (tHand1 > tHand2) { return(-1); } else if (tHand1 < tHand2) { return(1); } } // Couldn't find a winner! Return tie. :( return(0); }
/// <summary> /// Static Utility method /// </summary> /// <param name="pRankedHand1"></param> /// <param name="pRankedHand2"></param> /// <returns> /// return -2 if no winner /// return -1 if 1 wins /// return 0 if tie /// return 1 if 2 wins /// </returns> public static int CompareRankedHands(BaseRankedHand pRankedHand1, BaseRankedHand pRankedHand2) { bool tIsHand1Made = pRankedHand1.IsMade(); bool tIsHand2Made = pRankedHand2.IsMade(); if (tIsHand1Made && tIsHand2Made) { // Determine if one it's a tie or one of them is the winner return(pRankedHand1.CompareSameRankHand(pRankedHand2)); } else if (tIsHand1Made) { return(-1); } else if (tIsHand2Made) { return(1); } ; // no winner return(-2); }
private IEnumerable DrawCards() { //////////////// // Player Draw //////////////// int i; int iLen; Card tCard; float tNewX; float tNewY; float tNewZ; // Set and display discard info _context.playerHand.SetDiscardCards(); // Draw new cards to fill hand List <Card> tPlayerChosenCards = _context.playerHand.ChosenCards; iLen = 5; for (i = tPlayerChosenCards.Count; i < iLen; i++) { tCard = _context.playerHand.AddCardToChosenCards(_context.deck.DealCard()); GameObject tCardGO = tCard.InstantiatedGO; tCardGO.transform.parent = _context.table.transform; tNewX = _context.defaultCardLocalPosition.x + (_context.playerHand.ChosenCards.Count - 1) * Controller.cardWidth; tNewY = _context.defaultCardLocalPosition.y - Controller.cardHeight * 3; tNewZ = _context.defaultCardLocalPosition.z; Vector3 tPositionTarget = new Vector3(tNewX, tNewY, tNewZ); // Set position and rotation to pre-tween location tCardGO.transform.localPosition = _context.deckLocalPosition; tCardGO.transform.rotation = _context.cardRotationFaceDown; // Cascade entry tCardGO.SetActive(true); tCard.InstantiatedGO.transform.ZKlocalPositionTo(tPositionTarget, Controller.animationTimeSlow).setEaseType(EaseType.QuintOut).start(); tCard.InstantiatedGO.transform.ZKlocalRotationTo(_context.cardRotationFaceUp, Controller.animationTimeSlow).setEaseType(EaseType.QuintOut).start(); yield return(new WaitForSeconds(Controller.animationWaitSlow)); } //////////////// // Player Move Discards //////////////// // Move discarded cards the left iLen = _context.playerHand.DiscardCards.Count; for (i = 0; i < iLen; i++) { tCard = _context.playerHand.DiscardCards[i]; tNewX = _context.defaultCardLocalPosition.x + Controller.cardWidth * i; tNewY = tCard.InstantiatedGO.transform.localPosition.y; tNewZ = tCard.InstantiatedGO.transform.localPosition.z; Vector3 tPositionTarget = new Vector3(tNewX, tNewY, tNewZ); tCard.InstantiatedGO.transform.ZKlocalPositionTo(tPositionTarget, Controller.animationTimeQuick).setEaseType(EaseType.QuintOut).start(); yield return(new WaitForSeconds(Controller.animationWaitSlow)); } //////////////// // Dealer Draw //////////////// // Choose any Made cards, similar to the way player chose cards one by one BaseRankedHand tDealerRankedHand = _context.dealerHand.GetHighestMadeRankedHand(); List <Card> tDealerHandCards = _context.dealerHand.Cards; // If a hand was specified for the dealer in the Inspector // keep all cards so it can be tested against the player's chosen hand List <Card> tDealerMadeList; if (_context.dealerHandType == DebugHands.NormalHandDeal) { tDealerMadeList = tDealerRankedHand.GetMadeList(); } else { tDealerMadeList = new List <Card>(); foreach (Card tDealerCard in _context.dealerHand.Cards) { tDealerMadeList.Add(tDealerCard); } } iLen = tDealerMadeList.Count; for (i = 0; i < iLen; i++) { // Simulated Clicked Card is in the Dealer's Hand tCard = tDealerMadeList[i]; if (tCard != null) { _context.dealerHand.ChooseCard(tCard); tNewX = _context.defaultCardLocalPosition.x + (_context.dealerHand.ChosenCards.Count - 1) * Controller.cardWidth; tNewY = _context.defaultCardLocalPosition.y - Controller.cardHeight * 1; tNewZ = _context.defaultCardLocalPosition.z; tCard.InstantiatedGO.transform.ZKlocalPositionTo(new Vector3(tNewX, tNewY, tNewZ), Controller.animationTimeQuick).setEaseType(EaseType.QuintOut).start(); yield return(new WaitForSeconds(Controller.animationWaitSlow)); } } //////////////// // Dealer Draw //////////////// // Choose new cards and animate into place List <Card> tDealerChosenCards = _context.dealerHand.ChosenCards; iLen = 5; for (i = tDealerChosenCards.Count; i < iLen; i++) { tCard = _context.dealerHand.AddCardToChosenCards(_context.deck.DealCard()); GameObject tCardGO = tCard.InstantiatedGO; tCardGO.transform.parent = _context.table.transform; tNewX = _context.defaultCardLocalPosition.x + (_context.dealerHand.ChosenCards.Count - 1) * Controller.cardWidth; tNewY = _context.defaultCardLocalPosition.y - Controller.cardHeight; tNewZ = _context.defaultCardLocalPosition.z; Vector3 tPositionTarget = new Vector3(tNewX, tNewY, tNewZ); // Set position and rotation to pre-tween location tCardGO.transform.localPosition = _context.deckLocalPosition; tCardGO.transform.rotation = _context.cardRotationFaceDown; tCardGO.SetActive(true); tCard.InstantiatedGO.transform.ZKlocalPositionTo(tPositionTarget, Controller.animationTimeSlow).setEaseType(EaseType.QuintOut).start(); // Cascade entry if (i < iLen - 1) { yield return(new WaitForSeconds(Controller.animationWaitSlow)); } } //////////////// // Dealer Move Discard Cards //////////////// // Now finalize discard choices and move un-chosen cards to the discard stack _context.dealerHand.SetDiscardCards(); iLen = _context.dealerHand.DiscardCards.Count; for (i = 0; i < iLen; i++) { tCard = _context.dealerHand.DiscardCards[i]; tNewX = _context.defaultCardLocalPosition.x + Controller.cardWidth * i; tNewY = tCard.InstantiatedGO.transform.localPosition.y; tNewZ = tCard.InstantiatedGO.transform.localPosition.z; Vector3 tPositionTarget = new Vector3(tNewX, tNewY, tNewZ); tCard.InstantiatedGO.transform.ZKlocalPositionTo(tPositionTarget, Controller.animationTimeQuick).setEaseType(EaseType.QuintOut).start(); yield return(new WaitForSeconds(Controller.animationWaitFast)); } }