/// <summary> /// 计算牌的分值 /// </summary> /// <param name="cardFaces">手牌</param> /// <returns></returns> public float CalCardsScore(CardFace[] cardFaces) { MatchCardFacesInfo matchInfo = match.ComputeMatchCardFacesInfo(cardFaces); nextSlotCreater.CreateAllCardsTypeArray(matchInfo.computedCardFaces); CardsTypeInfo info = nextSlotCreater.GetMaxScoreCardsTypeInfo(); return(CalCardsScore(info, null)); }
public float CalCardsScore(CardFace[] cardFaces) { CardsTypeCreater cardCreater = new CardsTypeCreater(); cardCreater.CreateAllCardsTypeArray(cardFaces); CardsTypeInfo info = cardCreater.GetMaxScoreCardsTypeInfo(); CardInfo[] otherCards = CardsTransform.Instance.CreateRemoveFaceValues(cardFaces, info.cardFaceValues); return(CalCardsScore(info, otherCards)); }
/// <summary> /// 计算牌的分值 /// </summary> /// <param name="cardsTypeInfo">牌的牌型详细信息</param> /// <param name="otherCardValue">包含的其它杂牌</param> /// <returns></returns> float CalCardsScore(CardsTypeInfo cardsTypeInfo, CardInfo[] otherCardInfos) { int[] values = null; if (otherCardInfos != null && otherCardInfos.Length > 0) { values = new int[otherCardInfos.Length]; for (int i = 0; i < values.Length; i++) { values[i] = otherCardInfos[i].value; if (values[i] == 1) { values[i] = 14; } } } return(CalCardsScore(cardsTypeInfo, values)); }
int Cmp( CardsTypeInfo cardsTypeInfo1, int[] richCardValue1, CardsTypeInfo cardsTypeInfo2, int[] richCardValue2) { float score1 = CalCardsScore(cardsTypeInfo1, richCardValue1); float score2 = CalCardsScore(cardsTypeInfo2, richCardValue2); if (score1 > score2) { return(-1); } else if (score1 < score2) { return(1); } return(0); }
public float CalCardsScore(CardsTypeInfo cardsTypeInfo, int[] otherCardValue) { float score = ((float)cardsTypeInfo.type - 1) * 100; score += cardsTypeInfo.score; if (otherCardValue != null && otherCardValue.Length > 0) { int max = otherCardValue[0]; for (int i = 1; i < otherCardValue.Length; i++) { if (otherCardValue[i] > max) { max = otherCardValue[i]; } } score += max * 0.0001f; } return(score); }
/// <summary> /// 计算确定的牌型CardFaces /// </summary> /// <returns></returns> public CardFace[] ComputeCardFaces(CardFace[] cardFaces, ref CardsType cardsType) { CardsTypeInfo typeInfo; CardInfo[] cardInfos; CardFace[] removeLaizi = new CardFace[5]; CardFace[] computedCardFaces; CardFace[] resultCardFaces; CardFace[] cardFaces2; int idx = 0; if (cardsType == CardsType.None) { CardsTypeCreater creater = new CardsTypeCreater(); creater.SetLaizi(laizi); creater.CreateAllCardsTypeArray(cardFaces); typeInfo = creater.GetMaxScoreCardsTypeInfo(); cardsType = typeInfo.type; cardInfos = CardsTransform.Instance.CreateRemoveFaceValues(cardFaces, typeInfo.cardFaceValues); cardFaces2 = CardsTransform.Instance.CreateCardFaces(cardInfos); removeLaizi = new CardFace[5]; cardFaces2 = CardsTransform.Instance.RemoveLaiziByCount(cardFaces2, laizi, typeInfo.laiziCount, removeLaizi); computedCardFaces = ComputeCardFaces(typeInfo); resultCardFaces = new CardFace[cardFaces.Length]; for (int i = 0; i < computedCardFaces.Length; i++) { resultCardFaces[idx++] = computedCardFaces[i]; } for (int i = 0; i < cardFaces2.Length; i++) { resultCardFaces[idx++] = cardFaces2[i]; } return(resultCardFaces); } int laiziCount = 0; CardInfo[] cards = CardsTransform.Instance.CreateFormatCards(cardFaces, laizi, ref laiziCount); typeInfo = new CardsTypeInfo() { cardFaceValues = CardsTransform.Instance.CreateCardFaces(cards), laiziCount = laiziCount, type = cardsType }; cardInfos = CardsTransform.Instance.CreateRemoveFaceValues(cardFaces, typeInfo.cardFaceValues); cardFaces2 = CardsTransform.Instance.CreateCardFaces(cardInfos); removeLaizi = new CardFace[5]; cardFaces2 = CardsTransform.Instance.RemoveLaiziByCount(cardFaces2, laizi, typeInfo.laiziCount, removeLaizi); computedCardFaces = ComputeCardFaces(typeInfo); resultCardFaces = new CardFace[cardFaces.Length]; for (int i = 0; i < computedCardFaces.Length; i++) { resultCardFaces[idx++] = computedCardFaces[i]; } for (int i = 0; i < cardFaces2.Length; i++) { resultCardFaces[idx++] = cardFaces2[i]; } return(resultCardFaces); }
/// <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); } }