public PokerPattern SelectChuPai() { var selSeq = AsList( PatternType.A, PatternType.AA, PatternType.AAA, PatternType.AAABBB, PatternType.AAAXX, PatternType.AABBCC, PatternType.ABCDE); Shuffle(selSeq); var selected = PokerPattern.NULL; for (int i = 0; i < selSeq.Count; i++) { selected = SelectChuPai(selSeq[i]); if (!selected.IsNull) { break; } } if (selected.IsNull) { BuildPokerPool(); for (int i = 0; i < 4; i++) { if (!_pilePool.ContainsKey(i)) { continue; } var list = _pilePool[i]; if (list != null && list.Count > 0) { var pile = list[0]; list.RemoveAt(0); selected = new PokerPattern(i, Pile(pile.NumType, i), pile.NumType, GetAllPokers(pile, false)); } } if (selected.IsNull) { selected = SelectBiggerXXXXOrSuperABCDE(null, _heartHosts.Count, true); } } return(selected); }
private PokerPattern SelectBiggerXXXX(PokerPattern lastChuPai, int fromPokerCount, int toPokerCount, int heartHostCount) { for (int availableHeartHost = 0; availableHeartHost <= heartHostCount; availableHeartHost++) { for (int pokerCount = fromPokerCount - availableHeartHost; pokerCount <= toPokerCount; pokerCount++) { List <PokerPile> piles = null; if (_pilePool.ContainsKey(pokerCount)) { piles = _pilePool[pokerCount]; } if (piles != null && piles.Count > 0) { if (pokerCount + availableHeartHost == lastChuPai.PokerCount) { for (int n = 0; n < piles.Count; n++) { PokerPile pile = piles[n]; if (_value.Compare(pile.NumType, lastChuPai.MajorNumType) == CompareResult.BIGGER) { pile.AddPoker(availableHeartHost); return(new PokerPattern( PatternType.XXXX, pile, pile.NumType, GetAllPokers(pile, false))); } } } else if (pokerCount + availableHeartHost > lastChuPai.PokerCount) { PokerPile pile = piles[0]; pile.AddPoker(availableHeartHost); return(new PokerPattern( PatternType.XXXX, pile, pile.NumType, GetAllPokers(pile, false))); } } } } return(PokerPattern.NULL); }
public int Compare(PokerPattern p1, PokerPattern p2) { if (p1 == null || p2 == null) { return(CompareResult.PATTERN_NOT_MATCH); } if (p1.IsNull && !p2.IsNull) { return(CompareResult.SMALLER); } if (!p1.IsNull && p2.IsNull) { return(CompareResult.BIGGER); } if (p1.IsNull && p2.IsNull) { return(CompareResult.EQUAL); } if (p1.Type == PatternType.XXDD) { return(CompareResult.BIGGER); } if (p2.Type == PatternType.XXDD) { return(CompareResult.SMALLER); } if (PatternType.IsBomb(p1.Type) && !PatternType.IsBomb(p2.Type)) { return(CompareResult.BIGGER); } if (!PatternType.IsBomb(p1.Type) && PatternType.IsBomb(p2.Type)) { return(CompareResult.SMALLER); } if (PatternType.IsBomb(p1.Type) && PatternType.IsBomb(p2.Type)) { float c1 = 0; float c2 = 0; if (p1.Type == PatternType.XXXX) { c1 = p1.PokerCount; } else if (p1.Type == PatternType.SuperABCDE) { c1 = 5.5f; } if (p2.Type == PatternType.XXXX) { c2 = p2.PokerCount; } else if (p2.Type == PatternType.SuperABCDE) { c2 = 5.5f; } float res = c1 - c2; if (res > 0.4) { return(CompareResult.BIGGER); } else if (res < -0.4) { return(CompareResult.SMALLER); } else { int v1 = ValueOf(p1); int v2 = ValueOf(p2); if (v1 == v2) { return(CompareResult.EQUAL); } if (v1 > v2) { return(CompareResult.BIGGER); } else { return(CompareResult.SMALLER); } } } if (p1.Type == p2.Type && p1.PokerCount == p2.PokerCount) { int v1 = ValueOf(p1); int v2 = ValueOf(p2); if (v1 == v2) { return(CompareResult.EQUAL); } if (v1 > v2) { return(CompareResult.BIGGER); } else { return(CompareResult.SMALLER); } } return(CompareResult.PATTERN_NOT_MATCH); }
public List <SelectNode> BuildSelectChain(PokerPattern pattern) { var list = new List <SelectNode>(); var pileList = new List <PokerPile>(); var headPile = pattern.HeadPile; if (headPile == null) { return(null); } var nextPile = headPile; while (nextPile != null) { pileList.Add(nextPile); nextPile = nextPile.Next; } var majorCount = PatternType.GetMajorPileCount(pattern.Type); if (majorCount > pileList.Count) { return(null); } var majorPile = pileList[majorCount - 1]; var majorNode = _matcher.GetRoot(majorPile.Count); if (majorNode == null) { return(null); } IPileRelation rootRelation = null; if (pattern.Type == PatternType.XXXX) { rootRelation = new PRSelectXXXX(majorPile.NumType, majorPile.Count, _value); } else { rootRelation = new PRSelectRoot(majorPile.NumType, PatternType.IsStraight(pattern.Type), PatternType.GetMajorPileCount(pattern.Type), _value); } var rootNode = new SelectNode(majorNode.PokerCount, rootRelation); list.Add(rootNode); var curNode = majorNode; for (int i = majorCount - 2; i >= 0; i--) { var pile = pileList[i]; curNode = curNode.Next(pile.Count); if (curNode == null) { return(null); } list.Add(new SelectNode(curNode)); } for (int i = pileList.Count - 1, n = majorCount - 1; i > n; i--) { var pile = pileList[i]; curNode = curNode.Next(pile.Count); if (curNode == null) { return(null); } list.Add(new SelectNode(curNode)); } return(list); }
public PokerPattern GetSmallestPatternBiggerThan(PokerPattern lastChuPai, bool chaiPai, bool needBomb, int endSelectSize) { BuildPokerPool(); if (lastChuPai == null || lastChuPai.IsNull || lastChuPai.Type == PatternType.BUCHU) { return(SelectChuPai()); } if (lastChuPai.Type == PatternType.XXDD) { // 如果是王炸就没必要再找下去了。 return(PokerPattern.NULL); } if (PatternType.IsBomb(lastChuPai.Type)) { if (needBomb) { return(SelectBiggerXXXXOrSuperABCDE(lastChuPai, _heartHosts.Count, chaiPai)); } else { return(PokerPattern.NULL); } } var selectChain = BuildSelectChain(lastChuPai); if (selectChain == null) { return(PokerPattern.NULL); } PokerPile result = SelectNormal(PatternType.IsStraight(lastChuPai.Type), selectChain, 0, null, _heartHosts.Count, chaiPai, endSelectSize); if (result != null) { int majorNumType = result.NumType == PokerNumType.PHost ? _value.CurrentHost : result.NumType; result = AdjustPileOrder(result, lastChuPai.Type); return(new PokerPattern( lastChuPai.Type, result, majorNumType, GetAllPokers(result, false) )); } else { if (needBomb) { return(SelectBiggerXXXXOrSuperABCDE(null, _heartHosts.Count, chaiPai)); } else { return(PokerPattern.NULL); } } }
/// <summary> /// 平常不把炸弹包含在内的选牌方式。 /// </summary> /// <param name="lastChuPai"></param> /// <param name="chaiPai"></param> /// <param name="needBomb"></param> /// <returns></returns> public PokerPattern GetSmallestPatternBiggerThan(PokerPattern lastChuPai, bool chaiPai, bool needBomb) { return(GetSmallestPatternBiggerThan(lastChuPai, chaiPai, needBomb, 3)); }