106 lines
1.9 KiB
Lua
106 lines
1.9 KiB
Lua
|
|
-- 检测牌是否存在
|
|
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:tryPendulumRule()
|
|
local tempValue={}
|
|
for i=100,800,100 do
|
|
local tempWValue={}
|
|
for k=1,4 do
|
|
local tem = k + i
|
|
local count=cardNum(tem,self.cardList)
|
|
if count>0 then
|
|
removeCard(self.cardList,tem,count)
|
|
local tempFValue={}
|
|
for j=1,count do
|
|
table.insert(tempFValue,tem)
|
|
end
|
|
table.insert(tempWValue,tempFValue)
|
|
end
|
|
end
|
|
|
|
if #tempWValue>0 then
|
|
table.insert(tempValue,tempWValue)
|
|
end
|
|
|
|
end
|
|
return tempValue
|
|
end
|
|
|
|
|
|
|
|
local function init(self,cardInhand)
|
|
self.cardList= {}
|
|
self.stack = {}
|
|
self.cardList = membe_clone(cardInhand)
|
|
table.sort(self.cardList)
|
|
--printlog("排序后的牌型==>>>")
|
|
--pt(self.cardList)
|
|
return self:tryPendulumRule()
|
|
end
|
|
|
|
function M.GetHandCard(cardInhand)
|
|
local self = setmetatable({}, {__index = M})
|
|
if not cardInhand or #cardInhand == 0 then
|
|
return nil
|
|
end
|
|
local HandCardList = init(self,cardInhand)
|
|
return HandCardList
|
|
end
|
|
|
|
|
|
return M
|
|
|
|
|
|
|
|
|
|
|