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, threeAndTwo = 4, normolPlant = 5, zha = 6, onlyThree = 7, onlyPlant = 8, zhaAndThreee = 9 } 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) self._flag_fristCard = false if #cardList == 0 then self._flag_fristCard = true return end self.lastCardNum = #cardList table.sort(cardList) pt(cardList) self.lastMinCard = math.floor(cardList[1] / 10) local temp_long = 0 self:Clear() self._flag_allCards = false self._flag_checkLst = true 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 self.type = -1 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 self.type = self:CheckSanDai() return end print("lingmengCheckZha2") if self:CheckZha() then self.type = self:CheckZha() return end if self.type == -1 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 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) self.tipCardList = {} self.touchCardSet = {} self.touchCardMao = {} local cardMap = {} local cardSet = {} local cardType,only,longLength = self:CheckOutCardGetType() if cardType == 0 then return end 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 end table.sort(cardSet) local tipCardSet = self:CheckOutCardGetTouchSet(cardSet,cardMap,cardType,longLength) self:CheckOutCardSetTipList(tipCardSet,longLength,cardMap,cardType) end function M:CheckOutCardGetType() local cardType = 0 local only = 0 local longLength = 1 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 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.normolPlant or self.type == CardType.onlyPlant 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 = {} for i = 1, #cardSet do local card = cardSet[i] if (cardMap[card].value >= cardType or cardMap[card].value == 4) and card > self.lastMinCard then if tempLong == 0 then tempLong = 1 else if lastCard - card == -1 then tempLong = tempLong + 1 else if tempLong >= longLength 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 end if tempLong >= longLength then for j = 1,tempLong do table.insert(self.touchCardSet,tempCardSet[j]) self.touchCardMao[tempCardSet[j]] = 1 end end table.insert(tipCardSet,tempCardSet) return tipCardSet end function M:CheckOutCardSetTipList(tipCardSet,longLength,cardMap,cardType) print("lingmengCheckOutCardSetTipList",longLength,cardMap,cardType) pt(tipCardSet) for i = 1, #tipCardSet do local tipCardSetLen = #tipCardSet[i] if tipCardSetLen == longLength then local tempList = {} for j = 1, tipCardSetLen do local card = tipCardSet[i][j] local minNum = Mathf.Min(cardMap[card].value,cardType) for k = 1 , minNum do table.insert(tempList,cardMap[card].cardList[k]) end end table.insert(self.tipCardList,tempList) else for j = 1, tipCardSetLen do if j + longLength <= tipCardSetLen then local tempList = {} for k = j,j + longLength do local card = tipCardSet[i][k] local minNum = Mathf.Min(cardMap[card].value,cardType) for l = 1 , minNum do table.insert(tempList,cardMap[card].cardList[l]) end end table.insert(self.tipCardList,tempList) end end end 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.dui) 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.dui 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 end end end if self.threelack and self.cardNum == 4 and self.cardSize == 2 and self._flag_allCards and M:CheckType(CardType.threeAndTwo) then return CardType.threeAndTwo 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 num_san = 0 for i = 1, self.cardSize do local k = self.cardListSord[i] local v = self.cardList[k] if v >= 3 then num_san = num_san + 1 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 num_san >= temp_normol_feiji then return CardType.normolPlant else return end end print("liengmengCheckthreelack", self.threelack, self._flag_allCards) if self.threelack and self._flag_allCards and M:CheckType(CardType.normolPlant) then local last_k local num_san = 0 for k, v in pairs(self.cardList) do if v >= 3 then num_san = num_san + 1 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", num_san, self.cardNum - num_san * 3 < num_san * 2) if self.cardNum - num_san * 3 < num_san * 2 then return CardType.normolPlant 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 true end end return CardType.zhaAndThreee end end function M:CheckType(type) return self._flag_checkLst or self._flag_fristCard or type == self.type 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