local CardCheck = { cardList = {}, cardListSord = {}, cardNum = 0, cardSize = 0, long = false, planeNoBelt = false, threeNoBelt = false, planelack = false, threelack = false, fourDaiThree = false, fristCard = true, tipCardList = {}, touchCardSet = {}, touchCardMao = {} } local CardType = { one = 1, long = 2, dui = 3, duiLong = 10, threeAndTwo = 4, normolPlant = 5, zha = 6, onlyThree = 7, onlyPlant = 8, zhaAndThreee = 9, lessThree = 11, lessPlant = 12 } local M = CardCheck function M:InitFlag() local config = DataManager.CurrenRoom.room_config.config self.planeNoBelt = config.planeNoBelt == 1 self.threeNoBelt = config.threeNoBelt == 1 self.planelack = config.planelack == 1 self.threelack = config.threelack == 1 self.fourDaiThree = config.fourDaiThree self._flag_fristCard = true print("==============================lingmengcheckinitFlag") pt(config) pt(self) return self end function M:InitLastCard(cardList, mustPutMaxCard) self._flag_fristCard = false self:Clear() self._flag_mustMax = mustPutMaxCard self.type = 0 self.specilCard = {} self.lastCardNum = #cardList self._flag_allCards = false self._flag_checkLst = true if #cardList == 0 then self._flag_fristCard = true return end table.sort(cardList) pt(cardList) self.lastMinCard = math.floor(cardList[1] / 10) local temp_long = 0 for i = 1, #cardList do local number = math.floor(cardList[i] / 10) if self.cardList[number] then self.cardList[number] = self.cardList[number] + 1 else self.cardList[number] = 1 self.cardSize = self.cardSize + 1 table.insert(self.cardListSord, number) end self.cardNum = self.cardNum + 1 if i == 1 then temp_long = 1 elseif temp_long == i - 1 then if math.abs(math.floor(cardList[i - 1] / 10) - number) == 1 then temp_long = i end end end self.long = temp_long == self.cardNum and self.cardNum >= 5 print("lingmengCheckAloneOrLong2") if self:CheckAloneOrLong() then self.type = self:CheckAloneOrLong() return end print("lingmengCheckDuiZi2") if self:CheckDuiZi() then self.type = self:CheckDuiZi() return end print("lingmengCheckSanDai2") if self:CheckSanDai() then local a, b, c = self:CheckSanDai() self.type = a if b then self.specilCard = b end if c then self.lastMinCard = c end return end print("lingmengCheckZha2") if self:CheckZha() then local a, b, c = self:CheckZha() self.type = a if b then self.specilCard = b end if c then self.lastMinCard = c end return end if self.type == 0 then ViewUtil.ErrorTip(-1, "上一份牌型判断错误") end end function M:initCards(cardList, flag, flag_allCards) print("lingmenginitCards") pt(cardList) local temp_long = 0 self:Clear() self._flag_allCards = flag_allCards or false if flag then for i = 1, #cardList do local number = math.floor(cardList[i][1].card_code_number / 10) if self.cardList[number] then self.cardList[number] = self.cardList[number] + 1 else self.cardList[number] = 1 self.cardSize = self.cardSize + 1 table.insert(self.cardListSord, number) end self.cardNum = self.cardNum + 1 if i == 1 then temp_long = 1 elseif temp_long == i - 1 then if math.abs(math.floor(cardList[i - 1][1].card_code_number / 10) - number) == 1 then temp_long = i end end end else for i = 1, #cardList do local number = math.floor(cardList[i].card_code_number / 10) if self.cardList[number] then self.cardList[number] = self.cardList[number] + 1 else self.cardList[number] = 1 self.cardSize = self.cardSize + 1 table.insert(self.cardListSord, number) end self.cardNum = self.cardNum + 1 if i == 1 then temp_long = 1 elseif temp_long == i - 1 then if math.abs(math.floor(cardList[i - 1].card_code_number / 10) - number) == 1 then temp_long = i end end end end print(self.cardNum, self.cardSize, temp_long) pt(self.cardList) self.long = temp_long == self.cardNum and self.cardNum >= 5 end function M:CheckCards() if self.cardNum ~= 4 and self.cardNum ~= self.lastCardNum and not self._flag_fristCard then return end if self.cardNum == 1 and self._flag_mustMax and self.maxCard ~= self.cardListSord[1] then return end if self.cardNum == 0 then return end print("lingmengCheckAloneOrLong") if self:CheckAloneOrLong() then return true end print("lingmengCheckDuiZi") if self:CheckDuiZi() then return true end print("lingmengCheckSanDai") if self:CheckSanDai() then return true end print("lingmengCheckZha") if self:CheckZha() then return true end return false end function M:CheckOutCard(cardList) print("lingmengCheckOutCard===============") pt(cardList) self.tipCardList = {} self.touchCardSet = {} self.touchCardMao = {} local cardMap = {} local cardSet = {} local temp_long = 0 local temp_longList = {} local longList = {} local lastCard = -1 local flag_threeOrFour = false for i = 1, #cardList do local number = math.floor(cardList[i].card_code_number / 10) if cardMap[number] then cardMap[number].value = cardMap[number].value + 1 table.insert(cardMap[number].cardList, cardList[i]) else cardMap[number] = {} cardMap[number].value = 1 cardMap[number].cardList = {} table.insert(cardMap[number].cardList, cardList[i]) table.insert(cardSet, number) end if cardMap[number].value >= 3 then flag_threeOrFour = true end if lastCard ~= number then if lastCard - number ~= 1 then if temp_long >= 5 then table.insert(longList, temp_longList) end temp_long = 1 temp_longList = {} else temp_long = temp_long + 1 end lastCard = number table.insert(temp_longList, number) end end if temp_long >= 4 then table.insert(longList, temp_longList) end table.sort(cardSet) self.maxCard = cardSet[#cardSet] if self._flag_fristCard then if self._flag_mustMax then self:CheckOutCardGetMustMax(cardSet, cardMap, flag_threeOrFour, longList) else self:CheckOutCardGetFristTipList(cardSet, cardMap) end return end local cardType, only, longLength = self:CheckOutCardGetType() local tipCardSet = self:CheckOutCardGetTouchSet(cardSet, cardMap, cardType, longLength) self:CheckOutCardSetTipList(tipCardSet, longLength, cardMap, cardType) if cardType >= 3 and only == 0 then self:CheckOutCardGetAllCardSetAndMap() end end function M:CheckOutCardGetAllCardSetAndMap() self.touchCardSet = {} self.touchCardMao = {} for i = 3, 15 do table.insert(self.touchCardSet, i) self.touchCardMao[i] = 1 end end function M:CheckOutCardGetFristTipList(cardSet, cardMap) for i = 1, #cardSet do local card = cardSet[i] table.insert(self.touchCardSet, card) self.touchCardMao[card] = 1 local temp = {} table.insert(temp, cardMap[card].cardList[1]) table.insert(self.tipCardList, temp) end end function M:CheckOutCardGetMustMax(cardSet, cardMap, flag_threeOrFour, longList) if flag_threeOrFour then for i = 3, 15 do if cardMap[i] then if i == cardSet[#cardSet] then table.insert(self.touchCardSet, i) self.touchCardMao[i] = 1 table.insert(self.tipCardList, cardMap[i].cardList) elseif cardMap[i].value >= 2 then table.insert(self.touchCardSet, i) self.touchCardMao[i] = 1 table.insert(self.tipCardList, cardMap[i].cardList) else table.insert(self.touchCardSet, i) self.touchCardMao[i] = 1 end else table.insert(self.touchCardSet, i) self.touchCardMao[i] = 1 end end else for i = 1, #cardSet do local card = cardSet[i] if i == #cardSet then table.insert(self.touchCardSet, card) self.touchCardMao[card] = 1 table.insert(self.tipCardList, cardMap[card].cardList) elseif cardMap[card].value >= 2 then table.insert(self.touchCardSet, card) self.touchCardMao[card] = 1 table.insert(self.tipCardList, cardMap[card].cardList) end end end ---单数顺另外添加到提示和现实 for i = 1, #longList do local tempTipList = {} for j = 1, #longList[i] do local card = longList[i][j] if not self.touchCardMao[card] then table.insert(self.touchCardSet, card) self.touchCardMao[card] = 1 end table.insert(tempTipList, cardMap[card].cardList[1]) end table.insert(self.tipCardList, tempTipList) end end function M:CheckOutCardGetType() local cardType = 0 local only = 0 local longLength = 1 if self.type == 0 then return cardType, only, longLength end if self.type == CardType.one or self.type == CardType.long then cardType = 1 if self.type == CardType.long then longLength = self.lastCardNum end elseif self.type == CardType.dui or self.type == CardType.duiLong then cardType = 2 if self.lastCardNum > 2 then longLength = self.lastCardNum / 2 end elseif self.type == CardType.threeAndTwo or self.type == CardType.onlyThree or self.type == CardType.lessThree or self.type == CardType.normolPlant or self.type == CardType.onlyPlant or self.type == CardType.lessPlant then cardType = 3 if self.type == CardType.onlyThree or self.type == CardType.onlyPlant then only = 1 if self.type == CardType.onlyPlant then longLength = self.lastCardNum / 3 end end if self.type == CardType.normolPlant then longLength = self.lastCardNum / 5 end elseif self.type == CardType.zha or self.type == CardType.zhaAndThreee then cardType = 4 if self.type == CardType.zha then only = 1 end end return cardType, only, longLength end function M:CheckOutCardGetTouchSet(cardSet, cardMap, cardType, longLength) print("lingmengCheckOutCardGetTouchSet", cardType, longLength, self.lastMinCard) pt(cardSet) pt(cardMap) local tempLong = 0 local lastCard = 0 local tempCardSet = {} local tipCardSet = {} local ZhaCardList = {} for i = 1, #cardSet do local card = cardSet[i] if cardMap[card].value >= cardType and card > self.lastMinCard and cardMap[card].value ~= 4 then if tempLong == 0 then tempLong = 1 else if lastCard - card == -1 then tempLong = tempLong + 1 else if tempLong >= longLength and not self._flag_mustMax then for j = 1, tempLong do table.insert(self.touchCardSet, tempCardSet[j]) self.touchCardMao[tempCardSet[j]] = 1 end end table.insert(tipCardSet, tempCardSet) tempLong = 1 tempCardSet = {} end end table.insert(tempCardSet, card) lastCard = card end if cardMap[card].value == 4 then table.insert(self.touchCardSet, card) self.touchCardMao[card] = 1 table.insert(ZhaCardList, card) end end if tempLong >= longLength then for j = 1, tempLong do if j == tempLong or not self._flag_mustMax then table.insert(self.touchCardSet, tempCardSet[j]) self.touchCardMao[tempCardSet[j]] = 1 end end end table.insert(tipCardSet, tempCardSet) for i = 1, #ZhaCardList do table.insert(tipCardSet, ZhaCardList[i]) end return tipCardSet end function M:CheckOutCardSetTipList(tipCardSet, longLength, cardMap, cardType) print("lingmengCheckOutCardSetTipList", longLength, cardMap, cardType) pt(tipCardSet) for i = 1, #tipCardSet do if type(tipCardSet[i]) == 'number' then table.insert(self.tipCardList, cardMap[tipCardSet[i]].cardList) else local tipCardSetLen = #tipCardSet[i] if tipCardSetLen == longLength then local tempList = {} local tempSanDaiCard = {} for j = 1, tipCardSetLen do local card = tipCardSet[i][j] tempSanDaiCard[card] = true local minNum = Mathf.Min(cardMap[card].value, cardType) for k = 1, minNum do if not self._flag_mustMax or card == self.maxCard then table.insert(tempList, cardMap[card].cardList[k]) end end end if #tempList > 0 then if cardType == 3 then local removeSanDaiList = {} for k, v in pairs(cardMap) do if not tempSanDaiCard[k] then for i, v1 in ipairs(v.cardList) do table.insert(removeSanDaiList, v1) end end end if #removeSanDaiList <= longLength * 2 then table.insert(self.tipCardList, tempList) else self:GetSanDaiTips(tempList, longLength * 2, removeSanDaiList) end else table.insert(self.tipCardList, tempList) end end else for j = 1, tipCardSetLen do if j + longLength - 1 <= tipCardSetLen then local tempList = {} local tempSanDaiCard = {} for k = j, j + longLength - 1 do local card = tipCardSet[i][k] tempSanDaiCard[card] = true local minNum = Mathf.Min(cardMap[card].value, cardType) for l = 1, minNum do if not self._flag_mustMax or card == self.maxCard then table.insert(tempList, cardMap[card].cardList[l]) end end end if #tempList > 0 then if cardType == 3 then local removeSanDaiList = {} for k, v in pairs(cardMap) do if not tempSanDaiCard[k] then for i, v1 in ipairs(v.cardList) do table.insert(removeSanDaiList, v1) end end end if #removeSanDaiList <= longLength * 2 then table.insert(self.tipCardList, tempList) else self:GetSanDaiTips(tempList, longLength * 2, removeSanDaiList) end else table.insert(self.tipCardList, tempList) end end end end end end end end function M:GetSanDaiTips(tempList, childNum, cardList) local childIndex = {} local cardLen = #cardList for i = 1, childNum do childIndex[i] = i end while childIndex[1] <= cardLen - childNum do if childIndex[childNum] == cardLen then for i = childNum - 1, 1, -1 do if childIndex[i] ~= cardLen + i - childNum then childIndex[i] = childIndex[i] + 1 for j = i + 1, childNum do childIndex[j] = childIndex[j - 1] + 1 end end end else childIndex[childNum] = childIndex[childNum] + 1 end local tempList_copy = {} for i, v in ipairs(tempList) do tempList_copy[i] = v end for i = 1, childNum do table.insert(tempList_copy, cardList[childIndex[i]]) end table.insert(self.tipCardList, tempList_copy) end end function M:CheckAloneOrLong() if self.cardNum == 1 and M:CheckType(CardType.one) then return CardType.one end if self.long and M:CheckType(CardType.long) then return CardType.long end end function M:CheckDuiZi() if self.cardNum == 2 and self.cardSize == 1 and M:CheckType(CardType.dui) then return CardType.dui end if self.cardNum % 2 == 0 and M:CheckType(CardType.duiLong) then local last_k for i = 1, self.cardSize do local k = self.cardListSord[i] local v = self.cardList[k] if v == 2 then if not last_k then last_k = k else if math.abs(last_k - k) ~= 1 then return end last_k = k end else return end end return CardType.duiLong end end --三带有着不同比大小极致,需要返回是哪些牌三带和最小的三带牌 function M:CheckSanDai() --三张 if self.cardNum == 5 and M:CheckType(CardType.threeAndTwo) then for i = 1, self.cardSize do local k = self.cardListSord[i] local v = self.cardList[k] if v >= 3 then return CardType.threeAndTwo, { k }, k end end end if self.threelack and self.cardNum == 4 and self.cardSize == 2 and M:CheckType(CardType.lessThree) then for i = 1, self.cardSize do local k = self.cardListSord[i] local v = self.cardList[k] if v >= 3 then return CardType.lessThree, { k }, k end end return CardType.lessThree end if self.threeNoBelt and self.cardNum == 3 and self.cardSize == 1 and M:CheckType(CardType.onlyThree) then return CardType.onlyThree end --飞机 local temp_normol_feiji if self.cardNum % 5 == 0 then temp_normol_feiji = self.cardNum / 5 end if temp_normol_feiji and M:CheckType(CardType.normolPlant) then local last_k local key_table = {} for i = 1, self.cardSize do local k = self.cardListSord[i] local v = self.cardList[k] if v >= 3 then table.insert(key_table, k) if not last_k then last_k = k else if math.abs(last_k - k) ~= 1 then return end last_k = k end end end if #key_table >= temp_normol_feiji then return CardType.normolPlant, key_table, key_table[1] else return end end print("liengmengCheckthreelack", self.threelack, self._flag_allCards) if self.threelack and M:CheckType(CardType.lessPlant) then local last_k local key_table = {} local num_four = 0 for i = 1, self.cardSize do local k = self.cardListSord[i] local v = self.cardList[k] if v >= 3 then if v == 4 then num_four = 1 end table.insert(key_table, k) print("liengmengCheckthreelack2", last_k, k) if not last_k then last_k = k else if math.abs(last_k - k) ~= 1 then return end last_k = k end end end print("liengmengCheckthreelack4", #key_table, self.cardNum - #key_table * 3 < #key_table * 2) if self.cardNum - #key_table * 3 < #key_table * 2 and not (self.cardNum == 4 and num_four == 1) then return CardType.lessPlant, key_table, key_table[1] else return end end print("liengmengCheckplaneNoBelt", self.planeNoBelt, self.cardNum % 3) if self.planeNoBelt and self.cardNum % 3 == 0 and M:CheckType(CardType.onlyPlant) then local last_k for i = 1, self.cardSize do local k = self.cardListSord[i] local v = self.cardList[k] if v == 3 then if not last_k then last_k = k else if math.abs(last_k - k) ~= 1 then return end last_k = k end else return end end return CardType.onlyPlant end end function M:CheckZha() if self.cardNum == 4 and self.cardSize == 1 then return CardType.zha end if self.fourDaiThree and self.cardNum == 7 and M:CheckType(CardType.zhaAndThreee) then local flag_four for i = 1, self.cardSize do local k = self.cardListSord[i] local v = self.cardList[k] if v == 4 then return CardType.zhaAndThreee, { k }, k end end return end end function M:CheckType(type) if type == CardType.duiLong then return self._flag_checkLst or self._flag_fristCard or (type == self.type and self.cardNum == self.lastCardNum) elseif type == CardType.lessPlant or type == CardType.lessThree then return self._flag_checkLst or (self._flag_fristCard and self._flag_allCards) or type == self.type else return self._flag_checkLst or self._flag_fristCard or type == self.type end end function M:GetTipsList() return self.tipCardList end function M:GetTouchSet() return self.touchCardSet end function M:GetTouchCardMap() return self.touchCardMao end function M:Clear() self.cardList = {} self.cardListSord = {} self.cardNum = 0 self.cardSize = 0 self.long = false self._flag_checkLst = false end return M