//跟选:在有必选牌的情况下自动选择必选牌,方便玩家快捷出牌 public static void MustSelectedCardsNoShow(List <int> selectedCards, CurrentTrickState currentTrickState, CurrentPoker currentPoker) { var currentCards = (CurrentPoker)currentPoker.Clone(); var leadingCardsCp = new CurrentPoker(); leadingCardsCp.TrumpInt = (int)currentTrickState.Trump; leadingCardsCp.Rank = currentTrickState.Rank; foreach (int card in currentTrickState.LeadingCards) { leadingCardsCp.AddCard(card); } Suit leadingSuit = currentTrickState.LeadingSuit; bool isTrump = PokerHelper.IsTrump(currentTrickState.LeadingCards[0], currentCards.Trump, currentCards.Rank); if (isTrump) { leadingSuit = currentCards.Trump; } selectedCards.Clear(); List <int> currentSuitCards = currentCards.GetSuitCardsWithJokerAndRank((int)leadingSuit).ToList <int>(); List <int> leadingTractors = leadingCardsCp.GetTractor(leadingSuit); var leadingPairs = leadingCardsCp.GetPairs((int)leadingSuit); //如果别人出拖拉机,则选择我手中相同花色的拖拉机 List <int> currentTractors = currentCards.GetTractor(leadingSuit); if (currentTractors.Count <= leadingTractors.Count) { for (int i = 0; i < leadingTractors.Count && i < currentTractors.Count && selectedCards.Count < leadingCardsCp.Count; i++) { selectedCards.Add(currentTractors[i]); selectedCards.Add(currentTractors[i]); currentSuitCards.Remove(currentTractors[i]); currentSuitCards.Remove(currentTractors[i]); leadingPairs.Remove(currentTractors[i]); } } //如果别人出对子,则选择我手中相同花色的对子 var currentPairs = currentCards.GetPairs((int)leadingSuit); if (currentPairs.Count <= leadingPairs.Count) { for (int i = 0; i < leadingPairs.Count && i < currentPairs.Count && selectedCards.Count < leadingCardsCp.Count; i++) { if (selectedCards.Contains((int)currentPairs[i])) { continue; } selectedCards.Add((int)currentPairs[i]); selectedCards.Add((int)currentPairs[i]); currentSuitCards.Remove((int)currentPairs[i]); currentSuitCards.Remove((int)currentPairs[i]); } } //如果别人出单张,则选择我手中相同花色的单张 if (currentSuitCards.Count() <= leadingCardsCp.Count - selectedCards.Count) { selectedCards.AddRange(currentSuitCards); } }
/// <summary> /// 判断玩家出的牌是否合法 /// 不能检查甩牌是否成功 /// </summary> /// <param name="currentTrickState">这回和出牌的状态</param> /// <param name="selectedCards">玩家选择的牌</param> /// <param name="currentCards">玩家的牌(包括选择的)</param> /// <returns></returns> public static ShowingCardsValidationResult IsValid(CurrentTrickState currentTrickState, List <int> selectedCards, CurrentPoker currentCards) { //玩家选择牌之后剩下的牌 var leftCardsCp = (CurrentPoker)currentCards.Clone(); foreach (int card in selectedCards) { leftCardsCp.RemoveCard(card); } var showingCardsCp = new CurrentPoker(); showingCardsCp.TrumpInt = (int)currentCards.Trump; showingCardsCp.Rank = currentCards.Rank; foreach (int showingCard in selectedCards) { showingCardsCp.AddCard(showingCard); } //showingCardsCp.Sort(); var leadingCardsCp = new CurrentPoker(); leadingCardsCp.TrumpInt = (int)currentCards.Trump; leadingCardsCp.Rank = currentCards.Rank; foreach (int card in currentTrickState.LeadingCards) { leadingCardsCp.AddCard(card); } // leadingCardsCp.Sort(); //the first player to show cards if (!currentTrickState.IsStarted()) { if (showingCardsCp.Count > 0 && !showingCardsCp.IsMixed()) { if (selectedCards.Count == 1) //如果是单张牌 { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); } if (selectedCards.Count == 2 && (showingCardsCp.GetPairs().Count == 1)) //如果是一对 { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); } if ((showingCardsCp.GetTractorOfAnySuit().Count > 1) && selectedCards.Count == showingCardsCp.GetTractorOfAnySuit().Count *2) //如果是拖拉机 { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); } return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.TryToDump }); } } //牌的数量 if (currentTrickState.LeadingCards.Count != selectedCards.Count) { return new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Invalid } } ; //得到第一个家伙出的花色 Suit leadingSuit = currentTrickState.LeadingSuit; bool isTrump = PokerHelper.IsTrump(currentTrickState.LeadingCards[0], currentCards.Trump, currentCards.Rank); if (isTrump) { leadingSuit = currentCards.Trump; } //如果出的牌混合的,则判断手中是否还剩出的花色,如果剩,false;如果不剩;true if (showingCardsCp.IsMixed()) { if (leftCardsCp.HasSomeCards((int)leadingSuit)) { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Invalid }); } return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); } //出的牌的花色 Suit mysuit = PokerHelper.GetSuit(selectedCards[0]); isTrump = PokerHelper.IsTrump(selectedCards[0], currentCards.Trump, currentCards.Rank); if (isTrump) { mysuit = currentCards.Trump; } //花色是否一致 if (mysuit != leadingSuit) { //而且确实没有此花色 if (leftCardsCp.HasSomeCards((int)leadingSuit)) { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Invalid }); } return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); } //别人如果出对,我也应该出对 int leadingCardsPairs = leadingCardsCp.GetPairs().Count; int selectedCardsPairs = showingCardsCp.GetPairs().Count; int holdingCardsPairs = currentCards.GetPairs((int)leadingSuit).Count; //2.如果别人出拖拉机,我如果有,也应该出拖拉机 if (leadingCardsCp.HasTractors()) { if ((!showingCardsCp.HasTractors()) && (currentCards.GetTractor((int)leadingSuit) > -1)) { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Invalid }); } if ((selectedCardsPairs < leadingCardsPairs) && (holdingCardsPairs > selectedCardsPairs)) //出的对比第一个玩家少,而且没有出所有的对 { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Invalid }); } return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); } if (leadingCardsPairs > 0) { //如果对出的不够多,而且没有出所有的对 if ((holdingCardsPairs > selectedCardsPairs) && (selectedCardsPairs < leadingCardsPairs)) { return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Invalid }); } return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); } return(new ShowingCardsValidationResult { ResultType = ShowingCardsValidationResultType.Valid }); }
//跟出 public static void MustSelectedCards(List <int> selectedCards, CurrentTrickState currentTrickState, CurrentPoker currentPoker) { var currentCards = (CurrentPoker)currentPoker.Clone(); var leadingCardsCp = new CurrentPoker(); leadingCardsCp.TrumpInt = (int)currentTrickState.Trump; leadingCardsCp.Rank = currentTrickState.Rank; foreach (int card in currentTrickState.LeadingCards) { leadingCardsCp.AddCard(card); } Suit leadingSuit = currentTrickState.LeadingSuit; bool isTrump = PokerHelper.IsTrump(currentTrickState.LeadingCards[0], currentCards.Trump, currentCards.Rank); if (isTrump) { leadingSuit = currentCards.Trump; } selectedCards.Clear(); var allSuitCardsCp = (CurrentPoker)currentPoker.Clone(); var allSuitCards = allSuitCardsCp.Cards; List <int> leadingTractors = leadingCardsCp.GetTractor(leadingSuit); var leadingPairs = leadingCardsCp.GetPairs((int)leadingSuit); //如果别人出拖拉机,我如果有,也应该出拖拉机 List <int> currentTractors = currentCards.GetTractor(leadingSuit); for (int i = 0; i < leadingTractors.Count && i < currentTractors.Count && selectedCards.Count < leadingCardsCp.Count; i++) { selectedCards.Add(currentTractors[i]); selectedCards.Add(currentTractors[i]); allSuitCards[currentTractors[i]] -= 2; leadingPairs.Remove(currentTractors[i]); } //对子 var currentPairs = currentCards.GetPairs((int)leadingSuit); for (int i = 0; i < leadingPairs.Count && i < currentPairs.Count && selectedCards.Count < leadingCardsCp.Count; i++) { if (selectedCards.Contains((int)currentPairs[i])) { continue; } selectedCards.Add((int)currentPairs[i]); selectedCards.Add((int)currentPairs[i]); allSuitCards[(int)currentPairs[i]] -= 2; } //单张先跳过对子 var currentSuitCards = currentCards.GetSuitCardsWithJokerAndRank((int)leadingSuit); for (int i = 0; i < currentSuitCards.Length && selectedCards.Count < leadingCardsCp.Count; i++) { if (currentPairs.Contains(currentSuitCards[i]) || allSuitCards[(int)currentSuitCards[i]] <= 0) { continue; } selectedCards.Add(currentSuitCards[i]); allSuitCards[(int)currentSuitCards[i]]--; } //单张 for (int i = 0; i < currentSuitCards.Length && selectedCards.Count < leadingCardsCp.Count; i++) { if (allSuitCards[currentSuitCards[i]] <= 0) { continue; } selectedCards.Add(currentSuitCards[i]); allSuitCards[(int)currentSuitCards[i]]--; } //其他花色的牌先跳过所有主牌,和副牌对子,即副牌单张 for (int i = 0; i < allSuitCards.Length && selectedCards.Count < leadingCardsCp.Count; i++) { bool isITrump = PokerHelper.IsTrump(i, currentCards.Trump, currentCards.Rank); if (isITrump || allSuitCards[i] <= 0 || allSuitCards[i] == 2) { continue; } selectedCards.Add(i); allSuitCards[i]--; } //其他花色的牌跳过所有主牌 for (int i = 0; i < allSuitCards.Length && selectedCards.Count < leadingCardsCp.Count; i++) { bool isITrump = PokerHelper.IsTrump(i, currentCards.Trump, currentCards.Rank); if (isITrump || allSuitCards[i] <= 0) { continue; } while (allSuitCards[i] > 0 && selectedCards.Count < leadingCardsCp.Count) { selectedCards.Add(i); allSuitCards[i]--; } } //其他花色的牌先跳过对子 for (int i = 0; i < allSuitCards.Length && selectedCards.Count < leadingCardsCp.Count; i++) { if (allSuitCards[i] <= 0 || allSuitCards[i] == 2) { continue; } selectedCards.Add(i); allSuitCards[i]--; } //其他花色的牌 for (int i = 0; i < allSuitCards.Length && selectedCards.Count < leadingCardsCp.Count; i++) { while (allSuitCards[i] > 0 && selectedCards.Count < leadingCardsCp.Count) { selectedCards.Add(i); allSuitCards[i]--; } } }