Exemplo n.º 1
0
        public void GetTractorTest()
        {
            var        target = new CurrentPoker(new[] { 53, 52, 0, 13, 26, 12, 12, 11, 11 }, Suit.Spade, 0);
            List <int> actual = target.GetTractor(Suit.Heart);

            Assert.AreEqual(12, actual[0]);
            Assert.AreEqual(11, actual[1]);

            target = new CurrentPoker(new[] { 53, 52, 0, 13, 26, 12, 12, 11, 11, 10, 10 }, Suit.Spade, 0);
            actual = target.GetTractor(Suit.Heart);
            Assert.AreEqual(12, actual[0]);
            Assert.AreEqual(11, actual[1]);
            Assert.AreEqual(10, actual[2]);

            target = new CurrentPoker(new[] { 53, 52, 0, 13, 26, 1, 1, 2, 2 }, Suit.Spade, 0);
            actual = target.GetTractor(Suit.Heart);
            Assert.AreEqual(2, actual[0]);
            Assert.AreEqual(1, actual[1]);


            target = new CurrentPoker(new[] { 53, 52, 0, 0, 13, 26, 1, 1, 2, 2 }, Suit.Spade, 1);
            actual = target.GetTractor(Suit.Heart);
            Assert.AreEqual(2, actual[0]);
            Assert.AreEqual(0, actual[1]);
        }
Exemplo n.º 2
0
        public void IsValidTest2()
        {
            CurrentTrickState currentTrickState = new CurrentTrickState {
                Trump = Suit.Heart, Rank = 0, Learder = "p1"
            };

            currentTrickState.ShowedCards.Add("p1", new List <int> {
                39, 39, 0, 0
            });
            currentTrickState.ShowedCards.Add("p2", new List <int> {
            });
            currentTrickState.ShowedCards.Add("p3", new List <int> {
            });
            currentTrickState.ShowedCards.Add("p4", new List <int> {
            });
            List <int> selectedCards = new List <int> {
                1, 2, 5, 5
            };
            CurrentPoker currentCards = new CurrentPoker(new int[] { 1, 2, 3, 4, 5, 5 }, Suit.Heart, 0);
            ShowingCardsValidationResultType expected = ShowingCardsValidationResultType.Valid;
            ShowingCardsValidationResultType actual;

            actual = TractorRules.IsValid(currentTrickState, selectedCards, currentCards).ResultType;
            Assert.AreEqual(expected, actual);
        }
Exemplo n.º 3
0
        public void IsLeadingCardsValidTestTractor2()
        {
            Dictionary <string, CurrentPoker> playerHoldingCards = new Dictionary <string, CurrentPoker>();

            playerHoldingCards["p2"] = new CurrentPoker(new List <int>()
            {
                8, 8, 7, 7
            }, Suit.Spade, 0);
            List <int> selectedCards = new List <int> {
                3, 3, 4, 4, 5, 5, 12
            };
            string player = "p1";

            ShowingCardsValidationResult result = TractorRules.IsLeadingCardsValid(playerHoldingCards, selectedCards, player);

            Assert.AreEqual(ShowingCardsValidationResultType.DumpingSuccess, result.ResultType);

            selectedCards = new List <int> {
                3, 3, 4, 4, 5, 5
            };
            player = "p1";

            result = TractorRules.IsLeadingCardsValid(playerHoldingCards, selectedCards, player);
            Assert.AreEqual(ShowingCardsValidationResultType.Valid, result.ResultType);
        }
Exemplo n.º 4
0
        public void IsLeadingCardsValidTestTractor()
        {
            Dictionary <string, CurrentPoker> playerHoldingCards = new Dictionary <string, CurrentPoker>();

            playerHoldingCards["p2"] = new CurrentPoker(new List <int>()
            {
                8, 8, 7, 7
            }, Suit.Spade, 0);
            List <int> selectedCards = new List <int> {
                4, 4, 5, 5, 12
            };
            string player = "p1";

            ShowingCardsValidationResult result = TractorRules.IsLeadingCardsValid(playerHoldingCards, selectedCards, player);

            Assert.AreEqual(ShowingCardsValidationResultType.DumpingFail, result.ResultType);
            Assert.AreEqual(4, result.MustShowCardsForDumpingFail.Count);
            Assert.IsTrue(result.MustShowCardsForDumpingFail.Contains(4));
            Assert.IsTrue(result.MustShowCardsForDumpingFail.Contains(5));

            selectedCards = new List <int> {
                12, 10, 10, 9, 9
            };
            result = TractorRules.IsLeadingCardsValid(playerHoldingCards, selectedCards, player);
            Assert.AreEqual(ShowingCardsValidationResultType.DumpingSuccess, result.ResultType);
        }
Exemplo n.º 5
0
        public void IsLeadingCardsValidDumpSingles()
        {
            Dictionary <string, CurrentPoker> playerHoldingCards = new Dictionary <string, CurrentPoker>();

            playerHoldingCards["p2"] = new CurrentPoker(new List <int>()
            {
                35, 7, 9, 22, 52
            }, Suit.Spade, 0);
            playerHoldingCards["p3"] = new CurrentPoker(new List <int>()
            {
                30, 35, 36, 9, 10
            }, Suit.Spade, 0);
            playerHoldingCards["p4"] = new CurrentPoker(new List <int>()
            {
                27, 31, 37, 36, 16
            }, Suit.Spade, 0);
            List <int> selectedCards = new List <int> {
                42, 45, 47, 48, 49
            };
            string player = "p1";

            ShowingCardsValidationResult result = TractorRules.IsLeadingCardsValid(playerHoldingCards, selectedCards, player);

            Assert.AreEqual(ShowingCardsValidationResultType.DumpingSuccess, result.ResultType);
        }
Exemplo n.º 6
0
        public void TryExposingTrumpTest()
        {
            List <Suit> availableTrump = new List <Suit>()
            {
                Suit.Heart, Suit.Spade, Suit.Diamond, Suit.Club, Suit.Joker
            };
            bool fullDebug = true;

            CurrentPoker currentPoker = new CurrentPoker(new[] { 53, 53 }, Suit.None, 12);
            Suit         actual       = Algorithm.TryExposingTrump(availableTrump, currentPoker, fullDebug);

            Assert.AreEqual(Suit.None, actual);

            currentPoker = new CurrentPoker(new[] { 53, 53, 52, 52 }, Suit.None, 12);
            actual       = Algorithm.TryExposingTrump(availableTrump, currentPoker, fullDebug);
            Assert.AreEqual(Suit.Joker, actual);

            List <int> all6 = new List <int>()
            {
                0, 0, 1, 1, 2, 2, 13, 13, 14, 14, 15, 15, 26, 26, 27, 27, 28, 28, 39, 39, 40, 40, 41, 41
            };

            // all6
            currentPoker = new CurrentPoker(all6, Suit.None, 12);
            actual       = Algorithm.TryExposingTrump(availableTrump, currentPoker, fullDebug);
            Assert.AreEqual(Suit.Heart, actual);

            // heart7
            all6.Add(3);
            currentPoker = new CurrentPoker(all6, Suit.None, 12);
            actual       = Algorithm.TryExposingTrump(availableTrump, currentPoker, fullDebug);
            Assert.AreEqual(Suit.Heart, actual);

            // spade7
            all6.Remove(3);
            all6.Add(16);
            currentPoker = new CurrentPoker(all6, Suit.None, 12);
            actual       = Algorithm.TryExposingTrump(availableTrump, currentPoker, fullDebug);
            Assert.AreEqual(Suit.Spade, actual);

            // diamond7
            all6.Remove(16);
            all6.Add(29);
            currentPoker = new CurrentPoker(all6, Suit.None, 12);
            actual       = Algorithm.TryExposingTrump(availableTrump, currentPoker, fullDebug);
            Assert.AreEqual(Suit.Diamond, actual);

            // club7
            all6.Remove(29);
            all6.Add(42);
            currentPoker = new CurrentPoker(all6, Suit.None, 12);
            actual       = Algorithm.TryExposingTrump(availableTrump, currentPoker, fullDebug);
            Assert.AreEqual(Suit.Club, actual);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 得到某种花色牌的数量
        /// </summary>
        /// <param name="cp">牌</param>
        /// <param name="suit">主花色</param>
        /// <param name="rank">主Rank</param>
        /// <param name="mysuit">查找的花色</param>
        /// <returns>牌的数量</returns>
        internal static int GetSuitCount(CurrentPoker cp, int suit, int rank, int mysuit)
        {
            if (suit == mysuit)
            {
                int count = cp.MasterRank + cp.SubRank + cp.BigJack + cp.SmallJack;
                if (mysuit == 1)
                {
                    count += cp.HeartsNoRankTotal;
                }
                else if (mysuit == 2)
                {
                    count += cp.PeachsNoRankTotal;
                }
                else if (mysuit == 3)
                {
                    count += cp.DiamondsNoRankTotal;
                }
                else if (mysuit == 4)
                {
                    count += cp.ClubsNoRankTotal;
                }

                return(count);
            }
            else
            {
                if (mysuit == 1)
                {
                    return(cp.HeartsNoRankTotal);
                }

                if (mysuit == 2)
                {
                    return(cp.PeachsNoRankTotal);
                }

                if (mysuit == 3)
                {
                    return(cp.DiamondsNoRankTotal);
                }

                if (mysuit == 4)
                {
                    return(cp.ClubsNoRankTotal);
                }

                if (mysuit == 5)
                {
                    return(cp.SmallJack + cp.BigJack);
                }
            }

            return(0);
        }
Exemplo n.º 8
0
        /// <summary>
        /// </summary>
        /// <param name="handState"></param>
        /// <param name="lastTrickState">扣抵的牌</param>
        /// <returns></returns>
        public PlayerEntity NextRank(CurrentHandState handState, CurrentTrickState lastTrickState)
        {
            if (!Players.Exists(p => p.PlayerId == handState.Starter))
            {
                //log
                return(null);
            }


            if (handState.Rank != 9)
            {
                return(NextRank(handState.Starter, handState.Score));
            }
            if (handState.Score >= 80)
            {
                //主J勾到底

                var cardscp = new CurrentPoker(lastTrickState.ShowedCards[lastTrickState.LatestPlayerShowedCard()],
                                               handState.Trump, handState.Rank);
                if (cardscp.MasterRank > 0)
                {
                    foreach (PlayerEntity player in Players)
                    {
                        if (ArePlayersInSameTeam(handState.Starter,
                                                 player.PlayerId))
                        {
                            player.Rank = 0;
                        }
                    }
                }
                //副J勾一半
                else if (cardscp.SubRank > 0)
                {
                    foreach (PlayerEntity player in Players)
                    {
                        if (ArePlayersInSameTeam(handState.Starter,
                                                 player.PlayerId))
                        {
                            player.Rank = handState.Rank / 2;
                        }
                    }
                }

                return(GetNextPlayerAfterThePlayer(false, handState.Starter));
            }

            return(null);
        }
Exemplo n.º 9
0
        /// <summary>
        /// 从一堆牌中找出最大的牌,考虑主
        /// </summary>
        /// <param name="sendCards">一堆主</param>
        /// <param name="suit">花色</param>
        /// <param name="rank">主</param>
        /// <returns>最大的牌</returns>
        internal static int GetMaxCard(ArrayList sendCards, int suit, int rank)
        {
            CurrentPoker cp = new CurrentPoker();

            cp.Suit = suit;
            cp.Rank = rank;
            cp      = parse(sendCards, suit, rank);
            int thisSuit = CommonMethods.GetSuit((int)sendCards[0]);


            if (cp.IsMixed())
            {
                return(-1);
            }

            bool hasTractor = cp.HasTractors();
            int  pairTotal  = cp.GetPairs().Count;
            int  count      = cp.Count;

            //如果拖拉机
            if (hasTractor)
            {
                return(cp.GetTractor());
            }
            else if (count == 1) //单张牌
            {
                return((int)sendCards[0]);
            }
            else if (count == pairTotal * 2 && (count > 1)) //都是对
            {
                return((int)cp.GetPairs()[pairTotal - 1]);
            }
            else //有对和有单张牌,得到对的最大值
            {
                if (pairTotal > 0)
                {
                    return((int)cp.GetPairs()[pairTotal - 1]);
                }
                else
                {
                    return(cp.GetMaxCard(thisSuit));
                }
            }
        }
Exemplo n.º 10
0
        public void IsLeadingCardsValidDump2Pairs()
        {
            Dictionary <string, CurrentPoker> playerHoldingCards = new Dictionary <string, CurrentPoker>();

            playerHoldingCards["p2"] = new CurrentPoker(new List <int>()
            {
                18, 15, 22, 19, 21
            }, Suit.Spade, 0);
            playerHoldingCards["p3"] = new CurrentPoker(new List <int>()
            {
                25, 25, 24, 24, 22
            }, Suit.Spade, 0);
            List <int> selectedCards = new List <int> {
                10, 10, 6, 6
            };
            string player = "p1";

            ShowingCardsValidationResult result = TractorRules.IsLeadingCardsValid(playerHoldingCards, selectedCards, player);

            Assert.AreEqual(ShowingCardsValidationResultType.DumpingSuccess, result.ResultType);
        }
Exemplo n.º 11
0
        //我是否可以亮主
        internal static bool[] CanSetRank(MainForm mainForm, CurrentPoker currentPoker)
        {
            //如果目前无人亮主
            int rank = mainForm.currentRank;

            bool[] suits = new bool[5] {
                false, false, false, false, false
            };

            //

            if (mainForm.showSuits == 0) //
            {
                if (rank != 53)
                {
                    if (currentPoker.Clubs[rank] > 0)
                    {
                        suits[3] = true;
                    }
                    else if (currentPoker.Diamonds[rank] > 0)
                    {
                        suits[2] = true;
                    }
                    else if (currentPoker.Peachs[rank] > 0)
                    {
                        suits[1] = true;
                    }
                    else if (currentPoker.Hearts[rank] > 0)
                    {
                        suits[0] = true;
                    }
                }
            }
            //可以反主
            if ((mainForm.showSuits == 1))
            {
                if (rank != 53)
                {
                    if (currentPoker.Clubs[rank] > 1)
                    {
                        //是否加固,是否允许自反
                        //
                        suits[3] = IsInvalidRank(mainForm, 4);
                    }
                    else if (currentPoker.Diamonds[rank] > 1)
                    {
                        //是否加固,是否允许自反
                        suits[2] = IsInvalidRank(mainForm, 3);
                    }
                    else if (currentPoker.Peachs[rank] > 1)
                    {
                        //是否加固,是否允许自反
                        suits[1] = IsInvalidRank(mainForm, 2);
                    }
                    else if (currentPoker.Hearts[rank] > 1)
                    {
                        //是否加固,是否允许自反
                        suits[0] = IsInvalidRank(mainForm, 1);
                    }
                }
            }

            if (mainForm.currentRank != 53)
            {
                if ((currentPoker.SmallJack == 2 || currentPoker.BigJack == 2) && (mainForm.showSuits < 3))
                {
                    //是否允许自反
                    //是否允许反无主
                    suits[4] = IsInvalidRank(mainForm, 5);
                }
            }
            return(suits);
        }