Esempio n. 1
0
 public static PokerScoreOuts CalculateRiver(SixCardHand cards)
 {
     //if there are 4 of the same suit there are 9 more of that suit we can hit
     return(cards.CountFlush() == 4
         ? PokerHelper.CreateRiverOuts(9)
         : PokerHelper.CreateRiverOuts(0));
 }
Esempio n. 2
0
    public override IEnumerator Start()
    {
        List <Card> BoardCards = m_Manager.m_Board.getBoardCards();
        int         m_index    = 0;

        foreach (PlayerHand p in m_Manager.m_Players)
        {
            List <Card> CombinedHand = new List <Card>();
            List <Card> PlayerHand   = p.getHandCards();
            foreach (Card c in BoardCards)
            {
                CombinedHand.Add(c);
            }
            foreach (Card c in p.getHandCards())
            {
                CombinedHand.Add(c);
            }
            p.m_PokerHand = PokerHelper.CheckHand(ref PlayerHand, CombinedHand);
            p.setHandCards(PlayerHand);
            Debug.Log("Player_CardHand:" + p.getHandCards().Count + " poker hand" + p.m_PokerHand);
            m_Manager.m_Interface.SetPlayerResult(m_index++, p.m_PokerHand.ToString());
        }

        m_Manager.SetState(new CompResult(m_Manager));
        yield break;
    }
Esempio n. 3
0
        public void HighCardTieBreak_HandOneWinsTest()
        {
            PokerHelper poker = new PokerHelper();
            List <Card> hand1 = new List <Card>
            {
                new Card("KC"),
                new Card("KD"),
                new Card("9S"),
                new Card("9D"),
                new Card("2S")
            };

            List <Card> hand2 = new List <Card>
            {
                new Card("KS"),
                new Card("KH"),
                new Card("8S"),
                new Card("8D"),
                new Card("2C")
            };

            bool winner = poker.HighCardTieBreak_HandOneWins(hand1, hand2);

            Assert.IsTrue(winner);
        }
Esempio n. 4
0
    public void ShowCardType(PokerSide side)
    {
        CardType.gameObject.SetActive(true);
        List <PokerCard> cardList = new List <PokerCard>(side.Cards);
        PokerCardType    cardType = PokerHelper.GetCardsType(ref cardList);

        CardType.sprite = Resources.Load <Sprite>("cardtype/" + cardType);
    }
 public void ShowAllCards()
 {
     HandValue = 0;
     foreach (Card c in Hand)
     {
         c.ShowCard(true);
         HandValue += PokerHelper.ConvertToVal(c.GetCardValue());
     }
 }
Esempio n. 6
0
        public void Settlement()
        {
            LogHelper.DebugLog("Settlement begin1...");
            //自动结算,如果当前只有一个玩家,这个玩家赢得所有,如果不只一个就开始比牌
            List <PokerSide> winSides = new List <PokerSide>();

            foreach (var s in Battle.Sides)
            {
                if (s.IsFlipCard)
                {
                    continue;
                }
                if (winSides.Count == 0)
                {
                    winSides.Add(s);
                }
                else
                {
                    PokerSide        oneSide           = winSides.FirstOrDefault();
                    List <PokerCard> currentSiderCards = new List <PokerCard>(oneSide.Cards);
                    List <PokerCard> targetSiderCards  = new List <PokerCard>(s.Cards);
                    int compareResult = PokerHelper.CardGroupCompare(ref currentSiderCards, ref targetSiderCards);
                    if (compareResult == 0)
                    {
                        winSides.Add(s);
                    }
                    else if (compareResult < 0)
                    {
                        winSides.Clear();
                        winSides.Add(s);
                    }
                }
            }
            //开始结算金币
            LogHelper.DebugLog("Settlement begin2...");
            if (winSides.Count > 0)
            {
                int winGold = Battle.BetGoldNum / winSides.Count;
                foreach (var s in winSides)
                {
                    s.WinGold = winGold;
                    s.Gold   += winGold;
                    try
                    {
                        new AccountService().WinGold(int.Parse(s.AccountID), winGold);
                    }
                    catch (Exception ex)
                    {
                        LogHelper.LogError(ex.StackTrace);
                    }
                }
            }
            LogHelper.DebugLog("Settlement begin3...");
            ToPokerCleintCommand.SendToClient(PokerCommand.Settlement, Battle);
            CleanUpAndRestart();
        }
Esempio n. 7
0
    public int GetCardVal_OnIndex(int index)
    {
        if (index < NumberOfCards)
        {
            return(PokerHelper.ConvertToVal(BoardHand[index].GetCardValue()));
        }

        Debug.Log("hand Empty");
        return(0);
    }
        public static PokerScoreOuts CalculateTurn(FiveCardHand cards)
        {
            if (cards.HasThreeOfAKind())
            {
                return(TurnOutsDictionary[Pokerscore.ThreeOfAKind]);
            }
            if (cards.HasTwoPair())
            {
                return(TurnOutsDictionary[Pokerscore.TwoPair]);
            }

            return(PokerHelper.CreateTurnOuts(0, false));
        }
Esempio n. 9
0
        public static PokerScoreOuts CalculateTurn(FiveCardHand cards)
        {
            if (cards.CountFlush() == 4)
            {
                return(PokerHelper.CreateTurnOuts(9, false));
            }
            if (cards.CountFlush() == 3)
            {
                return new PokerScoreOuts {
                           Outs = 0, Percentage = 4.163, RunnerRunner = true
                }
            }
            ;

            return(PokerHelper.CreateTurnOuts(0, false));
        }
Esempio n. 10
0
        public static PokerScoreOuts CalculateRiver(SixCardHand cards)
        {
            if (cards.HasThreePair())
            {
                return(PokerHelper.CreateRiverOuts(6));
            }
            if (cards.HasThreeOfAKind())
            {
                return(PokerHelper.CreateRiverOuts(9));
            }
            if (cards.HasTwoPair())
            {
                return(PokerHelper.CreateRiverOuts(4));
            }

            return(PokerHelper.CreateRiverOuts(0));
        }
Esempio n. 11
0
        public void GetDuplicatesTest()
        {
            PokerHelper poker = new PokerHelper();
            List <Card> cards = new List <Card>
            {
                new Card("KS"),
                new Card("KH"),
                new Card("9S"),
                new Card("9D"),
                new Card("2S")
            };
            int expectedPairMax = 13;
            int expectedPairMin = 9;

            List <int> duplicates = poker.GetDuplicates(cards);

            Assert.AreEqual(expectedPairMax, duplicates.Max());
            Assert.AreEqual(expectedPairMin, duplicates.Min());
        }
    public override IEnumerator Start()
    {
        PlayerHand playerone = m_Manager.m_Players[0];
        PlayerHand playertwo = m_Manager.m_Players[1];

        if ((int)playerone.m_PokerHand > (int)playertwo.m_PokerHand)
        {
            m_Manager.m_Interface.SetWinnerResult(playerone.GetPlayerName());
        }
        else if ((int)playerone.m_PokerHand == (int)playertwo.m_PokerHand)
        {
            m_Manager.m_Interface.SetWinnerResult(PokerHelper.CheckDrawWinner(playerone, playertwo));
        }
        else
        {
            m_Manager.m_Interface.SetWinnerResult(playertwo.GetPlayerName());
        }

        m_Manager.SetState(new Idle(m_Manager));
        yield break;
    }
Esempio n. 13
0
        public void ComputeWinner_ForExampleData_ReturnsCorrectResult()
        {
            // Arrange
            var testPokerHands = TestData.ExamplePokerHandsProblem54();

            // Act
            var result1 = PokerHelper.ComputeWinner(testPokerHands.Item1[0], testPokerHands.Item2[0]);
            var result2 = PokerHelper.ComputeWinner(testPokerHands.Item1[1], testPokerHands.Item2[1]);
            var result3 = PokerHelper.ComputeWinner(testPokerHands.Item1[2], testPokerHands.Item2[2]);
            var result4 = PokerHelper.ComputeWinner(testPokerHands.Item1[3], testPokerHands.Item2[3]);
            var result5 = PokerHelper.ComputeWinner(testPokerHands.Item1[4], testPokerHands.Item2[4]);

            // Assert
            using (new AssertionScope())
            {
                result1.Should().Be(2);
                result2.Should().Be(1);
                result3.Should().Be(2);
                result4.Should().Be(1);
                result5.Should().Be(1);
            }
        }
Esempio n. 14
0
        public void GetNonDuplicatesTest()
        {
            PokerHelper poker = new PokerHelper();
            List <Card> cards = new List <Card>
            {
                new Card("KS"),
                new Card("KH"),
                new Card("9S"),
                new Card("9D"),
                new Card("2S")
            };
            List <int> duplicates = new List <int>
            {
                13,
                9
            };
            string      expectedCardValue = "2S";
            int         expectedCount     = 1;
            List <Card> nonDuplicates     = poker.GetNonDuplicates(cards, duplicates);

            Assert.AreEqual(expectedCount, nonDuplicates.Count());
            Assert.AreEqual(expectedCardValue, nonDuplicates[0].Value);
        }
Esempio n. 15
0
        public void OperationBack(string accountID, PokerOperationType operationType, bool look, string par1)
        {
            Countdown.ClearCommand();
            PokerSide currentSider = Battle.Sides.FirstOrDefault(c => c.AccountID == accountID);
            int       uid          = Convert.ToInt32(accountID);

            if (operationType == PokerOperationType.Bet)
            {
                int goldnum = Convert.ToInt32(par1);
                if (look && !currentSider.IsFlipCard)
                {
                    goldnum = goldnum + this.Battle.CurrentNoteNum;
                    currentSider.IsFlipCard = true;
                }
                currentSider.BatGold       = goldnum;
                currentSider.Gold         -= goldnum;
                this.Battle.CurrentNoteNum = goldnum;
            }
            else if (operationType == PokerOperationType.CompareCard)
            {
                string    targetAccountID = par1;
                PokerSide targetSider     = Battle.Sides.FirstOrDefault(c => c.AccountID == targetAccountID);

                int goldnum = this.Battle.CurrentNoteNum * 2;
                if (currentSider.IsFlipCard && targetSider.IsFlipCard)
                {
                    goldnum = this.Battle.CurrentNoteNum;
                }
                if (look)
                {
                    currentSider.IsFlipCard = true;
                }
                List <PokerCard> currentSiderCards = new List <PokerCard>(currentSider.Cards);
                List <PokerCard> targetSiderCards  = new List <PokerCard>(targetSider.Cards);
                int compareResult = PokerHelper.CardGroupCompare(ref currentSiderCards, ref targetSiderCards);
                if (compareResult <= 0)
                {
                    currentSider.IsDisCard = true;
                }
                else
                {
                    targetSider.IsDisCard = true;
                }
                currentSider.BatGold = goldnum;
                currentSider.Gold   -= goldnum;
            }
            else if (operationType == PokerOperationType.Discard)
            {
                currentSider.IsDisCard = true;
            }
            else if (operationType == PokerOperationType.Follow)
            {
                int goldnum = this.Battle.CurrentNoteNum;
                if (look && !currentSider.IsFlipCard)
                {
                    goldnum = goldnum + this.Battle.CurrentNoteNum;
                    currentSider.IsFlipCard = true;
                }
                currentSider.BatGold       = goldnum;
                currentSider.Gold         -= goldnum;
                this.Battle.CurrentNoteNum = goldnum;
            }
            Battle.OperationType = operationType;
            Battle.OperationLook = look;
            Battle.OperationPar1 = par1;
            ToPokerCleintCommand.SendToClient(PokerCommand.OperationBack, Battle);

            //每回合扣玩家金币,把金币放到战斗托管中心
            ThisTrunOperationNum++;
            if (ThisTrunOperationNum >= Battle.Sides.Count)
            {
                Battle.TrunNum++;
                ThisTrunOperationNum = 0;
                foreach (var s in Battle.Sides)
                {
                    if (s.BatGold > 0)
                    {
                        this.Battle.BetGoldNum += s.BatGold;
                        new AccountService().DeductedGold(int.Parse(s.AccountID), s.BatGold);
                    }
                    s.BatGold = 0;
                }
                ToPokerCleintCommand.SendToClient(PokerCommand.OneTrunComplated, Battle);
            }
            Operation();
        }
Esempio n. 16
0
        public static PokerScoreOuts CalculateRiver(SixCardHand cards)
        {
            ISet <int> inside  = new HashSet <int>(),
                       outside = new HashSet <int>();

            var withoutPair = cards.RemovePairs();
            var handList    = new List <int> {
                cards.Cards[0].ToInt(), cards.Cards[1].ToInt(), cards.Cards[2].ToInt(), cards.Cards[3].ToInt(), cards.Cards[4].ToInt(), cards.Cards[5].ToInt()
            };

            if (withoutPair.Count <= 3)
            {
                return(PokerHelper.CreateRiverOuts(0));
            }
            if (withoutPair.Count == 4)
            {
                if (withoutPair[3].Rank == Rank.Ace && withoutPair[2].Rank <= Rank.Five)
                {
                    withoutPair = new List <Card> {
                        withoutPair[3], withoutPair[0], withoutPair[1], withoutPair[2]
                    }
                }
                ;

                outside = PokerHelper.CountOutsideStraightDraws(handList, withoutPair);
                if (outside.Count > 0)
                {
                    return(PokerHelper.CreateTurnOuts(outside.Count * 4, false));
                }

                inside = PokerHelper.CountInsideStraightDraws(handList, withoutPair);
                if (inside.Count > 0)
                {
                    return(PokerHelper.CreateTurnOuts(inside.Count * 4, false));
                }

                return(PokerHelper.CreateRiverOuts(0));
            }
            if (withoutPair.Count == 5)
            {
                if (withoutPair[4].Rank == Rank.Ace && withoutPair[2].Rank <= Rank.Five)
                {
                    var comb = new List <Card> {
                        withoutPair[4], withoutPair[0], withoutPair[1], withoutPair[2]
                    };
                    outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                    if (outside.Count > 0)
                    {
                        return(PokerHelper.CreateTurnOuts(outside.Count * 4, false));
                    }

                    inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                    if (inside.Count > 0)
                    {
                        return(PokerHelper.CreateTurnOuts(inside.Count * 4, false));
                    }
                }

                foreach (var comb in PokerEnumerator.GetFourCardsFromFive(withoutPair))
                {
                    outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                    inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                }

                outside.UnionWith(inside);
                if (outside.Count > 0)
                {
                    return(PokerHelper.CreateRiverOuts(outside.Count * 4));
                }
                return(PokerHelper.CreateRiverOuts(0));
            }
            if (withoutPair.Count == 6)
            {
                if (withoutPair[5].Rank == Rank.Ace && withoutPair[2].Rank <= Rank.Five)
                {
                    var comb = new List <Card> {
                        withoutPair[5], withoutPair[0], withoutPair[1], withoutPair[2]
                    };
                    outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                    inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                }

                foreach (var comb in PokerEnumerator.GetFourCardsFromSix(withoutPair))
                {
                    outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                    inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                }

                outside.UnionWith(inside);
                if (outside.Count > 0)
                {
                    return(PokerHelper.CreateRiverOuts(outside.Count * 4));
                }
                return(PokerHelper.CreateRiverOuts(0));
            }
            throw new ArgumentException("Without pair count should never be more than six");
        }
    }
Esempio n. 17
0
        public static PokerScoreOuts CalculateTurn(FiveCardHand cards)
        {
            ISet <int> open       = new HashSet <int>(),
                       missingOne = new HashSet <int>(),
                       missingTwo = new HashSet <int>(),
                       inside     = new HashSet <int>(),
                       outside    = new HashSet <int>();

            var withoutPair = cards.RemovePairs();
            var handList    = new List <int> {
                cards.Cards[0].ToInt(), cards.Cards[1].ToInt(), cards.Cards[2].ToInt(), cards.Cards[3].ToInt(), cards.Cards[4].ToInt()
            };

            if (withoutPair.Count <= 2)
            {
                return(PokerHelper.CreateTurnOuts(0, true));
            }
            if (withoutPair.Count == 3)
            {
                if (withoutPair[2].Rank == Rank.Ace && withoutPair[0].Rank <= Rank.Four)
                {
                    withoutPair = new List <Card> {
                        withoutPair[2], withoutPair[0], withoutPair[1]
                    }
                }
                ;
                open       = PokerHelper.CountThreeOpenEnded(handList, withoutPair);
                missingOne = PokerHelper.CountThreeMissingOne(handList, withoutPair);
                missingTwo = PokerHelper.CountThreeMissingTwo(handList, withoutPair);

                return(PokerHelper.RunnerRunnerOuts(open, missingOne, missingTwo));
            }
            if (withoutPair.Count == 4)
            {
                outside = PokerHelper.CountOutsideStraightDraws(handList, withoutPair);
                if (outside.Count > 0)
                {
                    return(PokerHelper.CreateTurnOuts(outside.Count * 4, false));
                }

                inside = PokerHelper.CountInsideStraightDraws(handList, withoutPair);
                if (inside.Count > 0)
                {
                    return(PokerHelper.CreateTurnOuts(inside.Count * 4, false));
                }

                if (withoutPair[3].Rank == Rank.Ace)
                {
                    var comb = new List <Card> {
                        withoutPair[3], withoutPair[0], withoutPair[1]
                    };
                    open.UnionWith(PokerHelper.CountThreeOpenEnded(handList, comb));
                    missingOne.UnionWith(PokerHelper.CountThreeMissingOne(handList, comb));
                    missingTwo.UnionWith(PokerHelper.CountThreeMissingTwo(handList, comb));
                }

                foreach (var comb in PokerEnumerator.GetThreeCardsFromFour(withoutPair))
                {
                    open.UnionWith(PokerHelper.CountThreeOpenEnded(handList, comb));
                    missingOne.UnionWith(PokerHelper.CountThreeMissingOne(handList, comb));
                    missingTwo.UnionWith(PokerHelper.CountThreeMissingTwo(handList, comb));
                }

                return(PokerHelper.RunnerRunnerOuts(open, missingOne, missingTwo));
            }
            if (withoutPair.Count == 5)
            {
                //Four card collections
                if (withoutPair[4].Rank == Rank.Ace && withoutPair[2].Rank <= Rank.Five)
                {
                    var comb = new List <Card> {
                        withoutPair[4], withoutPair[0], withoutPair[1], withoutPair[2]
                    };

                    outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                    if (outside.Count > 0)
                    {
                        return(PokerHelper.CreateTurnOuts(outside.Count * 4, false));
                    }

                    inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                    if (inside.Count > 0)
                    {
                        return(PokerHelper.CreateTurnOuts(inside.Count * 4, false));
                    }
                }

                foreach (var comb in PokerEnumerator.GetFourCardsFromFive(withoutPair))
                {
                    outside.UnionWith(PokerHelper.CountOutsideStraightDraws(handList, comb));
                    inside.UnionWith(PokerHelper.CountInsideStraightDraws(handList, comb));
                }

                outside.UnionWith(inside);
                if (outside.Count > 0)
                {
                    return(PokerHelper.CreateRiverOuts(outside.Count * 4));
                }

                //Three card collections
                if (withoutPair[4].Rank == Rank.Ace)
                {
                    var comb = new List <Card> {
                        withoutPair[4], withoutPair[0], withoutPair[1]
                    };
                    open.UnionWith(PokerHelper.CountThreeOpenEnded(handList, comb));
                    missingOne.UnionWith(PokerHelper.CountThreeMissingOne(handList, comb));
                    missingTwo.UnionWith(PokerHelper.CountThreeMissingTwo(handList, comb));
                }

                foreach (var comb in PokerEnumerator.GetThreeCardsFromFive(withoutPair))
                {
                    open.UnionWith(PokerHelper.CountThreeOpenEnded(handList, comb));
                    missingOne.UnionWith(PokerHelper.CountThreeMissingOne(handList, comb));
                    missingTwo.UnionWith(PokerHelper.CountThreeMissingTwo(handList, comb));
                }

                return(PokerHelper.RunnerRunnerOuts(open, missingOne, missingTwo));
            }
            throw new ArgumentException("Without pair count should never be more than five");
        }
 public static PokerScoreOuts CalculateRiver(SixCardHand cards)
 {
     return(cards.HasThreeOfAKind()
         ? PokerHelper.CreateRiverOuts(1)
         : PokerHelper.CreateRiverOuts(0));
 }
Esempio n. 19
0
 public static PokerScoreOuts CalculateTurn(FiveCardHand cards)
 {
     return(PokerHelper.CreateTurnOuts(15, false));
 }
Esempio n. 20
0
 public static PokerScoreOuts CalculateRiver(SixCardHand cards)
 {
     return(PokerHelper.CreateRiverOuts(18));
 }
    public void AddToHand(Card card)
    {
        HandValue += PokerHelper.ConvertToVal(card.GetCardValue());

        Hand.Add(card);
    }