-- 检测牌是否存在 local function checkCard(eventCard, cardList, num) if num == nil then num = 1 end local result = 0 for i = 1, #cardList do if (cardList[i] == eventCard) then result = result + 1 if (result == num) then return true end end end return false end -- 移除指定数量的牌 local function removeCard(cardList, card, count) for i = 1, count do list_remove(cardList, card) end end local function checkCardAndRomve(eventCard, cardList, num) if (checkCard(eventCard, cardList, num)) then removeCard(cardList, eventCard, num) return true end return false end -- 获取列表中牌数量 local function cardNum(eventCard, cardList) local result = 0 for i = 1, #cardList do local card = cardList[i] if (card == eventCard) then result = result + 1 end end return result end local M = { pair_count = 0, cardList = nil, stack = nil, stackHuxi = nil } function M:push(cardGroup) self.stack[#self.stack + 1] = cardGroup end function M:pushhuxi(cardGroup) self.stackHuxi[#self.stackHuxi + 1] = cardGroup end function M:rollBack() local cardGroup = self.stack[#self.stack] table.remove(self.stack, #self.stack) for _, card in ipairs(cardGroup) do self.cardList[#self.cardList + 1] = card end table.sort(self.cardList) end -- 顺子 function M:tryShunzi1(card, player) if card < 300 and card % 100 > 8 then return false end if (checkCard(card + 1, self.cardList) and checkCard(card + 2, self.cardList)) then removeCard(self.cardList, card + 1, 1) removeCard(self.cardList, card + 2, 1) removeCard(self.cardList, card, 1) local cardGroup = {card, card + 1, card + 2} self:push(cardGroup) local _huxi = 0 self:pushhuxi(_huxi) return true end return false end -- 2 7 10 function M:tryShunzi3(card, player) if card % 100 == 2 then if (checkCard(card + 5, self.cardList, 1)) and (checkCard(card + 8, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card + 5, 1) removeCard(self.cardList, card + 8, 1) local cardGroup = {card, card + 5, card + 8} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) return true end end return false end -- 坎 function M:tryKezi(card, player) if (checkCard(card, self.cardList, 3)) then removeCard(self.cardList, card, 3) local cardGroup = {card, card, card} self:push(cardGroup) local _huxi = 1 if self.drawCard~=card then --printlog("tryKezi====>>>",self.drawCard,card) _huxi = 3 end self:pushhuxi(_huxi) return true end return false end function M:tryPair(card) if (self.pair_count > 0) then return false end if (checkCard(card, self.cardList, 2)) then removeCard(self.cardList, card, 2) local cardGroup = {card, card} self:push(cardGroup) local _huxi = 0 self:pushhuxi(_huxi) self.pair_count = 1 return true elseif (checkCard(card, self.cardList, 1)) then if card % 100 <=9 then if (checkCard(card+1, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card+1, 1) local cardGroup = {card, card+1} self:push(cardGroup) local _huxi = 0 self:pushhuxi(_huxi) self.pair_count = 1 return true end end if card % 100 <=8 then if (checkCard(card+2, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card+2, 1) local cardGroup = {card, card+2} self:push(cardGroup) local _huxi = 0 self:pushhuxi(_huxi) self.pair_count = 1 return true end end if card % 100 >=2 then if (checkCard(card-1, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card-1, 1) local cardGroup = {card, card-1} self:push(cardGroup) local _huxi = 0 self:pushhuxi(_huxi) self.pair_count = 1 return true end end if card % 100 >=3 then if (checkCard(card-2, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card-2, 1) local cardGroup = {card, card-2} self:push(cardGroup) local _huxi = 0 self:pushhuxi(_huxi) self.pair_count = 1 return true end end if card % 100 ==2 then if (checkCard(card+5, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card+5, 1) local cardGroup = {card, card+5} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end if (checkCard(card+8, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card+8, 1) local cardGroup = {card, card+8} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end end if card % 100 ==7 then if (checkCard(card-5, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card-5, 1) local cardGroup = {card, card-5} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end if (checkCard(card+3, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card+3, 1) local cardGroup = {card, card+3} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end end if card % 100 ==10 then if (checkCard(card-8, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card-8, 1) local cardGroup = {card, card-8} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end if (checkCard(card-3, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card-3, 1) local cardGroup = {card, card-3} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end end end return false end function M:tryPair2(card) if (self.pair_count > 0) then return false end if (checkCard(card, self.cardList, 1)) then if card % 100 ==2 then if (checkCard(card+5, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card+5, 1) local cardGroup = {card, card+5} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end if (checkCard(card+8, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card+8, 1) local cardGroup = {card, card+8} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end end if card % 100 ==7 then if (checkCard(card-5, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card-5, 1) local cardGroup = {card, card-5} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end if (checkCard(card+3, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card+3, 1) local cardGroup = {card, card+3} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end end if card % 100 ==10 then if (checkCard(card-8, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card-8, 1) local cardGroup = {card, card-8} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end if (checkCard(card-3, self.cardList, 1)) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card-3, 1) local cardGroup = {card, card-3} self:push(cardGroup) local _huxi = 1 self:pushhuxi(_huxi) self.pair_count = 1 return true end end end return false end function M:tryWin(player) if #self.cardList == 0 then if (self.pair_count == 1) then return true elseif self.pair_count == 2 and #self.stack==2 then local tempPList={} for i=1,#self.stack do local card1=self.stack[i][1] local card2=self.stack[i][2] table.insert(tempPList,card1) table.insert(tempPList,card2) end if #tempPList~=4 then return false end table.sort(tempPList) if tempPList[1]==tempPList[2]+1 and tempPList[2]==tempPList[3]+1 and tempPList[3]==tempPList[4]+1 then return true end end return false end local activeCard = 0 for i = 1, #self.cardList do if (self.cardList[i] == 201 or self.cardList[i] == 202) then activeCard = self.cardList[i] break end end if (activeCard == 0) then activeCard = self.cardList[1] end if (activeCard % 100 == 1) then if self:tryShunzi1(activeCard, player) then if self:tryWin(player) then return true end self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end if self:tryKezi(activeCard, player) then if self:tryWin(player) then return true end self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end if self:tryPair(activeCard) then if self:tryWin(player) then return true end self.pair_count = 0 self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end if self:tryPair2(activeCard) then if self:tryWin(player) then return true end self.pair_count = 0 self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end elseif activeCard % 100 == 2 then if self:tryShunzi3(activeCard, player) then if self:tryWin(player) then return true end self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end if self:tryKezi(activeCard, player) then if self:tryWin(player) then return true end self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end if self:tryPair(activeCard) then if self:tryWin(player) then return true end self.pair_count = 0 self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end if self:tryPair2(activeCard) then if self:tryWin(player) then return true end self.pair_count = 0 self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end if self:tryShunzi1(activeCard, player) then if self:tryWin(player) then return true end self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end else if self:tryKezi(activeCard, player) then if self:tryWin(player) then return true end self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end if self:tryPair(activeCard) then if self:tryWin(player) then return true end self.pair_count = 0 self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end if self:tryPair2(activeCard) then if self:tryWin(player) then return true end self.pair_count = 0 self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end if self:tryShunzi1(activeCard, player) then if self:tryWin(player) then return true end self:rollBack() table.remove(self.stackHuxi, #self.stackHuxi) end end return false end local function init(self, player, cardInhand, addCard) self.stack = {} self.stackHuxi = {} self.pair_count = 0 self.kong_count = 0 self.drawCard=0 self.cardList = membe_clone(cardInhand) if addCard == nil then self.kong_count = 1 else self.kong_count = 0 self.cardList[#self.cardList + 1] = addCard self.drawCard=addCard end table.sort(self.cardList) return self:tryWin(player) end function M.tingPai(player, room) local self = setmetatable({}, {__index = M}) local tingList = {} local cardInhand = player.handcard_list if not cardInhand or #cardInhand == 0 then return tingList end local kan_huxi = 0 local kan_cards = {} for j = 1, #player.fz_list do for i = 1, #cardInhand do if cardInhand[i] == player.fz_list[j].active_card and player.fz_list[j].type == 3 then kan_cards[#kan_cards + 1] = cardInhand[i] break end end end if #kan_cards > 0 then for i = 1, #kan_cards do kan_huxi = kan_huxi + 3 removeCard(cardInhand, kan_cards[i], 3) end end player.tiCount = 0 player.paoCount = 0 for k = 100, 200, 100 do for i = 1, 10 do local tem = k + i local result = init(self, player, cardInhand, tem) if result then --printlog("是否胡牌===>>>",tem) end local num = 0 for k = 1, #self.stackHuxi do num = num + self.stackHuxi[k] end if result then local num1 = 0 --pt(self.stackHuxi) for k = 1, #self.stackHuxi do num1 = num1 + self.stackHuxi[k] --printlog(self.stackHuxi[k]) end --printlog("胡息数量===>>>",player.hu_xi,num1,kan_huxi) if (player.hu_xi + num1 + kan_huxi) >= (self:getHuxi(room)-1) then tingList[#tingList + 1] = tem end end end end return tingList end function M:getHuxi(room) if room.game_id == 301 then return 8 end if room.game_id == 13 or room.game_id == 14 or room.game_id == 23 then return 15 elseif room.game_id == 26 then return 10 elseif room.game_id == 29 then if room.room_config.maxPlayers == 3 then return 15 else return 9 end end end function M:GetFzData(tem, ctype) local huxi if ctype == 1 then huxi=1 elseif ctype == 2 then huxi=1 elseif ctype == 3 then huxi = 3 elseif ctype == 4 then huxi = 3 elseif ctype == 5 then huxi = 3 elseif ctype == 7 then huxi = 5 end return huxi end return M