344 lines
9.2 KiB
Lua
344 lines
9.2 KiB
Lua
local CardCheck = {
|
|
|
|
cardList = {},
|
|
cardListSord = {},
|
|
cardNum = 0,
|
|
cardSize = 0,
|
|
long = false,
|
|
planeNoBelt = false,
|
|
threeNoBelt = false,
|
|
planelack = false,
|
|
threelack = false,
|
|
fourDaiThree = false,
|
|
fristCard = true
|
|
}
|
|
|
|
local cardType = {
|
|
one = 1,
|
|
long = 2,
|
|
dui = 3,
|
|
threeAndTwo = 4,
|
|
normolPlant = 5,
|
|
zha = 6,
|
|
onlyThree = 7,
|
|
onlyPlant = 8,
|
|
zhaAndThreee = 9
|
|
}
|
|
|
|
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
|
|
self._flag_fristCard = true
|
|
print("==============================lingmengcheckinitFlag")
|
|
pt(config)
|
|
pt(self)
|
|
return self
|
|
end
|
|
|
|
function M:initLastCard(cardList)
|
|
self._flag_fristCard = false
|
|
if #cardList == 0 then
|
|
self._flag_fristCard = true
|
|
return
|
|
end
|
|
self.lastCardNum = #cardList
|
|
table.sort(cardList)
|
|
pt(cardList)
|
|
local temp_long = 0
|
|
self:Clear()
|
|
self._flag_allCards = false
|
|
self._flag_checkLst = true
|
|
for i = 1, #cardList do
|
|
local number = math.floor(cardList[i] / 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] / 10) - number) == 1 then
|
|
temp_long = i
|
|
end
|
|
end
|
|
end
|
|
self.type = -1
|
|
print("lingmengCheckAloneOrLong2")
|
|
if self:CheckAloneOrLong() then
|
|
self.type = self:CheckAloneOrLong()
|
|
return
|
|
end
|
|
print("lingmengCheckDuiZi2")
|
|
if self:CheckDuiZi() then
|
|
self.type = self:CheckDuiZi()
|
|
return
|
|
end
|
|
print("lingmengCheckSanDai2")
|
|
|
|
if self:CheckSanDai() then
|
|
self.type = self:CheckSanDai()
|
|
return
|
|
end
|
|
print("lingmengCheckZha2")
|
|
|
|
if self:CheckZha() then
|
|
self.type = self:CheckZha()
|
|
return
|
|
end
|
|
if self.type == -1 then
|
|
ViewUtil.ErrorTip(-1, "上一份牌型判断错误")
|
|
end
|
|
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 and M:CheckType(cardType.one) then
|
|
return cardType.one
|
|
end
|
|
if self.long and M:CheckType(cardType.long) then
|
|
return cardType.long
|
|
end
|
|
end
|
|
|
|
function M:CheckDuiZi()
|
|
if self.cardNum == 2 and self.cardSize == 1 and M:CheckType(cardType.dui) then
|
|
return cardType.dui
|
|
end
|
|
if self.cardNum % 2 == 0 and M:CheckType(cardType.dui) 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 cardType.dui
|
|
end
|
|
end
|
|
|
|
function M:CheckSanDai()
|
|
--三张
|
|
if self.cardNum == 5 and self.cardSize < 4 and M:CheckType(cardType.threeAndTwo) then
|
|
return cardType.threeAndTwo
|
|
end
|
|
|
|
if self.threelack and self.cardNum == 4 and self.cardSize == 2 and self._flag_allCards and M:CheckType(cardType.threeAndTwo) then
|
|
return cardType.threeAndTwo
|
|
end
|
|
|
|
if self.threeNoBelt and self.cardNum == 3 and self.cardSize == 1 and M:CheckType(cardType.onlyThree) then
|
|
return cardType.onlyThree
|
|
end
|
|
|
|
|
|
--飞机
|
|
local temp_normol_feiji
|
|
if self.cardNum % 5 == 0 then
|
|
temp_normol_feiji = self.cardNum / 5
|
|
end
|
|
|
|
if temp_normol_feiji and M:CheckType(cardType.normolPlant) 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 cardType.normolPlant
|
|
else
|
|
return
|
|
end
|
|
end
|
|
|
|
print("liengmengCheckthreelack", self.threelack, self._flag_allCards)
|
|
|
|
if self.threelack and self._flag_allCards and M:CheckType(cardType.normolPlant) 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 cardType.normolPlant
|
|
else
|
|
return
|
|
end
|
|
end
|
|
|
|
print("liengmengCheckplaneNoBelt", self.planeNoBelt, self.cardNum % 3)
|
|
|
|
if self.planeNoBelt and self.cardNum % 3 == 0 and M:CheckType(cardType.onlyPlant) 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 cardType.onlyPlant
|
|
end
|
|
end
|
|
|
|
function M:CheckZha()
|
|
if self.cardNum == 4 and self.cardSize == 1 then
|
|
return cardType.zha
|
|
end
|
|
|
|
if self.fourDaiThree and self.cardNum == 7 and M:CheckType(cardType.zhaAndThreee) 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 cardType.zhaAndThreee
|
|
end
|
|
end
|
|
|
|
function M:CheckType(type)
|
|
return self._flag_checkLst or self._flag_fristCard or type == self.type
|
|
end
|
|
|
|
function M:Clear()
|
|
self.cardList = {}
|
|
self.cardListSord = {}
|
|
self.cardNum = 0
|
|
self.cardSize = 0
|
|
self.long = false
|
|
self._flag_checkLst = false
|
|
end
|
|
|
|
return M
|