//将牌转至Vector对象 public void ConverVerctor(List <int> handCard, ref CardVector vec) { foreach (int card in handCard) { vec.Add(GetCardSize(card), new List <int>(card)); } }
//取出王炸牌至wangVec,返回剩余的牌 public List <int> GetWangBombCard(List <int> handCard, ref CardVector wangVec) { List <int> arr = new List <int>(); List <int> temp = new List <int>(); int count = handCard.Count; for (int i = 0; i < count; ++i) { int card = handCard[i]; CardSize val = GetCardSize(card); if (val == mCW1 || val == mCW2) { temp.Add(card); } else { arr.Add(card); } } if (temp.Count == 2) { foreach (int card in temp) { wangVec.Add(GetCardSize(card), new List <int>(card)); } } else { arr.AddRange(temp); } return(arr); }
//拆牌算法 public CardVector SplitCard(List <int> handCard) { CardVector vec = new CardVector(DeckType.All); CardVector wangVec = new CardVector(DeckType.WangBomb); CardVector bombVec = new CardVector(DeckType.Bomb); CardVector shunVec = new CardVector(DeckType.Shunzi); CardVector threeVec = new CardVector(DeckType.Three); CardVector doubleVec = new CardVector(DeckType.Double); CardVector singleVec = new CardVector(DeckType.Single); List <int> lastCards = new List <int>(); if (2 == handCard.Count) { if (mCW1 == GetCardSize(handCard[0]) && mCW2 == GetCardSize(handCard[1])) { wangVec.Add(GetCardSize(handCard[0]), new List <int>(handCard[0])); wangVec.Add(GetCardSize(handCard[1]), new List <int>(handCard[1])); } } if (1 < handCard.Count) { lastCards = GetUnrelatedCard(handCard, ref singleVec); lastCards = GetBombCard(lastCards, ref bombVec); lastCards = GetFlyCard(lastCards, ref threeVec); lastCards = GetShunTwoCard(lastCards, ref shunVec); lastCards = GetThreeCard(lastCards, ref threeVec); lastCards = GetTwoCard(lastCards, ref doubleVec); lastCards = CheckSingleAsShun(lastCards, ref shunVec); } else { lastCards = handCard; } lastCards = GetSingleCard(lastCards, ref singleVec); vec.AddChild(wangVec); vec.AddChild(bombVec); vec.AddChild(shunVec); vec.AddChild(threeVec); vec.AddChild(doubleVec); vec.AddChild(singleVec); return(vec); }
//取出指定大小的牌至vec对象,返回剩余牌 public List <int> GetCard(List <int> handCard, CardSize cardVal, ref CardVector vec) { List <int> arr = new List <int>(); int count = handCard.Count; for (int i = 0; i < count; ++i) { int card = handCard[i]; CardSize val = GetCardSize(card); if (cardVal == val) { vec.Add(val, new List <int>(card)); } else { arr.Add(card); } } return(arr); }
//去除对子至Vector对象,返回剩余牌 public List <int> GetTwoCard(List <int> handCard, ref CardVector vec, bool matchThree = false) { List <int> lastCards = GetSameCard(handCard, 2, ref vec); if (matchThree) { CardVector threeVec = new CardVector(DeckType.Three); lastCards = GetSameCard(handCard, 3, ref threeVec); if (0 < threeVec.GetCount()) { List <CardSize> keys = threeVec.GetKeys(); foreach (CardSize key in keys) { List <int> val = threeVec.Get(key); List <int> arr = new List <int>(); CopyList(val, ref arr, 0, 2); vec.Add(key, arr); } } } return(lastCards); }
//取相同的牌,返回剩余的牌 public List <int> GetSameCard(List <int> handCard, int num, ref CardVector vec) { List <int> lastCards = new List <int>(); List <int> arr = new List <int>(); int count = handCard.Count; if (2 > count) { if (0 < count && 1 == num) { int card = handCard[0]; vec.Add(GetCardSize(card), new List <int>(card)); return(arr); } else { return(handCard); } } for (int i = 0; i < count; ++i) { int card = handCard[i]; if (0 == i) { arr.Add(card); continue; } int preCard = handCard[i - 1]; CardSize val = GetCardSize(card); CardSize preVal = GetCardSize(preCard); if (val == preVal) { arr.Add(card); } else { if (arr.Count == num) { if (1 == num) { vec.Add(preVal, new List <int>(arr[0])); } else { vec.Add(preVal, arr); } } else { lastCards.AddRange(arr); } arr = new List <int>(); arr.Add(card); } if (i == count - 1) { if (arr.Count == num) { if (1 == num) { vec.Add(val, new List <int>(arr[0])); } else { vec.Add(val, arr); } } else { lastCards.AddRange(arr); } } } return(lastCards); }
public List <int> GetShunCard(List <int> handCard, ref CardVector vec) { List <int> lastCards = new List <int>(); int count = handCard.Count; if (2 > count) { return(handCard); } List <int> arr = new List <int>(); List <int> arrIgnore = new List <int>(); List <int> arrLog = new List <int>(); for (int i = 0; i < count; ++i) { int card = handCard[i]; if (0 == i) { arr.Add(card); arrLog.Add(card); continue; } int preCard = handCard[i - 1]; CardSize preVal = GetCardSize(preCard); CardSize val = GetCardSize(card); if (preVal == val - 1 && val < mC2) { arr.Add(card); arrLog.Add(card); } else if (preVal == val) { arrIgnore.Add(card); arrLog.Add(card); } else { if (5 <= arr.Count) { vec.Add(GetCardSize(arr[0]), arr); lastCards.AddRange(arrIgnore); } else { lastCards.AddRange(arrLog); } arr = new List <int>(); arr.Add(card); arrLog = new List <int>(); arrLog.Add(card); arrIgnore = new List <int>(); } if (i == count - 1) { if (5 <= arr.Count) { vec.Add(GetCardSize(arr[0]), arr); lastCards.AddRange(arrIgnore); arrIgnore = new List <int>(); } else { lastCards.AddRange(arrLog); } } } return(lastCards); }