protected bool checkSanShunZi(PlayerDuns pDun, List <int> allCards) { //移除前 int[][] checkCnt = { new[] { 3, 5, 5 }, new[] { 5, 3, 5 }, new [] { 5, 5, 3 } }; foreach (int[] check1 in checkCnt) { List <int> check = new List <int>(allCards); List <List <int> > removeArr = new List <List <int> >(); bool is3 = false; foreach (int cnt in check1) { List <int> remove = new List <int>(); if (!removeLianXu(check, cnt, remove)) { break; } if (cnt == 3) { is3 = true; removeArr.Insert(0, remove); } else { if (is3) { removeArr.Insert(1, remove); } else { removeArr.Insert(0, remove); } } } if (check.Count == 0) { //成功重置 牌数据 pDun.Duns[0].Cards.Clear(); pDun.Duns[0].Cards.AddRange(removeArr[0]); pDun.Duns[1].Cards.Clear(); pDun.Duns[1].Cards.AddRange(removeArr[1]); pDun.Duns[2].Cards.Clear(); pDun.Duns[2].Cards.AddRange(removeArr[2]); return(true); } } return(false); }
public int CheckAllBig(PlayerDuns pdun) { if (!IsFullDun() || !pdun.IsFullDun()) { return(0); } for (int i = 0; i < Duns.Length; i++) { var ret = Duns[i].CompareLine(pdun.Duns[i]); if (ret > 0) { return(1); } } return(-1); }
public void GetTreeDuns(List <PlayerDuns> outList, TreeNode node) { if (node.Children.Count > 0) { foreach (TreeNode nodeC in node.Children) { GetTreeDuns(outList, nodeC); } } else { PlayerDuns pDun = new PlayerDuns(); pDun.AddDun(node.Dun); pDun.AddDun(node.Parent.Dun); pDun.AddDun(node.Parent.Parent.Dun); outList.Add(pDun); } }
//获取玩家的dun public List <PlayerDuns> getPlayerDuns(List <int> cards) { //筛选出来合适的牌 List <PlayerDuns> dunsOut = new List <PlayerDuns>(); SssDun dun = new SssDun { Cards = cards, CardType = CardType.none }; Root = new TreeNode(null, dun); SetTreeNode(cards, Root, 1); List <PlayerDuns> duns = new List <PlayerDuns>(); GetTreeDuns(duns, Root); dunsOut.Add(duns[0]); if (duns.Count > 1) { for (int i = 1; i < duns.Count; i++) { PlayerDuns dunTemp = duns[i]; bool isAdd = true; foreach (PlayerDuns outDun in dunsOut) { if (dunTemp.CheckAllBig(outDun) != 1) { isAdd = false; } } if (isAdd) { dunsOut.Add(dunTemp); } } } //将牌型补全 for (int i = 0; i < dunsOut.Count; i++) { List <int> temp = new List <int>(cards); PlayerDuns playerDun = dunsOut[i]; for (int j = 0; j < 3; j++) { SssDun pdun = playerDun.Duns[j]; if (pdun == null) { continue; } int cardCount = j == 0 ? 3 : 5; if (pdun.Cards.Count > cardCount) { pdun.Cards = pdun.Cards.GetRange(0, cardCount); } for (int z = 0; z < pdun.Cards.Count; z++) { if (pdun.Cards[z] == 0) { continue; } temp.Remove(pdun.Cards[z]); } } if (temp.Count <= 0) { continue; } int count = 0; for (int j = 0; j < 3; j++) { SssDun pdun = playerDun.Duns[j]; if (pdun == null) { pdun = new SssDun { Cards = temp.GetRange(0, j == 0 ? 3 : 5) }; pdun.CardType = CheckCardType(pdun.Cards, true); playerDun.Duns[j] = pdun; } for (int z = 0; z < pdun.Cards.Count; z++) { if (pdun.Cards[z] == 0) { pdun.Cards[z] = temp[count++]; } } } } //加入特殊牌型 GetSpecialCardType(cards, dunsOut); return(dunsOut); }
protected bool checkSanTongHua(PlayerDuns pDun, List <int> allCards) { CnList cnList = new CnList(allCards); if (cnList.Count == 3) { CnList list3 = cnList.GetEqualTo(3, true, true); CnList list5 = cnList.GetEqualTo(5, true, true); if (list3.Count == 1 && list5.Count == 2) { pDun.Duns[0].Cards.Clear(); pDun.Duns[0].Cards.AddRange(list3[0].Cards); pDun.Duns[1].Cards.Clear(); pDun.Duns[1].Cards.AddRange(list5[0].Cards); pDun.Duns[2].Cards.Clear(); pDun.Duns[2].Cards.AddRange(list5[1].Cards); return(true); } } else if (cnList.Count == 2) { CnList list3 = cnList.GetEqualTo(3, true, true); if (list3.Count == 1) { CnList list10 = cnList.GetEqualTo(10, true, true); if (list10.Count == 1) { pDun.Duns[0].Cards.Clear(); pDun.Duns[0].Cards.AddRange(list3[0].Cards); pDun.Duns[1].Cards.Clear(); pDun.Duns[1].Cards.AddRange(list10[0].Cards.GetRange(5, 5)); pDun.Duns[2].Cards.Clear(); pDun.Duns[2].Cards.AddRange(list10[0].Cards.GetRange(0, 5)); return(true); } } else if (list3.Count == 0) { CnList list5 = cnList.GetEqualTo(5, true, true); CnList list8 = cnList.GetEqualTo(8, true, true); if (list5.Count == 1 && list8.Count == 1) { pDun.Duns[0].Cards.Clear(); pDun.Duns[1].Cards.Clear(); pDun.Duns[2].Cards.Clear(); pDun.Duns[0].Cards.AddRange(list8[0].Cards.GetRange(0, 3)); List <int> list8_5 = list8[0].Cards.GetRange(3, 5); List <List <int> > sort = new List <List <int> >(); sort.Add(list8_5); sort.Add(list5[0].Cards); sort.Sort((o1, o2) => { for (int i = 0; i < o1.Count; i++) { int o1val = GetValue(o1[i]); int o2val = GetValue(o2[i]); if (o1val - o2val != 0) { return(o1val - o2val); } } for (int i = 0; i < o1.Count; i++) { int o1val = GetColor(o1[i]); int o2val = GetColor(o2[i]); if (o1val - o2val != 0) { return(o1val - o2val); } } return(0); }); pDun.Duns[1].Cards.AddRange(sort[0]); pDun.Duns[2].Cards.AddRange(sort[1]); return(true); } } } else if (cnList.Count == 1) { return(true); } return(false); }
/// <summary> /// 获取特殊牌型 /// </summary> /// <param name="cards"></param> /// <param name="dunsOut"></param> public void GetSpecialCardType(List <int> cards, List <PlayerDuns> dunsOut) { CardType type = CheckCardType(cards, true); VnList vnList = new VnList(cards); CnList cnList = new CnList(cards); List <int> cardValues = vnList.GetValues(); SssGameData gData = App.GetGameData <SssGameData>(); bool isJ_A = true; bool is8_k = true; bool is2_8 = true; foreach (int card in cardValues) { int val = GetValue(card); if (val < 11) { isJ_A = false; } if (val < 8) { is8_k = false; } if (val > 8) { is2_8 = false; } if (!isJ_A && !is8_k && !is2_8) { break; } } PlayerDuns pDun = new PlayerDuns { Special = CardType.none, Duns = dunsOut[0].Duns }; if (type == CardType.tonghuashun && gData.IsAllowSpecialType((int)CardType.tonghuashisanshui)) { pDun.Special = CardType.tonghuashisanshui; dunsOut.Insert(0, pDun); } else if ((type == CardType.shunzi || type == CardType.tonghuashun) && gData.IsAllowSpecialType((int)CardType.shisanshui)) { pDun.Special = CardType.shisanshui; dunsOut.Insert(0, pDun); } else if (isJ_A && gData.IsAllowSpecialType((int)CardType.shierhuang)) { pDun.Special = CardType.shierhuang; dunsOut.Insert(0, pDun); } else { PlayerDuns p = dunsOut[0]; CardType frist = CheckCardType(p.Duns[0].Cards, true); if (p.Duns[1].CardType == CardType.tonghuashun && p.Duns[2].CardType == CardType.tonghuashun && frist == CardType.tonghuashun && gData.IsAllowSpecialType((int)CardType.santonghuashun)) { pDun.Special = CardType.santonghuashun; dunsOut.Insert(0, pDun); } else if (vnList.GetMoreThan(4, false).Count >= 3 && gData.IsAllowSpecialType((int)CardType.santonghuashun)) { pDun.Special = CardType.santonghuashun; dunsOut.Insert(0, pDun); } else if (is8_k && gData.IsAllowSpecialType((int)CardType.quanda)) { pDun.Special = CardType.quanda; dunsOut.Insert(0, pDun); } else if (is2_8 && gData.IsAllowSpecialType((int)CardType.quanxiao)) { pDun.Special = CardType.quanxiao; dunsOut.Insert(0, pDun); } else if (cnList.Count == 2 && Mathf.Abs(cnList[0].Color - cnList[1].Color) == 0x10 && gData.IsAllowSpecialType((int)CardType.couyise)) { pDun.Special = CardType.couyise; dunsOut.Insert(0, pDun); } else if (vnList.GetMoreThan(3, false).Count >= 4 && gData.IsAllowSpecialType((int)CardType.sitiaosan)) { pDun.Special = CardType.sitiaosan; dunsOut.Insert(0, pDun); } else if (vnList.GetMoreThan(2, false).Count >= 6 && vnList.GetMoreThan(3, false).Count >= 1 && gData.IsAllowSpecialType((int)CardType.wuduisan)) { pDun.Special = CardType.wuduisan; dunsOut.Insert(0, pDun); } else if (vnList.GetMoreThan(2, false).Count >= 6 && gData.IsAllowSpecialType((int)CardType.liuduiban)) { pDun.Special = CardType.liuduiban; dunsOut.Insert(0, pDun); } else if (gData.IsAllowSpecialType((int)CardType.santonghua) && checkSanTongHua(pDun, cards)) { pDun.Special = CardType.santonghua; dunsOut.Insert(0, pDun); } else if (gData.IsAllowSpecialType((int)CardType.sanshunzi) && checkSanShunZi(pDun, cards)) { pDun.Special = CardType.sanshunzi; dunsOut.Insert(0, pDun); } } }