local CardCheck = { cardList = {}, cardListSord = {}, cardNum = 0, cardSize = 0, long = false, planeNoBelt = false, threeNoBelt = false, planelack = false, threelack = false, fourDaiThree = false } 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 print("==============================lingmengcheckinitFlag") pt(config) pt(self) return self 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() 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:CheckAloneOrLong() if self.cardNum == 1 or self.long then return true end end function M:CheckDuiZi() if self.cardNum == 2 and self.cardSize == 1 then return true end if self.cardNum % 2 == 0 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 true end end function M:CheckSanDai() --三张 if self.cardNum == 5 and self.cardSize < 4 then return true end if self.threelack and self.cardNum == 4 and self.cardSize == 2 and self._flag_allCards then return true end if self.threeNoBelt and self.cardNum == 3 and self.cardSize == 1 then return true end --飞机 local temp_normol_feiji if self.cardNum % 5 == 0 then temp_normol_feiji = self.cardNum / 5 end if temp_normol_feiji 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 true else return end end print("liengmengCheckthreelack", self.threelack, self._flag_allCards) if self.threelack and self._flag_allCards 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 true else return end end print("liengmengCheckplaneNoBelt", self.planeNoBelt, self.cardNum % 3) if self.planeNoBelt and self.cardNum % 3 == 0 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 true end end function M:CheckZha() if self.cardNum == 4 and self.cardSize == 1 then return true end if self.fourDaiThree and self.cardNum == 7 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 false end end function M:Clear() self.cardList = {} self.cardListSord = {} self.cardNum = 0 self.cardSize = 0 self.long = false end return M