using System.Collections.Generic; using System.Linq; using GameMessage; namespace GameFix.Poker { public abstract class CardStyleBaseHelper { public virtual int CardStyle => DataCardConst.CardStyle0; public virtual int CardCnt => 0; protected readonly int MaxShunLogicNum = 14; // 顺子所能到达得最大值 // 检测普通牌型 internal abstract bool CheckStyleNormal(CardBaseGroup group, out CardStyleInfo cardStyleInfo); // 检测癞子牌型 (有癞子的检测方法) internal virtual bool CheckStyleWithLZ(CardBaseGroup group, out CardStyleInfo cardStyleInfo) { return CheckStyleNormal(group, out cardStyleInfo); } // 获取group中所有符合牌型的组合 internal abstract List GetAllEatTipGroup(CardBaseGroup group, CardStyleInfo eatStyleInfo); // 获取group中所有符合牌型的组合(带癞子的手牌) internal virtual List GetAllEatTipGroupWithLZ(CardBaseGroup group, CardStyleInfo eatStyleInfo) { return GetAllEatTipGroup(group, eatStyleInfo); } /// /// 获取所有符合条件得牌型 /// internal virtual List GetAllStyleCards(CardBaseGroup group, bool isSplitCard) { return new List(); } // 是否都相同 protected bool IsAllSame(List cards) { if (cards.Count == 0) return false; if (cards.Count == 1) return true; for (int i = 1; i < cards.Count; i++) { if (cards[i].Value != cards[i-1].Value) { return false; } } return true; } /// /// 是否连续 /// protected bool IsContinuous(List continuousValues) { if (continuousValues.Count == 1) return false; continuousValues.Sort(); for (int i = 1; i < continuousValues.Count; i++) { if (continuousValues[i] - continuousValues[i-1] != 1) { return false; } } return true; } // 是否连续 protected bool IsContinuous(List cardValueCnt, int sameCnt, out List shunValueList) { shunValueList = new List(); for (int i = 0; i < cardValueCnt.Count; i++) { //顺子中断 if (cardValueCnt[i].Count < 1 && shunValueList.Count > 0) break; if (cardValueCnt[i].Count > sameCnt) break; if (cardValueCnt[i].Count == sameCnt) { shunValueList.Add(i); } } return shunValueList.Count > 0; } // 是否最大的连续 protected bool IsMaxContinuous(List cardValueCnt, int sameCnt, out List shunValueList) { List maxShunValueList = new List(); shunValueList = new List(); for (int i = 0; i < cardValueCnt.Count; i++) { if (cardValueCnt[i].Count >= sameCnt) { shunValueList.Add(i); } else if(shunValueList.Count >= maxShunValueList.Count) { maxShunValueList.Clear(); maxShunValueList.AddRange(shunValueList); shunValueList.Clear(); } } if (maxShunValueList.Count > shunValueList.Count) { shunValueList.Clear(); shunValueList.AddRange(maxShunValueList); } return shunValueList.Count > 0; } /// /// 判断带癞子的最大连顺 /// protected bool IsMaxContinuousByLZ(List cardValueCnt, int sameCnt, int lzCount, out List shunValueList, out List lackValueList) { shunValueList = new List(); lackValueList = new List(lzCount); List maxShunCards = new List(); List maxLackValues = new List(lzCount); int tmpLzCount = lzCount; for (int i = 0; i <= MaxShunLogicNum; i++) { int count = cardValueCnt[i].Count; int needCnt = sameCnt - count; if (cardValueCnt[i].Count == sameCnt) { shunValueList.Add(i); } else if (needCnt <= tmpLzCount && needCnt >= 0 && (shunValueList.Count > 0 || count > 0)) { // 用癞子补充 tmpLzCount -= needCnt; shunValueList.Add(i); lackValueList.AddRange(Enumerable.Repeat(i, needCnt)); } else { // 中断(记录这一次得连顺) if (shunValueList.Count > maxShunCards.Count) { maxShunCards.Clear(); maxShunCards.AddRange(shunValueList); maxLackValues.Clear(); maxLackValues.AddRange(lackValueList); } // 重置癞子 tmpLzCount = lzCount; shunValueList.Clear(); lackValueList.Clear(); } } if (maxShunCards.Count > shunValueList.Count) { shunValueList.Clear(); shunValueList.AddRange(maxShunCards); lackValueList.Clear(); lackValueList.AddRange(maxLackValues); } shunValueList.Sort(); return shunValueList.Count > 0; } // 相同牌组的值是否更大 protected bool IsSameGroupGreater(CardGroupList group, CardStyleInfo eatStyleInfo) { if (group.Count == 0) return false; if (eatStyleInfo != null && CardStyle == eatStyleInfo.CardStyle) return group[0].Value > eatStyleInfo.CardValue; return true; } protected bool IsJoker(CardGroupList group) { return IsContainJoker(group); } protected bool IsContainJoker(List cards) { for (int i = 0; i < cards.Count(); i++) { if (DataCardConst.JokerValues.Contains(cards[i].Value)) return true; } return false; } } }