void CreateTwoDuiDict() { twoduiKeyDict.Clear(); CardInfo[] cards = new CardInfo[4] { new CardInfo(), new CardInfo(), new CardInfo(), new CardInfo(), }; float score; float a, b; for (int i = 1; i <= 13; i++) { cards[0].value = i; cards[1].value = i; for (int s0 = 0; s0 < 4; s0++) { cards[0].suit = s0; for (int s1 = 0; s1 < 4; s1++) { cards[1].suit = s1; for (int j = 1; j <= 13; j++) { cards[2].value = j; cards[3].value = j; if (i == 1) { a = 14; } else { a = i; } if (j == 1) { b = 14; } else { b = j; } score = CardsTypeEvaluation.GetTwoDuiBaseScore(a, b); for (int m0 = 0; m0 < 4; m0++) { cards[2].suit = m0; for (int m1 = 0; m1 < 4; m1++) { cards[3].suit = m1; AddTwoDuiKeyToList(cards, score); } } } } } } }
void CreateShunziDict() { shunziKeyDict.Clear(); CardInfo[] cards = new CardInfo[5] { new CardInfo(), new CardInfo(), new CardInfo(), new CardInfo(), new CardInfo() }; float score = CardsTypeEvaluation.GetShunZiBaseScore(10); AddShunziKeyToList(null, 0, score); for (int i = 1; i <= 10; i++) { score = CardsTypeEvaluation.GetShunZiBaseScore(i); for (int s0 = -1; s0 < 4; s0++) { if (s0 != -1) { cards[0].value = i; cards[0].suit = s0; AddShunziKeyToList(cards, 1, score); } else { cards[0].value = -1; } for (int s1 = -1; s1 < 4; s1++) { if (s1 != -1) { cards[1].value = i + 1; cards[1].suit = s1; AddShunziKeyToList(cards, 2, score); } else { cards[1].value = -1; } for (int s2 = -1; s2 < 4; s2++) { if (s2 != -1) { cards[2].value = i + 2; cards[2].suit = s2; AddShunziKeyToList(cards, 3, score); } else { cards[2].value = -1; } for (int s3 = -1; s3 < 4; s3++) { if (s3 != -1) { cards[3].value = i + 3; cards[3].suit = s3; AddShunziKeyToList(cards, 4, score); } else { cards[3].value = -1; } for (int s4 = 0; s4 < 4; s4++) { cards[4].suit = s4; if (i + 4 == 14) { cards[4].value = 1; } else { cards[4].value = i + 4; } AddShunziKeyToList(cards, 5, score); } } } } } } }
/// <summary> /// 计算确定的牌型CardFaces /// </summary> /// <returns></returns> public CardFace[] ComputeCardFaces(CardsTypeInfo info) { if (info.laiziCount == 0) { CardFace[] cardFaces = new CardFace[info.cardFaceValues.Length]; for (int i = 0; i < cardFaces.Length; i++) { cardFaces[i] = info.cardFaceValues[i]; } return(cardFaces); } int maxCount = info.cardFaceValues.Length + info.laiziCount; switch (info.type) { case CardsType.WuTong: { CardFace[] cardFaces = new CardFace[5]; if (info.cardFaceValues == null || info.cardFaceValues.Length == 0) { for (int i = 0; i < 5; i++) { cardFaces[i] = CardFace.Heart_A; } return(cardFaces); } int idx = 0; for (int i = 0; i < info.cardFaceValues.Length; i++) { cardFaces[idx++] = info.cardFaceValues[i]; } for (int i = 0; i < info.laiziCount; i++) { cardFaces[idx++] = cardFaces[0]; } return(cardFaces); } case CardsType.TongHuaShun: { if (maxCount == 3) { CardFace[] cardFaces = new CardFace[3]; if (info.cardFaceValues == null || info.cardFaceValues.Length == 0) { cardFaces[0] = CardFace.Heart_Q; cardFaces[1] = CardFace.Heart_K; cardFaces[2] = CardFace.Heart_A; return(cardFaces); } CardFace cardface = info.cardFaceValues[0]; CardInfo cardinfo = CardsTransform.Instance.CreateCardInfo(cardface); if (cardinfo.value == 1) { for (int i = 0; i < info.cardFaceValues.Length; i++) { if (CardsTransform.Instance.GetValue(info.cardFaceValues[i]) >= 12) { cardFaces[0] = CardsTransform.Instance.GetCardFace(12, cardinfo.suit); cardFaces[1] = CardsTransform.Instance.GetCardFace(13, cardinfo.suit); cardFaces[2] = cardface; return(cardFaces); } } cardFaces[0] = cardface; cardFaces[1] = CardsTransform.Instance.GetCardFace(2, cardinfo.suit); cardFaces[2] = CardsTransform.Instance.GetCardFace(3, cardinfo.suit); return(cardFaces); } int value = cardinfo.value; if (cardinfo.value >= 12) { cardFaces[2] = CardsTransform.Instance.GetCardFace(12, cardinfo.suit); cardFaces[3] = CardsTransform.Instance.GetCardFace(13, cardinfo.suit); cardFaces[4] = CardsTransform.Instance.GetCardFace(1, cardinfo.suit); } else { cardFaces[0] = cardface; cardFaces[1] = CardsTransform.Instance.GetCardFace(cardinfo.value + 1, cardinfo.suit); cardFaces[2] = CardsTransform.Instance.GetCardFace(cardinfo.value + 2, cardinfo.suit); } return(cardFaces); } else { CardFace[] cardFaces = new CardFace[5]; if (info.cardFaceValues == null || info.cardFaceValues.Length == 0) { cardFaces[0] = CardFace.Heart_10; cardFaces[1] = CardFace.Heart_J; cardFaces[2] = CardFace.Heart_Q; cardFaces[3] = CardFace.Heart_K; cardFaces[4] = CardFace.Heart_A; return(cardFaces); } CardFace cardface = info.cardFaceValues[0]; CardInfo[] cardinfos = CardsTransform.Instance.CreateCardInfos(info.cardFaceValues); CardInfo cardinfo = cardinfos[0]; int idx; if (cardinfos[cardinfos.Length - 1].value <= 5) { int laiziCount = info.laiziCount; int i = 0; for (i = 1; i <= 5; i++) { idx = CardsTransform.Instance.FindCard(cardinfos, i); if (idx != -1) { cardFaces[i - 1] = info.cardFaceValues[idx]; } else { cardFaces[i - 1] = CardsTransform.Instance.GetCardFace(i, cardinfo.suit); laiziCount--; if (laiziCount < 0) { break; } } } if (i == 6) { return(cardFaces); } } if (cardinfo.value == 1) { for (int i = 0; i < info.cardFaceValues.Length; i++) { if (CardsTransform.Instance.GetValue(info.cardFaceValues[i]) >= 10) { cardFaces[0] = CardsTransform.Instance.GetCardFace(10, cardinfo.suit); cardFaces[1] = CardsTransform.Instance.GetCardFace(11, cardinfo.suit); cardFaces[2] = CardsTransform.Instance.GetCardFace(12, cardinfo.suit); cardFaces[3] = CardsTransform.Instance.GetCardFace(13, cardinfo.suit); cardFaces[4] = cardface; return(cardFaces); } } } int value = cardinfo.value; if (cardinfo.value >= 10) { cardFaces[0] = CardsTransform.Instance.GetCardFace(10, cardinfo.suit); cardFaces[1] = CardsTransform.Instance.GetCardFace(11, cardinfo.suit); cardFaces[2] = CardsTransform.Instance.GetCardFace(12, cardinfo.suit); cardFaces[3] = CardsTransform.Instance.GetCardFace(13, cardinfo.suit); cardFaces[4] = CardsTransform.Instance.GetCardFace(1, cardinfo.suit); } else { cardFaces[0] = cardface; cardFaces[1] = CardsTransform.Instance.GetCardFace(cardinfo.value + 1, cardinfo.suit); cardFaces[2] = CardsTransform.Instance.GetCardFace(cardinfo.value + 2, cardinfo.suit); cardFaces[3] = CardsTransform.Instance.GetCardFace(cardinfo.value + 3, cardinfo.suit); cardFaces[4] = CardsTransform.Instance.GetCardFace(cardinfo.value + 4, cardinfo.suit); } return(cardFaces); } } case CardsType.Bomb: { CardFace[] cardFaces = new CardFace[4]; if (info.cardFaceValues == null || info.cardFaceValues.Length == 0) { cardFaces[0] = CardFace.Heart_A; cardFaces[1] = CardFace.Heart_A; cardFaces[2] = CardFace.Heart_A; cardFaces[3] = CardFace.Heart_A; return(cardFaces); } CardInfo cardinfo = CardsTransform.Instance.CreateCardInfo(info.cardFaceValues[0]); for (int i = 0; i < info.cardFaceValues.Length; i++) { cardFaces[i] = info.cardFaceValues[i]; } for (int i = info.cardFaceValues.Length; i < 4; i++) { cardFaces[i] = CardsTransform.Instance.GetCardFace(cardinfo.value, 0); } return(cardFaces); } case CardsType.HuLu: { CardInfo[] cardinfos = CardsTransform.Instance.CreateCardInfos(info.cardFaceValues); int a = 0; int b = -1; for (int i = 1; i < cardinfos.Length; i++) { if (cardinfos[i].value != cardinfos[0].value) { b = i; break; } } CardFace[] cardFaces = new CardFace[5]; int[] aCardIdxs = CardsTransform.Instance.FindCards(cardinfos, cardinfos[a].value); int[] bCardIdxs = b > 0 ? CardsTransform.Instance.FindCards(cardinfos, cardinfos[b].value) : null; if (bCardIdxs == null) { if (info.laiziCount >= 3) { cardFaces[0] = CardFace.Heart_A; cardFaces[1] = CardFace.Heart_A; cardFaces[2] = CardFace.Heart_A; if (aCardIdxs.Length == 1) { cardFaces[3] = info.cardFaceValues[aCardIdxs[0]]; cardFaces[4] = cardFaces[3]; } else { cardFaces[3] = info.cardFaceValues[aCardIdxs[0]]; cardFaces[4] = info.cardFaceValues[aCardIdxs[1]]; } } else { int idx = 0; for (int i = 0; i < aCardIdxs.Length; i++) { cardFaces[idx++] = info.cardFaceValues[aCardIdxs[i]]; } for (int i = 0; i < 3 - aCardIdxs.Length; i++) { cardFaces[idx++] = info.cardFaceValues[0]; } cardFaces[3] = CardFace.Heart_A; cardFaces[4] = CardFace.Heart_A; } return(cardFaces); } if (aCardIdxs.Length == 3) { for (int i = 0; i < aCardIdxs.Length; i++) { cardFaces[i] = info.cardFaceValues[aCardIdxs[i]]; } cardFaces[3] = CardsTransform.Instance.GetCardFace(cardinfos[bCardIdxs[0]].value, cardinfos[bCardIdxs[0]].suit); if (bCardIdxs.Length == 1) { cardFaces[4] = cardFaces[3]; } else { cardFaces[4] = CardsTransform.Instance.GetCardFace(cardinfos[bCardIdxs[1]].value, cardinfos[bCardIdxs[1]].suit); } return(cardFaces); } else if (bCardIdxs.Length == 3) { for (int i = 0; i < aCardIdxs.Length; i++) { cardFaces[i] = info.cardFaceValues[bCardIdxs[i]]; } cardFaces[3] = CardsTransform.Instance.GetCardFace(cardinfos[aCardIdxs[0]].value, cardinfos[aCardIdxs[0]].suit); if (bCardIdxs.Length == 1) { cardFaces[4] = cardFaces[3]; } else { cardFaces[4] = CardsTransform.Instance.GetCardFace(cardinfos[aCardIdxs[1]].value, cardinfos[aCardIdxs[1]].suit); } return(cardFaces); } else { if (cardinfos[aCardIdxs[0]].value == 1 || cardinfos[aCardIdxs[0]].value > cardinfos[bCardIdxs[0]].value) { int idx = 0; for (int i = 0; i < aCardIdxs.Length; i++) { cardFaces[idx++] = info.cardFaceValues[aCardIdxs[i]]; } for (int i = 0; i < 3 - aCardIdxs.Length; i++) { cardFaces[idx++] = cardFaces[0]; } for (int i = 0; i < bCardIdxs.Length; i++) { cardFaces[idx++] = info.cardFaceValues[bCardIdxs[i]]; } for (int i = 0; i < 2 - bCardIdxs.Length; i++) { cardFaces[idx++] = cardFaces[3]; } } else { int idx = 0; for (int i = 0; i < bCardIdxs.Length; i++) { cardFaces[idx++] = info.cardFaceValues[bCardIdxs[i]]; } for (int i = 0; i < 3 - bCardIdxs.Length; i++) { cardFaces[idx++] = cardFaces[0]; } for (int i = 0; i < aCardIdxs.Length; i++) { cardFaces[idx++] = info.cardFaceValues[aCardIdxs[i]]; } for (int i = 0; i < 2 - aCardIdxs.Length; i++) { cardFaces[idx++] = cardFaces[3]; } } return(cardFaces); } } case CardsType.TwoDui: { CardInfo[] cardinfos = CardsTransform.Instance.CreateCardInfos(info.cardFaceValues); int a = 0; int b = -1; for (int i = 1; i < cardinfos.Length; i++) { if (cardinfos[i].value != cardinfos[0].value) { b = i; break; } } CardFace[] cardFaces = new CardFace[4]; int[] cardIdxs = CardsTransform.Instance.FindCards(cardinfos, cardinfos[a].value); cardFaces[0] = CardsTransform.Instance.GetCardFace(cardinfos[cardIdxs[0]].value, cardinfos[cardIdxs[0]].suit); if (cardIdxs.Length == 1) { cardFaces[1] = cardFaces[0]; } else { cardFaces[1] = CardsTransform.Instance.GetCardFace(cardinfos[cardIdxs[1]].value, cardinfos[cardIdxs[1]].suit); } if (b > 0) { cardIdxs = CardsTransform.Instance.FindCards(cardinfos, cardinfos[b].value); cardFaces[2] = CardsTransform.Instance.GetCardFace(cardinfos[cardIdxs[0]].value, cardinfos[cardIdxs[0]].suit); if (cardIdxs.Length == 1) { cardFaces[3] = cardFaces[2]; } else { cardFaces[3] = CardsTransform.Instance.GetCardFace(cardinfos[cardIdxs[1]].value, cardinfos[cardIdxs[1]].suit); } } else { cardFaces[2] = CardFace.Heart_A; cardFaces[3] = CardFace.Heart_A; } return(cardFaces); } case CardsType.TongHua: { CardFace[] cardFaces = new CardFace[5]; if (info.cardFaceValues == null || info.cardFaceValues.Length == 0) { cardFaces[0] = CardFace.Heart_A; cardFaces[1] = CardFace.Heart_A; cardFaces[2] = CardFace.Heart_A; cardFaces[3] = CardFace.Heart_A; return(cardFaces); } int idx = 0; for (int i = 0; i < info.cardFaceValues.Length; i++) { cardFaces[idx++] = info.cardFaceValues[i]; } CardInfo[] cardinfos = CardsTransform.Instance.TransToCardInfo(info.cardFaceValues); CardsTransform.Instance.SortCardsByMaxA(cardinfos); for (int i = 0; i < info.laiziCount; i++) { cardFaces[idx++] = CardsTransform.Instance.GetCardFace(cardinfos[cardinfos.Length - 1]); } return(cardFaces); } case CardsType.SanTiao: { CardFace[] cardFaces = new CardFace[3]; if (info.cardFaceValues == null || info.cardFaceValues.Length == 0) { for (int i = 0; i < 3; i++) { cardFaces[i] = CardFace.Heart_A; } return(cardFaces); } int idx = 0; for (int i = 0; i < info.cardFaceValues.Length; i++) { cardFaces[idx++] = info.cardFaceValues[i]; } for (int i = 0; i < info.laiziCount; i++) { cardFaces[idx++] = cardFaces[0]; } return(cardFaces); } case CardsType.DuiZi: { CardFace[] cardFaces = new CardFace[2]; if (info.cardFaceValues == null || info.cardFaceValues.Length == 0) { for (int i = 0; i < 2; i++) { cardFaces[i] = CardFace.Heart_A; } return(cardFaces); } int idx = 0; for (int i = 0; i < info.cardFaceValues.Length; i++) { cardFaces[idx++] = info.cardFaceValues[i]; } for (int i = 0; i < info.laiziCount; i++) { cardFaces[idx++] = cardFaces[0]; } return(cardFaces); } case CardsType.ShunZi: { if (maxCount == 3) { CardFace[] cardFaces = new CardFace[3]; if (info.cardFaceValues == null || info.cardFaceValues.Length == 0) { cardFaces[0] = CardFace.Heart_Q; cardFaces[1] = CardFace.Heart_K; cardFaces[2] = CardFace.Heart_A; return(cardFaces); } CardInfo[] cardinfo = CardsTransform.Instance.CreateCardInfos(info.cardFaceValues); int idx; if (cardinfo[0].value == 1) { for (int i = 0; i < info.cardFaceValues.Length; i++) { if (CardsTransform.Instance.GetValue(info.cardFaceValues[i]) >= 12) { for (int j = 0; j < 2; j++) { idx = CardsTransform.Instance.FindCard(cardinfo, 12 + j); if (idx != -1) { cardFaces[j] = info.cardFaceValues[idx]; } else { cardFaces[j] = CardsTransform.Instance.GetCardFace(12 + j, 0); } } cardFaces[2] = info.cardFaceValues[0]; return(cardFaces); } } cardFaces[0] = info.cardFaceValues[0]; for (int j = 1; j < 3; j++) { idx = CardsTransform.Instance.FindCard(cardinfo, 1 + j); if (idx != -1) { cardFaces[j] = info.cardFaceValues[idx]; } else { cardFaces[j] = CardsTransform.Instance.GetCardFace(1 + j, 0); } } return(cardFaces); } if (cardinfo[0].value >= 12) { for (int j = 0; j < 2; j++) { idx = CardsTransform.Instance.FindCard(cardinfo, 12 + j); if (idx != -1) { cardFaces[j] = info.cardFaceValues[idx]; } else { cardFaces[j] = CardsTransform.Instance.GetCardFace(12 + j, 0); } } idx = CardsTransform.Instance.FindCard(cardinfo, 1); if (idx != -1) { cardFaces[2] = info.cardFaceValues[idx]; } else { cardFaces[2] = CardsTransform.Instance.GetCardFace(1, 0); } } else { cardFaces[0] = info.cardFaceValues[0]; for (int j = 1; j < 3; j++) { idx = CardsTransform.Instance.FindCard(cardinfo, cardinfo[0].value + j); if (idx != -1) { cardFaces[j] = info.cardFaceValues[idx]; } else { cardFaces[j] = CardsTransform.Instance.GetCardFace(cardinfo[0].value + j, 0); } } } return(cardFaces); } else { CardFace[] cardFaces = new CardFace[5]; if (info.cardFaceValues == null || info.cardFaceValues.Length == 0) { cardFaces[0] = CardFace.Heart_10; cardFaces[1] = CardFace.Heart_J; cardFaces[2] = CardFace.Heart_Q; cardFaces[3] = CardFace.Heart_K; cardFaces[4] = CardFace.Heart_A; return(cardFaces); } CardInfo[] cardinfo = CardsTransform.Instance.CreateCardInfos(info.cardFaceValues); int idx; if (cardinfo[cardinfo.Length - 1].value <= 5) { int laiziCount = info.laiziCount; int i = 0; for (i = 1; i <= 5; i++) { idx = CardsTransform.Instance.FindCard(cardinfo, i); if (idx != -1) { cardFaces[i - 1] = info.cardFaceValues[idx]; } else { cardFaces[i - 1] = CardsTransform.Instance.GetCardFace(i, 0); laiziCount--; if (laiziCount < 0) { break; } } } if (i == 6) { return(cardFaces); } } if (cardinfo[0].value == 1) { for (int i = 0; i < info.cardFaceValues.Length; i++) { if (CardsTransform.Instance.GetValue(info.cardFaceValues[i]) >= 10) { for (int j = 0; j < 4; j++) { idx = CardsTransform.Instance.FindCard(cardinfo, 10 + j); if (idx != -1) { cardFaces[j] = info.cardFaceValues[idx]; } else { cardFaces[j] = CardsTransform.Instance.GetCardFace(10 + j, 0); } } cardFaces[4] = info.cardFaceValues[0]; return(cardFaces); } } } if (cardinfo[0].value >= 10) { for (int j = 0; j < 4; j++) { idx = CardsTransform.Instance.FindCard(cardinfo, 10 + j); if (idx != -1) { cardFaces[j] = info.cardFaceValues[idx]; } else { cardFaces[j] = CardsTransform.Instance.GetCardFace(10 + j, 0); } } idx = CardsTransform.Instance.FindCard(cardinfo, 1); if (idx != -1) { cardFaces[4] = info.cardFaceValues[idx]; } else { cardFaces[4] = CardsTransform.Instance.GetCardFace(1, 0); } } else { cardFaces[0] = info.cardFaceValues[0]; for (int j = 1; j < 5; j++) { idx = CardsTransform.Instance.FindCard(cardinfo, cardinfo[0].value + j); if (idx != -1) { cardFaces[j] = info.cardFaceValues[idx]; } else { cardFaces[j] = CardsTransform.Instance.GetCardFace(cardinfo[0].value + j, 0); } } } return(cardFaces); } } case CardsType.Single: { if (info.laiziCount >= 1) { return new CardFace[] { CardFace.Club_A } } ; } break; } return(null); } }
void CreateSingle5Dict() { single5KeyDict.Clear(); CardInfo[] cards = new CardInfo[5] { new CardInfo(), new CardInfo(), new CardInfo(), new CardInfo(), new CardInfo(), }; float score; for (int i = 1; i <= 13 - 4; i++) { cards[0].value = i; for (int s0 = 0; s0 < 4; s0++) { cards[0].suit = s0; for (int j = i + 1; j <= 13 - 3; j++) { cards[1].value = j; for (int s1 = 0; s1 < 4; s1++) { cards[1].suit = s1; for (int k = j + 1; k <= 13 - 2; k++) { cards[2].value = k; for (int s2 = 0; s2 < 4; s2++) { cards[2].suit = s2; for (int m = k + 1; m <= 13 - 1; m++) { cards[3].value = m; for (int s3 = 0; s3 < 4; s3++) { cards[3].suit = s3; for (int n = m + 1; n <= 13; n++) { cards[4].value = n; for (int s4 = 0; s4 < 4; s4++) { cards[4].suit = s4; if (i == 1) { score = 14; } else { score = n; } AddSingle5KeyToList(cards, score); } } } } } } } } } } }
public CardFace GetCardFace(CardInfo cardinfo) { return(GetCardFace(cardinfo.value, cardinfo.suit)); }