public PokerPile AdjustPileOrder(PokerPile head, int patternType) { var piles = new List <PokerPile>(); PokerPile next = head; while (next != null) { piles.Add(next); next = next.Next; } int majorCount = PatternType.GetMajorPileCount(patternType); if (piles.Count < majorCount) { return(null); } for (int i = majorCount - 1; i > 0; i--) { piles[i].Next = piles[i - 1]; } piles[0].Next = null; if (piles.Count > majorCount) { for (int i = piles.Count - 1; i > majorCount; i--) { piles[i].Next = piles[i - 1]; } piles[majorCount].Next = null; piles[0].Next = piles[piles.Count - 1]; } return(piles[majorCount - 1]); }
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); }