|
- --[[
- 3~KA2(从小到大)
- tip: 假设有个梅花3, 具体牌值则是为1,标准牌值是0x11
-
- 癞子(万能牌)相关:
- 癞子可以允许单独出,单独出为God_Card_Single_Value的值
- 癞子是否可以与癞子组合(即两个癞子是否可以组成对子,王炸),通过God_Card_Is_Can_Be_All_Same的值来获取
-
- 部分提示相关(这里1为标准值,具体值是3)
- (对子,顺子,三顺,连对,炸弹-------打头的不能为癞子)
- 即上家牌是"1,2,3,4,5",自己提示牌不会为"癞子,7,8,9,10",而是"7,8,9,10,癞子"
- (三带,4带,飞机--------打头牌,飞机牌不能为全癞子)
- 即上家牌是"1,1,1,2,",自己提示牌不会为存在"癞子,癞子,癞子",而是"8,癞子,癞子",(三带的提示只返回3张)
-
- 癞子替代牌相关:
- 返回的是替代的牌,单张则为定义的牌值,2张,3张等为min值,如果遇到带顺子属性的(顺子,飞机,连对等),则判断是哪个空缺,如果没空缺则往后补充
- ,被带的牌,如果为单张的话,则从最小(3~KA2)开始计算,判断手牌不超过当前基牌(如果3带的话,3带为基牌,这个意思。)的张数即可。若需要组成对子,则将该癞子牌转换为空缺的对子牌
-
- 代码组成:
- 一些方法/公有方法
- 癞子替代牌
- 牌型提示
- 牌型判断,返回值(是否可以为某个牌类型,牌类型,最小值/基类最小值,是否需要用癞子牌)
- ]]
-
- local defs = require("pk_nanchongdoudizhu.luaScript.Def_53")
- local PokerUtil = class("PokerUtil")
-
- -- 值
- local Value_2 = 0x0d -- 2的具体牌值
- local Value_Joker_Little = 0x0e -- 小鬼的具体牌值
- local Value_Joker_Big = 0x0f -- 大鬼的具体牌值
-
- -- 从小到大排序
- function PokerUtil.sortOrder(a, b)
- return a < b
- end
-
- -- 从小到大排序
- function PokerUtil.sortDesc(a, b)
- return a > b
- end
-
- -- 从小到大排序(根据扑克值) v指value, t指type
- function PokerUtil.sortOrder_By_PokerValue(a, b)
- local v_a = PokerUtil:getCardValue(a)
- local v_b = PokerUtil:getCardValue(b)
- if v_a ~= v_b then
- return v_a < v_b
- else
- local t_a = PokerUtil:getCardType(a)
- local t_b = PokerUtil:getCardType(b)
- return t_a < t_b
- end
- end
-
- function PokerUtil:ctor(param)
- self:initFunction()
- end
-
- -- 获得牌类型 0方块 1梅花 2红桃 3黑桃
- function PokerUtil:getCardType(card)
- return toint(getNumBand(card, 0xf0) / 0x0f)
- end
-
- -- 获得牌的具体牌值
- function PokerUtil:getCardValue(card)
- return getNumBand(card, 0x0f)
- end
-
- function PokerUtil:initFunction()
- self:initTypeMap()
- -- self:initTipMap()
- end
-
- -- 定义数组,key是手牌的长度,value则是可能组成长度为key的牌型判断方法
- --[[
- tip: 判断张数的先后与前到后插入有关。
- 即假设手中有1,1,1,万能牌:
- 如果是先插入三带一,那么则判断为3带1,如果是先插入4个的炸弹,则判断为炸弹。
-
- 通过Card_Tip_Check_Order_By_Desc开关,来确认是正序还是逆序,当然也可以重写initTypeMap方法来实现自己独有的判断顺序
- 重写后,Card_Tip_Check_Order_By_Desc还是会有作用,所以根据个人需求需要注意下。
- ]]
- function PokerUtil:initTypeMap()
- for i = 1, self.Card_Max_Length do
- self.Card_Type_Map[i] = {}
- end
-
- -- 单张
- table.insert(self.Card_Type_Map[1], self.isSingle)
-
- -- 对子
- table.insert(self.Card_Type_Map[2], self.isDouble)
-
- -- 三张
- table.insert(self.Card_Type_Map[3], self.isThree)
-
- -- 顺子
- for i = self.Less_Line, self.Max_Line do
- table.insert(self.Card_Type_Map[i], self.isLine)
- end
-
- -- 连对
- for i = self.Less_Lian_Dui, self.Card_Max_Length do
- if i % 2 == 0 then
- table.insert(self.Card_Type_Map[i], self.isDoubleLine)
- end
- end
-
- -- 三带一
- table.insert(self.Card_Type_Map[4], self.isThreeTakeOne)
-
- -- 三带二
- table.insert(self.Card_Type_Map[5], self.isThreeTakeTwo)
-
- -- 四带一张
- table.insert(self.Card_Type_Map[5], self.isFourTakeOneSingle)
-
- -- 四带一对
- table.insert(self.Card_Type_Map[6], self.isFourTakeOneDouble)
-
- -- 四带二张单排
- table.insert(self.Card_Type_Map[6], self.isFourTakeTwoSingle)
-
- -- 四带二对子
- table.insert(self.Card_Type_Map[8], self.isFourTakeTwoDouble)
-
- -- 飞机带单
- for i = self.Less_Plane + 2, self.Card_Max_Length do
- if i % 4 == 0 then
- table.insert(self.Card_Type_Map[i], self.isPlaneTakeSingle)
- end
- end
-
- -- 飞机带对子
- for i = self.Less_Plane + 4, self.Card_Max_Length do
- if i % 5 == 0 then
- table.insert(self.Card_Type_Map[i], self.isPlanetakeDouble)
- end
- end
-
- -- 飞机不带
- for i = self.Less_Plane, self.Card_Max_Length do
- if i % 3 == 0 then
- table.insert(self.Card_Type_Map[i], self.isPlaneNoTake)
- end
- end
-
- -- 炸弹
- table.insert(self.Card_Type_Map[4], self.isBomb)
-
- -- 王炸
- table.insert(self.Card_Type_Map[2], self.isKingBomb)
- end
-
- -- 获得提示(cards是userdata)
- function PokerUtil:getTip(cards, lastData)
- print('jxjx 进入getTip')
- dump(cards, 'cards')
- dump(lastData, 'lastData')
- local tipResult = {}
- local lastCardInfo = self:getCardsType(lastData)
-
- if lastCardInfo.cardType < defs.CARD_TYPE.BOMB then
- local f = self.Card_Tip_Map[lastCardInfo.cardType]
- if f then
- print(string.format('jxjx..牌型提示..%s', defs.CARD_TYPE_NAME[lastCardInfo.cardType]))
- -- tipResult = self.Card_Tip_Map[lastCardInfo.cardType](self, cards, lastData) -- f是方法 启用initTipMap
- tipResult = self[f](self, cards, lastData) -- f是str
- end
- end
-
- -- 添加炸弹
- if lastCardInfo.cardType <= defs.CARD_TYPE.BOMB then
- print('jxjx..getTip 添加炸弹')
- local result = self:getBombTip(cards, lastData)
- if table.nums(result) > 0 then
- for _, bomb in ipairs(result) do
- table.insert(tipResult, bomb)
- end
- end
- end
-
- --王炸
- if lastCardInfo.cardType <= defs.CARD_TYPE.BOMB_KING then
- print('jxjx..getTip 添加王炸')
- local result = self:getBombKingTip(cards, lastData)
- if table.nums(result) > 0 then
- for _, bomb in ipairs(result) do -- 王炸只有1个,虽然多此一举用了循环...
- table.insert(tipResult, bomb)
- end
- end
- end
-
- dump(tipResult, 'jxjx gettip 结果')
- return tipResult
- end
-
- -- 解析牌值,将牌值分成牌值数量表和牌表
- --[[
- valueList: key具体牌值, value数量
- valueCard: key具体牌值, value标准牌值(16进制转10进制的)
- 如果有癞子(万能牌)玩法,则还会返回万能牌数组,并且valueList, valueCard里面不会有包含万能牌
- ]]
- function PokerUtil:parseCard(cards)
- local valueList = {}
- local valueCard = {}
- local godCards = {}
-
- --初始化
- for i = 1, 15 do
- valueList[i] = 0
- valueCard[i] = {}
- end
-
- -- 赋值
- for k,v in ipairs(cards) do
- if self:isUseGodCard() and self:isGodCard(v) then
- table.insert(godCards, v)
- else
- local value = self:getCardValue(v)
- if not valueList[value] then
- valueList[value] = 0
- end
- if not valueCard[value] then
- valueCard[value] = {}
- end
- valueList[value] = valueList[value] + 1
- table.insert(valueCard[value], v)
- end
- end
-
- return valueList, valueCard, godCards
- end
-
- -- 解析牌值,将牌值分成牌值数量表和牌表(扩展版)
- --[[
- valueCard: key有序, value是个标准牌值组成的表(16进制转10进制的)
- 如果有癞子(万能牌)玩法,则还会返回万能牌数组,并且valueCard里面不会有包含万能牌
- ]]
- function PokerUtil:parseCardEx(cards)
- local temp = {}
- local godCards = {}
- for k,v in ipairs(cards) do
- if self:isUseGodCard() and self:isGodCard(v) then
- table.insert(godCards, v)
- else
- local value = self:getCardValue(v)
- if not temp[value] then
- temp[value] = {}
- end
- table.insert(temp[value], v)
- end
- end
-
- local valueCard = {}
- for _,v in pairs(temp) do
- table.insert(valueCard, v)
- end
-
- return valueCard, godCards
- end
-
- -- 反解析牌值,返回key为数量,value为具体牌值的表
- --[[
- result: key数量, value具体牌值
- 如果有癞子(万能牌)玩法,则还会返回万能牌数组,并且result里面不会有包含万能牌(这个不用太注意,因为repaese也是做parsecard,如果没有癞子玩法,godCards是为空表)
- ]]
- function PokerUtil:reParseCard(cards)
- local valueList, _, godCards = self:parseCard(cards)
- local result = {{}, {}, {}, {}} -- 一副牌,最多4张
- for k,v in pairs(valueList) do
- if v > 0 then
- table.insert(result[v], k)
- end
- end
-
- return result, godCards
- end
-
- -- 移除牌组中的癞子牌,只用于癞子玩法
- function PokerUtil:removeGodCards(cards)
- local temp = clone(cards)
- if self:isUseGodCard() then
- for i = #temp, 1, -1 do
- if self:isGodCard(temp[i]) then
- table.remove(temp, i)
- end
- end
- end
-
- return temp
- end
-
- -- 通过牌的标准值,转换为具体值
- function PokerUtil:changeCardValue_Standard_To_Specific(cards)
- if type(cards) == 'number' then
- return self:getCardValue(cards)
- elseif type(cards) == 'table' then
- local result = {}
- for i, v in ipairs(cards) do
- table.insert(result, self:getCardValue(v))
- end
- return result
- end
-
- return
- end
-
- -- 组合两个表(必须是有序)
- function PokerUtil:addTableData(t1, t2)
- local temp = clone(t1)
- for i, v in ipairs(t2) do
- table.insert(temp, v)
- end
-
- return temp
- end
-
- -- 获取牌组1中,不与牌组2中相同值的表(取异或表)
- function PokerUtil:xorTableData(t1, t2)
- local result = {}
- for i1, v1 in pairs(t1) do
- local tag = false
- for i2, v2 in pairs(t2) do
- if v1 == v2 then
- tag = true
- break
- end
-
- end
-
- if not tag then
- table.insert(result, v1)
- end
- end
-
- return result
- end
-
- -- 判断牌组中是否包含炸弹
- function PokerUtil:getIsHaveBomb(cards)
- -- 4张
- local reValueList, godCards = self:reParseCard(cards)
- local godCardCount = #godCards
-
- if #reValueList[4] > 0 then
- return true
- end
-
- -- 王炸
- local valueList = self:parseCard(cards)
- if (valueList[Value_Joker_Little] or 0) > 0 and (valueList[Value_Joker_Big] or 0) > 0 then
- return true
- end
-
- -- 带癞子的炸弹
- if self:isUseGodCard() and godCardCount > 0 then
- local needGodCardCount = 0
-
- -- 癞子炸弹
- while godCardCount > needGodCardCount and needGodCardCount <= 3 do
- if valueList[4 - needGodCardCount] > 0 then
- return true
- end
- needGodCardCount = needGodCardCount + 1
- end
-
- -- 癞子王炸
- if (valueList[Value_Joker_Little] or 0) > 0 or (valueList[Value_Joker_Big] or 0) > 0 then
- return true
- end
- end
-
- return false
- end
-
- -- 获得癞子取代的牌,返回的是具体值(也可以说是最低的标准值)
- function PokerUtil:getGodCardReplaceCard(cards)
- print('jxjx 进入方法getGodCardReplaceCard,获得癞子取代的牌')
- dump(cards, '牌数据是')
-
- if not cards then
- return
- end
-
- if not self:isUseGodCard() then
- return
- end
-
- local valueList, valueCard, godCards = self:parseCard(cards)
- local godCardCount = #godCards
- if godCardCount <= 0 then
- return
- end
-
- local result = {}
- local handCardType = self:getCardsType(cards)
-
- dump(handCardType, 'jxjx 获得癞子取代的牌, 当前cards组成的类型是 handCardType')
- if not handCardType.isUseGodCard then
- print(string.format('jxjx 没有handCardType.isUseGodCard,可能是没有在defs里面对应的类型后面,传达正确的值 返回'))
- return
- end
-
- print('jxjx 获得癞子取代的牌,传入类型是', defs.CARD_TYPE_NAME[handCardType.cardType])
- local f = self.God_Card_Replace_Card_Map[handCardType.cardType]
- if f then
- result = self[f](self, cards, handCardType.min)
- else
- print(string.format('jxjx 类型%s未定义,或许是类型声明不对', handCardType.cardType))
- end
-
- dump(result, 'jxjx 获得癞子取代的牌, 返回结果是,这里默认是0x0打头')
-
- print('是否把取代的牌,更改为0x5x打头值', self.God_Card_ReplaceCard_Is_Use_God_Card_Value)
- if self.God_Card_ReplaceCard_Is_Use_God_Card_Value then
- local temp = {}
- for i, v in ipairs(result) do
- table.insert(temp, self:getCardValue(v) + 5 * 16)
- end
- result = temp
- end
-
- return result
- end
-
- -- 获得带牌中,除值valmin~valmax外,最小,并且不在valCards牌组中的牌(针对获取替代牌) valCards在parseCard中得来
- function PokerUtil:getReplaceValTableExceptValInTakeCard(valCards, replaceCount, valmin, valmax)
- local valmin = valmin
- local valmax = valmax or valmin
- local rpCount = replaceCount
-
- local temp = clone(valCards)
- local tReplace = {}
- local result = {}
-
- local val = 1
- while rpCount > 0 do
- if rpCount > 1 then
- if temp[val] and temp[val] < 2 then
- table.insert(result, val)
- table.insert(result, val)
- rpCount = rpCount - 2
- end
- else
- if temp[val] and temp[val] < 1 then
- table.insert(result, val)
- rpCount = rpCount - 1
- end
- end
-
- val = val + 1
- end
-
- return result
- end
-
- -- 获得牌类型(返回类型和最小值)
- function PokerUtil:getCardsType(cards)
- local result = {min = -1, cardType = defs.CARD_TYPE.NULL, isUseGodCard = false}
- local maxLen = table.nums(cards)
- if maxLen == 0 then
- print('jxjx 牌长度错误,获得牌类型,牌长度是0,返回')
- return result
- end
-
- local tt = {} -- 普通牌(具体牌值)
- local gt = {} -- 万能牌(标准牌值),启动了Is_Use_God_Card才会有作用
- for k,v in ipairs(cards) do
- if self:isUseGodCard() and (self:isGodCard(v) or self:isGodCardReplaceCard(v)) then
- table.insert(gt, v)
- else
- table.insert(tt, self:getCardValue(v))
- end
- end
-
- table.sort(tt, function(a, b)
- return a < b
- end)
-
- print('jxjx 获得牌提示,长度是', maxLen)
- if self.Card_Type_Map[maxLen] then
- print(string.format('jxjx 判断方法共有%d个', #self.Card_Type_Map[maxLen]))
- end
-
- if self.Card_Tip_Check_Order_By_Desc then
- for i = #self.Card_Type_Map[maxLen], 1, -1 do
- local fun = self.Card_Type_Map[maxLen][i]
- if type(fun) == 'function' then
- local isType, ct, min, isUseGodCard = fun(self, tt, gt)
- if isType and ct > -1 then
- result = {min = min, cardType = ct, isUseGodCard = isUseGodCard and true or false}
- print('jxjx 获得牌提示,牌的类型是', defs.CARD_TYPE_NAME[ct])
- break
- end
- end
- end
- else
- for i, fun in ipairs(self.Card_Type_Map[maxLen]) do
- if type(fun) == 'function' then
- local isType, ct, min, isUseGodCard = fun(self, tt, gt)
- if isType and ct > -1 then
- result = {min = min, cardType = ct, isUseGodCard = isUseGodCard and true or false}
- print('jxjx 获得牌提示,牌的类型是', defs.CARD_TYPE_NAME[ct])
- break
- end
- end
- end
- end
-
- return result
- end
-
- -- 是否一手出完所有牌
- function PokerUtil:checkIsCanOneOutCard(cards, lastData)
- print('jxjx 是否一手出完所有牌')
- dump(cards, 'cards>>')
- dump(lastData, 'lastData>>')
-
- -- 压牌(如果有提示牌,并且只有1种)
- if lastData and table.nums(lastData) > 0 then
- local tips = self:getTip(cards, lastData)
- if tips and table.nums(tips) == 1 and #tips[1] == #cards then
- print('压牌,可以出完一手牌')
- return true
- end
- end
-
- -- 自己出牌(判断手中的所有牌是否可以组成某个牌型,并且没有炸弹)
- if not lastData or table.nums(lastData) <= 0 then
- local handCardType = self:getCardsType(cards)
- if handCardType.cardType > defs.CARD_TYPE.NULL and not self:getIsHaveBomb(cards) then
- print('自己出牌,可以出完一手牌')
- return true
- end
- end
-
- print('jxjx 不可一手出完所有牌')
- return false
- end
-
- -- 是否传入的cards中,都是相同的
- function PokerUtil:checkIsTheSameCards(cards)
- if not cards or #cards <= 0 then
- return
- end
-
- local tag = true
- local value = cards[1]
- for i, v in ipairs(cards) do
- if v ~= value then
- tag = false
- break
- end
- end
-
- return tag
- end
-
- -- 是否传入的cards和godCards中,cards各对应的个数数量与癞子牌组合后能大于等于maxCount(针对带牌,这里只按1副牌处理)
- function PokerUtil:checkIsCanCombination(cards, godCards, maxCount)
- local maxCount = maxCount or 4
- local reValueList = self:reParseCard(cards)
- local godCardCount = #godCards
-
- if #cards == 0 then
- if godCardCount >= maxCount then
- return true
- end
- end
-
- for count, vt in ipairs(reValueList) do
- if table.nums(vt) > 0 then
- if count + godCardCount >= maxCount then
- return true
- end
- end
- end
-
- return false
- end
-
- -- 是否可以3带1
- function PokerUtil:can31()
- if not app.room then
- return true
- end
-
- local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
- return getNumBand(0x01, (gameInfo.sanDai or 0x1)) > 0
- end
-
- -- 是否可以3带2
- function PokerUtil:can32()
- if not app.room then
- return true
- end
-
- local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
- return getNumBand(0x02, (gameInfo.sanDai or 0x2)) > 0
- end
-
- -- 是否可以4带1
- function PokerUtil:can41()
- return false
- end
-
- -- 是否可以4带2(4带1对子)
- function PokerUtil:can42()
- return true
- end
-
- -- 是否可以4带单单(2个单张)
- function PokerUtil:can411()
- if not app.room then
- return true
- end
-
- local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
- return getNumBand(0x02, (gameInfo.siDai or 0x02)) > 0
- end
-
- -- 是否可以4带双双(2个对子)
- function PokerUtil:can422()
- if not app.room then
- return true
- end
-
- local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
- return getNumBand(0x08, (gameInfo.siDai or 0x08)) > 0
- end
-
- -- 是否启用万能牌
- function PokerUtil:isUseGodCard()
- return self.Is_Use_God_Card
- end
-
- -- 是否启用万能牌与万能牌之间可以组合
- function PokerUtil:isUseAllSameGodCard()
- return self.God_Card_Is_Can_Be_All_Same
- end
-
- -- 是否是万能牌
- function PokerUtil:isGodCard(card)
- return card == self.God_Card_Value
- end
-
- -- 是否是万能牌幻化的值(0x5x)
- function PokerUtil:isGodCardReplaceCard(card)
- if self.God_Card_ReplaceCard_Is_Use_God_Card_Value then
- return self:getCardType(card) == 5
- end
-
- return
- end
-
- -- 是否包含万能牌
- function PokerUtil:isHaveGodCard(cards)
- if not self:isUseGodCard() then
- return
- end
- if not cards then
- return
- end
-
- for i, v in ipairs(cards) do
- if self:isGodCard(v) then
- return true
- end
- end
- end
-
- -----------------------------------------------------------------------------------------------------------------
- -------------------------------------- 以下是癞子替代牌 ----------------------------------------------------
- -----------------------------------------------------------------------------------------------------------------
-
- function PokerUtil:getGodCardSingleReplace(cards, min)
- return {min}
- end
-
- function PokerUtil:getGodCardDuiZiReplReplace(cards, min)
- return {min}
- end
-
- function PokerUtil:getGodCardSanZhangReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local result = {}
-
- for i = 1, 3 - valueList[min] do
- table.insert(result, min)
- end
-
- return result
- end
-
- function PokerUtil:getGodCardShunZiReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local result = {}
-
- for i = min, min + #cards - 1 do
- if valueList[i] < 1 then
- table.insert(result, i)
- end
- end
-
- return result
- end
-
- function PokerUtil:getGodCardLianDuiReplace(cards, min)
- print('jxjx 进入连对 万能牌替代牌判断')
- local valueList, valueCard, godCards = self:parseCard(cards)
- local result = {}
-
- for i = min, min + #cards/2 - 1 do
- if valueList[i] < 2 then
- for j = 1, 2 - valueList[i] do
- table.insert(result, i)
- end
- end
- end
-
- return result
- end
-
- function PokerUtil:getGodCardSanShunReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local result = {}
-
- for i = min, min + #cards/3 - 1 do
- if valueList[i] < 3 then
- for j = 1, 3 - valueList[i] do
- table.insert(result, i)
- end
- end
- end
-
- return result
- end
-
- function PokerUtil:getGodCardSanDaiYiReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local godCardCount = #godCards
- local count = 0
- local result = {}
-
- if valueList[min] < 3 then
- for j = 1, 3 - valueList[min] do
- table.insert(result, min)
- count = count + 1
- end
- end
-
- -- 如果还有多出的万能牌
- if count < godCardCount then
- local leftReplaceCount = godCardCount - count
- local valTable = self:getReplaceValTableExceptValInTakeCard(valueList, leftReplaceCount, min)
- result = self:addTableData(result, valTable)
- end
-
- return result
- end
-
- function PokerUtil:getGodCardSanDaiYiDuiReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local godCardCount = #godCards
- local count = 0
- local result = {}
-
- if valueList[min] < 3 then
- for j = 1, 3 - valueList[min] do
- table.insert(result, min)
- count = count + 1
- end
- end
-
- -- 如果还有多出的万能牌
- if count < godCardCount then
- for i = 1, (godCardCount - count) do
- table.insert(result, godCards[1])
- end
- end
-
- return result
- end
-
- function PokerUtil:getGodCardSiDaiErSingleReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local godCardCount = #godCards
- local count = 0
- local result = {}
-
- if valueList[min] < 4 then
- for j = 1, 4 - valueList[min] do
- table.insert(result, min)
- count = count + 1
- end
- end
-
- -- 如果还有多出的万能牌
- if count < godCardCount then
- local leftReplaceCount = godCardCount - count
- local valTable = self:getReplaceValTableExceptValInTakeCard(valueList, leftReplaceCount, min)
- result = self:addTableData(result, valTable)
- end
-
- return result
- end
-
- function PokerUtil:getGodCardSiDaiErDuiReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local reValueList = self:reParseCard(cards)
- local godCardCount = #godCards
- local count = 0
- local result = {}
-
- if valueList[min] < 4 then
- for j = 1, 4 - valueList[min] do
- table.insert(result, min)
- count = count + 1
- end
- end
-
- if #reValueList[1] > 0 then
- for i, v in pairs(reValueList[1]) do
- table.insert(result, v)
- count = count + 1
- end
- end
-
- -- 如果还有多出的万能牌
- if count < godCardCount then
- local leftReplaceCount = godCardCount - count
- local valTable = self:getReplaceValTableExceptValInTakeCard(valueList, leftReplaceCount, min)
- result = self:addTableData(result, valTable)
- end
-
- return result
- end
-
- function PokerUtil:getGodCardAirPlaneSingleReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local reValueList = self:reParseCard(cards)
- local feiLen = #cards / 4
- local godCardCount = #godCards
- local count = 0
- local result = {}
-
- for i = min, min + feiLen - 1 do
- if valueList[i] < 3 then
- for j = 1, 3 - valueList[i] do
- table.insert(result, i)
- count = count + 1
- end
- end
- end
-
- -- 如果还有多出的万能牌
- if count < godCardCount then
- local leftReplaceCount = godCardCount - count
- local valTable = self:getReplaceValTableExceptValInTakeCard(valueList, leftReplaceCount, min, min+feiLen-1)
- result = self:addTableData(result, valTable)
- end
-
- return result
- end
-
- function PokerUtil:getGodCardAirPlaneDuiReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local reValueList = self:reParseCard(cards)
- local feiLen = #cards / 5
- local godCardCount = #godCards
- local count = 0
- local result = {}
-
- for i = min, min + feiLen - 1 do
- if valueList[i] < 3 then
- for j = 1, 3 - valueList[i] do
- table.insert(result, i)
- count = count + 1
- end
- end
- end
-
- if #reValueList[1] > 0 then
- for i, v in pairs(reValueList[1]) do
- table.insert(result, v)
- count = count + 1
- end
- end
-
- -- 如果还有多出的万能牌
- if count < godCardCount then
- local leftReplaceCount = godCardCount - count
- local valTable = self:getReplaceValTableExceptValInTakeCard(valueList, leftReplaceCount, min, min+feiLen-1)
- result = self:addTableData(result, valTable)
- end
-
- return result
- end
-
- function PokerUtil:getGodCardBombReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local result = {}
-
- for i = 1, 4 - valueList[min] do
- table.insert(result, min)
- end
-
- return result
- end
-
- function PokerUtil:getGodCardBombKingReplace(cards, min)
- local valueList, valueCard, godCards = self:parseCard(cards)
- if valueList[Value_Joker_Little] > 0 then
- table.insert(result, Value_Joker_Big)
- elseif valueList[Value_Joker_Big] > 0 then
- table.insert(result, Value_Joker_Big)
- end
-
- return result
- end
-
- -----------------------------------------------------------------------------------------------------------------
- -------------------------------------- 以下是牌型提示 ------------------------------------------------------
- -----------------------------------------------------------------------------------------------------------------
-
- -- 获得单张提示
- --[[
- tip: 先从1张按顺序获取,在从2张,最后到4张
- 有癞子下,不会提示癞子打出
- ]]
- function PokerUtil:getSingleTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local result = {}
-
- local reValueList = self:reParseCard(cards)
- for i = 1, 4 do
- for k2,v2 in pairs(reValueList[i]) do
- if v2 > lastCardInfo.min then
- table.insert(result, { valueCard[v2][1] })
- end
- end
- end
-
- return result
- end
-
- -- 获得对子提示
- --[[
- tip:直接就是从小到大,直接在2,3,4张中获取,不按是否有3张还是4张的
- 有癞子下,在最后添加判断(只从1张中寻找)
- ]]
- function PokerUtil:getDuiZiTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local godCardCount = #godCards
- local result = {}
-
- for i = lastCardInfo.min + 1, 13 do
- local tpReplace = {}
- if (valueList[i] or 0) >= 2 then
- for j = 1, 2 do
- table.insert(tpReplace, valueCard[i][j])
- end
- table.insert(result, tpReplace)
- end
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- for i = lastCardInfo.min + 1, 13 do
- local tpReplace = {}
- if (valueList[i] or 0) == 1 then
- table.insert(tpReplace, valueCard[i][1])
- table.insert(tpReplace, godCards[1])
- table.insert(result, tpReplace)
- end
- end
- end
-
- return result
- end
-
- -- 获得三张提示
- --[[
- tip:直接就是从小到大,直接在3,4张中获取,不按是否有3张还是4张的
- 有癞子下,往最后添加判断(值从1,2张中寻找,以从小到大排序,不按需癞子个数排序)
- ]]
- function PokerUtil:getSanZhangTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local godCardCount = #godCards
- local result = {}
-
- for i = lastCardInfo.min + 1, 13 do
- local tpReplace = {}
- if (valueList[i] or 0) >= 3 then
- for j = 1, 3 do
- table.insert(tpReplace, valueCard[i][j])
- end
- table.insert(result, tpReplace)
- end
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- for i = lastCardInfo.min + 1, 13 do
- local tpReplace = {}
- if (valueList[i] or 0) == 1 or (valueList[i] or 0) == 2 then
- local needGodCardCount = 3 - valueList[i]
- if godCardCount >= needGodCardCount then
- for _, v in ipairs(valueCard[i]) do
- table.insert(tpReplace, v)
- end
- for j = 1, needGodCardCount do
- table.insert(tpReplace, godCards[j])
- end
-
- table.insert(result, tpReplace)
- end
- end
- end
- end
- return result
- end
-
- -- 获得顺子提示
- --[[
- tip:先for循环最小值+1,直到13-长度(为了减少复杂度);然后在while循环中判断是否有当前出牌的长度的个数
- 有癞子下,不管癞子个数,直接就是返回从小到大的顺子,如果需要把包含癞子的放置最后,请自行判断
- ]]
- function PokerUtil:getShunZiTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local nowCardsLen = table.nums(cards)
- local lastCardsLen = table.nums(lastData)
- local godCardCount = #godCards
- local result = {}
-
- for i = lastCardInfo.min + 1, 13 - lastCardsLen do
- local tpIdx = i
- local tpCount = 0
- local tpReplace = {}
- local needGodCardCount = 0
-
- -- 4个判断条件(当前顺子长度比手牌长度短,当前顺子长度(如遇到癞子不+1)+癞子长度)小于上次出牌长度, 当前牌值小于2(具体值13), 需要的癞子牌小于癞子数量)
- while tpCount < nowCardsLen and (tpCount + needGodCardCount) < lastCardsLen and tpIdx <= 12 and needGodCardCount <= godCardCount do
- valueList[tpIdx] = valueList[tpIdx] or 0
- if valueList[tpIdx] <= 0 then
- if self:isUseGodCard() and godCardCount > 0 then
- needGodCardCount = needGodCardCount + 1
- else
- break
- end
- end
-
- -- 如果手牌中有该tpIdx值
- if valueList[tpIdx] > 0 then
- table.insert(tpReplace, valueCard[tpIdx][1])
- tpCount = tpCount + 1
- end
- tpIdx = tpIdx + 1
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
- if godCardCount >= needGodCardCount then
- for j = 1, needGodCardCount do
- table.insert(tpReplace, godCards[j])
- tpCount = tpCount + 1
- end
- end
- end
- end
-
- if tpCount == lastCardsLen then
- table.insert(result, tpReplace)
- end
- end
-
- return result
- end
-
- -- 获得连对提示
- --[[
- tip:先for循环最小值+1,直到13-长度/2(为了减少复杂度,这里/2是因为连对中是一半一半相对的);然后在while循环中判断是否有当前出牌的长度的个数
- 有癞子下,不管癞子个数,直接就是返回从小到大的连对,如果需要把包含癞子的放置最后,请自行判断
- ]]
- function PokerUtil:getLianDuiTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local nowCardsLen = table.nums(cards)
- local lastCardsLen = table.nums(lastData)
- local godCardCount = #godCards
- local result = {}
-
- for i = lastCardInfo.min + 1, 13 - lastCardsLen / 2 do
- local tpIdx = i
- local tpCount = 0
- local tpReplace = {}
- local needGodCardCount = 0
-
- -- 4个判断条件(当前顺子长度比手牌长度短,当前顺子长度(如遇到癞子不+1)+癞子长度)小于上次出牌长度, 当前牌值小于2(具体值13), 需要的癞子牌小于癞子数量)
- while tpCount < nowCardsLen and (tpCount + needGodCardCount) < lastCardsLen and tpIdx <= 12 and needGodCardCount <= godCardCount do
- valueList[tpIdx] = valueList[tpIdx] or 0
- if valueList[tpIdx] <= 1 then
- if self:isUseGodCard() and godCardCount > 0 then
- needGodCardCount = needGodCardCount + (2 - valueList[tpIdx])
- else
- break
- end
- end
-
- if valueList[tpIdx] > 1 then
- for j = 1, 2 do
- table.insert(tpReplace, valueCard[tpIdx][j])
- end
- tpCount = tpCount + 2
- elseif self:isUseGodCard() and valueList[tpIdx] > 0 then -- 连对中,如果是癞子玩法,也需要把1张的插入,然后再看看是否癞子个数够
- table.insert(tpReplace, valueCard[tpIdx][1])
- tpCount = tpCount + 1
- end
-
- tpIdx = tpIdx + 1
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
- if godCardCount >= needGodCardCount then
- for j = 1, needGodCardCount do
- table.insert(tpReplace, godCards[j])
- tpCount = tpCount + 1
- end
- end
- end
- end
-
- if tpCount == lastCardsLen then
- table.insert(result, tpReplace)
- end
- end
-
- return result
- end
-
- -- 获得三顺提示(飞机不带翅膀)
- --[[
- tip:先for循环最小值+1,直到13-长度/3(为了减少复杂度,这里/3是因为连对中是每3分之1相对的);然后在while循环中判断是否有当前出牌的长度的个数
- 有癞子下,不管癞子个数,直接就是返回从小到大的连对,如果需要把包含癞子的放置最后,请自行判断
- ]]
- function PokerUtil:getSanShunTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local nowCardsLen = table.nums(cards)
- local lastCardsLen = table.nums(lastData)
- local godCardCount = #godCards
- local result = {}
-
- for i = lastCardInfo.min + 1, 13 - lastCardsLen / 3 do
- local tpIdx = i
- local tpCount = 0
- local tpReplace = {}
- local needGodCardCount = 0
-
- while tpCount < nowCardsLen and (tpCount + needGodCardCount) < lastCardsLen and tpIdx <= 12 and needGodCardCount <= godCardCount do
- valueList[tpIdx] = valueList[tpIdx] or 0
- if valueList[tpIdx] < 3 then
- if self:isUseGodCard() and godCardCount > 0 then
- needGodCardCount = needGodCardCount + (3 - valueList[tpIdx])
- else
- break
- end
- end
-
- if valueList[tpIdx] >= 3 then
- for j = 1, 3 do
- table.insert(tpReplace, valueCard[tpIdx][j])
- end
- tpCount = tpCount + 3
- elseif self:isUseGodCard() and valueList[tpIdx] > 0 then -- 三顺中,如果是癞子玩法,也需要把1张,2张的插入,然后再看看是否癞子个数够
- local count = valueList[tpIdx]
- for j = 1, count do
- table.insert(tpReplace, valueCard[tpIdx][j])
- end
- tpCount = tpCount + count
- end
-
- tpIdx = tpIdx + 1
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
- if godCardCount >= needGodCardCount then
- for j = 1, needGodCardCount do
- table.insert(tpReplace, godCards[j])
- tpCount = tpCount + 1
- end
- end
- end
- end
-
- if tpCount == lastCardsLen then
- table.insert(result, tpReplace)
- end
- end
-
- return result
- end
-
- -- 获得3带1提示
- --[[
- tips:直接获取判断是否有大于等于3张的牌值
- 有癞子下,往最后添加判断(值从1,2张中寻找,以从小到大排序,不按需癞子个数排序)
- 只返回3张
- ]]
- function PokerUtil:getSanDaiYiTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local nowCardsLen = table.nums(cards)
- local godCardCount = #godCards
- local result = {}
-
- -- 正常流程
- for i = lastCardInfo.min + 1, 13 do
- local tpReplace = {}
-
- -- 不包括带自己
- if ((valueList[i] or 0) == 3 and nowCardsLen > 3) or ((valueList[i] or 0) > 3 and nowCardsLen > 4) then
- for j = 1, 3 do
- table.insert(tpReplace, valueCard[i][j])
- end
- table.insert(result, tpReplace)
- end
- end
-
- -- 癞子流程
- if self:isUseGodCard() and godCardCount > 0 then
- if nowCardsLen > 3 then -- 手牌一定要超过3张
- for i = lastCardInfo.min + 1, 13 do
- local tpReplace = {}
-
- -- 从1张中获取,2张同理
- if ((valueList[i] or 0) == 1) or ((valueList[i] or 0) == 2) then
- local needGodCardCount = 3 - valueList[i]
- if godCardCount >= needGodCardCount then
- for _, v in ipairs(valueCard[i]) do
- table.insert(tpReplace, v)
- end
- for j = 1, needGodCardCount do
- table.insert(tpReplace, godCards[j])
- end
-
- table.insert(result, tpReplace)
- end
- end
- end
- end
- end
-
- return result
- end
-
- -- 获得3带1对提示(3带2)
- --[[
- tip:只返回3张,在for循环前,会判断是否有对子
- 有癞子下,往最后添加判断(值根据以下判断查找
- 1.有3张,没对子
- 2.没3张,有对子
- 3.没3张,没对子
- 其实就是在需要补充癞子的情况中,添加即可了
- 以从小到大排序,不按需癞子个数排序)
- ]]
- function PokerUtil:getSanDaiYiDuiTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local reValueList = self:reParseCard(cards)
- local lastCardsLen = table.nums(lastData)
- local godCardCount = #godCards
- local tResult = {} -- 已添加过的3张数据(用于癞子中,不会重复添加到)
- local result = {}
-
- -- 正常流程
- if table.nums(reValueList[2]) > 0 then
- for i = lastCardInfo.min + 1, 13 do
- local tpReplace = {}
- if (valueList[i] or 0) >= 3 then
- for j = 1, 3 do
- table.insert(tpReplace, valueCard[i][j])
- end
- table.insert(result, tpReplace)
- tResult[i] = true
- end
- end
- end
-
- -- 癞子流程
- if self:isUseGodCard() and godCardCount > 0 then
- for i = lastCardInfo.min + 1, 13 do
- local needGodCardCount = 0
- local vCount = valueList[i] or 0
- if vCount <= 3 then
- needGodCardCount = needGodCardCount + (3 - vCount)
- end
-
- local temp = self:removeGodCards(clone(cards))
- local xorData = self:xorTableData(temp, {i}) -- 排除当前牌i的剩余牌(2张,3张,4张中)
- local t = self:reParseCard(xorData)
- local tCount = #t[2] + #t[3] + #t[4]
-
- -- 带对子,如果2张,3张,4张都没有情况下
- if tCount <= 0 then
- local needCount = (#reValueList[1] > 0) and 1 or 2 -- 从单张里面补充1张,或者直接补充2张
- needGodCardCount = needGodCardCount + needCount
- end
-
- if godCardCount >= needGodCardCount then
- if vCount ~= 0 or self:isUseAllSameGodCard() then
- if not tResult[i] then -- 如果之前没有添加过
- local tpReplace = {}
- for j = 1, vCount do
- table.insert(tpReplace, valueCard[i][j])
- end
-
- for j = 1, (3 - vCount) do
- table.insert(tpReplace, godCards[j])
- end
- table.insert(result, tpReplace)
- tResult[i] = true
- end
- end
- end
- end
- end
-
- return result
- end
-
- -- 获得飞机带单提示
- --[[
- tip:根据当前循环for的i值,往后延长最长的,如果一个111222,手中有333444555,则会提示444555
- 有癞子下,不管癞子个数,直接就是返回从小到大的飞机带单,如果需要把包含癞子的放置最后,请自行判断
- 如果有炸弹和3个也能组成飞机,也会先提示
- ]]
- function PokerUtil:getAirPlaneSingleTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local nowCardsLen = table.nums(cards)
- local lastCardsLen = table.nums(lastData)
- local godCardCount = #godCards
- local result = {}
-
- -- if table.nums(valueList) > lastCardsLen / 4 then -- 之前的,不知道为什么这么判断
- if nowCardsLen >= lastCardsLen then
- for i = lastCardInfo.min + 1, 13 - lastCardsLen / 4 do
- local tpIdx = i
- local tpCount = 0
- local tpReplace = {}
- local needGodCardCount = 0
-
- while tpCount < nowCardsLen and (tpCount + needGodCardCount) < lastCardsLen and tpIdx <= 12 and needGodCardCount <= godCardCount do
- valueList[tpIdx] = valueList[tpIdx] or 0
- if valueList[tpIdx] < 3 then
- if self:isUseGodCard() and godCardCount > 0 then
- needGodCardCount = needGodCardCount + (3 - valueList[tpIdx])
- else
- break
- end
- end
-
- if valueList[tpIdx] >= 3 then
- for j = 1, 3 do
- table.insert(tpReplace, valueCard[tpIdx][j])
- end
- tpCount = tpCount + 3
- elseif self:isUseGodCard() and valueList[tpIdx] > 0 then
- local count = valueList[tpIdx]
- for j = 1, count do
- table.insert(tpReplace, valueCard[tpIdx][j])
- end
- tpCount = tpCount + count
- end
-
- tpCount = tpCount + 1 -- (包含带牌,所以+1)
- tpIdx = tpIdx + 1
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
- if godCardCount >= needGodCardCount then
- for j = 1, needGodCardCount do
- table.insert(tpReplace, godCards[j])
- tpCount = tpCount + 1
- end
- end
- end
- end
-
- if tpCount == lastCardsLen then
- table.insert(result, tpReplace)
- end
- end
- end
-
- return result
- end
-
- -- 获得飞机带对提示
- --[[
- tip:会先判断手牌中2张是否大于等于2个数量
- 有癞子下,不管癞子个数,直接就是返回从小到大的飞机带单,如果需要把包含癞子的放置最后,请自行判断
- 如果有炸弹和3个也能组成飞机,也会先提示
-
- 飞机带对的流程比较麻烦,这里理一下:
- 1,判断手牌是否大于等于出的牌
- 2.判断飞机牌是否有满足的(运用for从min到A,运用while判断连续值)
- while跳出循环的条件
- <1>(连续值长度大于手牌长度(这里有点多余,因为是飞机票和带牌独立判断))
- <2>(连续值长度与需要癞子牌数量超过飞机长度lastCardsLen/5*3,不用特殊判断是否有癞子,如果没癞子,needGodCardCount为0)
- <3>当前连续值tpIdx超过A值(2,小王,大王)
- <4>需要癞子牌数量超过手牌癞子牌数量
-
- 1)有癞子的情况,如果连续值中没有超过3张,先不跳出while循环,存储需要癞子的数量needGodCardCount.
- 2)没有癞子额情况,如果连续值中没有3张,直接跳出while循环.
- 3)如果1),2)条件都满足了,并且该连续值大于等于3张,插入值待用牌组tpReplace.
- 4)如果1),2)条件都满足了,但是连续值并没有3张。如果开启了癞子玩法,则还是把当前的连续值个数插入待用牌组tpReplace,这里不需要增加所需癞子个数,因为1)条件内已增加.
- 5)while循环后,补充当前所需的癞子牌个数,插入至待用牌组.
- 6)此时tpCount一定等于lastCardsLen/5*3(飞机长度),如果有错,可以查看是否跳出了while循环.
- 3.然后判断带的牌是否有满足的
- 1)可带对子canBeDuiZiCount里面是否满足带牌数量
- 2)如果不够则用癞子数量补充
- 3)1),2)条件过后,tpCount一定等于出牌长度,才可插入result表内,否则则认为是癞子牌数量不够.
- ]]
- function PokerUtil:getAirPlaneDuiTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local nowCardsLen = table.nums(cards)
- local lastCardsLen = table.nums(lastData)
- local reValueList = self:reParseCard(cards)
- local godCardCount = #godCards
- local result = {}
-
- if nowCardsLen >= lastCardsLen then
- for i = lastCardInfo.min + 1, 13 - lastCardsLen / 5 do
- local tpIdx = i
- local tpCount = 0
- local tpReplace = {}
- local needGodCardCount = 0
-
- -- 判断飞机牌
- while tpCount < nowCardsLen and (tpCount + needGodCardCount) < (lastCardsLen/5*3) and tpIdx <= 12 and needGodCardCount <= godCardCount do
- valueList[tpIdx] = valueList[tpIdx] or 0
- if valueList[tpIdx] < 3 then
- if self:isUseGodCard() and godCardCount > 0 then
- needGodCardCount = needGodCardCount + (3 - valueList[tpIdx])
- else
- break
- end
- end
-
- if valueList[tpIdx] >= 3 then
- for j = 1, 3 do
- table.insert(tpReplace, valueCard[tpIdx][j])
- end
- tpCount = tpCount + 3
- elseif self:isUseGodCard() and valueList[tpIdx] > 0 then
- local count = valueList[tpIdx]
- for j = 1, count do
- table.insert(tpReplace, valueCard[tpIdx][j])
- end
- tpCount = tpCount + count
- end
- tpIdx = tpIdx + 1
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- if godCardCount >= needGodCardCount then
- for j = 1, needGodCardCount do
- table.insert(tpReplace, godCards[j])
- tpCount = tpCount + 1
- end
- end
- end
-
- -- 判断飞机带的牌
- local temp = self:removeGodCards(clone(cards))
- local rTemp = {} -- 成为飞机的飞机牌
- for j = i, (i + lastCardsLen/5 - 1) do
- table.insert(rTemp, j)
- end
- local xorData = self:xorTableData(temp, rTemp)
- local t = self:reParseCard(xorData)
- local canBeDuiZiCount = #t[2] + #t[3] + #t[4] * 2 -- 可组成对子个数(4个可以组成2个对子)
-
- if canBeDuiZiCount >= lastCardsLen/5 then -- 带的对子是否刚好或者超过上家牌的飞机长度
- tpCount = tpCount + (lastCardsLen/5*2) -- 补充带的牌的牌数
- elseif self:isUseGodCard() and godCardCount > 0 then -- 如果不够的话,补充
- local totalNeedCount = lastCardsLen/5 -- 总共需要的对子
- totalNeedCount = totalNeedCount - canBeDuiZiCount -- 移除现在的对子数量,即,最后剩下补充的对子个数
- tpCount = tpCount + canBeDuiZiCount * 2 -- 补充有的对子
-
- local needCount = 0
- for j = 1, totalNeedCount do
- if #t[1] - j >= 0 then -- 1个的数量够
- tpCount = tpCount + 1 -- 如果有1张,先补充1张
- needCount = needCount + 1
- else
- needCount = needCount + 2
- end
- end
- needGodCardCount = needGodCardCount + needCount
-
- if godCardCount >= needGodCardCount then
- for i = 1, needCount do
- tpCount = tpCount + 1 -- 剩余的万能牌,补充数量
- end
- end
- end
-
- if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
- if tpCount == lastCardsLen then
- table.insert(result, tpReplace)
- end
- end
- end
- end
-
- return result
- end
-
- -- 获得4带2单提示
- --[[
- tips:先判断手牌是否大于等于6张,然后寻找4个
- 有癞子下,往最后添加判断(值从1,2张中寻找,以从小到大排序,不按需癞子个数排序)
- 只返回4张,所以可能会跟炸弹一致.
- ]]
- function PokerUtil:getSiDaiErSingleTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local nowCardsLen = table.nums(cards)
- local godCardCount = #godCards
- local result = {}
-
- -- 正常流程
- if nowCardsLen >= 6 then
- for i = lastCardInfo.min + 1, 13 do
- local tpReplace = {}
- if (valueList[i] or 0) >= 4 and nowCardsLen > 4 then
- for j = 1, 4 do
- table.insert(tpReplace, valueCard[i][j])
- end
- table.insert(result, tpReplace)
- end
- end
- end
-
- -- 癞子流程
- if self:isUseGodCard() and godCardCount > 0 then
- if nowCardsLen > 4 then
- for i = lastCardInfo.min + 1, 13 do
- local tpReplace = {}
-
- -- 从1张中获取,2张,3张同理
- if ((valueList[i] or 0) == 1) or ((valueList[i] or 0) == 2) or ((valueList[i] or 0) == 3) then
- local needGodCardCount = 4 - valueList[i]
- if godCardCount >= needGodCardCount then
- for _, v in ipairs(valueCard[i]) do
- table.insert(tpReplace, v)
- end
- for j = 1, needGodCardCount do
- table.insert(tpReplace, godCards[j])
- end
-
- table.insert(result, tpReplace)
- end
- end
- end
- end
- end
-
- return result
- end
-
- -- 获得4带2对提示
- --[[
- tips:会先判断手牌中2张是否大于等于2个数量,只弹4张
- 无癞子(正常流程)情况下,这里有bug,因为只会从对子中判断,不会冲超过2张中判断。不过没什么事,因为是只贪4张,所以炸弹也会算进去
- 有癞子情况下则不会
- ]]
- function PokerUtil:getSiDaiErDuiTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local nowCardsLen = table.nums(cards)
- local lastCardsLen = table.nums(lastData)
- local reValueList = self:reParseCard(cards)
- local godCardCount = #godCards
- local tResult = {} -- 已添加过的3张数据(用于癞子中,不会重复添加到)
- local result = {}
-
- -- 正常流程
- if table.nums(reValueList[2]) >= 2 then
- for i = lastCardInfo.min + 1, 13 do
- local tpReplace = {}
- if (valueList[i] or 0) >= 4 and nowCardsLen > 4 then
- for j = 1, 4 do
- table.insert(tpReplace, valueCard[i][j])
- end
- table.insert(result, tpReplace)
- tResult[i] = true
- end
- end
- end
-
- -- 癞子流程
- if self:isUseGodCard() and godCardCount > 0 then
- for i = lastCardInfo.min + 1, 13 do
- local needGodCardCount = 0
- local vCount = valueList[i] or 0
- if vCount <= 4 then
- needGodCardCount = needGodCardCount + (4 - vCount)
- end
-
- local temp = self:removeGodCards(clone(cards))
- local xorData = self:xorTableData(temp, {i}) -- 排除当前牌i的剩余牌(2张,3张,4张中)
- local t = self:reParseCard(xorData)
- local canBeDuiZiCount = #t[2] + #t[3] + #t[4] * 2 -- 可组成对子个数(4个可以组成2个对子)
-
- -- 带对子,如果2张,3张,4张所组成的对子个数总和少于1个
- if canBeDuiZiCount <= 1 then
- local totalNeedCount = 2 - canBeDuiZiCount
- local needCount = 0
- for j = 1, totalNeedCount do
- if #t[1] - j >= 0 then -- 1个的数量够
- needCount = needCount + 1
- else
- needCount = needCount + 2
- end
- end
- needGodCardCount = needGodCardCount + needCount
- end
-
- if godCardCount >= needGodCardCount then
- if vCount ~= 0 or self:isUseAllSameGodCard() then
- if not tResult[i] then -- 如果之前没有添加过
- local tpReplace = {}
- for j = 1, vCount do
- table.insert(tpReplace, valueCard[i][j])
- end
-
- for j = 1, (4 - vCount) do
- table.insert(tpReplace, godCards[j])
- end
- table.insert(result, tpReplace)
- tResult[i] = true
- end
- end
- end
- end
- end
-
- return result
- end
-
- -- 获得炸弹提示
- --[[
- 无癞子情况下,从4张中查找
- 有癞子情况下,从1,2,3张中查找(以大到小排序,不按所需癞子个数),往最后添加
- ]]
- function PokerUtil:getBombTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local lastCardInfo = self:getCardsType(lastData)
- local godCardCount = #godCards
- local result = {}
-
- local tpIndex = lastCardInfo.cardType < defs.CARD_TYPE.BOMB and 1 or lastCardInfo.min + 1
- for i = tpIndex, 13 do
- local tpReplace = {}
- if (valueList[i] or 0) >= 4 then
- for j = 1, 4 do
- table.insert(tpReplace, valueCard[i][j])
- end
- table.insert(result, tpReplace)
- end
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- for i = tpIndex, 13 do
- local tpReplace = {}
- valueList[i] = valueList[i] or 0
- if valueList[i] < 4 then
- local needGodCardCount = 4 - valueList[i]
- if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
- if godCardCount >= needGodCardCount then
- for _, v in ipairs(valueCard[i]) do
- table.insert(tpReplace, v)
- end
- for j = 1, needGodCardCount do
- table.insert(tpReplace, godCards[j])
- end
- table.insert(result, tpReplace)
- end
- end
- end
- end
- end
-
- return result
- end
-
- -- 获得王炸提示
- --[[
- 有癞子下,往后插入
- 两张癞子不算王炸
- ]]
- function PokerUtil:getBombKingTip(cards, lastData)
- local valueList, valueCard, godCards = self:parseCard(cards)
- local godCardCount = #godCards
- local result = {}
-
- if (valueList[Value_Joker_Little] or 0) > 0 and (valueList[Value_Joker_Big] or 0) > 0 then
- local tpReplace = {}
- table.insert(tpReplace, 0x4e)
- table.insert(tpReplace, 0x4f)
- table.insert(result, tpReplace)
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- if (valueList[Value_Joker_Little] or 0) > 0 then
- local tpReplace = {}
- table.insert(tpReplace, 0x4e)
- table.insert(tpReplace, godCards[1])
- table.insert(result, tpReplace)
- end
-
- if (valueList[Value_Joker_Big] or 0) > 0 then
- local tpReplace = {}
- table.insert(tpReplace, 0x4f)
- table.insert(tpReplace, godCards[1])
- table.insert(result, tpReplace)
- end
-
- if self:isUseAllSameGodCard() and godCardCount > 1 then
- local tpReplace = {}
- table.insert(tpReplace, godCards[1])
- table.insert(tpReplace, godCards[2])
- table.insert(result, tpReplace)
- end
- end
-
- return result
- end
-
- -----------------------------------------------------------------------------------------------------------------
- -------------------------------------- 以下是检查牌型 ------------------------------------------------------
- -----------------------------------------------------------------------------------------------------------------
- --[[
- cards 是具体牌值,即1~K,从小到大排序
- ]]
-
- -- 是否是单张
- function PokerUtil:isSingle(cards, godCards)
- if #cards > 0 then
- return true, defs.CARD_TYPE.SINGLE, cards[1]
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- local godCardSingleValue = (self.God_Card_Single_Value and self.God_Card_Single_Value > 0) and self.God_Card_Single_Value or godCards[1]
- return true, defs.CARD_TYPE.SINGLE, self.God_Card_Single_Value or godCardSingleValue, true
- end
-
- return false
- end
-
- -- 是否是对子
- function PokerUtil:isDouble(cards, godCards)
- if cards[1] and cards[2] then
- if cards[1] == cards[2] then
- return true, defs.CARD_TYPE.DUIZI,cards[1]
- end
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- if self:checkIsTheSameCards(cards) then
- return true, defs.CARD_TYPE.DUIZI, cards[1], true
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.DUIZI, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 是否是三张(不带)
- function PokerUtil:isThree(cards, godCards)
- if cards[1] and cards[2] and cards[3] then
- if cards[1] == cards[2] and cards[2] == cards[3] then
- return true, defs.CARD_TYPE.SANZHANG, cards[1]
- end
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- if self:checkIsTheSameCards(cards) then
- return true, defs.CARD_TYPE.SANZHANG, cards[1], true
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.SANZHANG, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 是否是顺子
- function PokerUtil:isLine(cards, godCards)
- local isHaveKindOr2 = false
- for i, val in ipairs(cards) do
- if val == Value_Joker_Little or val == Value_Joker_Big or val == Value_2 then
- isHaveKindOr2 = true
- break
- end
- end
-
- -- 顺子中不允许包括2,大王,小王
- if isHaveKindOr2 then
- return false
- end
-
- -- 检查单张总长度是否与传入相同,因为顺子是必须都是单个值
- local reValueList = self:reParseCard(cards)
- if table.nums(reValueList[1]) ~= #(cards) then
- return false
- end
-
- -- 判断是否为顺子,计算最大值与最小值的差的绝对值是否与总长度-1相同
- local m = (#cards > 0) and (math.abs(cards[1] - cards[#cards])) or 0
- local godCardCount = #godCards
- if m == #cards - 1 and godCardCount == 0 then
- return true, defs.CARD_TYPE.SHUNZI, cards[1]
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- local needGodCardCount = m + 1 - #cards
-
- print('jxjx 是否是顺子判断')
- print('jxjx 是否是顺子判断 godCardCount万能牌数', godCardCount)
- print('jxjx 是否是顺子判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
-
- if #cards > 0 then
- -- 判断空缺位是否少于万能牌数即可。m为最大差值,m+1-#cards(needGodCardCount)即为cards的空缺数字个数。倘若为0,则说明cards是个连续数值,那么万能牌在后面添加即可
- if godCardCount >= needGodCardCount then -- 有万能牌支撑
- return true, defs.CARD_TYPE.SHUNZI, cards[1], true
- end
- else
- -- 全是万能牌
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.SHUNZI, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 是否是双顺(连对)
- function PokerUtil:isDoubleLine(cards, godCards)
- local isHaveKindOr2 = false
- for i, val in ipairs(cards) do
- if val == Value_Joker_Little or val == Value_Joker_Big or val == Value_2 then
- isHaveKindOr2 = true
- break
- end
- end
-
- -- 顺子中不允许包括2,大王,小王
- if isHaveKindOr2 then
- return false
- end
-
- -- 连对里面不能有超过2张的牌组
- local reValueList = self:reParseCard(cards)
- if #reValueList[3] > 0 or #reValueList[4] > 0 then
- return false
- end
-
- -- 检查2张的个数是否与总长度的一半相同,因为连对是必须都是对子值
- local godCardCount = #godCards
- if godCardCount == 0 then -- 这里需要加万能牌数量判断,因为下面的判断条件只针对没有万能牌,不然3345带万能牌这样会直接false
- if table.nums(reValueList[2]) ~= math.floor(#(cards) / 2) then
- return false
- end
- end
-
- -- 判断是否为对子,计算最大值与最小值的差的绝对值是否与总长度/2-1相同
- local m = (#cards > 0) and (math.abs(cards[1] - cards[#cards])) or 0
- if m == #cards/2 - 1 and godCardCount == 0 then
- return true, defs.CARD_TYPE.SHUANGSHUN, cards[1]
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- local needGodCardCount = (m + 1)*2 - #cards
-
- print('jxjx 是否是连对判断')
- print('jxjx 是否是连对判断 godCardCount万能牌数', godCardCount)
- print('jxjx 是否是连对判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
-
- if #cards > 0 then
- -- 判断空缺位是否少于万能牌数即可。m为最大差值,m+1-#cards(needGodCardCount)即为cards的空缺数字个数。倘若为0,则说明cards是个连续数值,那么万能牌在后面添加即可
- if godCardCount >= needGodCardCount then -- 有万能牌支撑
- return true, defs.CARD_TYPE.SHUANGSHUN, cards[1], true
- end
- else
- -- 全是万能牌
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.SHUANGSHUN, godCards[1], true
- end
- end
- end
- return false
- end
-
- -- 是否是三带一(单张)
- function PokerUtil:isThreeTakeOne(cards, godCards)
- print('jxjx 判断是否是三带一 isThreeTakeOne')
-
- if not self:can31() then
- return false
- end
-
- -- 1张,2张,3张的数量的总和最多数量不能超过2个
- local reValueList = self:reParseCard(cards)
- local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3])
- if count > 2 then
- return false
- end
-
- -- 2张的数量不能超过1个(3带单,4带单独有判断)
- if table.nums(reValueList[2]) > 1 then
- return false
- end
-
- if table.nums(reValueList[3]) == 1 then
- return true, defs.CARD_TYPE.SANDAIYI, reValueList[3][1]
- elseif table.nums(reValueList[4]) == 1 then -- 该文件兼容所有牌型,所以4张一样也可以是3带1,所以牌型判断的先后顺序要插入正确
- return true, defs.CARD_TYPE.SANDAIYI, reValueList[4][1]
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- local needGodCardCount = 4 - #cards
- print('jxjx 是否是三带一判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
- if godCardCount >= needGodCardCount then
- if needGodCardCount == 3 then
- return true, defs.CARD_TYPE.SANDAIYI, cards[1], true
- else
- if table.nums(reValueList[3]) > 0 then
- return true, defs.CARD_TYPE.SANDAIYI, reValueList[3][1], true
- elseif table.nums(reValueList[2]) > 0 then
- return true, defs.CARD_TYPE.SANDAIYI, reValueList[2][1], true
- else
- -- 这里因为不会有1对的数据进来,所以不加判断或者连接表了(与下面的3带2判断相似又非似)
- local temp = clone(reValueList[1])
- table.sort(temp, PokerUtil.sortOrder)
-
- return true, defs.CARD_TYPE.SANDAIYI, temp[#temp], true
- end
- end
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.SANDAIYI, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 是否是三带二(对子)
- function PokerUtil:isThreeTakeTwo(cards, godCards)
- if not self:can32() then
- return false
- end
-
- -- 1张,2张,3张的数量的总和最多数量不能超过2个
- local reValueList = self:reParseCard(cards)
- local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3])
- if count > 2 then
- return false
- end
-
- -- 3带1对里面不能有4张(如果有4张,剩余带的牌一定是单张不是对子)
- if table.nums(reValueList[4]) > 0 then
- return false
- end
-
- if table.nums(reValueList[3]) == 1 and table.nums(reValueList[2]) == 1 then
- return true, defs.CARD_TYPE.SANDAIDUI, reValueList[3][1]
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- local needGodCardCount = 5 - #cards
- print('jxjx 是否是三带二判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
- if godCardCount >= needGodCardCount then
- if needGodCardCount == 4 then
- return true, defs.CARD_TYPE.SANDAIDUI, cards[1], true
- else
- if table.nums(reValueList[3]) > 0 then
- return true, defs.CARD_TYPE.SANDAIDUI, reValueList[3][1], true
- else
- -- 如果是2手牌与3万能牌(2+3)或者3手牌与2张万能牌(3+2)或者4手牌与1张万能牌(4+1)组合,则判断手牌中最大的,作为3带
- local t1 = clone(reValueList[1])
- local t2 = clone(reValueList[2])
- local temp = self:addTableData(t1, t2)
- table.sort(temp, PokerUtil.sortOrder)
-
- return true, defs.CARD_TYPE.SANDAIDUI, temp[#temp], true
- end
- end
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.SANDAIDUI, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 是否是四带一(单)
- function PokerUtil:isFourTakeOneSingle(cards, godCards)
- if not self:can41() then
- return false
- end
-
- -- 1张,2张,3张,4张的数量的总和最多数量不能超过2个
- local reValueList = self:reParseCard(cards)
- local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3]) + table.nums(reValueList[4])
- if count > 2 then
- return false
- end
-
- -- 2张的数量不能超过1个(3带单,4带单独有判断)
- if table.nums(reValueList[2]) > 1 then
- return false
- end
-
- if table.nums(reValueList[4]) == 1 then
- return true, defs.CARD_TYPE.SIDAIYI, reValueList[4][1]
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- local needGodCardCount = 5 - #cards
- print('jxjx 是否是四带一判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
- if godCardCount >= needGodCardCount then
- if needGodCardCount == 4 then
- return true, defs.CARD_TYPE.SIDAIYI, cards[1], true
- else
- if table.nums(reValueList[4]) > 0 then
- return true, defs.CARD_TYPE.SIDAIYI, reValueList[4][1], true
- elseif table.nums(reValueList[3]) > 0 then
- return true, defs.CARD_TYPE.SIDAIYI, reValueList[3][1], true
- elseif table.nums(reValueList[2]) > 0 then
- return true, defs.CARD_TYPE.SIDAIYI, reValueList[2][1], true
- else
- local temp = clone(reValueList[1])
- table.sort(temp, PokerUtil.sortOrder)
-
- return true, defs.CARD_TYPE.SIDAIYI, temp[#temp], true
- end
- end
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.SIDAIYI, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 是否是四带一对(对子)
- function PokerUtil:isFourTakeOneDouble(cards, godCards)
- if not self:can42() then
- return false
- end
- -- 1张,2张,3张,4张的数量的总和最多数量不能超过2个
- local reValueList = self:reParseCard(cards)
- local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3]) + table.nums(reValueList[4])
- if count > 2 then
- return false
- end
-
- if table.nums(reValueList[4]) == 1 and table.nums(reValueList[2]) == 1 then
- return true, defs.CARD_TYPE.SIDAIYIDUI, reValueList[4][1]
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- local needGodCardCount = 6 - #cards
- print('jxjx 是否是四带一对判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
- if godCardCount >= needGodCardCount then
- if needGodCardCount == 5 then
- return true, defs.CARD_TYPE.SIDAIYIDUI, cards[1], true
- else
- if table.nums(reValueList[4]) > 0 then
- return true, defs.CARD_TYPE.SIDAIYIDUI, reValueList[4][1], true
- elseif table.nums(reValueList[3]) > 0 then
- return true, defs.CARD_TYPE.SIDAIYIDUI, reValueList[3][1], true
- else
- local t1 = clone(reValueList[1])
- local t2 = clone(reValueList[2])
- local temp = self:addTableData(t1, t2)
- table.sort(temp, PokerUtil.sortOrder)
-
- return true, defs.CARD_TYPE.SIDAIYIDUI, temp[#temp], true
- end
- end
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.SIDAIYIDUI, godCards[1], true
- end
- end
- end
- return false
- end
-
- -- 是否是四带二单张
- function PokerUtil:isFourTakeTwoSingle(cards, godCards)
- if not self:can411() then
- return false
- end
-
- if not self:checkIsCanCombination(cards, godCards, 4) then
- return false
- end
-
- -- 1张,2张,3张,4张的数量的总和最多数量不能超过3个
- local reValueList = self:reParseCard(cards)
- local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3]) + table.nums(reValueList[4])
- if count > 3 then
- return false
- end
-
- -- 2张的数量不能超过2个
- if table.nums(reValueList[2]) > 2 then
- return false
- end
-
- if table.nums(reValueList[4]) == 1 then
- return true, defs.CARD_TYPE.SIDAIER, reValueList[4][1]
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- local needGodCardCount = 6 - #cards
- print('jxjx 是否是四带二单张判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
- if godCardCount >= needGodCardCount then
-
- if needGodCardCount == 5 then
- return true, defs.CARD_TYPE.SIDAIER, cards[1], true
- elseif needGodCardCount == 2 then -- 针对1223**这种
- if table.nums(reValueList[3]) > 0 then
- return true, defs.CARD_TYPE.SIDAIER, reValueList[3][1], true
- elseif table.nums(reValueList[2]) > 0 then
- local temp = clone(reValueList[2])
- table.sort(temp, PokerUtil.sortOrder)
- return true, defs.CARD_TYPE.SIDAIER, temp[#temp], true
- end
- else
- if table.nums(reValueList[4]) > 0 then
- return true, defs.CARD_TYPE.SIDAIER, reValueList[4][1], true
- elseif table.nums(reValueList[3]) > 0 then
- return true, defs.CARD_TYPE.SIDAIER, reValueList[3][1], true
- else
- local t1 = clone(reValueList[1])
- local t2 = clone(reValueList[2])
- local temp = self:addTableData(t1, t2)
- table.sort(temp, PokerUtil.sortOrder)
-
- return true, defs.CARD_TYPE.SIDAIER, temp[#temp], true
- end
- end
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.SIDAIER, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 是否是四带二对子
- function PokerUtil:isFourTakeTwoDouble(cards, godCards)
- if not self:can422() then
- return false
- end
-
- if not self:checkIsCanCombination(cards, godCards, 4) then
- return false
- end
-
- -- 1张,2张,3张,4张的数量的总和最多数量不能超过3个
- local reValueList = self:reParseCard(cards)
- local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3]) + table.nums(reValueList[4])
- if count > 3 then
- return false
- end
-
- -- 3张的数量不能超过1个
- if table.nums(reValueList[3]) > 1 then
- return false
- end
-
- if table.nums(reValueList[4]) == 1 and table.nums(reValueList[2]) == 2 then
- return true, defs.CARD_TYPE.SIDAIERDUI, reValueList[4][1]
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- local needGodCardCount = 8 - #cards
- print('jxjx 是否是四带二对子判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
- if godCardCount >= needGodCardCount then
- if needGodCardCount == 7 then
- return true, defs.CARD_TYPE.SIDAIERDUI, cards[1], true
- else
- if table.nums(reValueList[4]) > 0 then
- return true, defs.CARD_TYPE.SIDAIERDUI, reValueList[4][1], true
- elseif table.nums(reValueList[3]) > 0 then
- return true, defs.CARD_TYPE.SIDAIERDUI, reValueList[3][1], true
- else
- local t1 = clone(reValueList[1])
- local t2 = clone(reValueList[2])
- local temp = self:addTableData(t1, t2)
- table.sort(temp, PokerUtil.sortOrder)
-
- return true, defs.CARD_TYPE.SIDAIERDUI, temp[#temp], true
- end
- end
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.SIDAIERDUI, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 是否是三顺(飞机不带333444)
- function PokerUtil:isPlaneNoTake(cards, godCards)
- local isHaveKindOr2 = false
- for i, val in ipairs(cards) do
- if val == Value_Joker_Little or val == Value_Joker_Big or val == Value_2 then
- isHaveKindOr2 = true
- break
- end
- end
-
- -- 三顺中不允许包括2,大王,小王
- if isHaveKindOr2 then
- return false
- end
-
- -- 三顺里面不能有超过3张的牌组
- local reValueList = self:reParseCard(cards)
- if table.nums(reValueList[4]) > 0 then
- return false
- end
-
- -- 检查3张的个数是否与总长度的/3相同,因为三顺是必须都是三个个值
- local godCardCount = #godCards
- if godCardCount == 0 then
- if table.nums(reValueList[3]) ~= #(cards) / 3 then
- return false
- end
- end
-
-
- -- 判断是否为三顺,计算最大值与最小值的差的绝对值是否与总长度/3-1相同
- local m = (#cards > 0) and (math.abs(cards[1] - cards[#cards])) or 0
- if m == #cards/3 - 1 then
- return true, defs.CARD_TYPE.SANSHUN, cards[1]
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- local needGodCardCount = (m + 1)*3 - #cards
-
- print('jxjx 是否是连对判断')
- print('jxjx 是否是连对判断 godCardCount万能牌数', godCardCount)
- print('jxjx 是否是连对判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
-
- if #cards > 0 then
- if godCardCount >= needGodCardCount then -- 有万能牌支撑
- return true, defs.CARD_TYPE.SANSHUN, cards[1], true
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.SANSHUN, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 是否是飞机带单
- function PokerUtil:isPlaneTakeSingle(cards, godCards)
- -- if not self:can31() then
- -- return false
- -- end
-
- local reValueList = self:reParseCard(cards)
- local t3 = clone(reValueList[3])
- local t4 = clone(reValueList[4])
- for i = #t3, 1, -1 do -- 移除三张中带2的值
- if t3[i] == Value_2 then
- table.remove(t3, i)
- end
- end
-
- for i = #t4, 1, -1 do -- 移除四张中带2的值
- if t4[i] == Value_2 then
- table.remove(t4, i)
- end
- end
-
- local tpLianMin = self:tpLianInNormal(t3, t4, #cards/4)
- if tpLianMin then
- return true, defs.CARD_TYPE.AIRPLANE_SINGLE, tpLianMin.min
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- local totalCardCount = #cards + #godCards
- if #cards > 0 then
- local temp = clone(cards)
- local tpLian = self:tpLianInGodcard(temp, totalCardCount/4)
- if tpLian then
- dump(tpLian,'jxjx 飞机带单总数据是')
- local valueList = self:parseCard(cards)
- local plane = {}
- for i, v in ipairs(tpLian) do
- dump(v,'jxjx 当前判断飞机带单数据是===========>>>')
- local notBePlaneTag = false -- 不能成为飞机牌标记,飞机牌包含2,小王,大王
- local needGodCardCount = 0
- for i = 1, v.feiLen do
- local cCard = v.min + i - 1
- local count = 0
-
- if cCard == Value_2 or cCard == Value_Joker_Little or cCard == Value_Joker_Big then
- notBePlaneTag = true
- print(string.format('jxjx 飞机带单中,飞机牌包含%d, 跳出判断', cCard))
- break
- end
-
- if not valueList[cCard] then
- count = 3
- else
- count = (3 - valueList[cCard]) > 0 and (3 - valueList[cCard]) or 0
- end
-
- print(string.format('jxjx 飞机带单,飞机牌数量判断,当前飞机牌是%d, 数量是%d, 需要补充%d张万能牌', cCard, valueList[cCard] or 0, count))
- needGodCardCount = needGodCardCount + count
- end
-
- if not notBePlaneTag then
- print('jxjx 飞机带单判断needGodCardCount', needGodCardCount)
- print('jxjx 飞机带单判断godCardCount', godCardCount)
- if godCardCount >= needGodCardCount then
- table.insert(plane, v)
- end
- end
- end
-
- if #plane > 0 then
- table.sort(plane, function(a, b)
- return a.min < b.min
- end)
- return true, defs.CARD_TYPE.AIRPLANE_SINGLE, plane[#plane].min, true
- end
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.AIRPLANE_SINGLE, godCards[1], true
- end
- end
- end
- return false
- end
-
- -- 是否是飞机带对子
- function PokerUtil:isPlanetakeDouble(cards, godCards)
- -- if not self:can32() then
- -- return false
- -- end
-
- local reValueList = self:reParseCard(cards)
- local t2 = clone(reValueList[2])
- local t3 = clone(reValueList[3])
- local t4 = clone(reValueList[4])
-
- for i = #t3, 1, -1 do -- 移除三张中带2的值
- if t3[i] == Value_2 then
- table.remove(t3, i)
- end
- end
-
- for i = #t4, 1, -1 do -- 移除四张中带2的值
- if t4[i] == Value_2 then
- table.remove(t4, i)
- end
- end
-
- local tpLianMin = self:tpLianInNormal(t3, t4, #cards/5)
- local godCardCount = #godCards
- if tpLianMin and godCardCount == 0 then
- -- 判断除飞机长度外,组成对子的是否能超过飞机的个数
- local canBeDuiZiCount = #t2 + #t3 + #t4 * 2 -- 炸弹算2个对子,所以t4要*2
- print(string.format('%d可组成对子,飞机长度是%d', canBeDuiZiCount, tpLianMin.feiLen))
- local isMoreThan_2DuiZi = (canBeDuiZiCount - tpLianMin.feiLen) >= tpLianMin.feiLen
- if not isMoreThan_2DuiZi then
- return false
- end
-
- return true, defs.CARD_TYPE.AIRPLANE_DUAD, tpLianMin.min
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- local totalCardCount = #cards + #godCards
- if #cards > 0 then
- local temp = clone(cards)
- local tpLian = self:tpLianInGodcard(temp, totalCardCount/5)
- if tpLian then
- dump(tpLian,'jxjx 飞机带对子总数据是')
- local valueList = self:parseCard(cards)
- local plane = {}
- local temp = {}
- local t = {} -- 所有非万能牌的手牌,整合一起,转换为具体值,不按数量
- for i, v in pairs(valueList) do
- if v > 0 then
- table.insert(t, i)
- end
- end
-
- local t1 = self:changeCardValue_Standard_To_Specific(t)
- for i, v in ipairs(tpLian) do
- dump(v,'jxjx 当前判断飞机带对子数据是===========>>>')
- local notBePlaneTag = false -- 不能成为飞机牌标记,飞机牌包含2,小王,大王
- local needGodCardCount = 0
- temp = {}
- for i = 1, v.feiLen do
- local cCard = v.min + i - 1
- local count = 0
-
- if cCard == Value_2 or cCard == Value_Joker_Little or cCard == Value_Joker_Big then
- notBePlaneTag = true
- print(string.format('jxjx 飞机带对子中,飞机牌包含%d, 跳出判断', cCard))
- break
- end
-
- if not valueList[cCard] then
- count = 3
- else
- count = math.abs(3 - valueList[cCard]) -- 这里用绝对值是因为,如果飞机牌是4张,则多出的1张牌可以与万能牌组成对子当带牌使用
- end
-
- needGodCardCount = needGodCardCount + count
- print(string.format('jxjx 飞机带对子,飞机牌数量判断,当前飞机牌是%d, 数量是%d, 需要补充%d张万能牌', cCard, valueList[cCard] or 0, count))
- table.insert(temp, cCard)
- end
-
- if not notBePlaneTag then
- dump(temp, 'jxjx 飞机带对子,当前飞机牌是')
- -- 判断对子(判断非飞机头的牌,如果不是2张的牌,则需要补1张万能牌)
- local xorData = self:xorTableData(t1, temp)
- dump(xorData, '带牌数据有xorData,这里只算非飞机牌的,如果飞机牌是4张,则上面判断飞机牌数量已经有做处理!!!!')
- for i, v in ipairs(xorData) do
- local count = 0
- if valueList[v] % 2 ~= 0 then
- count = 1
- end
- needGodCardCount = needGodCardCount + count
- print(string.format('jxjx 飞机带对子,带牌数量判断,当前带牌具体值是%d, 数量是%d, 需要补充%d张万能牌', v, valueList[v], count))
- end
-
- print('jxjx 飞机带对子判断needGodCardCount', needGodCardCount)
- print('jxjx 飞机带对子判断godCardCount', godCardCount)
- if godCardCount >= needGodCardCount then
- table.insert(plane, v)
- end
- end
- end
-
- if #plane > 0 then
- table.sort(plane, function(a, b)
- return a.min < b.min
- end)
- return true, defs.CARD_TYPE.AIRPLANE_DUAD, plane[#plane].min, true
- end
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.AIRPLANE_DUAD, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 飞机的判断
- -- tip:主要是根据3张,4张中,通过while循环获取与传入的飞机长度feiLen相同长度的值
- function PokerUtil:tpLianInNormal(la3, la4, feiLen)
- local feiLen = feiLen or 0
- local lc = {}
- for _,v in ipairs(la3) do
- table.insert(lc, v)
- end
-
- for _,v in ipairs(la4) do
- table.insert(lc, v)
- end
-
- if table.nums(lc) <= 0 then
- return nil
- end
-
- table.sort(lc, function (a, b)
- return a < b
- end)
-
- local lenEx = 1
- local feiji = {}
- local lcLen = table.nums(lc)
- for k,v in ipairs(lc) do
- lenEx = 1
- local j = k + 1
- while j <= lcLen and (feiLen == 0 or lenEx < feiLen) do
- if lc[j] ~= lc[j-1] + 1 then -- 判断是否是连续的
- break
- end
- j = j + 1
- lenEx = lenEx + 1
- end
- if lenEx == feiLen then
- table.insert(feiji, {
- feiLen = lenEx,
- min = lc[k],
- })
- end
- end
-
- if table.nums(feiji) > 0 then
- table.sort(feiji, function (a, b)
- return b.feiLen ~= a.feiLen and b.feiLen - a.feiLen or b.min - a.min
- end)
- return feiji[1]
- else
- return nil
- end
- end
-
- -- 飞机的判断,返回可组成顺子的表
- -- tip 只用于万能牌
- function PokerUtil:tpLianInGodcard(cards, feiLen)
- local t = self:reParseCard(cards)
- local temp = {}
- for i, v in ipairs(t) do
- for _, val in ipairs(v) do
- table.insert(temp, val)
- end
- end
- table.sort(temp, PokerUtil.sortOrder)
-
- local feiLen = feiLen or 0
- local lc = clone(temp)
- local lenEx = 1
- local feiji = {}
- local lcLen = table.nums(lc)
- for k,v in ipairs(lc) do
- lenEx = 1
- local j = k + 1
- while j <= lcLen and (feiLen == 0 or lenEx < feiLen) do
- if lc[j] ~= lc[j-1] + 1 then -- 判断是否是连续的
- break
- end
- j = j + 1
- lenEx = lenEx + 1
- end
- -- if lenEx == feiLen then -- 让333 *** ** 也进来,所以在外部判断是否满足3张即可,这里不做判断处理
- table.insert(feiji, {
- feiLen = feiLen,
- min = lc[k],
- })
- -- end
- end
-
- if table.nums(feiji) > 0 then
- return feiji
- else
- return nil
- end
- end
-
- -- 是否是炸弹
- function PokerUtil:isBomb(cards, godCards)
- local tag = self:checkIsTheSameCards(cards)
- local godCardCount = #godCards
-
- if not (#cards == 0) then
- if not tag then
- return false
- end
- end
-
- if #cards == 4 then
- return true, defs.CARD_TYPE.BOMB, cards[1]
- end
-
- if self:isUseGodCard() and godCardCount > 0 then
- local needGodCardCount = 4 - #cards
- if #cards > 0 then
- if godCardCount >= needGodCardCount then
- return true, defs.CARD_TYPE.BOMB, cards[1], true
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.BOMB, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -- 是否是王炸
- function PokerUtil:isKingBomb(cards, godCards)
- local temp = clone(cards)
- for i, v in ipairs(temp) do
- if v ~= Value_Joker_Little and v ~= Value_Joker_Big then
- return false
- end
- end
-
- if cards[1] == Value_Joker_Little and cards[2] == Value_Joker_Big then
- return true, defs.CARD_TYPE.BOMB_KING, cards[1]
- end
-
- local godCardCount = #godCards
- if self:isUseGodCard() and godCardCount > 0 then
- if #cards > 0 then
- local needGodCardCount = 2 - #cards
- if godCardCount >= needGodCardCount then
- return true, defs.CARD_TYPE.BOMB_KING, cards[1], true
- end
- else
- if self:isUseAllSameGodCard() then
- return true, defs.CARD_TYPE.BOMB_KING, godCards[1], true
- end
- end
- end
-
- return false
- end
-
- -----------------------------------------------------------------------------------------------------------------
- ---------------------------------------- 以下是配置 --------------------------------------------------------
- -----------------------------------------------------------------------------------------------------------------
-
- -- 配置
- PokerUtil.Card_Max_Length = 20 -- 手牌最多的个数
- PokerUtil.Less_Line = 5 -- 顺子最小长度
- PokerUtil.Max_Line = 12 -- 顺子最大长度(3~A)
- PokerUtil.Less_Lian_Dui = 6 -- 最小组成的连对长度
- PokerUtil.Less_Plane = 6 -- 最小组成的飞机长度
- PokerUtil.Card_Type_Map = {} -- 牌类型方法表
- PokerUtil.Card_Tip_Map = {} -- 牌提示方法表
- PokerUtil.Card_Tip_Check_Order_By_Desc = true -- 牌提示是否用倒序(查看initTypeMap方法)
-
- -- 癞子
- PokerUtil.Is_Use_God_Card = false -- 是否使用癞子牌,词穷,godCard = 癞子,神牌,万能牌
- PokerUtil.God_Card_Count_Max = 0 -- 癞子牌最大数量(待用,暂没使用)
- PokerUtil.God_Card_Value = 100 -- 癞子牌的标准值
- PokerUtil.God_Card_Single_Value = 1 -- 如果癞子牌以单牌形式出现,转换成该值(如果不想要这个,单牌的值就是癞子值,可以赋值为nil或者0)
- PokerUtil.God_Card_Is_Can_Be_All_Same = false -- 是否可以都是癞子牌(都是癞子牌。涉及部分牌提示和类型判断;若启用的话,类型判断内,min返回的是万能牌值,即使启用的话,getTip里面有部分提示是不包括判断全是手牌的,这个需注意或者待优化)
- PokerUtil.God_Card_ReplaceCard_Is_Use_God_Card_Value = true -- 是否使用癞子的值来取代替代牌(开启后,替代牌的值为0x5x的值,如果为false的话,则为0x0x的值(0x0x为方块值)。之后可以看着改为定好的值,并非0x5x jxtd)
-
- -- 获得癞子对应替代牌的方法 <- (这是替代方法),感觉之后可以把这个对应的方法直接放到牌型判断里面的返回值,就不需要配置了(jxtd)
- PokerUtil.God_Card_Replace_Card_Map = {
- [defs.CARD_TYPE.NULL] = nil,
- [defs.CARD_TYPE.SINGLE] = 'getGodCardSingleReplace',
- [defs.CARD_TYPE.DUIZI] = 'getGodCardDuiZiReplReplace',
- [defs.CARD_TYPE.SANZHANG] = 'getGodCardSanZhangReplace',
- [defs.CARD_TYPE.SHUNZI] = 'getGodCardShunZiReplace',
- [defs.CARD_TYPE.SHUANGSHUN] = 'getGodCardLianDuiReplace',
- [defs.CARD_TYPE.SANSHUN] = 'getGodCardSanShunReplace',
- [defs.CARD_TYPE.SANDAIYI] = 'getGodCardSanDaiYiReplace',
- [defs.CARD_TYPE.SANDAIDUI] = 'getGodCardSanDaiYiDuiReplace',
- [defs.CARD_TYPE.SIDAIYI] = nil,
- [defs.CARD_TYPE.SIDAIYIDUI] = nil,
- [defs.CARD_TYPE.SIDAIER] = 'getGodCardSiDaiErSingleReplace',
- [defs.CARD_TYPE.SIDAIERDUI] = 'getGodCardSiDaiErDuiReplace',
- [defs.CARD_TYPE.AIRPLANE_SINGLE] = 'getGodCardAirPlaneSingleReplace',
- [defs.CARD_TYPE.AIRPLANE_DUAD] = 'getGodCardAirPlaneDuiReplace',
- [defs.CARD_TYPE.BOMB] = 'getGodCardBombReplace',
- [defs.CARD_TYPE.BOMB_KING] = 'getGodCardBombKingReplace',
- }
-
- -- 牌型提示对应的方法(后面对应的是方法) <- (这是提示方法)
- PokerUtil.Card_Tip_Map = {
- [defs.CARD_TYPE.NULL] = nil,
- [defs.CARD_TYPE.SINGLE] = 'getSingleTip',
- [defs.CARD_TYPE.DUIZI] = 'getDuiZiTip',
- [defs.CARD_TYPE.SANZHANG] = 'getSanZhangTip',
- [defs.CARD_TYPE.SHUNZI] = 'getShunZiTip',
- [defs.CARD_TYPE.SHUANGSHUN] = 'getLianDuiTip',
- [defs.CARD_TYPE.SANSHUN] = 'getSanShunTip',
- [defs.CARD_TYPE.SANDAIYI] = 'getSanDaiYiTip',
- [defs.CARD_TYPE.SANDAIDUI] = 'getSanDaiYiDuiTip',
- [defs.CARD_TYPE.SIDAIYI] = nil,
- [defs.CARD_TYPE.SIDAIYIDUI] = nil,
- [defs.CARD_TYPE.SIDAIER] = 'getSiDaiErSingleTip',
- [defs.CARD_TYPE.SIDAIERDUI] = 'getSiDaiErDuiTip',
- [defs.CARD_TYPE.AIRPLANE_SINGLE] = 'getAirPlaneSingleTip',
- [defs.CARD_TYPE.AIRPLANE_DUAD] = 'getAirPlaneDuiTip',
- [defs.CARD_TYPE.BOMB] = 'getBombTip',
- [defs.CARD_TYPE.BOMB_KING] = 'getBombKingTip',
- }
-
- -- 初始化牌提示方法,不能用表驱动,因为子类重写时,调用的话,还是用的父类方法
- -- function PokerUtil:initTipMap()
- -- PokerUtil.Card_Tip_Map = {
- -- [defs.CARD_TYPE.NULL] = nil,
- -- [defs.CARD_TYPE.SINGLE] = self.getSingleTip,
- -- [defs.CARD_TYPE.DUIZI] = self.getDuiZiTip,
- -- [defs.CARD_TYPE.SANZHANG] = self.getSanZhangTip,
- -- [defs.CARD_TYPE.SHUNZI] = self.getShunZiTip,
- -- [defs.CARD_TYPE.SHUANGSHUN] = self.getLianDuiTip,
- -- [defs.CARD_TYPE.SANSHUN] = self.getSanShunTip,
- -- [defs.CARD_TYPE.SANDAIYI] = self.getSanDaiYiTip,
- -- [defs.CARD_TYPE.SANDAIDUI] = self.getSanDaiYiDuiTip,
- -- [defs.CARD_TYPE.SIDAIYI] = nil,
- -- [defs.CARD_TYPE.SIDAIYIDUI] = nil,
- -- [defs.CARD_TYPE.SIDAIER] = self.getSiDaiErSingleTip,
- -- [defs.CARD_TYPE.SIDAIERDUI] = self.getSiDaiErDuiTip,
- -- [defs.CARD_TYPE.AIRPLANE_SINGLE] = self.getAirPlaneSingleTip,
- -- [defs.CARD_TYPE.AIRPLANE_DUAD] = self.getAirPlaneDuiTip,
- -- [defs.CARD_TYPE.BOMB] = self.getBombTip,
- -- [defs.CARD_TYPE.BOMB_KING] = self.getBombKingTip,
- -- }
- -- end
-
- return PokerUtil
|