-- 检测牌是否存在 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 end end if(result ==num) then return true 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 = { cardList = nil, stack = nil, } function M:push(cardGroup) self.stack[#self.stack+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,type1 ) if card < 300 and card % 100 > 8 then return false end if (checkCard(card, self.cardList)) and (checkCard(card + 1, self.cardList) and checkCard(card + 2, self.cardList)) then if type1 ~=nil then return true end 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) return true end return false end function M:tryShunzi2( card ,type1) if card -card%100 == 100 then if self:tryShunzi1(card+100,0) or self:tryShunzi3(card+100,0) then return false end if checkCard(card+100,self.cardList,1) and checkCard(card,self.cardList,2) then if type1 ~=nil then return true end removeCard(self.cardList,card,2) removeCard(self.cardList,card+100,1) local cardGroup = {card,card,card+100} self:push(cardGroup) return true end if (checkCard(card+100,self.cardList,2)) and (checkCard(card,self.cardList,1)) then if type1 ~=nil then return true end removeCard(self.cardList,card,1) removeCard(self.cardList,card+100,2) local cardGroup = {card+100,card+100,card} self:push(cardGroup) return true end else if self:tryShunzi1(card-100) or self:tryShunzi3(card-100) then return false end if (checkCard(card-100,self.cardList,1)) and checkCard(card,self.cardList,2) then if type1 ~=nil then return true end removeCard(self.cardList,card,2) removeCard(self.cardList,card-100,1) local cardGroup = {card,card,card-100} self:push(cardGroup) return true end if (checkCard(card-100,self.cardList,2)) and checkCard(card,self.cardList,1) then if type1 ~=nil then return true end removeCard(self.cardList,card,1) removeCard(self.cardList,card-100,2) local cardGroup = {card-100,card-100,card} self:push(cardGroup) return true end end return false end function M:tryShunzi3( card,type1 ) if card % 100 == 2 then if (checkCard(card, self.cardList, 1)) and (checkCard(card+5, self.cardList, 1)) and (checkCard(card+8, self.cardList, 1)) then if type1 ~=nil then return true end 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) return true end return false end return false end function M:tryKezi(card) if (checkCard(card, self.cardList, 3)) then removeCard(self.cardList,card,3) local cardGroup = {card,card,card} self:push(cardGroup) return true end return false end function M:tryTi(card) if (checkCard(card, self.cardList, 4)) then removeCard(self.cardList,card,4) local cardGroup = {card,card,card,card} self:push(cardGroup) return true end return false end function M:tryPair(card) if (checkCard(card, self.cardList, 2)) then removeCard(self.cardList,card,2) local cardGroup = {card,card} self:push(cardGroup) return true end return false end function M:tryShunzi4( card ) if card -card%100 == 100 then if self:tryShunzi1(card+100,0) or self:tryShunzi3(card+100,0) or self:tryShunzi5(card+100,0) then return false end if checkCard(card+100,self.cardList,1) and checkCard(card,self.cardList,1) then removeCard(self.cardList,card,1) removeCard(self.cardList,card+100,1) local cardGroup = {card,card+100} self:push(cardGroup) return true end if (checkCard(card+100,self.cardList,1)) and (checkCard(card,self.cardList,1)) then removeCard(self.cardList,card,1) removeCard(self.cardList,card+100,1) local cardGroup = {card,card+100} self:push(cardGroup) return true end else if self:tryShunzi1(card-100,0) or self:tryShunzi3(card-100,0) or self:tryShunzi5(card-100,0) then return false end if (checkCard(card-100,self.cardList,1)) and checkCard(card,self.cardList,1) then removeCard(self.cardList,card,1) removeCard(self.cardList,card-100,1) local cardGroup = {card-100,card} self:push(cardGroup) return true end if (checkCard(card-100,self.cardList,1)) and checkCard(card,self.cardList,1) then removeCard(self.cardList,card,1) removeCard(self.cardList,card-100,1) local cardGroup = {card,card-100} self:push(cardGroup) return true end end return false end function M:tryShunzi5( card ,type1) if card % 100 == 2 then if (checkCard(card, self.cardList, 1)) and (checkCard(card+5, self.cardList, 1)) then if self:tryShunzi2(card+5,0) or self:tryShunzi1(card+5,0) then return false end if type1 ~=nil then return true end removeCard(self.cardList,card,1) removeCard(self.cardList,card+5,1) local cardGroup = {card,card+5} self:push(cardGroup) return true end if (checkCard(card, self.cardList, 1)) and (checkCard(card+8, self.cardList, 1)) then if self:tryShunzi2(card+8,0) or self:tryShunzi1(card+8,0) then return false end if type1 ~=nil then return true end removeCard(self.cardList,card,1) removeCard(self.cardList,card+8,1) local cardGroup = {card,card+8} self:push(cardGroup) return true end elseif card % 100 == 7 then if (checkCard(card, self.cardList, 1)) and (checkCard(card+3, self.cardList, 1)) then if self:tryShunzi2(card+3,0) or self:tryShunzi1(card+3,0) then return false end if type1 ~=nil then return true end removeCard(self.cardList,card,1) removeCard(self.cardList,card+3,1) local cardGroup = {card,card+3} self:push(cardGroup) return true end end return false end function M:tryMenzi1( card ) if (checkCard(card, self.cardList, 1)) and (checkCard(card+1, self.cardList, 1)) then if self:tryShunzi2(card+1,0) or self:tryShunzi1(card+1,0) or self:tryShunzi3(card+1,0) then return false end removeCard(self.cardList,card,1) removeCard(self.cardList,card+1,1) local cardGroup = {card,card+1} self:push(cardGroup) return true end if (checkCard(card, self.cardList, 1)) and (checkCard(card+2, self.cardList, 1)) then if self:tryShunzi2(card+2,0) or self:tryShunzi1(card+2,0) or self:tryShunzi3(card+2,0) then return false end removeCard(self.cardList,card,1) removeCard(self.cardList,card+2,1) local cardGroup = {card,card+2} self:push(cardGroup) return true end return false end function M:tryOneCard(card) if (checkCard(card, self.cardList, 1)) then removeCard(self.cardList,card,1) local cardGroup = {card} self:push(cardGroup) return true end return false end -- 摆牌规则 先四后三 对子 顺子 单个 function M:tryPendulumRule() for i=1,10 do for k=100,200,100 do local tem = k + i local x = true if x and self:tryTi(tem) then x =false end if x and self:tryKezi(tem) then x =false end if x and self:tryShunzi2(tem) then x =false end if x and self:tryPair(tem) then x =false end if x and self:tryShunzi3(tem) then x =false end if x and self:tryShunzi1(tem) then x =false end if x and self:tryShunzi5(tem) then x =false end if x and self:tryShunzi4(tem) then x =false end if x and self:tryMenzi1(tem) then x =false end if x and self:tryOneCard(tem) then x =false end end end if #self.stack >10 then --变成10列--这里牌多了也不会报错了 local removeitem = 0 local card = 0 for i=#self.stack,1,-1 do if #self.stack[i] == 1 and removeitem ==0 then removeitem = i card = self.stack[i][1] list_remove(self.stack[i],self.stack[i][1]) end end if card ~= 0 then list_remove(self.stack,self.stack[removeitem]) for i=#self.stack,1,-1 do if #self.stack[i] >0 and #self.stack[i] <3 then self.stack[i][#self.stack[i] +1] = card break end end end end return self.stack end --摆牌规则 优先胡息 function M:tryPendulumRule2() local card_count = #self.cardList local cards_map = {} local CountCards = {} for i=1,#self.cardList do CountCards[self.cardList[i]]= CountCards[self.cardList[i]] == nil and 1 or CountCards[self.cardList[i]] + 1 end --pt(self.cardList) --printlog("摆牌规则 优先胡息====》》》") --pt(CountCards) --find4 for k,v in pairs(CountCards) do if (v == 4 and k<200) then local cs = {} cs[1]= k cs[2]= k cs[3]= k cs[4]= k cards_map[#cards_map+1]=cs CountCards[k] = 0 card_count =card_count- 4 end end --find3 for k,v in pairs(CountCards) do if (v >= 3 and k<200) then local cs = {} cs[1]= k cs[2]= k cs[3]= k cards_map[#cards_map+1]=cs CountCards[k] = CountCards[k] -3 card_count =card_count- 3 end end --find2 for k,v in pairs(CountCards) do if (v >= 2 and k<200) then local cs = {} cs[1] = k cs[2] = k cards_map[#cards_map+1]=cs CountCards[k] = CountCards[k] - 2 card_count =card_count- 2 end end --find 小 2 7 10 local counta = CountCards[102] if counta ~=nil and counta>0 then for i=1,counta do if CountCards[102]~=nil and CountCards[107]~=nil and CountCards[110]~=nil and CountCards[102] >0 and CountCards[107] >0 and CountCards[110] >0 then local cs = {} cs[1]= 102 cs[2]= 107 cs[3]= 110 cards_map[#cards_map+1] = cs CountCards[102] = CountCards[102]-1 CountCards[107] = CountCards[107]-1 CountCards[110] = CountCards[110]-1 card_count = card_count - 3 end end end --find 小 123 local counta = CountCards[101] if counta ~=nil and counta>0 then for i=1,counta do if CountCards[101]~=nil and CountCards[102]~=nil and CountCards[103]~=nil and CountCards[101] >0 and CountCards[102] >0 and CountCards[103] >0 then local cs = {} cs[1]= 101 cs[2]= 102 cs[3]= 103 cards_map[#cards_map+1] = cs CountCards[101] = CountCards[101]-1 CountCards[102] = CountCards[102]-1 CountCards[103] = CountCards[103]-1 card_count = card_count - 3 end end end --find abc for i=101,110 do if (CountCards[i] ~=nil and CountCards[i + 1] ~=nil and CountCards[i + 2] ~=nil) and CountCards[i] == CountCards[i + 1] and CountCards[i] == CountCards[i + 2] then if CountCards[i] >0 then local cs = {} cs[1]= i cs[2]= i+1 cs[3]= i+2 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]-1 CountCards[i+1] = CountCards[i+1]-1 CountCards[i+2] = CountCards[i+2]-1 card_count = card_count - 3 end end end --find ab for i=101,110 do if (CountCards[i] ~=nil and CountCards[i + 1] ~=nil ) and (CountCards[i] > 0 and CountCards[i + 1] > 0 ) then local cs = {} cs[1]= i cs[2]= i+1 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]-1 CountCards[i+1] = CountCards[i+1]-1 card_count = card_count - 2 end end --find 小 2 7 两个 for i=101,110 do if CountCards[102]~=nil and CountCards[107]~=nil and CountCards[102] ==1 and CountCards[107] ==1 then local cs = {} cs[1]= 102 cs[2]= 107 cards_map[#cards_map+1]=cs CountCards[102] = CountCards[102]-1 CountCards[107] = CountCards[107]-1 card_count = card_count - 2 end end for i=101,110 do if CountCards[102]~=nil and CountCards[110]~=nil and CountCards[102] ==1 and CountCards[110] ==1 then local cs = {} cs[1]= 102 cs[2]= 110 cards_map[#cards_map+1]=cs CountCards[102] = CountCards[102]-1 CountCards[110] = CountCards[110]-1 card_count = card_count - 2 end end for i=101,110 do if CountCards[107]~=nil and CountCards[110]~=nil and CountCards[107] ==1 and CountCards[110] ==1 then local cs = {} cs[1]= 107 cs[2]= 110 cards_map[#cards_map+1]=cs CountCards[107] = CountCards[107]-1 CountCards[110] = CountCards[110]-1 card_count = card_count - 2 end end local tempCardList={} for i = 101, 110 do if CountCards[i]~=nil and (CountCards[i] == 1) then table.insert(tempCardList,i) CountCards[i]=CountCards[i]-1 end end local cs={} local count=1 for i=1,#tempCardList do --[[if i%3==1 then cs[count]={} end table.insert(cs[count],tempCardList[i]) if i%3==0 then count=count+1 end--]] local cst={} table.insert(cst,tempCardList[i]) table.insert(cs,cst) end for i=1 , #cs do cards_map[#cards_map+1]=cs[i] card_count =card_count- #cs[i] end ----------------------------- --find4 for k,v in pairs(CountCards) do if (v == 4 and k>200) then local cs = {} cs[1]= k cs[2]= k cs[3]= k cs[4]= k cards_map[#cards_map+1]=cs CountCards[k] = 0 card_count =card_count- 4 end end --find3 for k,v in pairs(CountCards) do if (v >= 3 and k>200) then local cs = {} cs[1]= k cs[2]= k cs[3]= k cards_map[#cards_map+1]=cs CountCards[k] = CountCards[k] -3 card_count =card_count- 3 end end --find2 for k,v in pairs(CountCards) do if (v >= 2 and k>200) then local cs = {} cs[1] = k cs[2] = k cards_map[#cards_map+1]=cs CountCards[k] = CountCards[k] - 2 card_count =card_count- 2 end end --find 大 2 7 10 local countA = CountCards[202] if countA ~=nil and countA>0 then for i=1,countA do if CountCards[202]~=nil and CountCards[207]~=nil and CountCards[210]~=nil and CountCards[202] >0 and CountCards[207] >0 and CountCards[210] >0 then local cs = {} cs[1]= 202 cs[2]= 207 cs[3]= 210 cards_map[#cards_map+1]=cs CountCards[202] = CountCards[202]-1 CountCards[207] = CountCards[207]-1 CountCards[210] = CountCards[210]-1 card_count = card_count - 3 end end end --find 大 123 local countA = CountCards[201] if countA ~=nil and countA>0 then for i=1,countA do if CountCards[201]~=nil and CountCards[202]~=nil and CountCards[203]~=nil and CountCards[201] >0 and CountCards[202] >0 and CountCards[203] >0 then local cs = {} cs[1]= 201 cs[2]= 202 cs[3]= 203 cards_map[#cards_map+1]=cs CountCards[201] = CountCards[201]-1 CountCards[202] = CountCards[202]-1 CountCards[203] = CountCards[203]-1 card_count = card_count - 3 end end end --find ABC for i=201,210 do if (CountCards[i] ~=nil and CountCards[i + 1] ~=nil and CountCards[i + 2] ~=nil) and CountCards[i] == CountCards[i + 1] and CountCards[i] == CountCards[i + 2] then if CountCards[i] >0 then local cs = {} cs[1]= i cs[2]= i+1 cs[3]= i+2 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]-1 CountCards[i+1] = CountCards[i+1]-1 CountCards[i+2] = CountCards[i+2]-1 card_count = card_count - 3 end end end --[[ --find AAa for i = 201, 210 do if CountCards[i]~=nil and CountCards[i] >= 2 then if CountCards[i-100]~=nil and CountCards[i-100] == 1 then local cs = {} cs[1]= i cs[2]= i cs[3]= i-100 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]- 2; CountCards[i - 100] = CountCards[i - 100]-1 card_count = card_count-3; end end end --find Aa for i = 201, 210 do if CountCards[i]~=nil and CountCards[i] == 1 then if CountCards[i-100]~=nil and CountCards[i-100] == 1 then local cs = {} cs[1]= i cs[2]= i-100 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]- 1; CountCards[i - 100] = CountCards[i - 100]-1 card_count = card_count-2 end end end --]] --find AB for i=201,210 do if (CountCards[i] ~=nil and CountCards[i + 1] ~=nil ) and (CountCards[i] > 0 and CountCards[i + 1] > 0 ) then local cs = {} cs[1]= i cs[2]= i+1 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]-1 CountCards[i+1] = CountCards[i+1]-1 card_count = card_count - 2 end end --find 大 2 7 两个 for i=201,210 do if CountCards[202]~=nil and CountCards[207]~=nil and CountCards[202] ==1 and CountCards[207] ==1 then local cs = {} cs[1]= 202 cs[2]= 207 cards_map[#cards_map+1]=cs CountCards[202] = CountCards[202]-1 CountCards[207] = CountCards[207]-1 card_count = card_count - 2 end end for i=201,210 do if CountCards[202]~=nil and CountCards[210]~=nil and CountCards[202] ==1 and CountCards[210] ==1 then local cs = {} cs[1]= 202 cs[2]= 210 cards_map[#cards_map+1]=cs CountCards[202] = CountCards[202]-1 CountCards[210] = CountCards[210]-1 card_count = card_count - 2 end end for i=201,210 do if CountCards[207]~=nil and CountCards[210]~=nil and CountCards[207] ==1 and CountCards[210] ==1 then local cs = {} cs[1]= 207 cs[2]= 210 cards_map[#cards_map+1]=cs CountCards[207] = CountCards[207]-1 CountCards[210] = CountCards[210]-1 card_count = card_count - 2 end end -------------------- local singleList = {} --find else for k,v in pairs(CountCards) do if (v == 1) then singleList[#singleList+1] = k CountCards[k] = CountCards[k] -1 end end for i=1,#singleList do local cs={} table.insert(cs,singleList[i]) cards_map[#cards_map + 1]= cs end --[[local index = 3 for i=1,#singleList,index do local cs ={} cs[#cs+1] = singleList[i] if i < #singleList then cs[#cs+1] = singleList[i+1] end if i < #singleList - 1 then cs[#cs+1] = singleList[i+2] end cards_map[#cards_map + 1]=cs end--]] --变成9列--这里牌多了也不会报错了 --[[for i=9 ,1,-1 do for j = #cards_map , 9,-1 do if #cards_map[i] < 3 then cards_map[i][#cards_map[i]+1] = cards_map[j][1] list_remove(cards_map[j],cards_map[j][1]) end end end--]] --pt(cards_map) --printlog("11111111111111111111") local mapCount=#cards_map if mapCount>10 then local tempCardMpList1={} local tempCardMpList2={} local tempCardMpList3={} for i=1,mapCount do if #cards_map[i]>=2 then table.insert(tempCardMpList1,cards_map[i]) else if cards_map[i][1]<200 then table.insert(tempCardMpList2,cards_map[i][1]) elseif cards_map[i][1]>200 then table.insert(tempCardMpList3,cards_map[i][1]) end end end --pt(tempCardMpList1) --pt(tempCardMpList2) --pt(tempCardMpList3) local cs={} local count=1 for i=1,#tempCardMpList2 do if i%3==1 then cs[count]={} end table.insert(cs[count],tempCardMpList2[i]) if i%3==0 then count=count+1 end end for i=1 , #cs do tempCardMpList1[#tempCardMpList1+1]=cs[i] end local cs={} local count=1 for i=1,#tempCardMpList3 do if i%3==1 then cs[count]={} end table.insert(cs[count],tempCardMpList3[i]) if i%3==0 then count=count+1 end end for i=1 , #cs do tempCardMpList1[#tempCardMpList1+1]=cs[i] end cards_map=tempCardMpList1 end table.sort(cards_map, ViewUtil.HandCardSort3) --pt(cards_map) return cards_map end --摆牌规则 优先顺子 -AAa- 对子 - 单牌 function M:tryPendulumRule3() local card_count = #self.cardList local cards_map = {} local CountCards = {} for i=1,#self.cardList do CountCards[self.cardList[i]]= CountCards[self.cardList[i]] == nil and 1 or CountCards[self.cardList[i]] + 1 end --find4 for k,v in pairs(CountCards) do if (v == 4) then local cs = {} cs[1]= k cs[2]= k cs[3]= k cs[4]= k cards_map[#cards_map+1]=cs CountCards[k] = 0 card_count =card_count- 4 end end --find3 for k,v in pairs(CountCards) do if (v >= 3) then local cs = {} cs[1]= k cs[2]= k cs[3]= k cards_map[#cards_map+1]=cs CountCards[k] = CountCards[k] -3 card_count =card_count- 3 end end --find abc for i=101,110 do if (CountCards[i] ~=nil and CountCards[i + 1] ~=nil and CountCards[i + 2] ~=nil) and CountCards[i] >0 and CountCards[i + 1]>0 and CountCards[i + 2]>0 then if CountCards[i] >0 then local cs = {} cs[1]= i cs[2]= i+1 cs[3]= i+2 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]-1 CountCards[i+1] = CountCards[i+1]-1 CountCards[i+2] = CountCards[i+2]-1 card_count = card_count - 3 end end end --find ABC for i=201,210 do if (CountCards[i] ~=nil and CountCards[i + 1] ~=nil and CountCards[i + 2] ~=nil) and CountCards[i] >0 and CountCards[i + 1]>0 and CountCards[i + 2]>0 then if CountCards[i] >0 then local cs = {} cs[1]= i cs[2]= i+1 cs[3]= i+2 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]-1 CountCards[i+1] = CountCards[i+1]-1 CountCards[i+2] = CountCards[i+2]-1 card_count = card_count - 3 end end end --find 大 2 7 10 local countA = CountCards[202] if countA ~=nil and countA>0 then for i=1,countA do if CountCards[202]~=nil and CountCards[207]~=nil and CountCards[210]~=nil and CountCards[202] >0 and CountCards[207] >0 and CountCards[210] >0 then local cs = {} cs[1]= 202 cs[2]= 207 cs[3]= 210 cards_map[#cards_map+1]=cs CountCards[202] = CountCards[202]-1 CountCards[207] = CountCards[207]-1 CountCards[210] = CountCards[210]-1 card_count = card_count - 3 end end end --find 小 2 7 10 local counta = CountCards[102] if counta ~=nil and counta>0 then for i=1,counta do if CountCards[102]~=nil and CountCards[107]~=nil and CountCards[110]~=nil and CountCards[102] >0 and CountCards[107] >0 and CountCards[110] >0 then local cs = {} cs[1]= 102 cs[2]= 107 cs[3]= 110 cards_map[#cards_map+1] = cs CountCards[102] = CountCards[102]-1 CountCards[107] = CountCards[107]-1 CountCards[110] = CountCards[110]-1 card_count = card_count - 3 end end end --find AAa for i = 201, 210 do if CountCards[i]~=nil and CountCards[i] >= 2 then if CountCards[i-100]~=nil and CountCards[i-100] == 1 then local cs = {} cs[1]= i cs[2]= i cs[3]= i-100 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]- 2; CountCards[i - 100] = CountCards[i - 100]-1 card_count = card_count-3; end end end --find aaA for i = 101, 110 do if CountCards[i]~=nil and (CountCards[i] >= 2) then if CountCards[i + 100]~=nil and (CountCards[i + 100] == 1) then local cs = {} cs[1]= i cs[2]= i cs[3]= i+100 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]- 2; CountCards[i +100] = CountCards[i +100] - 1 card_count = card_count-3; end end end --find2 for k,v in pairs(CountCards) do if (v >= 2) then local cs = {} cs[1] = k cs[2] = k cards_map[#cards_map+1]=cs CountCards[k] = CountCards[k] - 2 card_count =card_count- 2 end end --find Aa for i = 201, 210 do if CountCards[i]~=nil and CountCards[i] == 1 then if CountCards[i-100]~=nil and CountCards[i-100] == 1 then local cs = {} cs[1]= i cs[2]= i-100 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]- 1; CountCards[i - 100] = CountCards[i - 100]-1 card_count = card_count-2 end end end --find ab for i=101,110 do if (CountCards[i] ~=nil and CountCards[i + 1] ~=nil ) and (CountCards[i] > 0 and CountCards[i + 1] > 0 ) then local cs = {} cs[1]= i cs[2]= i+1 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]-1 CountCards[i+1] = CountCards[i+1]-1 card_count = card_count - 2 end end --find AB for i=201,210 do if (CountCards[i] ~=nil and CountCards[i + 1] ~=nil ) and (CountCards[i] > 0 and CountCards[i + 1] > 0 ) then local cs = {} cs[1]= i cs[2]= i+1 cards_map[#cards_map+1]=cs CountCards[i] = CountCards[i]-1 CountCards[i+1] = CountCards[i+1]-1 card_count = card_count - 2 end end --find 大 2 7 两个 for i=201,210 do if CountCards[202]~=nil and CountCards[207]~=nil and CountCards[202] ==1 and CountCards[207] ==1 then local cs = {} cs[1]= 202 cs[2]= 207 cards_map[#cards_map+1]=cs CountCards[202] = CountCards[202]-1 CountCards[207] = CountCards[207]-1 card_count = card_count - 2 end end for i=201,210 do if CountCards[202]~=nil and CountCards[210]~=nil and CountCards[202] ==1 and CountCards[210] ==1 then local cs = {} cs[1]= 202 cs[2]= 210 cards_map[#cards_map+1]=cs CountCards[202] = CountCards[202]-1 CountCards[210] = CountCards[210]-1 card_count = card_count - 2 end end for i=201,210 do if CountCards[207]~=nil and CountCards[210]~=nil and CountCards[207] ==1 and CountCards[210] ==1 then local cs = {} cs[1]= 207 cs[2]= 210 cards_map[#cards_map+1]=cs CountCards[207] = CountCards[207]-1 CountCards[210] = CountCards[210]-1 card_count = card_count - 2 end end --find 小 2 7 两个 for i=101,110 do if CountCards[102]~=nil and CountCards[107]~=nil and CountCards[102] ==1 and CountCards[107] ==1 then local cs = {} cs[1]= 102 cs[2]= 107 cards_map[#cards_map+1]=cs CountCards[102] = CountCards[102]-1 CountCards[107] = CountCards[107]-1 card_count = card_count - 2 end end for i=101,110 do if CountCards[102]~=nil and CountCards[110]~=nil and CountCards[102] ==1 and CountCards[110] ==1 then local cs = {} cs[1]= 102 cs[2]= 110 cards_map[#cards_map+1]=cs CountCards[102] = CountCards[102]-1 CountCards[110] = CountCards[110]-1 card_count = card_count - 2 end end for i=101,110 do if CountCards[107]~=nil and CountCards[110]~=nil and CountCards[107] ==1 and CountCards[110] ==1 then local cs = {} cs[1]= 107 cs[2]= 110 cards_map[#cards_map+1]=cs CountCards[107] = CountCards[107]-1 CountCards[110] = CountCards[110]-1 card_count = card_count - 2 end end local singleList = {} --find else for k,v in pairs(CountCards) do if (v == 1) then singleList[#singleList+1] = k CountCards[k] = CountCards[k] -1 end end local index = 3 for i=1,#singleList,index do local cs ={} cs[#cs+1] = singleList[i] if i < #singleList then cs[#cs+1] = singleList[i+1] end if i < #singleList - 1 then cs[#cs+1] = singleList[i+2] end cards_map[#cards_map + 1]=cs end --变成9列--这里牌多了也不会报错了 for i=10 ,1,-1 do for j = #cards_map , 10,-1 do if #cards_map[i] < 3 then cards_map[i][#cards_map[i]+1] = cards_map[j][1] list_remove(cards_map[j],cards_map[j][1]) end end end return cards_map end local function init(self,cardInhand,index) self.cardList= {} self.stack = {} self.cardList = membe_clone(cardInhand) table.sort(self.cardList) if index== nil or index ==0 then return self:tryPendulumRule() elseif index == 1 then return self:tryPendulumRule() elseif index == 2 then return self:tryPendulumRule2() elseif index == 3 then return self:tryPendulumRule3() end end function M.GetHandCard(cardInhand,index) local self = setmetatable({}, {__index = M}) if not cardInhand or #cardInhand == 0 then return nil end local HandCardList = init(self,cardInhand,index) return HandCardList end return M