--[[牌 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, //方块 6 - KA2 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, //梅花 6 - KA2 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, //红桃 6 - KA2 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, //黑桃 6 - KA2 0x4B, 0x4C,//小王 大王 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, //方块 6 - KA2 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, //梅花 6 - KA2 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, //红桃 6 - KA2 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, //黑桃 6 - KA2 0x4B, 0x4C,//小王 大王 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, //方块 6 - KA2 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, //梅花 6 - KA2 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, //红桃 6 - KA2 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, //黑桃 6 - KA2 0x4B, 0x4C,//小王 大王 0x5D,0x5D,0x5D,0x5D,0x5D //五张癞子 ]] local GUI_VAL = 0x0d --鬼的牌值 local ER_VAL = 0x0a --2的牌值 local A_VAL = 0x09 --A的牌值 local X_KING = 0x0B --小王 local D_KING = 0x0C --大王 local zgwrDdzUtil1 = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzPokerUtil"):new({isChai=nil, isFAT=nil}) local DdzRoomViewConfig = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzRoomViewConfig") local ETS = DdzRoomViewConfig.EffectType local zgwrDdzUtil2 = {} --从点击的牌里面获取可以管上家牌的牌组合,没有则不提示 function zgwrDdzUtil2.getOneTip(selectCards,handCards,lastCards,lastType)--选中的牌,手牌,牌桌上最后出的牌,牌桌上最后出的牌的牌型 if #lastCards == 0 or lastType == 0 then--如果没有最后一手牌,自己第一个出 return selectCards end if not selectCards or type(selectCards) ~= 'table' then return nil end local selectCardsNum = #selectCards if selectCardsNum == 1 then--单点一张牌 local card = selectCards[1] local cval = zgwrDdzUtil1:getCardValue(card) if cval == GUI_VAL then return card end if cval == X_KING or cval == D_KING then--如果点的是王 local isHaveGuil,guiNuml = zgwrDdzUtil1:checkHaveGui2(lastCards) if lastType == ETS.SINGLE_CARD then return card elseif lastType < ETS.TWO_SMALL_KING then return zgwrDdzUtil2.getTwoKingBombByCard(card,handCards) elseif lastType == ETS.TWO_SMALL_KING then if cval == X_KING then return zgwrDdzUtil2.getTwoSKingBombByCard(card,handCards,false) or zgwrDdzUtil2.getSBKingBombByCard(card,handCards) or zgwrDdzUtil2.getFourKingBombByCard(card,handCards) elseif cval == D_KING then return zgwrDdzUtil2.getSBKingBombByCard(card,handCards) or zgwrDdzUtil2.getTwoBKingBombByCard(card,handCards,true) or zgwrDdzUtil2.getFourKingBombByCard(card,handCards) end elseif lastType == ETS.BIG_SMALL_KING then if cval == X_KING then return zgwrDdzUtil2.getFourKingBombByCard(card,handCards) elseif cval == D_KING then return zgwrDdzUtil2.getTwoBKingBombByCard(card,handCards,true) end elseif lastType == ETS.TWO_BIG_KING then return zgwrDdzUtil2.getTwoBKingBombByCard(card,handCards,false) or zgwrDdzUtil2.getFourKingBombByCard(card,handCards) elseif lastType < ETS.FOUR_SMALL_KING then return zgwrDdzUtil2.getFourKingBombByCard(card,handCards) elseif lastType >= ETS.FOUR_SMALL_KING and lastType <= ETS.FOUR_BIG_KING then local tresult = zgwrDdzUtil2.getMaxFourKingBombByCard(card,handCards) if tresult then local tipType = zgwrDdzUtil1:checkType(tresult) if tipType > lastType then return tresult elseif tipType == lastType then local isHaveGui,guiNum = zgwrDdzUtil1:checkHaveGui2(tresult) if guiNum < guiNuml then return tresult else return card end else return card end end end end if lastType == ETS.SINGLE_CARD then local lval = zgwrDdzUtil1:getCardValue(lastCards[1]) if cval > lval then return cval else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif lastType == ETS.DUI_ZI then local lval = zgwrDdzUtil1:getCardsMin(lastCards,ETS.DUI_ZI) if cval > lval then return zgwrDdzUtil2.getDuiTpsByCard(card,handCards) else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif lastType == ETS.THREE then local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType) if cval > lval then return zgwrDdzUtil2.getThreeTpsByCard(card,handCards) else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif lastType == ETS.SHUN_ZI then--顺子 local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType) if cval > lval then --[[if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 3 then return card else--]] return zgwrDdzUtil2.getShunZiTpsByCard(card,handCards,#lastCards,lval) --end else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif lastType == ETS.LIAN_DUI then--连对 local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType) if cval > lval then if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 4 then return card else return zgwrDdzUtil2.getLianDuiTpsByCard(card,handCards,#lastCards,lval) end else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif lastType == ETS.SAN_SHUN then--三顺 local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType) if cval > lval then if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 4 then return card else return zgwrDdzUtil2.getSanShunTpsByCard(card,handCards,#lastCards,lval) end else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif lastType == ETS.THREE_AND_ONE then--三带一 local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType) if cval > lval then if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 3 then return zgwrDdzUtil2.getSanDaiYiTpsByCard(card,handCards) elseif zgwrDdzUtil2.getCardNumByCard(card,handCards) == 2 and zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) > 0 then--癞子牌大于1 return zgwrDdzUtil2.getSanDaiYiTpsByCard(card,handCards) else local three = zgwrDdzUtil2.getMinThree(handCards,lval,true) if three then table.insert(three,card) return three else return card end end else if zgwrDdzUtil2.getCardNumByCard(card,handCards) == 1 then--点击的是单张 local three = zgwrDdzUtil2.getMinThree(handCards,lval,true) if three then table.insert(three,card) return three else return card end elseif zgwrDdzUtil2.getCardNumByCard(card,handCards) == 2 and zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) < 2 then local three = zgwrDdzUtil2.getMinThree(handCards,lval,true) if three then table.insert(three,card) return three else return card end else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end end elseif lastType == ETS.THREE_AND_DUI then--三带一对 local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType) if cval > lval then if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 3 then return zgwrDdzUtil2.getSanDaiDuiTpsByCard(card,handCards) elseif zgwrDdzUtil2.getCardNumByCard(card,handCards) == 2 and zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) > 0 then--癞子牌大于1 return zgwrDdzUtil2.getSanDaiDuiTpsByCard(card,handCards) else if zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) == 1 then local three = zgwrDdzUtil2.getMinThree(handCards,lval,true) if three then table.insert(three,card) table.insert(three,0x5D) return three else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) > 1 then return zgwrDdzUtil2.getSanDaiDuiTpsByCard(card,handCards) else return card end end else if zgwrDdzUtil2.getCardNumByCard(card,handCards) == 1 then--点击的是单张 if zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) == 0 then return card elseif zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) == 1 then local three = zgwrDdzUtil2.getMinThree(handCards,lval,true) if three then table.insert(three,card) table.insert(three,0x5D) return three else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif zgwrDdzUtil2.getCardNumByCard(card,handCards) == 2 then local three = zgwrDdzUtil2.getMinThree(handCards,lval,true) if three then table.insert(three,card) table.insert(three,card) return three else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif zgwrDdzUtil2.getCardNumByCard(card,handCards) == 3 then if zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) > 0 then return zgwrDdzUtil2.getFourBombByCard(card,handCards) else local three = zgwrDdzUtil2.getMinThree(handCards,lval,true) if three then table.insert(three,card) table.insert(three,card) return three else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end end else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end end elseif lastType == ETS.AIRPLANE_SINGLE then--飞机(带单张) local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType) if cval > lval then if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 4 then return card else local needNum = #lastCards - #lastCards/4 local sanShun = zgwrDdzUtil2.getSanShunTpsByCard(card,handCards,needNum,lval) if type(sanShun) == 'table' then local needSigleNums = #lastCards/4 local minLimit = nil for i=1,needSigleNums do local card = zgwrDdzUtil2.getMinSigle(handCards,minLimit) if card then minLimit = zgwrDdzUtil1:getCardValue(card) table.insert(sanShun,card) end end return sanShun else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end end else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif lastType == ETS.AIRPLANE_DUI then--飞机带对 local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType) if cval > lval then if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 4 then return card else local needNum = #lastCards - (#lastCards*2/5) local sanShun = zgwrDdzUtil2.getSanShunTpsByCard(card,handCards,needNum,lval) if type(sanShun) == 'table' then local needDuiNums = #lastCards/5 local minLimit = nil for i=1,needDuiNums do local tcard = zgwrDdzUtil2.getMinDuiZi(handCards,minLimit) if tcard then minLimit = zgwrDdzUtil1:getCardValue(tcard[1]) for i,v in pairs(tcard) do table.insert(sanShun,v) end end end return sanShun else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end end else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end elseif lastType == ETS.BOMB_FOUR then--炸弹4张 local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType) if cval > lval then return zgwrDdzUtil2.getFourBombByCard(card,handCards) else return zgwrDdzUtil2.getEightBombByCard(card,handCards) end elseif lastType >= ETS.TWO_SMALL_KING and lastType <= ETS.TWO_BIG_KING then--双王炸 return zgwrDdzUtil2.getEightBombByCard(card,handCards) elseif lastType == ETS.BOMB_EIGHT then--双王炸 local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType) if cval > lval then return zgwrDdzUtil2.getEightBombByCard(card,handCards) else return zgwrDdzUtil2.getTwelveBombByCard(card,handCards) end elseif lastType >= ETS.FOUR_SMALL_KING and lastType >= ETS.FOUR_BIG_KING then--双王炸 return zgwrDdzUtil2.getTwelveBombByCard(card,handCards) end elseif selectCardsNum > 1 then--选了多张牌 end end --获取指定牌有多少张 function zgwrDdzUtil2.getCardNumByCard(card,handCards) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) if valueList[val] and valueList[val] > 0 then return valueList[val] else return 0 end end --根据一张牌,从手牌获取炸弹 function zgwrDdzUtil2.getFourBombByCard(card,handCards) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) local tipresult = {} if (valueList[val] > 0 and valueList[val] + laiCount >= 4) then local _tpNum4 = 4 - valueList[val]; _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0 for _l4 = 1, _tpNum4 do table.insert(tipresult,cardList[GUI_VAL][_l4]) end for _m4 = 1, 4 - _tpNum4 do table.insert(tipresult,cardList[val][_m4]) end return tipresult end return card end --根据一张牌,从手牌获取炸弹 function zgwrDdzUtil2.getEightBombByCard(card,handCards) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) local tipresult = {} if (valueList[val] > 0 and valueList[val] + laiCount >= 8) then local _tpNum4 = 8 - valueList[val]; _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0 for _l4 = 1, _tpNum4 do table.insert(tipresult,cardList[GUI_VAL][_l4]) end for _m4 = 1, 8 - _tpNum4 do table.insert(tipresult,cardList[val][_m4]) end return tipresult end return card end --根据一张牌,从手牌获取炸弹 function zgwrDdzUtil2.getTwelveBombByCard(card,handCards) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) local tipresult = {} if (valueList[val] > 0 and valueList[val] + laiCount >= 12) then local _tpNum4 = 12 - valueList[val]; _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0 for _l4 = 1, _tpNum4 do table.insert(tipresult,cardList[GUI_VAL][_l4]) end for _m4 = 1, 12 - _tpNum4 do table.insert(tipresult,cardList[val][_m4]) end return tipresult end return card end function zgwrDdzUtil2.getDuiTpsByCard(card,handCards) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) local tipresult = {} if (valueList[val] > 0 and valueList[val] + laiCount >= 2) then local _tpNum4 = 2 - valueList[val]; _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0 for _l4 = 1, _tpNum4 do table.insert(tipresult,cardList[GUI_VAL][_l4]) end for _m4 = 1, 2 - _tpNum4 do table.insert(tipresult,cardList[val][_m4]) end return tipresult end return card end function zgwrDdzUtil2.getThreeTpsByCard(card,handCards) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) local tipresult = {} if (valueList[val] > 0 and valueList[val] + laiCount >= 3) then local _tpNum4 = 3 - valueList[val]; _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0 for _l4 = 1, _tpNum4 do table.insert(tipresult,cardList[GUI_VAL][_l4]) end for _m4 = 1, 3 - _tpNum4 do table.insert(tipresult,cardList[val][_m4]) end return tipresult end return card end --获取两小王炸提示 function zgwrDdzUtil2.getTwoSKingBombByCard(card,handCards,isCanUseGui) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) valueList[X_KING] = valueList[X_KING] or 0 valueList[D_KING] = valueList[D_KING] or 0 valueList[GUI_VAL] = valueList[GUI_VAL] or 0 local tipresult = {} if isCanUseGui and (valueList[val] > 0 and (valueList[val] + laiCount >= 2)) then table.insert(tipresult,cardList[val][1]) if valueList[GUI_VAL] > 0 then table.insert(tipresult,cardList[GUI_VAL][1]) elseif valueList[X_KING] and valueList[X_KING] > 1 then table.insert(tipresult,cardList[X_KING][2]) end return tipresult elseif valueList[val] >= 2 then table.insert(tipresult,cardList[val][1]) table.insert(tipresult,cardList[val][2]) return tipresult end return nil end --获取小王大王炸提示 function zgwrDdzUtil2.getSBKingBombByCard(card,handCards) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) valueList[D_KING] = valueList[D_KING] or 0 valueList[X_KING] = valueList[X_KING] or 0 local tipresult = {} if valueList[X_KING] >= 1 and valueList[D_KING] >= 1 then table.insert(tipresult,cardList[val][1]) if val == X_KING then table.insert(tipresult,cardList[D_KING][1]) elseif val == D_KING then table.insert(tipresult,cardList[X_KING][1]) end return tipresult end return nil end --获取两大王炸提示 function zgwrDdzUtil2.getTwoBKingBombByCard(card,handCards,isCanUseGui) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) valueList[D_KING] = valueList[D_KING] or 0 valueList[X_KING] = valueList[X_KING] or 0 valueList[GUI_VAL] = valueList[GUI_VAL] or 0 local tipresult = {} if isCanUseGui and (valueList[val] > 0 and (valueList[val] + laiCount >= 2)) then table.insert(tipresult,cardList[val][1]) if valueList[GUI_VAL] > 0 then table.insert(tipresult,cardList[GUI_VAL][1]) elseif valueList[D_KING] and valueList[D_KING] > 1 then table.insert(tipresult,cardList[D_KING][2]) end return tipresult elseif valueList[val] >= 2 then table.insert(tipresult,cardList[val][1]) table.insert(tipresult,cardList[val][2]) return tipresult end return nil end -- 获取王炸提示 function zgwrDdzUtil2.getTwoKingBombByCard(card,handCards) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) valueList[D_KING] = valueList[D_KING] or 0 valueList[X_KING] = valueList[X_KING] or 0 valueList[GUI_VAL] = valueList[GUI_VAL] or 0 local tipresult = {} if (valueList[val] > 0 and (valueList[X_KING] + valueList[D_KING] >= 2 or valueList[val] + laiCount >= 2)) then table.insert(tipresult,cardList[val][1]) if val == X_KING then if valueList[X_KING] and valueList[X_KING] > 1 then table.insert(tipresult,cardList[X_KING][2]) elseif valueList[GUI_VAL] > 0 then table.insert(tipresult,cardList[GUI_VAL][1]) elseif valueList[D_KING] > 0 then table.insert(tipresult,cardList[D_KING][1]) end elseif val == D_KING then if valueList[X_KING] and valueList[X_KING] > 0 then table.insert(tipresult,cardList[X_KING][1]) elseif valueList[GUI_VAL] > 0 then table.insert(tipresult,cardList[GUI_VAL][1]) elseif valueList[D_KING] > 1 then table.insert(tipresult,cardList[D_KING][2]) end end return tipresult end return card end --获取四王炸 function zgwrDdzUtil2.getFourKingBombByCard(card,handCards) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) valueList[D_KING] = valueList[D_KING] or 0 valueList[X_KING] = valueList[X_KING] or 0 valueList[GUI_VAL] = valueList[GUI_VAL] or 0 local tipresult = {} local tpNum = 4 if (valueList[val] > 0 and (valueList[X_KING] + valueList[D_KING] + laiCount >= 4)) then table.insert(tipresult,cardList[val][1]) if val == X_KING then if valueList[X_KING] and valueList[X_KING] > 1 then for i=2,valueList[X_KING] do table.insert(tipresult,cardList[X_KING][i]) if #tipresult == 4 then return tipresult end end end if valueList[GUI_VAL] > 0 then for i=1,valueList[GUI_VAL] do table.insert(tipresult,cardList[GUI_VAL][i]) if #tipresult == 4 then return tipresult end end end if valueList[D_KING] > 0 then for i=1,valueList[D_KING] do table.insert(tipresult,cardList[D_KING][i]) if #tipresult == 4 then return tipresult end end end elseif val == D_KING then if valueList[X_KING] and valueList[X_KING] > 0 then for i=1,valueList[X_KING] do table.insert(tipresult,cardList[X_KING][i]) if #tipresult == 4 then return tipresult end end end if valueList[GUI_VAL] > 0 then for i=1,valueList[GUI_VAL] do table.insert(tipresult,cardList[GUI_VAL][i]) if #tipresult == 4 then return tipresult end end end if valueList[D_KING] > 1 then for i=2,valueList[D_KING] do table.insert(tipresult,cardList[D_KING][i]) if #tipresult == 4 then return tipresult end end end end return tipresult end return card end --获取最大四王炸 function zgwrDdzUtil2.getMaxFourKingBombByCard(card,handCards) local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) valueList[D_KING] = valueList[D_KING] or 0 valueList[X_KING] = valueList[X_KING] or 0 valueList[GUI_VAL] = valueList[GUI_VAL] or 0 local tipresult = {} if (valueList[val] > 0 and (valueList[X_KING] + valueList[D_KING] + laiCount >= 4)) then table.insert(tipresult,cardList[val][1]) if val == X_KING then if valueList[D_KING] > 0 then for i=1,valueList[D_KING] do table.insert(tipresult,cardList[D_KING][i]) if #tipresult == 4 then return tipresult end end end if valueList[GUI_VAL] > 0 then for i=1,valueList[GUI_VAL] do table.insert(tipresult,cardList[GUI_VAL][i]) if #tipresult == 4 then return tipresult end end end if valueList[X_KING] and valueList[X_KING] > 1 then for i=2,valueList[X_KING] do table.insert(tipresult,cardList[X_KING][i]) if #tipresult == 4 then return tipresult end end end elseif val == D_KING then if valueList[D_KING] > 1 then for i=2,valueList[D_KING] do table.insert(tipresult,cardList[D_KING][i]) if #tipresult == 4 then return tipresult end end end if valueList[GUI_VAL] > 0 then for i=1,valueList[GUI_VAL] do table.insert(tipresult,cardList[GUI_VAL][i]) if #tipresult == 4 then return tipresult end end end if valueList[X_KING] and valueList[X_KING] > 0 then for i=1,valueList[X_KING] do table.insert(tipresult,cardList[X_KING][i]) if #tipresult == 4 then return tipresult end end end end end return nil end function zgwrDdzUtil2.getShunZiTpsByCard(card,handCards,needNum,minVal)--选中的牌,手牌,需要的张数,最小的起始牌 local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) if val > 9 then return card end--选中的是2,不能组成顺子 返回 if val > 5 or (val + needNum > 10) then--选中的牌值大于10 val = 10 - needNum end if val <= minVal then return zgwrDdzUtil2.getFourBombByCard(card,handCards) end local _tpIdx = val; local _tpCount = 0; local _tpReplace2 = {} local tpNotAllLai = false; local _haveLai = laiCount; while _tpCount < #handCards and _tpCount < needNum and _tpIdx <= 10 do valueList[_tpIdx] = valueList[_tpIdx] or 0; if (not (valueList[_tpIdx] + _haveLai >= 1)) then break end; local _tpNum = 1 - valueList[_tpIdx]; _tpNum = _tpNum >= 0 and _tpNum or 0; local lai = laiCount - _haveLai + 1 for p = 1, _tpNum do table.insert(_tpReplace2,cardList[GUI_VAL][lai]) lai = lai + 1 end for _m = 1, 1 - _tpNum do table.insert(_tpReplace2, cardList[_tpIdx][_m]) tpNotAllLai = true; end _haveLai = _haveLai - _tpNum; _tpCount = _tpCount + 1; _tpIdx = _tpIdx + 1 end if _tpCount == needNum then return _tpReplace2 else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end end function zgwrDdzUtil2.getLianDuiTpsByCard(card,handCards,needNum,minVal)--选中的牌,手牌,需要的张数,最小的起始牌 local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) if val > 9 then return card end--选中的是2,不能组成顺子 返回 if val > 7 or (val + needNum/2 > 10) then--选中的牌值大于Q val = 10 - needNum/2 end if val <= minVal then return card end local _tpIdx = val; local _tpCount = 0; local _tpReplace2 = {} local tpNotAllLai = false; local _haveLai = laiCount; while _tpCount < #handCards and _tpCount < needNum and _tpIdx <= 9 do valueList[_tpIdx] = valueList[_tpIdx] or 0; if (not (valueList[_tpIdx] + _haveLai >= 2)) then break end; local _tpNum = 2 - valueList[_tpIdx]; _tpNum = _tpNum >= 0 and _tpNum or 0; local lai = laiCount - _haveLai + 1 if _tpNum >= 2 then break end for p = 1, _tpNum do table.insert(_tpReplace2,cardList[GUI_VAL][lai]) lai = lai + 1 end for _m = 1, 2 - _tpNum do table.insert(_tpReplace2, cardList[_tpIdx][_m]) tpNotAllLai = true; end _haveLai = _haveLai - _tpNum; _tpCount = _tpCount + 2; _tpIdx = _tpIdx + 1 end if _tpCount == needNum then return _tpReplace2 else return zgwrDdzUtil2.getFourBombByCard(card,handCards) end end function zgwrDdzUtil2.getSanShunTpsByCard(card,handCards,needNum,minVal)--选中的牌,手牌,需要的张数,最小的起始牌 local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end local val = zgwrDdzUtil1:getCardValue(card) if val > 9 then return card end--选中的是2,不能组成顺子 返回 if val > 8 or (val + needNum/3 > 10) then--选中的牌值大于K val = 10 - needNum/3 end if val <= minVal then return card end local _tpIdx = val; local _tpCount = 0; local _tpReplace2 = {} local tpNotAllLai = false; local _haveLai = laiCount; while _tpCount < #handCards and _tpCount < needNum and _tpIdx <= 9 do valueList[_tpIdx] = valueList[_tpIdx] or 0; if (not (valueList[_tpIdx] + _haveLai >= 3)) then break end; local _tpNum = 3 - valueList[_tpIdx]; _tpNum = _tpNum >= 0 and _tpNum or 0; local lai = laiCount - _haveLai + 1 for p = 1, _tpNum do table.insert(_tpReplace2,cardList[GUI_VAL][lai]) lai = lai + 1 end for _m = 1, 3 - _tpNum do table.insert(_tpReplace2, cardList[_tpIdx][_m]) tpNotAllLai = true; end _haveLai = _haveLai - _tpNum; _tpCount = _tpCount + 3; _tpIdx = _tpIdx + 1 end if _tpCount == needNum then return _tpReplace2 else return card end end --获取最小单牌 function zgwrDdzUtil2.getMinSigle(handCards,minVal,isCanChai)--是否可以拆,如果可以则从2张及以上的牌里面找 local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end if minVal and minVal >=10 then return nil end local limit = (minVal or 0) + 1 for i = limit,10 do if valueList[i] and valueList[i] == 1 then return cardList[i][1] end end if isCanChai then for i = limit,10 do if valueList[i] and valueList[i] > 1 then return cardList[i][1] end end end return nil end --获取最小对子 function zgwrDdzUtil2.getMinDuiZi(handCards,minVal,isCanChai)--是否可以拆,如果可以则从3张及以上的牌里面找 local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end if minVal and minVal >=10 then return nil end--没有比2个2还大的对牌 local limit = (minVal or 0) + 1 for i = limit,10 do if valueList[i] and valueList[i] == 2 then return cardList[i] end end local result = {} if isCanChai then for i = limit,10 do local isfind = false if valueList[i] and valueList[i] == 3 then isfind = true for j=1,2 do table.insert(result,cardList[i][j]) end end if isfind then return result end end for i = limit,10 do local isfind = false if valueList[i] and valueList[i] >= 4 then isfind = true for j=1,2 do table.insert(result,cardList[i][j]) end end if isfind then return result end end end return nil end --获取最小三张 function zgwrDdzUtil2.getMinThree(handCards,minVal,isCanChai)--手牌,被限制的最小牌(即获取的三张牌至少要大于这个值),是否可以拆 local valueList = {} local cardList = {} local laiCount = 0 for k,v in ipairs(handCards) do local value = zgwrDdzUtil1:getCardValue(v) valueList[value] = valueList[value] or 0 valueList[value] = valueList[value] + 1 cardList[value] = cardList[value] or {} table.insert(cardList[value], v) if value == GUI_VAL then laiCount = laiCount + 1 elseif value == X_KING or value == D_KING then--小王和大王 end end if minVal and minVal >=10 then return nil end--没有比三个2还大的三牌 local limit = 1 if minVal then limit = minVal + 1 end for i = limit,10 do if valueList[i] and valueList[i] == 3 then return cardList[i] end end local result = {} if isCanChai then for i = limit,10 do local isfind = false if valueList[i] and valueList[i] > 3 then isfind = true for j=1,3 do table.insert(result,cardList[i][j]) end end if isfind then return result end end end return nil end --获取三带一提示 function zgwrDdzUtil2.getSanDaiYiTpsByCard(card,handCards) local three = zgwrDdzUtil2.getThreeTpsByCard(card,handCards) if type(three) == 'table' then local sigle = zgwrDdzUtil2.getMinSigle(handCards) if sigle then table.insert(three,sigle) end return three else return card end end --获取三带对提示 function zgwrDdzUtil2.getSanDaiDuiTpsByCard(card,handCards) local three = zgwrDdzUtil2.getThreeTpsByCard(card,handCards) if three and type(three) == 'table' then local duiZi = zgwrDdzUtil2.getMinDuiZi(handCards) if duiZi then for i,v in pairs(duiZi) do table.insert(three,v) end end return three else return card end end return zgwrDdzUtil2