-- 检测牌是否存在 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 cardType(card) return card/100 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:tryKezi(card, player) if cardNum(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 _huxi = 3 end self:pushhuxi(_huxi) return true end return false end --顺子1 function M:tryShunzi1(card, player) if card < 200 and card % 100 > 8 then return false end if (cardNum(card + 1, self.cardList)> 0 and cardNum(card + 2, self.cardList) > 0 ) then removeCard(self.cardList, card, 1) removeCard(self.cardList, card + 1, 1) removeCard(self.cardList, card + 2, 1) local cardGroup = {card, card + 1, card + 2} self:push(cardGroup) local _huxi = 0 if card%100==1 then if card>200 then _huxi = 6 else _huxi = 3 end end self:pushhuxi(_huxi) return true end return false end --顺子2 function M:tryShunzi2(card, player) if cardType(card) == 1 then if cardNum(card+100,self.cardList) >= 1 and cardNum(card,self.cardList)>=2 then removeCard(self.cardList, card, 2) removeCard(self.cardList, card + 100, 1) local cardGroup = {card, card, card+100} self:push(cardGroup) local _huxi = 0 self:pushhuxi(_huxi) return true end if cardNum(card+100,self.cardList)>=2 then removeCard(self.cardList, card, 1) removeCard(self.cardList, card+100, 2) local cardGroup = {card, card+100, card+100} self:push(cardGroup) local _huxi = 0 self:pushhuxi(_huxi) return true end else if cardNum(card-100,self.cardList) >= 1 and cardNum(card,self.cardList)>=2 then removeCard(self.cardList, card, 2) removeCard(self.cardList, card - 100, 1) local cardGroup = {card, card, card-100} self:push(cardGroup) local _huxi = 0 self:pushhuxi(_huxi) return true end if cardNum(card-100,self.cardList)>=2 then removeCard(self.cardList, card, 1) removeCard(self.cardList, card-100, 2) local cardGroup = {card, card-100, card-100} self:push(cardGroup) local _huxi = 0 self:pushhuxi(_huxi) return true end end return false end function M:tryShunzi3(card, player) if card % 100 == 2 then if cardNum(card + 5, self.cardList)>0 and cardNum(card + 8, self.cardList)>0 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:tryHuazi(card) end function M:tryPair(card) if (self.pair_count > 0) then return false end if cardNum(card, self.cardList)>=2 then removeCard(self.cardList, card, 2) local cardGroup = {card, card , card} self:push(cardGroup) self.pair_count = 1; local _huxi = 0 self:pushhuxi(_huxi) return true end end function M:tryWin(player) --[[ if #self.cardList == 0 then if (self.pair_count == 1) then return true elseif #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 ]] if #self.cardList == 0 then if (player.tiCount+player.paoCount)>0 then if self.pair_count ==1 then return true end return false else if self.pair_count >0 then return false end return true end 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 (player.tiCount + player.paoCount)>0 then 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 end if self:tryShunzi2(activeCard, player) then if self:tryWin(player) then return true end 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 (player.tiCount + player.paoCount)>0 then 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 end 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:tryShunzi2(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 (player.tiCount + player.paoCount)>0 then 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 end 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:tryShunzi2(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) local res = self:tryWin(player) return res 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 = {} if player.tiCount==nil then player.tiCount = 0 end if player.paoCount==nil then player.paoCount = 0 end 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 if player.fz_list[j].type==6 then player.paoCount = 1 if cardType(player.fz_list[j].active_card) ==2 then kan_huxi = kan_huxi + 9 else kan_huxi = kan_huxi + 6 end end if player.fz_list[j].type==7 then player.tiCount = 1 if cardType(player.fz_list[j].active_card) ==2 then kan_huxi = kan_huxi + 12 else kan_huxi = kan_huxi + 9 end end if player.fz_list[j].type==2 then if cardType(player.fz_list[j].active_card) ==2 then kan_huxi = kan_huxi + 3 else kan_huxi = kan_huxi + 1 end end end end if #kan_cards > 0 then for i = 1, #kan_cards do if cardType(kan_cards[i])==2 then kan_huxi = kan_huxi + 6 else kan_huxi = kan_huxi + 3 end removeCard(cardInhand, kan_cards[i], 3) end end for k = 100, 200, 100 do for i = 1, 10 do local tem = k + i local result = init(self, player, cardInhand, tem) local num = 0 for k = 1, #self.stackHuxi do num = num + self.stackHuxi[k] end if result then local num1 = 0 for k = 1, #self.stackHuxi do num1 = num1 + self.stackHuxi[k] end 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.room_config.config.hunum==0 then return 15 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