/// <summary> /// check if the player's selected cards valid /// 检查出牌或者甩牌合理 /// </summary> /// <param name="playerHoldingCards">所有玩家当前手里的牌</param> /// <param name="selectedCards"></param> /// <param name="player">出牌的玩家</param> /// <returns></returns> public static ShowingCardsValidationResult IsLeadingCardsValid( Dictionary <string, CurrentPoker> playerHoldingCards, List <int> selectedCards, string player) { var mustShowCardsForDumpingFail = new List <int>(); CurrentPoker holdingCardsCp = playerHoldingCards.Values.FirstOrDefault(); if (holdingCardsCp == null) { return new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Unknown } } ; var selectedCardsCp = new CurrentPoker(selectedCards, holdingCardsCp.TrumpInt, holdingCardsCp.Rank); int selectedCardSuit = CommonMethods.GetSuit(selectedCards[0], selectedCardsCp.TrumpInt, selectedCardsCp.Rank); int trump = selectedCardsCp.TrumpInt; int rank = selectedCardsCp.Rank; List <int> tractor = selectedCardsCp.GetTractorOfAnySuit(); if (selectedCards.Count == 1) //如果是单张牌 { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); } if (selectedCards.Count == 2 && (selectedCardsCp.GetPairs().Count == 1)) //如果是一对 { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); } if (tractor.Count > 1 && selectedCards.Count == tractor.Count * 2) //如果是拖拉机 { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); } if (selectedCardsCp.IsMixed()) { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Invalid }); } if (tractor.Count > 1) { int myMax = tractor[0]; foreach (int card in tractor) { selectedCardsCp.RemoveCard(card); selectedCardsCp.RemoveCard(card); } foreach (var keyValue in playerHoldingCards) { if (keyValue.Key != player) { List <int> tractor1 = keyValue.Value.GetTractor((Suit)selectedCardSuit); if (tractor1.Count < tractor.Count) { continue; } int max = tractor1[0]; if (!CommonMethods.CompareTo(myMax, max, trump, rank, selectedCardSuit)) { foreach (int card in tractor) { mustShowCardsForDumpingFail.Add(card); mustShowCardsForDumpingFail.Add(card); } return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.DumpingFail, MustShowCardsForDumpingFail = mustShowCardsForDumpingFail, CardsToShow = selectedCards }); } } } } if (selectedCardsCp.GetPairs().Count > 0) { ArrayList list0 = selectedCardsCp.GetPairs(); for (int i = 0; i < list0.Count; i++) { var myMax = (int)list0[i]; selectedCardsCp.RemoveCard(myMax); selectedCardsCp.RemoveCard(myMax); foreach (var keyValue in playerHoldingCards) { if (keyValue.Key != player) { ArrayList list = keyValue.Value.GetPairs(selectedCardSuit); if (list.Count == 0) { continue; } var max = (int)list[list.Count - 1]; if (!CommonMethods.CompareTo(myMax, max, trump, rank, selectedCardSuit) && max > -1) { mustShowCardsForDumpingFail.Add(myMax); mustShowCardsForDumpingFail.Add(myMax); return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.DumpingFail, MustShowCardsForDumpingFail = mustShowCardsForDumpingFail, CardsToShow = selectedCards }); } } } } } int[] cards = selectedCardsCp.GetCards(); foreach (var keyValue in playerHoldingCards) { if (keyValue.Key != player) { int max = keyValue.Value.GetMaxCard(selectedCardSuit); for (int i = 0; i < 54; i++) { if (cards[i] == 1) { if (!CommonMethods.CompareTo(i, max, trump, rank, selectedCardSuit)) { mustShowCardsForDumpingFail.Add(i); return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.DumpingFail, MustShowCardsForDumpingFail = mustShowCardsForDumpingFail, CardsToShow = selectedCards }); } } } } } return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.DumpingSuccess }); }