25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

2777 satır
84 KiB

  1. --[[
  2. 3~KA2(从小到大)
  3. tip: 假设有个梅花3, 具体牌值则是为1,标准牌值是0x11
  4. 癞子(万能牌)相关:
  5. 癞子可以允许单独出,单独出为God_Card_Single_Value的值
  6. 癞子是否可以与癞子组合(即两个癞子是否可以组成对子,王炸),通过God_Card_Is_Can_Be_All_Same的值来获取
  7. 部分提示相关(这里1为标准值,具体值是3)
  8. (对子,顺子,三顺,连对,炸弹-------打头的不能为癞子)
  9. 即上家牌是"1,2,3,4,5",自己提示牌不会为"癞子,7,8,9,10",而是"7,8,9,10,癞子"
  10. (三带,4带,飞机--------打头牌,飞机牌不能为全癞子)
  11. 即上家牌是"1,1,1,2,",自己提示牌不会为存在"癞子,癞子,癞子",而是"8,癞子,癞子",(三带的提示只返回3张)
  12. 癞子替代牌相关:
  13. 返回的是替代的牌,单张则为定义的牌值,2张,3张等为min值,如果遇到带顺子属性的(顺子,飞机,连对等),则判断是哪个空缺,如果没空缺则往后补充
  14. ,被带的牌,如果为单张的话,则从最小(3~KA2)开始计算,判断手牌不超过当前基牌(如果3带的话,3带为基牌,这个意思。)的张数即可。若需要组成对子,则将该癞子牌转换为空缺的对子牌
  15. 代码组成:
  16. 一些方法/公有方法
  17. 癞子替代牌
  18. 牌型提示
  19. 牌型判断,返回值(是否可以为某个牌类型,牌类型,最小值/基类最小值,是否需要用癞子牌)
  20. ]]
  21. local defs = require("pk_nanchongdoudizhu.luaScript.Def_53")
  22. local PokerUtil = class("PokerUtil")
  23. -- 值
  24. local Value_2 = 0x0d -- 2的具体牌值
  25. local Value_Joker_Little = 0x0e -- 小鬼的具体牌值
  26. local Value_Joker_Big = 0x0f -- 大鬼的具体牌值
  27. -- 从小到大排序
  28. function PokerUtil.sortOrder(a, b)
  29. return a < b
  30. end
  31. -- 从小到大排序
  32. function PokerUtil.sortDesc(a, b)
  33. return a > b
  34. end
  35. -- 从小到大排序(根据扑克值) v指value, t指type
  36. function PokerUtil.sortOrder_By_PokerValue(a, b)
  37. local v_a = PokerUtil:getCardValue(a)
  38. local v_b = PokerUtil:getCardValue(b)
  39. if v_a ~= v_b then
  40. return v_a < v_b
  41. else
  42. local t_a = PokerUtil:getCardType(a)
  43. local t_b = PokerUtil:getCardType(b)
  44. return t_a < t_b
  45. end
  46. end
  47. function PokerUtil:ctor(param)
  48. self:initFunction()
  49. end
  50. -- 获得牌类型 0方块 1梅花 2红桃 3黑桃
  51. function PokerUtil:getCardType(card)
  52. return toint(getNumBand(card, 0xf0) / 0x0f)
  53. end
  54. -- 获得牌的具体牌值
  55. function PokerUtil:getCardValue(card)
  56. return getNumBand(card, 0x0f)
  57. end
  58. function PokerUtil:initFunction()
  59. self:initTypeMap()
  60. -- self:initTipMap()
  61. end
  62. -- 定义数组,key是手牌的长度,value则是可能组成长度为key的牌型判断方法
  63. --[[
  64. tip: 判断张数的先后与前到后插入有关。
  65. 即假设手中有1,1,1,万能牌:
  66. 如果是先插入三带一,那么则判断为3带1,如果是先插入4个的炸弹,则判断为炸弹。
  67. 通过Card_Tip_Check_Order_By_Desc开关,来确认是正序还是逆序,当然也可以重写initTypeMap方法来实现自己独有的判断顺序
  68. 重写后,Card_Tip_Check_Order_By_Desc还是会有作用,所以根据个人需求需要注意下。
  69. ]]
  70. function PokerUtil:initTypeMap()
  71. for i = 1, self.Card_Max_Length do
  72. self.Card_Type_Map[i] = {}
  73. end
  74. -- 单张
  75. table.insert(self.Card_Type_Map[1], self.isSingle)
  76. -- 对子
  77. table.insert(self.Card_Type_Map[2], self.isDouble)
  78. -- 三张
  79. table.insert(self.Card_Type_Map[3], self.isThree)
  80. -- 顺子
  81. for i = self.Less_Line, self.Max_Line do
  82. table.insert(self.Card_Type_Map[i], self.isLine)
  83. end
  84. -- 连对
  85. for i = self.Less_Lian_Dui, self.Card_Max_Length do
  86. if i % 2 == 0 then
  87. table.insert(self.Card_Type_Map[i], self.isDoubleLine)
  88. end
  89. end
  90. -- 三带一
  91. table.insert(self.Card_Type_Map[4], self.isThreeTakeOne)
  92. -- 三带二
  93. table.insert(self.Card_Type_Map[5], self.isThreeTakeTwo)
  94. -- 四带一张
  95. table.insert(self.Card_Type_Map[5], self.isFourTakeOneSingle)
  96. -- 四带一对
  97. table.insert(self.Card_Type_Map[6], self.isFourTakeOneDouble)
  98. -- 四带二张单排
  99. table.insert(self.Card_Type_Map[6], self.isFourTakeTwoSingle)
  100. -- 四带二对子
  101. table.insert(self.Card_Type_Map[8], self.isFourTakeTwoDouble)
  102. -- 飞机带单
  103. for i = self.Less_Plane + 2, self.Card_Max_Length do
  104. if i % 4 == 0 then
  105. table.insert(self.Card_Type_Map[i], self.isPlaneTakeSingle)
  106. end
  107. end
  108. -- 飞机带对子
  109. for i = self.Less_Plane + 4, self.Card_Max_Length do
  110. if i % 5 == 0 then
  111. table.insert(self.Card_Type_Map[i], self.isPlanetakeDouble)
  112. end
  113. end
  114. -- 飞机不带
  115. for i = self.Less_Plane, self.Card_Max_Length do
  116. if i % 3 == 0 then
  117. table.insert(self.Card_Type_Map[i], self.isPlaneNoTake)
  118. end
  119. end
  120. -- 炸弹
  121. table.insert(self.Card_Type_Map[4], self.isBomb)
  122. -- 王炸
  123. table.insert(self.Card_Type_Map[2], self.isKingBomb)
  124. end
  125. -- 获得提示(cards是userdata)
  126. function PokerUtil:getTip(cards, lastData)
  127. print('jxjx 进入getTip')
  128. dump(cards, 'cards')
  129. dump(lastData, 'lastData')
  130. local tipResult = {}
  131. local lastCardInfo = self:getCardsType(lastData)
  132. if lastCardInfo.cardType < defs.CARD_TYPE.BOMB then
  133. local f = self.Card_Tip_Map[lastCardInfo.cardType]
  134. if f then
  135. print(string.format('jxjx..牌型提示..%s', defs.CARD_TYPE_NAME[lastCardInfo.cardType]))
  136. -- tipResult = self.Card_Tip_Map[lastCardInfo.cardType](self, cards, lastData) -- f是方法 启用initTipMap
  137. tipResult = self[f](self, cards, lastData) -- f是str
  138. end
  139. end
  140. -- 添加炸弹
  141. if lastCardInfo.cardType <= defs.CARD_TYPE.BOMB then
  142. print('jxjx..getTip 添加炸弹')
  143. local result = self:getBombTip(cards, lastData)
  144. if table.nums(result) > 0 then
  145. for _, bomb in ipairs(result) do
  146. table.insert(tipResult, bomb)
  147. end
  148. end
  149. end
  150. --王炸
  151. if lastCardInfo.cardType <= defs.CARD_TYPE.BOMB_KING then
  152. print('jxjx..getTip 添加王炸')
  153. local result = self:getBombKingTip(cards, lastData)
  154. if table.nums(result) > 0 then
  155. for _, bomb in ipairs(result) do -- 王炸只有1个,虽然多此一举用了循环...
  156. table.insert(tipResult, bomb)
  157. end
  158. end
  159. end
  160. dump(tipResult, 'jxjx gettip 结果')
  161. return tipResult
  162. end
  163. -- 解析牌值,将牌值分成牌值数量表和牌表
  164. --[[
  165. valueList: key具体牌值, value数量
  166. valueCard: key具体牌值, value标准牌值(16进制转10进制的)
  167. 如果有癞子(万能牌)玩法,则还会返回万能牌数组,并且valueList, valueCard里面不会有包含万能牌
  168. ]]
  169. function PokerUtil:parseCard(cards)
  170. local valueList = {}
  171. local valueCard = {}
  172. local godCards = {}
  173. --初始化
  174. for i = 1, 15 do
  175. valueList[i] = 0
  176. valueCard[i] = {}
  177. end
  178. -- 赋值
  179. for k,v in ipairs(cards) do
  180. if self:isUseGodCard() and self:isGodCard(v) then
  181. table.insert(godCards, v)
  182. else
  183. local value = self:getCardValue(v)
  184. if not valueList[value] then
  185. valueList[value] = 0
  186. end
  187. if not valueCard[value] then
  188. valueCard[value] = {}
  189. end
  190. valueList[value] = valueList[value] + 1
  191. table.insert(valueCard[value], v)
  192. end
  193. end
  194. return valueList, valueCard, godCards
  195. end
  196. -- 解析牌值,将牌值分成牌值数量表和牌表(扩展版)
  197. --[[
  198. valueCard: key有序, value是个标准牌值组成的表(16进制转10进制的)
  199. 如果有癞子(万能牌)玩法,则还会返回万能牌数组,并且valueCard里面不会有包含万能牌
  200. ]]
  201. function PokerUtil:parseCardEx(cards)
  202. local temp = {}
  203. local godCards = {}
  204. for k,v in ipairs(cards) do
  205. if self:isUseGodCard() and self:isGodCard(v) then
  206. table.insert(godCards, v)
  207. else
  208. local value = self:getCardValue(v)
  209. if not temp[value] then
  210. temp[value] = {}
  211. end
  212. table.insert(temp[value], v)
  213. end
  214. end
  215. local valueCard = {}
  216. for _,v in pairs(temp) do
  217. table.insert(valueCard, v)
  218. end
  219. return valueCard, godCards
  220. end
  221. -- 反解析牌值,返回key为数量,value为具体牌值的表
  222. --[[
  223. result: key数量, value具体牌值
  224. 如果有癞子(万能牌)玩法,则还会返回万能牌数组,并且result里面不会有包含万能牌(这个不用太注意,因为repaese也是做parsecard,如果没有癞子玩法,godCards是为空表)
  225. ]]
  226. function PokerUtil:reParseCard(cards)
  227. local valueList, _, godCards = self:parseCard(cards)
  228. local result = {{}, {}, {}, {}} -- 一副牌,最多4张
  229. for k,v in pairs(valueList) do
  230. if v > 0 then
  231. table.insert(result[v], k)
  232. end
  233. end
  234. return result, godCards
  235. end
  236. -- 移除牌组中的癞子牌,只用于癞子玩法
  237. function PokerUtil:removeGodCards(cards)
  238. local temp = clone(cards)
  239. if self:isUseGodCard() then
  240. for i = #temp, 1, -1 do
  241. if self:isGodCard(temp[i]) then
  242. table.remove(temp, i)
  243. end
  244. end
  245. end
  246. return temp
  247. end
  248. -- 通过牌的标准值,转换为具体值
  249. function PokerUtil:changeCardValue_Standard_To_Specific(cards)
  250. if type(cards) == 'number' then
  251. return self:getCardValue(cards)
  252. elseif type(cards) == 'table' then
  253. local result = {}
  254. for i, v in ipairs(cards) do
  255. table.insert(result, self:getCardValue(v))
  256. end
  257. return result
  258. end
  259. return
  260. end
  261. -- 组合两个表(必须是有序)
  262. function PokerUtil:addTableData(t1, t2)
  263. local temp = clone(t1)
  264. for i, v in ipairs(t2) do
  265. table.insert(temp, v)
  266. end
  267. return temp
  268. end
  269. -- 获取牌组1中,不与牌组2中相同值的表(取异或表)
  270. function PokerUtil:xorTableData(t1, t2)
  271. local result = {}
  272. for i1, v1 in pairs(t1) do
  273. local tag = false
  274. for i2, v2 in pairs(t2) do
  275. if v1 == v2 then
  276. tag = true
  277. break
  278. end
  279. end
  280. if not tag then
  281. table.insert(result, v1)
  282. end
  283. end
  284. return result
  285. end
  286. -- 判断牌组中是否包含炸弹
  287. function PokerUtil:getIsHaveBomb(cards)
  288. -- 4张
  289. local reValueList, godCards = self:reParseCard(cards)
  290. local godCardCount = #godCards
  291. if #reValueList[4] > 0 then
  292. return true
  293. end
  294. -- 王炸
  295. local valueList = self:parseCard(cards)
  296. if (valueList[Value_Joker_Little] or 0) > 0 and (valueList[Value_Joker_Big] or 0) > 0 then
  297. return true
  298. end
  299. -- 带癞子的炸弹
  300. if self:isUseGodCard() and godCardCount > 0 then
  301. local needGodCardCount = 0
  302. -- 癞子炸弹
  303. while godCardCount > needGodCardCount and needGodCardCount <= 3 do
  304. if valueList[4 - needGodCardCount] > 0 then
  305. return true
  306. end
  307. needGodCardCount = needGodCardCount + 1
  308. end
  309. -- 癞子王炸
  310. if (valueList[Value_Joker_Little] or 0) > 0 or (valueList[Value_Joker_Big] or 0) > 0 then
  311. return true
  312. end
  313. end
  314. return false
  315. end
  316. -- 获得癞子取代的牌,返回的是具体值(也可以说是最低的标准值)
  317. function PokerUtil:getGodCardReplaceCard(cards)
  318. print('jxjx 进入方法getGodCardReplaceCard,获得癞子取代的牌')
  319. dump(cards, '牌数据是')
  320. if not cards then
  321. return
  322. end
  323. if not self:isUseGodCard() then
  324. return
  325. end
  326. local valueList, valueCard, godCards = self:parseCard(cards)
  327. local godCardCount = #godCards
  328. if godCardCount <= 0 then
  329. return
  330. end
  331. local result = {}
  332. local handCardType = self:getCardsType(cards)
  333. dump(handCardType, 'jxjx 获得癞子取代的牌, 当前cards组成的类型是 handCardType')
  334. if not handCardType.isUseGodCard then
  335. print(string.format('jxjx 没有handCardType.isUseGodCard,可能是没有在defs里面对应的类型后面,传达正确的值 返回'))
  336. return
  337. end
  338. print('jxjx 获得癞子取代的牌,传入类型是', defs.CARD_TYPE_NAME[handCardType.cardType])
  339. local f = self.God_Card_Replace_Card_Map[handCardType.cardType]
  340. if f then
  341. result = self[f](self, cards, handCardType.min)
  342. else
  343. print(string.format('jxjx 类型%s未定义,或许是类型声明不对', handCardType.cardType))
  344. end
  345. dump(result, 'jxjx 获得癞子取代的牌, 返回结果是,这里默认是0x0打头')
  346. print('是否把取代的牌,更改为0x5x打头值', self.God_Card_ReplaceCard_Is_Use_God_Card_Value)
  347. if self.God_Card_ReplaceCard_Is_Use_God_Card_Value then
  348. local temp = {}
  349. for i, v in ipairs(result) do
  350. table.insert(temp, self:getCardValue(v) + 5 * 16)
  351. end
  352. result = temp
  353. end
  354. return result
  355. end
  356. -- 获得带牌中,除值valmin~valmax外,最小,并且不在valCards牌组中的牌(针对获取替代牌) valCards在parseCard中得来
  357. function PokerUtil:getReplaceValTableExceptValInTakeCard(valCards, replaceCount, valmin, valmax)
  358. local valmin = valmin
  359. local valmax = valmax or valmin
  360. local rpCount = replaceCount
  361. local temp = clone(valCards)
  362. local tReplace = {}
  363. local result = {}
  364. local val = 1
  365. while rpCount > 0 do
  366. if rpCount > 1 then
  367. if temp[val] and temp[val] < 2 then
  368. table.insert(result, val)
  369. table.insert(result, val)
  370. rpCount = rpCount - 2
  371. end
  372. else
  373. if temp[val] and temp[val] < 1 then
  374. table.insert(result, val)
  375. rpCount = rpCount - 1
  376. end
  377. end
  378. val = val + 1
  379. end
  380. return result
  381. end
  382. -- 获得牌类型(返回类型和最小值)
  383. function PokerUtil:getCardsType(cards)
  384. local result = {min = -1, cardType = defs.CARD_TYPE.NULL, isUseGodCard = false}
  385. local maxLen = table.nums(cards)
  386. if maxLen == 0 then
  387. print('jxjx 牌长度错误,获得牌类型,牌长度是0,返回')
  388. return result
  389. end
  390. local tt = {} -- 普通牌(具体牌值)
  391. local gt = {} -- 万能牌(标准牌值),启动了Is_Use_God_Card才会有作用
  392. for k,v in ipairs(cards) do
  393. if self:isUseGodCard() and (self:isGodCard(v) or self:isGodCardReplaceCard(v)) then
  394. table.insert(gt, v)
  395. else
  396. table.insert(tt, self:getCardValue(v))
  397. end
  398. end
  399. table.sort(tt, function(a, b)
  400. return a < b
  401. end)
  402. print('jxjx 获得牌提示,长度是', maxLen)
  403. if self.Card_Type_Map[maxLen] then
  404. print(string.format('jxjx 判断方法共有%d个', #self.Card_Type_Map[maxLen]))
  405. end
  406. if self.Card_Tip_Check_Order_By_Desc then
  407. for i = #self.Card_Type_Map[maxLen], 1, -1 do
  408. local fun = self.Card_Type_Map[maxLen][i]
  409. if type(fun) == 'function' then
  410. local isType, ct, min, isUseGodCard = fun(self, tt, gt)
  411. if isType and ct > -1 then
  412. result = {min = min, cardType = ct, isUseGodCard = isUseGodCard and true or false}
  413. print('jxjx 获得牌提示,牌的类型是', defs.CARD_TYPE_NAME[ct])
  414. break
  415. end
  416. end
  417. end
  418. else
  419. for i, fun in ipairs(self.Card_Type_Map[maxLen]) do
  420. if type(fun) == 'function' then
  421. local isType, ct, min, isUseGodCard = fun(self, tt, gt)
  422. if isType and ct > -1 then
  423. result = {min = min, cardType = ct, isUseGodCard = isUseGodCard and true or false}
  424. print('jxjx 获得牌提示,牌的类型是', defs.CARD_TYPE_NAME[ct])
  425. break
  426. end
  427. end
  428. end
  429. end
  430. return result
  431. end
  432. -- 是否一手出完所有牌
  433. function PokerUtil:checkIsCanOneOutCard(cards, lastData)
  434. print('jxjx 是否一手出完所有牌')
  435. dump(cards, 'cards>>')
  436. dump(lastData, 'lastData>>')
  437. -- 压牌(如果有提示牌,并且只有1种)
  438. if lastData and table.nums(lastData) > 0 then
  439. local tips = self:getTip(cards, lastData)
  440. if tips and table.nums(tips) == 1 and #tips[1] == #cards then
  441. print('压牌,可以出完一手牌')
  442. return true
  443. end
  444. end
  445. -- 自己出牌(判断手中的所有牌是否可以组成某个牌型,并且没有炸弹)
  446. if not lastData or table.nums(lastData) <= 0 then
  447. local handCardType = self:getCardsType(cards)
  448. if handCardType.cardType > defs.CARD_TYPE.NULL and not self:getIsHaveBomb(cards) then
  449. print('自己出牌,可以出完一手牌')
  450. return true
  451. end
  452. end
  453. print('jxjx 不可一手出完所有牌')
  454. return false
  455. end
  456. -- 是否传入的cards中,都是相同的
  457. function PokerUtil:checkIsTheSameCards(cards)
  458. if not cards or #cards <= 0 then
  459. return
  460. end
  461. local tag = true
  462. local value = cards[1]
  463. for i, v in ipairs(cards) do
  464. if v ~= value then
  465. tag = false
  466. break
  467. end
  468. end
  469. return tag
  470. end
  471. -- 是否传入的cards和godCards中,cards各对应的个数数量与癞子牌组合后能大于等于maxCount(针对带牌,这里只按1副牌处理)
  472. function PokerUtil:checkIsCanCombination(cards, godCards, maxCount)
  473. local maxCount = maxCount or 4
  474. local reValueList = self:reParseCard(cards)
  475. local godCardCount = #godCards
  476. if #cards == 0 then
  477. if godCardCount >= maxCount then
  478. return true
  479. end
  480. end
  481. for count, vt in ipairs(reValueList) do
  482. if table.nums(vt) > 0 then
  483. if count + godCardCount >= maxCount then
  484. return true
  485. end
  486. end
  487. end
  488. return false
  489. end
  490. -- 是否可以3带1
  491. function PokerUtil:can31()
  492. if not app.room then
  493. return true
  494. end
  495. local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
  496. return getNumBand(0x01, (gameInfo.sanDai or 0x1)) > 0
  497. end
  498. -- 是否可以3带2
  499. function PokerUtil:can32()
  500. if not app.room then
  501. return true
  502. end
  503. local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
  504. return getNumBand(0x02, (gameInfo.sanDai or 0x2)) > 0
  505. end
  506. -- 是否可以4带1
  507. function PokerUtil:can41()
  508. return false
  509. end
  510. -- 是否可以4带2(4带1对子)
  511. function PokerUtil:can42()
  512. return true
  513. end
  514. -- 是否可以4带单单(2个单张)
  515. function PokerUtil:can411()
  516. if not app.room then
  517. return true
  518. end
  519. local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
  520. return getNumBand(0x02, (gameInfo.siDai or 0x02)) > 0
  521. end
  522. -- 是否可以4带双双(2个对子)
  523. function PokerUtil:can422()
  524. if not app.room then
  525. return true
  526. end
  527. local gameInfo = json.decode(app.room.roomInfo.strGameInfo)
  528. return getNumBand(0x08, (gameInfo.siDai or 0x08)) > 0
  529. end
  530. -- 是否启用万能牌
  531. function PokerUtil:isUseGodCard()
  532. return self.Is_Use_God_Card
  533. end
  534. -- 是否启用万能牌与万能牌之间可以组合
  535. function PokerUtil:isUseAllSameGodCard()
  536. return self.God_Card_Is_Can_Be_All_Same
  537. end
  538. -- 是否是万能牌
  539. function PokerUtil:isGodCard(card)
  540. return card == self.God_Card_Value
  541. end
  542. -- 是否是万能牌幻化的值(0x5x)
  543. function PokerUtil:isGodCardReplaceCard(card)
  544. if self.God_Card_ReplaceCard_Is_Use_God_Card_Value then
  545. return self:getCardType(card) == 5
  546. end
  547. return
  548. end
  549. -- 是否包含万能牌
  550. function PokerUtil:isHaveGodCard(cards)
  551. if not self:isUseGodCard() then
  552. return
  553. end
  554. if not cards then
  555. return
  556. end
  557. for i, v in ipairs(cards) do
  558. if self:isGodCard(v) then
  559. return true
  560. end
  561. end
  562. end
  563. -----------------------------------------------------------------------------------------------------------------
  564. -------------------------------------- 以下是癞子替代牌 ----------------------------------------------------
  565. -----------------------------------------------------------------------------------------------------------------
  566. function PokerUtil:getGodCardSingleReplace(cards, min)
  567. return {min}
  568. end
  569. function PokerUtil:getGodCardDuiZiReplReplace(cards, min)
  570. return {min}
  571. end
  572. function PokerUtil:getGodCardSanZhangReplace(cards, min)
  573. local valueList, valueCard, godCards = self:parseCard(cards)
  574. local result = {}
  575. for i = 1, 3 - valueList[min] do
  576. table.insert(result, min)
  577. end
  578. return result
  579. end
  580. function PokerUtil:getGodCardShunZiReplace(cards, min)
  581. local valueList, valueCard, godCards = self:parseCard(cards)
  582. local result = {}
  583. for i = min, min + #cards - 1 do
  584. if valueList[i] < 1 then
  585. table.insert(result, i)
  586. end
  587. end
  588. return result
  589. end
  590. function PokerUtil:getGodCardLianDuiReplace(cards, min)
  591. print('jxjx 进入连对 万能牌替代牌判断')
  592. local valueList, valueCard, godCards = self:parseCard(cards)
  593. local result = {}
  594. for i = min, min + #cards/2 - 1 do
  595. if valueList[i] < 2 then
  596. for j = 1, 2 - valueList[i] do
  597. table.insert(result, i)
  598. end
  599. end
  600. end
  601. return result
  602. end
  603. function PokerUtil:getGodCardSanShunReplace(cards, min)
  604. local valueList, valueCard, godCards = self:parseCard(cards)
  605. local result = {}
  606. for i = min, min + #cards/3 - 1 do
  607. if valueList[i] < 3 then
  608. for j = 1, 3 - valueList[i] do
  609. table.insert(result, i)
  610. end
  611. end
  612. end
  613. return result
  614. end
  615. function PokerUtil:getGodCardSanDaiYiReplace(cards, min)
  616. local valueList, valueCard, godCards = self:parseCard(cards)
  617. local godCardCount = #godCards
  618. local count = 0
  619. local result = {}
  620. if valueList[min] < 3 then
  621. for j = 1, 3 - valueList[min] do
  622. table.insert(result, min)
  623. count = count + 1
  624. end
  625. end
  626. -- 如果还有多出的万能牌
  627. if count < godCardCount then
  628. local leftReplaceCount = godCardCount - count
  629. local valTable = self:getReplaceValTableExceptValInTakeCard(valueList, leftReplaceCount, min)
  630. result = self:addTableData(result, valTable)
  631. end
  632. return result
  633. end
  634. function PokerUtil:getGodCardSanDaiYiDuiReplace(cards, min)
  635. local valueList, valueCard, godCards = self:parseCard(cards)
  636. local godCardCount = #godCards
  637. local count = 0
  638. local result = {}
  639. if valueList[min] < 3 then
  640. for j = 1, 3 - valueList[min] do
  641. table.insert(result, min)
  642. count = count + 1
  643. end
  644. end
  645. -- 如果还有多出的万能牌
  646. if count < godCardCount then
  647. for i = 1, (godCardCount - count) do
  648. table.insert(result, godCards[1])
  649. end
  650. end
  651. return result
  652. end
  653. function PokerUtil:getGodCardSiDaiErSingleReplace(cards, min)
  654. local valueList, valueCard, godCards = self:parseCard(cards)
  655. local godCardCount = #godCards
  656. local count = 0
  657. local result = {}
  658. if valueList[min] < 4 then
  659. for j = 1, 4 - valueList[min] do
  660. table.insert(result, min)
  661. count = count + 1
  662. end
  663. end
  664. -- 如果还有多出的万能牌
  665. if count < godCardCount then
  666. local leftReplaceCount = godCardCount - count
  667. local valTable = self:getReplaceValTableExceptValInTakeCard(valueList, leftReplaceCount, min)
  668. result = self:addTableData(result, valTable)
  669. end
  670. return result
  671. end
  672. function PokerUtil:getGodCardSiDaiErDuiReplace(cards, min)
  673. local valueList, valueCard, godCards = self:parseCard(cards)
  674. local reValueList = self:reParseCard(cards)
  675. local godCardCount = #godCards
  676. local count = 0
  677. local result = {}
  678. if valueList[min] < 4 then
  679. for j = 1, 4 - valueList[min] do
  680. table.insert(result, min)
  681. count = count + 1
  682. end
  683. end
  684. if #reValueList[1] > 0 then
  685. for i, v in pairs(reValueList[1]) do
  686. table.insert(result, v)
  687. count = count + 1
  688. end
  689. end
  690. -- 如果还有多出的万能牌
  691. if count < godCardCount then
  692. local leftReplaceCount = godCardCount - count
  693. local valTable = self:getReplaceValTableExceptValInTakeCard(valueList, leftReplaceCount, min)
  694. result = self:addTableData(result, valTable)
  695. end
  696. return result
  697. end
  698. function PokerUtil:getGodCardAirPlaneSingleReplace(cards, min)
  699. local valueList, valueCard, godCards = self:parseCard(cards)
  700. local reValueList = self:reParseCard(cards)
  701. local feiLen = #cards / 4
  702. local godCardCount = #godCards
  703. local count = 0
  704. local result = {}
  705. for i = min, min + feiLen - 1 do
  706. if valueList[i] < 3 then
  707. for j = 1, 3 - valueList[i] do
  708. table.insert(result, i)
  709. count = count + 1
  710. end
  711. end
  712. end
  713. -- 如果还有多出的万能牌
  714. if count < godCardCount then
  715. local leftReplaceCount = godCardCount - count
  716. local valTable = self:getReplaceValTableExceptValInTakeCard(valueList, leftReplaceCount, min, min+feiLen-1)
  717. result = self:addTableData(result, valTable)
  718. end
  719. return result
  720. end
  721. function PokerUtil:getGodCardAirPlaneDuiReplace(cards, min)
  722. local valueList, valueCard, godCards = self:parseCard(cards)
  723. local reValueList = self:reParseCard(cards)
  724. local feiLen = #cards / 5
  725. local godCardCount = #godCards
  726. local count = 0
  727. local result = {}
  728. for i = min, min + feiLen - 1 do
  729. if valueList[i] < 3 then
  730. for j = 1, 3 - valueList[i] do
  731. table.insert(result, i)
  732. count = count + 1
  733. end
  734. end
  735. end
  736. if #reValueList[1] > 0 then
  737. for i, v in pairs(reValueList[1]) do
  738. table.insert(result, v)
  739. count = count + 1
  740. end
  741. end
  742. -- 如果还有多出的万能牌
  743. if count < godCardCount then
  744. local leftReplaceCount = godCardCount - count
  745. local valTable = self:getReplaceValTableExceptValInTakeCard(valueList, leftReplaceCount, min, min+feiLen-1)
  746. result = self:addTableData(result, valTable)
  747. end
  748. return result
  749. end
  750. function PokerUtil:getGodCardBombReplace(cards, min)
  751. local valueList, valueCard, godCards = self:parseCard(cards)
  752. local result = {}
  753. for i = 1, 4 - valueList[min] do
  754. table.insert(result, min)
  755. end
  756. return result
  757. end
  758. function PokerUtil:getGodCardBombKingReplace(cards, min)
  759. local valueList, valueCard, godCards = self:parseCard(cards)
  760. if valueList[Value_Joker_Little] > 0 then
  761. table.insert(result, Value_Joker_Big)
  762. elseif valueList[Value_Joker_Big] > 0 then
  763. table.insert(result, Value_Joker_Big)
  764. end
  765. return result
  766. end
  767. -----------------------------------------------------------------------------------------------------------------
  768. -------------------------------------- 以下是牌型提示 ------------------------------------------------------
  769. -----------------------------------------------------------------------------------------------------------------
  770. -- 获得单张提示
  771. --[[
  772. tip: 先从1张按顺序获取,在从2张,最后到4张
  773. 有癞子下,不会提示癞子打出
  774. ]]
  775. function PokerUtil:getSingleTip(cards, lastData)
  776. local valueList, valueCard, godCards = self:parseCard(cards)
  777. local lastCardInfo = self:getCardsType(lastData)
  778. local result = {}
  779. local reValueList = self:reParseCard(cards)
  780. for i = 1, 4 do
  781. for k2,v2 in pairs(reValueList[i]) do
  782. if v2 > lastCardInfo.min then
  783. table.insert(result, { valueCard[v2][1] })
  784. end
  785. end
  786. end
  787. return result
  788. end
  789. -- 获得对子提示
  790. --[[
  791. tip:直接就是从小到大,直接在2,3,4张中获取,不按是否有3张还是4张的
  792. 有癞子下,在最后添加判断(只从1张中寻找)
  793. ]]
  794. function PokerUtil:getDuiZiTip(cards, lastData)
  795. local valueList, valueCard, godCards = self:parseCard(cards)
  796. local lastCardInfo = self:getCardsType(lastData)
  797. local godCardCount = #godCards
  798. local result = {}
  799. for i = lastCardInfo.min + 1, 13 do
  800. local tpReplace = {}
  801. if (valueList[i] or 0) >= 2 then
  802. for j = 1, 2 do
  803. table.insert(tpReplace, valueCard[i][j])
  804. end
  805. table.insert(result, tpReplace)
  806. end
  807. end
  808. if self:isUseGodCard() and godCardCount > 0 then
  809. for i = lastCardInfo.min + 1, 13 do
  810. local tpReplace = {}
  811. if (valueList[i] or 0) == 1 then
  812. table.insert(tpReplace, valueCard[i][1])
  813. table.insert(tpReplace, godCards[1])
  814. table.insert(result, tpReplace)
  815. end
  816. end
  817. end
  818. return result
  819. end
  820. -- 获得三张提示
  821. --[[
  822. tip:直接就是从小到大,直接在3,4张中获取,不按是否有3张还是4张的
  823. 有癞子下,往最后添加判断(值从1,2张中寻找,以从小到大排序,不按需癞子个数排序)
  824. ]]
  825. function PokerUtil:getSanZhangTip(cards, lastData)
  826. local valueList, valueCard, godCards = self:parseCard(cards)
  827. local lastCardInfo = self:getCardsType(lastData)
  828. local godCardCount = #godCards
  829. local result = {}
  830. for i = lastCardInfo.min + 1, 13 do
  831. local tpReplace = {}
  832. if (valueList[i] or 0) >= 3 then
  833. for j = 1, 3 do
  834. table.insert(tpReplace, valueCard[i][j])
  835. end
  836. table.insert(result, tpReplace)
  837. end
  838. end
  839. if self:isUseGodCard() and godCardCount > 0 then
  840. for i = lastCardInfo.min + 1, 13 do
  841. local tpReplace = {}
  842. if (valueList[i] or 0) == 1 or (valueList[i] or 0) == 2 then
  843. local needGodCardCount = 3 - valueList[i]
  844. if godCardCount >= needGodCardCount then
  845. for _, v in ipairs(valueCard[i]) do
  846. table.insert(tpReplace, v)
  847. end
  848. for j = 1, needGodCardCount do
  849. table.insert(tpReplace, godCards[j])
  850. end
  851. table.insert(result, tpReplace)
  852. end
  853. end
  854. end
  855. end
  856. return result
  857. end
  858. -- 获得顺子提示
  859. --[[
  860. tip:先for循环最小值+1,直到13-长度(为了减少复杂度);然后在while循环中判断是否有当前出牌的长度的个数
  861. 有癞子下,不管癞子个数,直接就是返回从小到大的顺子,如果需要把包含癞子的放置最后,请自行判断
  862. ]]
  863. function PokerUtil:getShunZiTip(cards, lastData)
  864. local valueList, valueCard, godCards = self:parseCard(cards)
  865. local lastCardInfo = self:getCardsType(lastData)
  866. local nowCardsLen = table.nums(cards)
  867. local lastCardsLen = table.nums(lastData)
  868. local godCardCount = #godCards
  869. local result = {}
  870. for i = lastCardInfo.min + 1, 13 - lastCardsLen do
  871. local tpIdx = i
  872. local tpCount = 0
  873. local tpReplace = {}
  874. local needGodCardCount = 0
  875. -- 4个判断条件(当前顺子长度比手牌长度短,当前顺子长度(如遇到癞子不+1)+癞子长度)小于上次出牌长度, 当前牌值小于2(具体值13), 需要的癞子牌小于癞子数量)
  876. while tpCount < nowCardsLen and (tpCount + needGodCardCount) < lastCardsLen and tpIdx <= 12 and needGodCardCount <= godCardCount do
  877. valueList[tpIdx] = valueList[tpIdx] or 0
  878. if valueList[tpIdx] <= 0 then
  879. if self:isUseGodCard() and godCardCount > 0 then
  880. needGodCardCount = needGodCardCount + 1
  881. else
  882. break
  883. end
  884. end
  885. -- 如果手牌中有该tpIdx值
  886. if valueList[tpIdx] > 0 then
  887. table.insert(tpReplace, valueCard[tpIdx][1])
  888. tpCount = tpCount + 1
  889. end
  890. tpIdx = tpIdx + 1
  891. end
  892. if self:isUseGodCard() and godCardCount > 0 then
  893. if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
  894. if godCardCount >= needGodCardCount then
  895. for j = 1, needGodCardCount do
  896. table.insert(tpReplace, godCards[j])
  897. tpCount = tpCount + 1
  898. end
  899. end
  900. end
  901. end
  902. if tpCount == lastCardsLen then
  903. table.insert(result, tpReplace)
  904. end
  905. end
  906. return result
  907. end
  908. -- 获得连对提示
  909. --[[
  910. tip:先for循环最小值+1,直到13-长度/2(为了减少复杂度,这里/2是因为连对中是一半一半相对的);然后在while循环中判断是否有当前出牌的长度的个数
  911. 有癞子下,不管癞子个数,直接就是返回从小到大的连对,如果需要把包含癞子的放置最后,请自行判断
  912. ]]
  913. function PokerUtil:getLianDuiTip(cards, lastData)
  914. local valueList, valueCard, godCards = self:parseCard(cards)
  915. local lastCardInfo = self:getCardsType(lastData)
  916. local nowCardsLen = table.nums(cards)
  917. local lastCardsLen = table.nums(lastData)
  918. local godCardCount = #godCards
  919. local result = {}
  920. for i = lastCardInfo.min + 1, 13 - lastCardsLen / 2 do
  921. local tpIdx = i
  922. local tpCount = 0
  923. local tpReplace = {}
  924. local needGodCardCount = 0
  925. -- 4个判断条件(当前顺子长度比手牌长度短,当前顺子长度(如遇到癞子不+1)+癞子长度)小于上次出牌长度, 当前牌值小于2(具体值13), 需要的癞子牌小于癞子数量)
  926. while tpCount < nowCardsLen and (tpCount + needGodCardCount) < lastCardsLen and tpIdx <= 12 and needGodCardCount <= godCardCount do
  927. valueList[tpIdx] = valueList[tpIdx] or 0
  928. if valueList[tpIdx] <= 1 then
  929. if self:isUseGodCard() and godCardCount > 0 then
  930. needGodCardCount = needGodCardCount + (2 - valueList[tpIdx])
  931. else
  932. break
  933. end
  934. end
  935. if valueList[tpIdx] > 1 then
  936. for j = 1, 2 do
  937. table.insert(tpReplace, valueCard[tpIdx][j])
  938. end
  939. tpCount = tpCount + 2
  940. elseif self:isUseGodCard() and valueList[tpIdx] > 0 then -- 连对中,如果是癞子玩法,也需要把1张的插入,然后再看看是否癞子个数够
  941. table.insert(tpReplace, valueCard[tpIdx][1])
  942. tpCount = tpCount + 1
  943. end
  944. tpIdx = tpIdx + 1
  945. end
  946. if self:isUseGodCard() and godCardCount > 0 then
  947. if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
  948. if godCardCount >= needGodCardCount then
  949. for j = 1, needGodCardCount do
  950. table.insert(tpReplace, godCards[j])
  951. tpCount = tpCount + 1
  952. end
  953. end
  954. end
  955. end
  956. if tpCount == lastCardsLen then
  957. table.insert(result, tpReplace)
  958. end
  959. end
  960. return result
  961. end
  962. -- 获得三顺提示(飞机不带翅膀)
  963. --[[
  964. tip:先for循环最小值+1,直到13-长度/3(为了减少复杂度,这里/3是因为连对中是每3分之1相对的);然后在while循环中判断是否有当前出牌的长度的个数
  965. 有癞子下,不管癞子个数,直接就是返回从小到大的连对,如果需要把包含癞子的放置最后,请自行判断
  966. ]]
  967. function PokerUtil:getSanShunTip(cards, lastData)
  968. local valueList, valueCard, godCards = self:parseCard(cards)
  969. local lastCardInfo = self:getCardsType(lastData)
  970. local nowCardsLen = table.nums(cards)
  971. local lastCardsLen = table.nums(lastData)
  972. local godCardCount = #godCards
  973. local result = {}
  974. for i = lastCardInfo.min + 1, 13 - lastCardsLen / 3 do
  975. local tpIdx = i
  976. local tpCount = 0
  977. local tpReplace = {}
  978. local needGodCardCount = 0
  979. while tpCount < nowCardsLen and (tpCount + needGodCardCount) < lastCardsLen and tpIdx <= 12 and needGodCardCount <= godCardCount do
  980. valueList[tpIdx] = valueList[tpIdx] or 0
  981. if valueList[tpIdx] < 3 then
  982. if self:isUseGodCard() and godCardCount > 0 then
  983. needGodCardCount = needGodCardCount + (3 - valueList[tpIdx])
  984. else
  985. break
  986. end
  987. end
  988. if valueList[tpIdx] >= 3 then
  989. for j = 1, 3 do
  990. table.insert(tpReplace, valueCard[tpIdx][j])
  991. end
  992. tpCount = tpCount + 3
  993. elseif self:isUseGodCard() and valueList[tpIdx] > 0 then -- 三顺中,如果是癞子玩法,也需要把1张,2张的插入,然后再看看是否癞子个数够
  994. local count = valueList[tpIdx]
  995. for j = 1, count do
  996. table.insert(tpReplace, valueCard[tpIdx][j])
  997. end
  998. tpCount = tpCount + count
  999. end
  1000. tpIdx = tpIdx + 1
  1001. end
  1002. if self:isUseGodCard() and godCardCount > 0 then
  1003. if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
  1004. if godCardCount >= needGodCardCount then
  1005. for j = 1, needGodCardCount do
  1006. table.insert(tpReplace, godCards[j])
  1007. tpCount = tpCount + 1
  1008. end
  1009. end
  1010. end
  1011. end
  1012. if tpCount == lastCardsLen then
  1013. table.insert(result, tpReplace)
  1014. end
  1015. end
  1016. return result
  1017. end
  1018. -- 获得3带1提示
  1019. --[[
  1020. tips:直接获取判断是否有大于等于3张的牌值
  1021. 有癞子下,往最后添加判断(值从1,2张中寻找,以从小到大排序,不按需癞子个数排序)
  1022. 只返回3张
  1023. ]]
  1024. function PokerUtil:getSanDaiYiTip(cards, lastData)
  1025. local valueList, valueCard, godCards = self:parseCard(cards)
  1026. local lastCardInfo = self:getCardsType(lastData)
  1027. local nowCardsLen = table.nums(cards)
  1028. local godCardCount = #godCards
  1029. local result = {}
  1030. -- 正常流程
  1031. for i = lastCardInfo.min + 1, 13 do
  1032. local tpReplace = {}
  1033. -- 不包括带自己
  1034. if ((valueList[i] or 0) == 3 and nowCardsLen > 3) or ((valueList[i] or 0) > 3 and nowCardsLen > 4) then
  1035. for j = 1, 3 do
  1036. table.insert(tpReplace, valueCard[i][j])
  1037. end
  1038. table.insert(result, tpReplace)
  1039. end
  1040. end
  1041. -- 癞子流程
  1042. if self:isUseGodCard() and godCardCount > 0 then
  1043. if nowCardsLen > 3 then -- 手牌一定要超过3张
  1044. for i = lastCardInfo.min + 1, 13 do
  1045. local tpReplace = {}
  1046. -- 从1张中获取,2张同理
  1047. if ((valueList[i] or 0) == 1) or ((valueList[i] or 0) == 2) then
  1048. local needGodCardCount = 3 - valueList[i]
  1049. if godCardCount >= needGodCardCount then
  1050. for _, v in ipairs(valueCard[i]) do
  1051. table.insert(tpReplace, v)
  1052. end
  1053. for j = 1, needGodCardCount do
  1054. table.insert(tpReplace, godCards[j])
  1055. end
  1056. table.insert(result, tpReplace)
  1057. end
  1058. end
  1059. end
  1060. end
  1061. end
  1062. return result
  1063. end
  1064. -- 获得3带1对提示(3带2)
  1065. --[[
  1066. tip:只返回3张,在for循环前,会判断是否有对子
  1067. 有癞子下,往最后添加判断(值根据以下判断查找
  1068. 1.有3张,没对子
  1069. 2.没3张,有对子
  1070. 3.没3张,没对子
  1071. 其实就是在需要补充癞子的情况中,添加即可了
  1072. 以从小到大排序,不按需癞子个数排序)
  1073. ]]
  1074. function PokerUtil:getSanDaiYiDuiTip(cards, lastData)
  1075. local valueList, valueCard, godCards = self:parseCard(cards)
  1076. local lastCardInfo = self:getCardsType(lastData)
  1077. local reValueList = self:reParseCard(cards)
  1078. local lastCardsLen = table.nums(lastData)
  1079. local godCardCount = #godCards
  1080. local tResult = {} -- 已添加过的3张数据(用于癞子中,不会重复添加到)
  1081. local result = {}
  1082. -- 正常流程
  1083. if table.nums(reValueList[2]) > 0 then
  1084. for i = lastCardInfo.min + 1, 13 do
  1085. local tpReplace = {}
  1086. if (valueList[i] or 0) >= 3 then
  1087. for j = 1, 3 do
  1088. table.insert(tpReplace, valueCard[i][j])
  1089. end
  1090. table.insert(result, tpReplace)
  1091. tResult[i] = true
  1092. end
  1093. end
  1094. end
  1095. -- 癞子流程
  1096. if self:isUseGodCard() and godCardCount > 0 then
  1097. for i = lastCardInfo.min + 1, 13 do
  1098. local needGodCardCount = 0
  1099. local vCount = valueList[i] or 0
  1100. if vCount <= 3 then
  1101. needGodCardCount = needGodCardCount + (3 - vCount)
  1102. end
  1103. local temp = self:removeGodCards(clone(cards))
  1104. local xorData = self:xorTableData(temp, {i}) -- 排除当前牌i的剩余牌(2张,3张,4张中)
  1105. local t = self:reParseCard(xorData)
  1106. local tCount = #t[2] + #t[3] + #t[4]
  1107. -- 带对子,如果2张,3张,4张都没有情况下
  1108. if tCount <= 0 then
  1109. local needCount = (#reValueList[1] > 0) and 1 or 2 -- 从单张里面补充1张,或者直接补充2张
  1110. needGodCardCount = needGodCardCount + needCount
  1111. end
  1112. if godCardCount >= needGodCardCount then
  1113. if vCount ~= 0 or self:isUseAllSameGodCard() then
  1114. if not tResult[i] then -- 如果之前没有添加过
  1115. local tpReplace = {}
  1116. for j = 1, vCount do
  1117. table.insert(tpReplace, valueCard[i][j])
  1118. end
  1119. for j = 1, (3 - vCount) do
  1120. table.insert(tpReplace, godCards[j])
  1121. end
  1122. table.insert(result, tpReplace)
  1123. tResult[i] = true
  1124. end
  1125. end
  1126. end
  1127. end
  1128. end
  1129. return result
  1130. end
  1131. -- 获得飞机带单提示
  1132. --[[
  1133. tip:根据当前循环for的i值,往后延长最长的,如果一个111222,手中有333444555,则会提示444555
  1134. 有癞子下,不管癞子个数,直接就是返回从小到大的飞机带单,如果需要把包含癞子的放置最后,请自行判断
  1135. 如果有炸弹和3个也能组成飞机,也会先提示
  1136. ]]
  1137. function PokerUtil:getAirPlaneSingleTip(cards, lastData)
  1138. local valueList, valueCard, godCards = self:parseCard(cards)
  1139. local lastCardInfo = self:getCardsType(lastData)
  1140. local nowCardsLen = table.nums(cards)
  1141. local lastCardsLen = table.nums(lastData)
  1142. local godCardCount = #godCards
  1143. local result = {}
  1144. -- if table.nums(valueList) > lastCardsLen / 4 then -- 之前的,不知道为什么这么判断
  1145. if nowCardsLen >= lastCardsLen then
  1146. for i = lastCardInfo.min + 1, 13 - lastCardsLen / 4 do
  1147. local tpIdx = i
  1148. local tpCount = 0
  1149. local tpReplace = {}
  1150. local needGodCardCount = 0
  1151. while tpCount < nowCardsLen and (tpCount + needGodCardCount) < lastCardsLen and tpIdx <= 12 and needGodCardCount <= godCardCount do
  1152. valueList[tpIdx] = valueList[tpIdx] or 0
  1153. if valueList[tpIdx] < 3 then
  1154. if self:isUseGodCard() and godCardCount > 0 then
  1155. needGodCardCount = needGodCardCount + (3 - valueList[tpIdx])
  1156. else
  1157. break
  1158. end
  1159. end
  1160. if valueList[tpIdx] >= 3 then
  1161. for j = 1, 3 do
  1162. table.insert(tpReplace, valueCard[tpIdx][j])
  1163. end
  1164. tpCount = tpCount + 3
  1165. elseif self:isUseGodCard() and valueList[tpIdx] > 0 then
  1166. local count = valueList[tpIdx]
  1167. for j = 1, count do
  1168. table.insert(tpReplace, valueCard[tpIdx][j])
  1169. end
  1170. tpCount = tpCount + count
  1171. end
  1172. tpCount = tpCount + 1 -- (包含带牌,所以+1)
  1173. tpIdx = tpIdx + 1
  1174. end
  1175. if self:isUseGodCard() and godCardCount > 0 then
  1176. if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
  1177. if godCardCount >= needGodCardCount then
  1178. for j = 1, needGodCardCount do
  1179. table.insert(tpReplace, godCards[j])
  1180. tpCount = tpCount + 1
  1181. end
  1182. end
  1183. end
  1184. end
  1185. if tpCount == lastCardsLen then
  1186. table.insert(result, tpReplace)
  1187. end
  1188. end
  1189. end
  1190. return result
  1191. end
  1192. -- 获得飞机带对提示
  1193. --[[
  1194. tip:会先判断手牌中2张是否大于等于2个数量
  1195. 有癞子下,不管癞子个数,直接就是返回从小到大的飞机带单,如果需要把包含癞子的放置最后,请自行判断
  1196. 如果有炸弹和3个也能组成飞机,也会先提示
  1197. 飞机带对的流程比较麻烦,这里理一下:
  1198. 1,判断手牌是否大于等于出的牌
  1199. 2.判断飞机牌是否有满足的(运用for从min到A,运用while判断连续值)
  1200. while跳出循环的条件
  1201. <1>(连续值长度大于手牌长度(这里有点多余,因为是飞机票和带牌独立判断))
  1202. <2>(连续值长度与需要癞子牌数量超过飞机长度lastCardsLen/5*3,不用特殊判断是否有癞子,如果没癞子,needGodCardCount为0)
  1203. <3>当前连续值tpIdx超过A值(2,小王,大王)
  1204. <4>需要癞子牌数量超过手牌癞子牌数量
  1205. 1)有癞子的情况,如果连续值中没有超过3张,先不跳出while循环,存储需要癞子的数量needGodCardCount.
  1206. 2)没有癞子额情况,如果连续值中没有3张,直接跳出while循环.
  1207. 3)如果1),2)条件都满足了,并且该连续值大于等于3张,插入值待用牌组tpReplace.
  1208. 4)如果1),2)条件都满足了,但是连续值并没有3张。如果开启了癞子玩法,则还是把当前的连续值个数插入待用牌组tpReplace,这里不需要增加所需癞子个数,因为1)条件内已增加.
  1209. 5)while循环后,补充当前所需的癞子牌个数,插入至待用牌组.
  1210. 6)此时tpCount一定等于lastCardsLen/5*3(飞机长度),如果有错,可以查看是否跳出了while循环.
  1211. 3.然后判断带的牌是否有满足的
  1212. 1)可带对子canBeDuiZiCount里面是否满足带牌数量
  1213. 2)如果不够则用癞子数量补充
  1214. 3)1),2)条件过后,tpCount一定等于出牌长度,才可插入result表内,否则则认为是癞子牌数量不够.
  1215. ]]
  1216. function PokerUtil:getAirPlaneDuiTip(cards, lastData)
  1217. local valueList, valueCard, godCards = self:parseCard(cards)
  1218. local lastCardInfo = self:getCardsType(lastData)
  1219. local nowCardsLen = table.nums(cards)
  1220. local lastCardsLen = table.nums(lastData)
  1221. local reValueList = self:reParseCard(cards)
  1222. local godCardCount = #godCards
  1223. local result = {}
  1224. if nowCardsLen >= lastCardsLen then
  1225. for i = lastCardInfo.min + 1, 13 - lastCardsLen / 5 do
  1226. local tpIdx = i
  1227. local tpCount = 0
  1228. local tpReplace = {}
  1229. local needGodCardCount = 0
  1230. -- 判断飞机牌
  1231. while tpCount < nowCardsLen and (tpCount + needGodCardCount) < (lastCardsLen/5*3) and tpIdx <= 12 and needGodCardCount <= godCardCount do
  1232. valueList[tpIdx] = valueList[tpIdx] or 0
  1233. if valueList[tpIdx] < 3 then
  1234. if self:isUseGodCard() and godCardCount > 0 then
  1235. needGodCardCount = needGodCardCount + (3 - valueList[tpIdx])
  1236. else
  1237. break
  1238. end
  1239. end
  1240. if valueList[tpIdx] >= 3 then
  1241. for j = 1, 3 do
  1242. table.insert(tpReplace, valueCard[tpIdx][j])
  1243. end
  1244. tpCount = tpCount + 3
  1245. elseif self:isUseGodCard() and valueList[tpIdx] > 0 then
  1246. local count = valueList[tpIdx]
  1247. for j = 1, count do
  1248. table.insert(tpReplace, valueCard[tpIdx][j])
  1249. end
  1250. tpCount = tpCount + count
  1251. end
  1252. tpIdx = tpIdx + 1
  1253. end
  1254. if self:isUseGodCard() and godCardCount > 0 then
  1255. if godCardCount >= needGodCardCount then
  1256. for j = 1, needGodCardCount do
  1257. table.insert(tpReplace, godCards[j])
  1258. tpCount = tpCount + 1
  1259. end
  1260. end
  1261. end
  1262. -- 判断飞机带的牌
  1263. local temp = self:removeGodCards(clone(cards))
  1264. local rTemp = {} -- 成为飞机的飞机牌
  1265. for j = i, (i + lastCardsLen/5 - 1) do
  1266. table.insert(rTemp, j)
  1267. end
  1268. local xorData = self:xorTableData(temp, rTemp)
  1269. local t = self:reParseCard(xorData)
  1270. local canBeDuiZiCount = #t[2] + #t[3] + #t[4] * 2 -- 可组成对子个数(4个可以组成2个对子)
  1271. if canBeDuiZiCount >= lastCardsLen/5 then -- 带的对子是否刚好或者超过上家牌的飞机长度
  1272. tpCount = tpCount + (lastCardsLen/5*2) -- 补充带的牌的牌数
  1273. elseif self:isUseGodCard() and godCardCount > 0 then -- 如果不够的话,补充
  1274. local totalNeedCount = lastCardsLen/5 -- 总共需要的对子
  1275. totalNeedCount = totalNeedCount - canBeDuiZiCount -- 移除现在的对子数量,即,最后剩下补充的对子个数
  1276. tpCount = tpCount + canBeDuiZiCount * 2 -- 补充有的对子
  1277. local needCount = 0
  1278. for j = 1, totalNeedCount do
  1279. if #t[1] - j >= 0 then -- 1个的数量够
  1280. tpCount = tpCount + 1 -- 如果有1张,先补充1张
  1281. needCount = needCount + 1
  1282. else
  1283. needCount = needCount + 2
  1284. end
  1285. end
  1286. needGodCardCount = needGodCardCount + needCount
  1287. if godCardCount >= needGodCardCount then
  1288. for i = 1, needCount do
  1289. tpCount = tpCount + 1 -- 剩余的万能牌,补充数量
  1290. end
  1291. end
  1292. end
  1293. if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
  1294. if tpCount == lastCardsLen then
  1295. table.insert(result, tpReplace)
  1296. end
  1297. end
  1298. end
  1299. end
  1300. return result
  1301. end
  1302. -- 获得4带2单提示
  1303. --[[
  1304. tips:先判断手牌是否大于等于6张,然后寻找4个
  1305. 有癞子下,往最后添加判断(值从1,2张中寻找,以从小到大排序,不按需癞子个数排序)
  1306. 只返回4张,所以可能会跟炸弹一致.
  1307. ]]
  1308. function PokerUtil:getSiDaiErSingleTip(cards, lastData)
  1309. local valueList, valueCard, godCards = self:parseCard(cards)
  1310. local lastCardInfo = self:getCardsType(lastData)
  1311. local nowCardsLen = table.nums(cards)
  1312. local godCardCount = #godCards
  1313. local result = {}
  1314. -- 正常流程
  1315. if nowCardsLen >= 6 then
  1316. for i = lastCardInfo.min + 1, 13 do
  1317. local tpReplace = {}
  1318. if (valueList[i] or 0) >= 4 and nowCardsLen > 4 then
  1319. for j = 1, 4 do
  1320. table.insert(tpReplace, valueCard[i][j])
  1321. end
  1322. table.insert(result, tpReplace)
  1323. end
  1324. end
  1325. end
  1326. -- 癞子流程
  1327. if self:isUseGodCard() and godCardCount > 0 then
  1328. if nowCardsLen > 4 then
  1329. for i = lastCardInfo.min + 1, 13 do
  1330. local tpReplace = {}
  1331. -- 从1张中获取,2张,3张同理
  1332. if ((valueList[i] or 0) == 1) or ((valueList[i] or 0) == 2) or ((valueList[i] or 0) == 3) then
  1333. local needGodCardCount = 4 - valueList[i]
  1334. if godCardCount >= needGodCardCount then
  1335. for _, v in ipairs(valueCard[i]) do
  1336. table.insert(tpReplace, v)
  1337. end
  1338. for j = 1, needGodCardCount do
  1339. table.insert(tpReplace, godCards[j])
  1340. end
  1341. table.insert(result, tpReplace)
  1342. end
  1343. end
  1344. end
  1345. end
  1346. end
  1347. return result
  1348. end
  1349. -- 获得4带2对提示
  1350. --[[
  1351. tips:会先判断手牌中2张是否大于等于2个数量,只弹4张
  1352. 无癞子(正常流程)情况下,这里有bug,因为只会从对子中判断,不会冲超过2张中判断。不过没什么事,因为是只贪4张,所以炸弹也会算进去
  1353. 有癞子情况下则不会
  1354. ]]
  1355. function PokerUtil:getSiDaiErDuiTip(cards, lastData)
  1356. local valueList, valueCard, godCards = self:parseCard(cards)
  1357. local lastCardInfo = self:getCardsType(lastData)
  1358. local nowCardsLen = table.nums(cards)
  1359. local lastCardsLen = table.nums(lastData)
  1360. local reValueList = self:reParseCard(cards)
  1361. local godCardCount = #godCards
  1362. local tResult = {} -- 已添加过的3张数据(用于癞子中,不会重复添加到)
  1363. local result = {}
  1364. -- 正常流程
  1365. if table.nums(reValueList[2]) >= 2 then
  1366. for i = lastCardInfo.min + 1, 13 do
  1367. local tpReplace = {}
  1368. if (valueList[i] or 0) >= 4 and nowCardsLen > 4 then
  1369. for j = 1, 4 do
  1370. table.insert(tpReplace, valueCard[i][j])
  1371. end
  1372. table.insert(result, tpReplace)
  1373. tResult[i] = true
  1374. end
  1375. end
  1376. end
  1377. -- 癞子流程
  1378. if self:isUseGodCard() and godCardCount > 0 then
  1379. for i = lastCardInfo.min + 1, 13 do
  1380. local needGodCardCount = 0
  1381. local vCount = valueList[i] or 0
  1382. if vCount <= 4 then
  1383. needGodCardCount = needGodCardCount + (4 - vCount)
  1384. end
  1385. local temp = self:removeGodCards(clone(cards))
  1386. local xorData = self:xorTableData(temp, {i}) -- 排除当前牌i的剩余牌(2张,3张,4张中)
  1387. local t = self:reParseCard(xorData)
  1388. local canBeDuiZiCount = #t[2] + #t[3] + #t[4] * 2 -- 可组成对子个数(4个可以组成2个对子)
  1389. -- 带对子,如果2张,3张,4张所组成的对子个数总和少于1个
  1390. if canBeDuiZiCount <= 1 then
  1391. local totalNeedCount = 2 - canBeDuiZiCount
  1392. local needCount = 0
  1393. for j = 1, totalNeedCount do
  1394. if #t[1] - j >= 0 then -- 1个的数量够
  1395. needCount = needCount + 1
  1396. else
  1397. needCount = needCount + 2
  1398. end
  1399. end
  1400. needGodCardCount = needGodCardCount + needCount
  1401. end
  1402. if godCardCount >= needGodCardCount then
  1403. if vCount ~= 0 or self:isUseAllSameGodCard() then
  1404. if not tResult[i] then -- 如果之前没有添加过
  1405. local tpReplace = {}
  1406. for j = 1, vCount do
  1407. table.insert(tpReplace, valueCard[i][j])
  1408. end
  1409. for j = 1, (4 - vCount) do
  1410. table.insert(tpReplace, godCards[j])
  1411. end
  1412. table.insert(result, tpReplace)
  1413. tResult[i] = true
  1414. end
  1415. end
  1416. end
  1417. end
  1418. end
  1419. return result
  1420. end
  1421. -- 获得炸弹提示
  1422. --[[
  1423. 无癞子情况下,从4张中查找
  1424. 有癞子情况下,从1,2,3张中查找(以大到小排序,不按所需癞子个数),往最后添加
  1425. ]]
  1426. function PokerUtil:getBombTip(cards, lastData)
  1427. local valueList, valueCard, godCards = self:parseCard(cards)
  1428. local lastCardInfo = self:getCardsType(lastData)
  1429. local godCardCount = #godCards
  1430. local result = {}
  1431. local tpIndex = lastCardInfo.cardType < defs.CARD_TYPE.BOMB and 1 or lastCardInfo.min + 1
  1432. for i = tpIndex, 13 do
  1433. local tpReplace = {}
  1434. if (valueList[i] or 0) >= 4 then
  1435. for j = 1, 4 do
  1436. table.insert(tpReplace, valueCard[i][j])
  1437. end
  1438. table.insert(result, tpReplace)
  1439. end
  1440. end
  1441. if self:isUseGodCard() and godCardCount > 0 then
  1442. for i = tpIndex, 13 do
  1443. local tpReplace = {}
  1444. valueList[i] = valueList[i] or 0
  1445. if valueList[i] < 4 then
  1446. local needGodCardCount = 4 - valueList[i]
  1447. if valueList[i] ~= 0 or self:isUseAllSameGodCard() then
  1448. if godCardCount >= needGodCardCount then
  1449. for _, v in ipairs(valueCard[i]) do
  1450. table.insert(tpReplace, v)
  1451. end
  1452. for j = 1, needGodCardCount do
  1453. table.insert(tpReplace, godCards[j])
  1454. end
  1455. table.insert(result, tpReplace)
  1456. end
  1457. end
  1458. end
  1459. end
  1460. end
  1461. return result
  1462. end
  1463. -- 获得王炸提示
  1464. --[[
  1465. 有癞子下,往后插入
  1466. 两张癞子不算王炸
  1467. ]]
  1468. function PokerUtil:getBombKingTip(cards, lastData)
  1469. local valueList, valueCard, godCards = self:parseCard(cards)
  1470. local godCardCount = #godCards
  1471. local result = {}
  1472. if (valueList[Value_Joker_Little] or 0) > 0 and (valueList[Value_Joker_Big] or 0) > 0 then
  1473. local tpReplace = {}
  1474. table.insert(tpReplace, 0x4e)
  1475. table.insert(tpReplace, 0x4f)
  1476. table.insert(result, tpReplace)
  1477. end
  1478. if self:isUseGodCard() and godCardCount > 0 then
  1479. if (valueList[Value_Joker_Little] or 0) > 0 then
  1480. local tpReplace = {}
  1481. table.insert(tpReplace, 0x4e)
  1482. table.insert(tpReplace, godCards[1])
  1483. table.insert(result, tpReplace)
  1484. end
  1485. if (valueList[Value_Joker_Big] or 0) > 0 then
  1486. local tpReplace = {}
  1487. table.insert(tpReplace, 0x4f)
  1488. table.insert(tpReplace, godCards[1])
  1489. table.insert(result, tpReplace)
  1490. end
  1491. if self:isUseAllSameGodCard() and godCardCount > 1 then
  1492. local tpReplace = {}
  1493. table.insert(tpReplace, godCards[1])
  1494. table.insert(tpReplace, godCards[2])
  1495. table.insert(result, tpReplace)
  1496. end
  1497. end
  1498. return result
  1499. end
  1500. -----------------------------------------------------------------------------------------------------------------
  1501. -------------------------------------- 以下是检查牌型 ------------------------------------------------------
  1502. -----------------------------------------------------------------------------------------------------------------
  1503. --[[
  1504. cards 是具体牌值,即1~K,从小到大排序
  1505. ]]
  1506. -- 是否是单张
  1507. function PokerUtil:isSingle(cards, godCards)
  1508. if #cards > 0 then
  1509. return true, defs.CARD_TYPE.SINGLE, cards[1]
  1510. end
  1511. local godCardCount = #godCards
  1512. if self:isUseGodCard() and godCardCount > 0 then
  1513. local godCardSingleValue = (self.God_Card_Single_Value and self.God_Card_Single_Value > 0) and self.God_Card_Single_Value or godCards[1]
  1514. return true, defs.CARD_TYPE.SINGLE, self.God_Card_Single_Value or godCardSingleValue, true
  1515. end
  1516. return false
  1517. end
  1518. -- 是否是对子
  1519. function PokerUtil:isDouble(cards, godCards)
  1520. if cards[1] and cards[2] then
  1521. if cards[1] == cards[2] then
  1522. return true, defs.CARD_TYPE.DUIZI,cards[1]
  1523. end
  1524. end
  1525. local godCardCount = #godCards
  1526. if self:isUseGodCard() and godCardCount > 0 then
  1527. if #cards > 0 then
  1528. if self:checkIsTheSameCards(cards) then
  1529. return true, defs.CARD_TYPE.DUIZI, cards[1], true
  1530. end
  1531. else
  1532. if self:isUseAllSameGodCard() then
  1533. return true, defs.CARD_TYPE.DUIZI, godCards[1], true
  1534. end
  1535. end
  1536. end
  1537. return false
  1538. end
  1539. -- 是否是三张(不带)
  1540. function PokerUtil:isThree(cards, godCards)
  1541. if cards[1] and cards[2] and cards[3] then
  1542. if cards[1] == cards[2] and cards[2] == cards[3] then
  1543. return true, defs.CARD_TYPE.SANZHANG, cards[1]
  1544. end
  1545. end
  1546. local godCardCount = #godCards
  1547. if self:isUseGodCard() and godCardCount > 0 then
  1548. if #cards > 0 then
  1549. if self:checkIsTheSameCards(cards) then
  1550. return true, defs.CARD_TYPE.SANZHANG, cards[1], true
  1551. end
  1552. else
  1553. if self:isUseAllSameGodCard() then
  1554. return true, defs.CARD_TYPE.SANZHANG, godCards[1], true
  1555. end
  1556. end
  1557. end
  1558. return false
  1559. end
  1560. -- 是否是顺子
  1561. function PokerUtil:isLine(cards, godCards)
  1562. local isHaveKindOr2 = false
  1563. for i, val in ipairs(cards) do
  1564. if val == Value_Joker_Little or val == Value_Joker_Big or val == Value_2 then
  1565. isHaveKindOr2 = true
  1566. break
  1567. end
  1568. end
  1569. -- 顺子中不允许包括2,大王,小王
  1570. if isHaveKindOr2 then
  1571. return false
  1572. end
  1573. -- 检查单张总长度是否与传入相同,因为顺子是必须都是单个值
  1574. local reValueList = self:reParseCard(cards)
  1575. if table.nums(reValueList[1]) ~= #(cards) then
  1576. return false
  1577. end
  1578. -- 判断是否为顺子,计算最大值与最小值的差的绝对值是否与总长度-1相同
  1579. local m = (#cards > 0) and (math.abs(cards[1] - cards[#cards])) or 0
  1580. local godCardCount = #godCards
  1581. if m == #cards - 1 and godCardCount == 0 then
  1582. return true, defs.CARD_TYPE.SHUNZI, cards[1]
  1583. end
  1584. if self:isUseGodCard() and godCardCount > 0 then
  1585. local needGodCardCount = m + 1 - #cards
  1586. print('jxjx 是否是顺子判断')
  1587. print('jxjx 是否是顺子判断 godCardCount万能牌数', godCardCount)
  1588. print('jxjx 是否是顺子判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
  1589. if #cards > 0 then
  1590. -- 判断空缺位是否少于万能牌数即可。m为最大差值,m+1-#cards(needGodCardCount)即为cards的空缺数字个数。倘若为0,则说明cards是个连续数值,那么万能牌在后面添加即可
  1591. if godCardCount >= needGodCardCount then -- 有万能牌支撑
  1592. return true, defs.CARD_TYPE.SHUNZI, cards[1], true
  1593. end
  1594. else
  1595. -- 全是万能牌
  1596. if self:isUseAllSameGodCard() then
  1597. return true, defs.CARD_TYPE.SHUNZI, godCards[1], true
  1598. end
  1599. end
  1600. end
  1601. return false
  1602. end
  1603. -- 是否是双顺(连对)
  1604. function PokerUtil:isDoubleLine(cards, godCards)
  1605. local isHaveKindOr2 = false
  1606. for i, val in ipairs(cards) do
  1607. if val == Value_Joker_Little or val == Value_Joker_Big or val == Value_2 then
  1608. isHaveKindOr2 = true
  1609. break
  1610. end
  1611. end
  1612. -- 顺子中不允许包括2,大王,小王
  1613. if isHaveKindOr2 then
  1614. return false
  1615. end
  1616. -- 连对里面不能有超过2张的牌组
  1617. local reValueList = self:reParseCard(cards)
  1618. if #reValueList[3] > 0 or #reValueList[4] > 0 then
  1619. return false
  1620. end
  1621. -- 检查2张的个数是否与总长度的一半相同,因为连对是必须都是对子值
  1622. local godCardCount = #godCards
  1623. if godCardCount == 0 then -- 这里需要加万能牌数量判断,因为下面的判断条件只针对没有万能牌,不然3345带万能牌这样会直接false
  1624. if table.nums(reValueList[2]) ~= math.floor(#(cards) / 2) then
  1625. return false
  1626. end
  1627. end
  1628. -- 判断是否为对子,计算最大值与最小值的差的绝对值是否与总长度/2-1相同
  1629. local m = (#cards > 0) and (math.abs(cards[1] - cards[#cards])) or 0
  1630. if m == #cards/2 - 1 and godCardCount == 0 then
  1631. return true, defs.CARD_TYPE.SHUANGSHUN, cards[1]
  1632. end
  1633. if self:isUseGodCard() and godCardCount > 0 then
  1634. local needGodCardCount = (m + 1)*2 - #cards
  1635. print('jxjx 是否是连对判断')
  1636. print('jxjx 是否是连对判断 godCardCount万能牌数', godCardCount)
  1637. print('jxjx 是否是连对判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
  1638. if #cards > 0 then
  1639. -- 判断空缺位是否少于万能牌数即可。m为最大差值,m+1-#cards(needGodCardCount)即为cards的空缺数字个数。倘若为0,则说明cards是个连续数值,那么万能牌在后面添加即可
  1640. if godCardCount >= needGodCardCount then -- 有万能牌支撑
  1641. return true, defs.CARD_TYPE.SHUANGSHUN, cards[1], true
  1642. end
  1643. else
  1644. -- 全是万能牌
  1645. if self:isUseAllSameGodCard() then
  1646. return true, defs.CARD_TYPE.SHUANGSHUN, godCards[1], true
  1647. end
  1648. end
  1649. end
  1650. return false
  1651. end
  1652. -- 是否是三带一(单张)
  1653. function PokerUtil:isThreeTakeOne(cards, godCards)
  1654. print('jxjx 判断是否是三带一 isThreeTakeOne')
  1655. if not self:can31() then
  1656. return false
  1657. end
  1658. -- 1张,2张,3张的数量的总和最多数量不能超过2个
  1659. local reValueList = self:reParseCard(cards)
  1660. local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3])
  1661. if count > 2 then
  1662. return false
  1663. end
  1664. -- 2张的数量不能超过1个(3带单,4带单独有判断)
  1665. if table.nums(reValueList[2]) > 1 then
  1666. return false
  1667. end
  1668. if table.nums(reValueList[3]) == 1 then
  1669. return true, defs.CARD_TYPE.SANDAIYI, reValueList[3][1]
  1670. elseif table.nums(reValueList[4]) == 1 then -- 该文件兼容所有牌型,所以4张一样也可以是3带1,所以牌型判断的先后顺序要插入正确
  1671. return true, defs.CARD_TYPE.SANDAIYI, reValueList[4][1]
  1672. end
  1673. local godCardCount = #godCards
  1674. if self:isUseGodCard() and godCardCount > 0 then
  1675. if #cards > 0 then
  1676. local needGodCardCount = 4 - #cards
  1677. print('jxjx 是否是三带一判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
  1678. if godCardCount >= needGodCardCount then
  1679. if needGodCardCount == 3 then
  1680. return true, defs.CARD_TYPE.SANDAIYI, cards[1], true
  1681. else
  1682. if table.nums(reValueList[3]) > 0 then
  1683. return true, defs.CARD_TYPE.SANDAIYI, reValueList[3][1], true
  1684. elseif table.nums(reValueList[2]) > 0 then
  1685. return true, defs.CARD_TYPE.SANDAIYI, reValueList[2][1], true
  1686. else
  1687. -- 这里因为不会有1对的数据进来,所以不加判断或者连接表了(与下面的3带2判断相似又非似)
  1688. local temp = clone(reValueList[1])
  1689. table.sort(temp, PokerUtil.sortOrder)
  1690. return true, defs.CARD_TYPE.SANDAIYI, temp[#temp], true
  1691. end
  1692. end
  1693. end
  1694. else
  1695. if self:isUseAllSameGodCard() then
  1696. return true, defs.CARD_TYPE.SANDAIYI, godCards[1], true
  1697. end
  1698. end
  1699. end
  1700. return false
  1701. end
  1702. -- 是否是三带二(对子)
  1703. function PokerUtil:isThreeTakeTwo(cards, godCards)
  1704. if not self:can32() then
  1705. return false
  1706. end
  1707. -- 1张,2张,3张的数量的总和最多数量不能超过2个
  1708. local reValueList = self:reParseCard(cards)
  1709. local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3])
  1710. if count > 2 then
  1711. return false
  1712. end
  1713. -- 3带1对里面不能有4张(如果有4张,剩余带的牌一定是单张不是对子)
  1714. if table.nums(reValueList[4]) > 0 then
  1715. return false
  1716. end
  1717. if table.nums(reValueList[3]) == 1 and table.nums(reValueList[2]) == 1 then
  1718. return true, defs.CARD_TYPE.SANDAIDUI, reValueList[3][1]
  1719. end
  1720. local godCardCount = #godCards
  1721. if self:isUseGodCard() and godCardCount > 0 then
  1722. if #cards > 0 then
  1723. local needGodCardCount = 5 - #cards
  1724. print('jxjx 是否是三带二判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
  1725. if godCardCount >= needGodCardCount then
  1726. if needGodCardCount == 4 then
  1727. return true, defs.CARD_TYPE.SANDAIDUI, cards[1], true
  1728. else
  1729. if table.nums(reValueList[3]) > 0 then
  1730. return true, defs.CARD_TYPE.SANDAIDUI, reValueList[3][1], true
  1731. else
  1732. -- 如果是2手牌与3万能牌(2+3)或者3手牌与2张万能牌(3+2)或者4手牌与1张万能牌(4+1)组合,则判断手牌中最大的,作为3带
  1733. local t1 = clone(reValueList[1])
  1734. local t2 = clone(reValueList[2])
  1735. local temp = self:addTableData(t1, t2)
  1736. table.sort(temp, PokerUtil.sortOrder)
  1737. return true, defs.CARD_TYPE.SANDAIDUI, temp[#temp], true
  1738. end
  1739. end
  1740. end
  1741. else
  1742. if self:isUseAllSameGodCard() then
  1743. return true, defs.CARD_TYPE.SANDAIDUI, godCards[1], true
  1744. end
  1745. end
  1746. end
  1747. return false
  1748. end
  1749. -- 是否是四带一(单)
  1750. function PokerUtil:isFourTakeOneSingle(cards, godCards)
  1751. if not self:can41() then
  1752. return false
  1753. end
  1754. -- 1张,2张,3张,4张的数量的总和最多数量不能超过2个
  1755. local reValueList = self:reParseCard(cards)
  1756. local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3]) + table.nums(reValueList[4])
  1757. if count > 2 then
  1758. return false
  1759. end
  1760. -- 2张的数量不能超过1个(3带单,4带单独有判断)
  1761. if table.nums(reValueList[2]) > 1 then
  1762. return false
  1763. end
  1764. if table.nums(reValueList[4]) == 1 then
  1765. return true, defs.CARD_TYPE.SIDAIYI, reValueList[4][1]
  1766. end
  1767. local godCardCount = #godCards
  1768. if self:isUseGodCard() and godCardCount > 0 then
  1769. if #cards > 0 then
  1770. local needGodCardCount = 5 - #cards
  1771. print('jxjx 是否是四带一判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
  1772. if godCardCount >= needGodCardCount then
  1773. if needGodCardCount == 4 then
  1774. return true, defs.CARD_TYPE.SIDAIYI, cards[1], true
  1775. else
  1776. if table.nums(reValueList[4]) > 0 then
  1777. return true, defs.CARD_TYPE.SIDAIYI, reValueList[4][1], true
  1778. elseif table.nums(reValueList[3]) > 0 then
  1779. return true, defs.CARD_TYPE.SIDAIYI, reValueList[3][1], true
  1780. elseif table.nums(reValueList[2]) > 0 then
  1781. return true, defs.CARD_TYPE.SIDAIYI, reValueList[2][1], true
  1782. else
  1783. local temp = clone(reValueList[1])
  1784. table.sort(temp, PokerUtil.sortOrder)
  1785. return true, defs.CARD_TYPE.SIDAIYI, temp[#temp], true
  1786. end
  1787. end
  1788. end
  1789. else
  1790. if self:isUseAllSameGodCard() then
  1791. return true, defs.CARD_TYPE.SIDAIYI, godCards[1], true
  1792. end
  1793. end
  1794. end
  1795. return false
  1796. end
  1797. -- 是否是四带一对(对子)
  1798. function PokerUtil:isFourTakeOneDouble(cards, godCards)
  1799. if not self:can42() then
  1800. return false
  1801. end
  1802. -- 1张,2张,3张,4张的数量的总和最多数量不能超过2个
  1803. local reValueList = self:reParseCard(cards)
  1804. local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3]) + table.nums(reValueList[4])
  1805. if count > 2 then
  1806. return false
  1807. end
  1808. if table.nums(reValueList[4]) == 1 and table.nums(reValueList[2]) == 1 then
  1809. return true, defs.CARD_TYPE.SIDAIYIDUI, reValueList[4][1]
  1810. end
  1811. local godCardCount = #godCards
  1812. if self:isUseGodCard() and godCardCount > 0 then
  1813. if #cards > 0 then
  1814. local needGodCardCount = 6 - #cards
  1815. print('jxjx 是否是四带一对判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
  1816. if godCardCount >= needGodCardCount then
  1817. if needGodCardCount == 5 then
  1818. return true, defs.CARD_TYPE.SIDAIYIDUI, cards[1], true
  1819. else
  1820. if table.nums(reValueList[4]) > 0 then
  1821. return true, defs.CARD_TYPE.SIDAIYIDUI, reValueList[4][1], true
  1822. elseif table.nums(reValueList[3]) > 0 then
  1823. return true, defs.CARD_TYPE.SIDAIYIDUI, reValueList[3][1], true
  1824. else
  1825. local t1 = clone(reValueList[1])
  1826. local t2 = clone(reValueList[2])
  1827. local temp = self:addTableData(t1, t2)
  1828. table.sort(temp, PokerUtil.sortOrder)
  1829. return true, defs.CARD_TYPE.SIDAIYIDUI, temp[#temp], true
  1830. end
  1831. end
  1832. end
  1833. else
  1834. if self:isUseAllSameGodCard() then
  1835. return true, defs.CARD_TYPE.SIDAIYIDUI, godCards[1], true
  1836. end
  1837. end
  1838. end
  1839. return false
  1840. end
  1841. -- 是否是四带二单张
  1842. function PokerUtil:isFourTakeTwoSingle(cards, godCards)
  1843. if not self:can411() then
  1844. return false
  1845. end
  1846. if not self:checkIsCanCombination(cards, godCards, 4) then
  1847. return false
  1848. end
  1849. -- 1张,2张,3张,4张的数量的总和最多数量不能超过3个
  1850. local reValueList = self:reParseCard(cards)
  1851. local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3]) + table.nums(reValueList[4])
  1852. if count > 3 then
  1853. return false
  1854. end
  1855. -- 2张的数量不能超过2个
  1856. if table.nums(reValueList[2]) > 2 then
  1857. return false
  1858. end
  1859. if table.nums(reValueList[4]) == 1 then
  1860. return true, defs.CARD_TYPE.SIDAIER, reValueList[4][1]
  1861. end
  1862. local godCardCount = #godCards
  1863. if self:isUseGodCard() and godCardCount > 0 then
  1864. if #cards > 0 then
  1865. local needGodCardCount = 6 - #cards
  1866. print('jxjx 是否是四带二单张判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
  1867. if godCardCount >= needGodCardCount then
  1868. if needGodCardCount == 5 then
  1869. return true, defs.CARD_TYPE.SIDAIER, cards[1], true
  1870. elseif needGodCardCount == 2 then -- 针对1223**这种
  1871. if table.nums(reValueList[3]) > 0 then
  1872. return true, defs.CARD_TYPE.SIDAIER, reValueList[3][1], true
  1873. elseif table.nums(reValueList[2]) > 0 then
  1874. local temp = clone(reValueList[2])
  1875. table.sort(temp, PokerUtil.sortOrder)
  1876. return true, defs.CARD_TYPE.SIDAIER, temp[#temp], true
  1877. end
  1878. else
  1879. if table.nums(reValueList[4]) > 0 then
  1880. return true, defs.CARD_TYPE.SIDAIER, reValueList[4][1], true
  1881. elseif table.nums(reValueList[3]) > 0 then
  1882. return true, defs.CARD_TYPE.SIDAIER, reValueList[3][1], true
  1883. else
  1884. local t1 = clone(reValueList[1])
  1885. local t2 = clone(reValueList[2])
  1886. local temp = self:addTableData(t1, t2)
  1887. table.sort(temp, PokerUtil.sortOrder)
  1888. return true, defs.CARD_TYPE.SIDAIER, temp[#temp], true
  1889. end
  1890. end
  1891. end
  1892. else
  1893. if self:isUseAllSameGodCard() then
  1894. return true, defs.CARD_TYPE.SIDAIER, godCards[1], true
  1895. end
  1896. end
  1897. end
  1898. return false
  1899. end
  1900. -- 是否是四带二对子
  1901. function PokerUtil:isFourTakeTwoDouble(cards, godCards)
  1902. if not self:can422() then
  1903. return false
  1904. end
  1905. if not self:checkIsCanCombination(cards, godCards, 4) then
  1906. return false
  1907. end
  1908. -- 1张,2张,3张,4张的数量的总和最多数量不能超过3个
  1909. local reValueList = self:reParseCard(cards)
  1910. local count = table.nums(reValueList[1]) + table.nums(reValueList[2]) + table.nums(reValueList[3]) + table.nums(reValueList[4])
  1911. if count > 3 then
  1912. return false
  1913. end
  1914. -- 3张的数量不能超过1个
  1915. if table.nums(reValueList[3]) > 1 then
  1916. return false
  1917. end
  1918. if table.nums(reValueList[4]) == 1 and table.nums(reValueList[2]) == 2 then
  1919. return true, defs.CARD_TYPE.SIDAIERDUI, reValueList[4][1]
  1920. end
  1921. local godCardCount = #godCards
  1922. if self:isUseGodCard() and godCardCount > 0 then
  1923. if #cards > 0 then
  1924. local needGodCardCount = 8 - #cards
  1925. print('jxjx 是否是四带二对子判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
  1926. if godCardCount >= needGodCardCount then
  1927. if needGodCardCount == 7 then
  1928. return true, defs.CARD_TYPE.SIDAIERDUI, cards[1], true
  1929. else
  1930. if table.nums(reValueList[4]) > 0 then
  1931. return true, defs.CARD_TYPE.SIDAIERDUI, reValueList[4][1], true
  1932. elseif table.nums(reValueList[3]) > 0 then
  1933. return true, defs.CARD_TYPE.SIDAIERDUI, reValueList[3][1], true
  1934. else
  1935. local t1 = clone(reValueList[1])
  1936. local t2 = clone(reValueList[2])
  1937. local temp = self:addTableData(t1, t2)
  1938. table.sort(temp, PokerUtil.sortOrder)
  1939. return true, defs.CARD_TYPE.SIDAIERDUI, temp[#temp], true
  1940. end
  1941. end
  1942. end
  1943. else
  1944. if self:isUseAllSameGodCard() then
  1945. return true, defs.CARD_TYPE.SIDAIERDUI, godCards[1], true
  1946. end
  1947. end
  1948. end
  1949. return false
  1950. end
  1951. -- 是否是三顺(飞机不带333444)
  1952. function PokerUtil:isPlaneNoTake(cards, godCards)
  1953. local isHaveKindOr2 = false
  1954. for i, val in ipairs(cards) do
  1955. if val == Value_Joker_Little or val == Value_Joker_Big or val == Value_2 then
  1956. isHaveKindOr2 = true
  1957. break
  1958. end
  1959. end
  1960. -- 三顺中不允许包括2,大王,小王
  1961. if isHaveKindOr2 then
  1962. return false
  1963. end
  1964. -- 三顺里面不能有超过3张的牌组
  1965. local reValueList = self:reParseCard(cards)
  1966. if table.nums(reValueList[4]) > 0 then
  1967. return false
  1968. end
  1969. -- 检查3张的个数是否与总长度的/3相同,因为三顺是必须都是三个个值
  1970. local godCardCount = #godCards
  1971. if godCardCount == 0 then
  1972. if table.nums(reValueList[3]) ~= #(cards) / 3 then
  1973. return false
  1974. end
  1975. end
  1976. -- 判断是否为三顺,计算最大值与最小值的差的绝对值是否与总长度/3-1相同
  1977. local m = (#cards > 0) and (math.abs(cards[1] - cards[#cards])) or 0
  1978. if m == #cards/3 - 1 then
  1979. return true, defs.CARD_TYPE.SANSHUN, cards[1]
  1980. end
  1981. if self:isUseGodCard() and godCardCount > 0 then
  1982. local needGodCardCount = (m + 1)*3 - #cards
  1983. print('jxjx 是否是连对判断')
  1984. print('jxjx 是否是连对判断 godCardCount万能牌数', godCardCount)
  1985. print('jxjx 是否是连对判断 needGodCardCount牌组中需要补万能牌的个数', needGodCardCount)
  1986. if #cards > 0 then
  1987. if godCardCount >= needGodCardCount then -- 有万能牌支撑
  1988. return true, defs.CARD_TYPE.SANSHUN, cards[1], true
  1989. end
  1990. else
  1991. if self:isUseAllSameGodCard() then
  1992. return true, defs.CARD_TYPE.SANSHUN, godCards[1], true
  1993. end
  1994. end
  1995. end
  1996. return false
  1997. end
  1998. -- 是否是飞机带单
  1999. function PokerUtil:isPlaneTakeSingle(cards, godCards)
  2000. -- if not self:can31() then
  2001. -- return false
  2002. -- end
  2003. local reValueList = self:reParseCard(cards)
  2004. local t3 = clone(reValueList[3])
  2005. local t4 = clone(reValueList[4])
  2006. for i = #t3, 1, -1 do -- 移除三张中带2的值
  2007. if t3[i] == Value_2 then
  2008. table.remove(t3, i)
  2009. end
  2010. end
  2011. for i = #t4, 1, -1 do -- 移除四张中带2的值
  2012. if t4[i] == Value_2 then
  2013. table.remove(t4, i)
  2014. end
  2015. end
  2016. local tpLianMin = self:tpLianInNormal(t3, t4, #cards/4)
  2017. if tpLianMin then
  2018. return true, defs.CARD_TYPE.AIRPLANE_SINGLE, tpLianMin.min
  2019. end
  2020. local godCardCount = #godCards
  2021. if self:isUseGodCard() and godCardCount > 0 then
  2022. local totalCardCount = #cards + #godCards
  2023. if #cards > 0 then
  2024. local temp = clone(cards)
  2025. local tpLian = self:tpLianInGodcard(temp, totalCardCount/4)
  2026. if tpLian then
  2027. dump(tpLian,'jxjx 飞机带单总数据是')
  2028. local valueList = self:parseCard(cards)
  2029. local plane = {}
  2030. for i, v in ipairs(tpLian) do
  2031. dump(v,'jxjx 当前判断飞机带单数据是===========>>>')
  2032. local notBePlaneTag = false -- 不能成为飞机牌标记,飞机牌包含2,小王,大王
  2033. local needGodCardCount = 0
  2034. for i = 1, v.feiLen do
  2035. local cCard = v.min + i - 1
  2036. local count = 0
  2037. if cCard == Value_2 or cCard == Value_Joker_Little or cCard == Value_Joker_Big then
  2038. notBePlaneTag = true
  2039. print(string.format('jxjx 飞机带单中,飞机牌包含%d, 跳出判断', cCard))
  2040. break
  2041. end
  2042. if not valueList[cCard] then
  2043. count = 3
  2044. else
  2045. count = (3 - valueList[cCard]) > 0 and (3 - valueList[cCard]) or 0
  2046. end
  2047. print(string.format('jxjx 飞机带单,飞机牌数量判断,当前飞机牌是%d, 数量是%d, 需要补充%d张万能牌', cCard, valueList[cCard] or 0, count))
  2048. needGodCardCount = needGodCardCount + count
  2049. end
  2050. if not notBePlaneTag then
  2051. print('jxjx 飞机带单判断needGodCardCount', needGodCardCount)
  2052. print('jxjx 飞机带单判断godCardCount', godCardCount)
  2053. if godCardCount >= needGodCardCount then
  2054. table.insert(plane, v)
  2055. end
  2056. end
  2057. end
  2058. if #plane > 0 then
  2059. table.sort(plane, function(a, b)
  2060. return a.min < b.min
  2061. end)
  2062. return true, defs.CARD_TYPE.AIRPLANE_SINGLE, plane[#plane].min, true
  2063. end
  2064. end
  2065. else
  2066. if self:isUseAllSameGodCard() then
  2067. return true, defs.CARD_TYPE.AIRPLANE_SINGLE, godCards[1], true
  2068. end
  2069. end
  2070. end
  2071. return false
  2072. end
  2073. -- 是否是飞机带对子
  2074. function PokerUtil:isPlanetakeDouble(cards, godCards)
  2075. -- if not self:can32() then
  2076. -- return false
  2077. -- end
  2078. local reValueList = self:reParseCard(cards)
  2079. local t2 = clone(reValueList[2])
  2080. local t3 = clone(reValueList[3])
  2081. local t4 = clone(reValueList[4])
  2082. for i = #t3, 1, -1 do -- 移除三张中带2的值
  2083. if t3[i] == Value_2 then
  2084. table.remove(t3, i)
  2085. end
  2086. end
  2087. for i = #t4, 1, -1 do -- 移除四张中带2的值
  2088. if t4[i] == Value_2 then
  2089. table.remove(t4, i)
  2090. end
  2091. end
  2092. local tpLianMin = self:tpLianInNormal(t3, t4, #cards/5)
  2093. local godCardCount = #godCards
  2094. if tpLianMin and godCardCount == 0 then
  2095. -- 判断除飞机长度外,组成对子的是否能超过飞机的个数
  2096. local canBeDuiZiCount = #t2 + #t3 + #t4 * 2 -- 炸弹算2个对子,所以t4要*2
  2097. print(string.format('%d可组成对子,飞机长度是%d', canBeDuiZiCount, tpLianMin.feiLen))
  2098. local isMoreThan_2DuiZi = (canBeDuiZiCount - tpLianMin.feiLen) >= tpLianMin.feiLen
  2099. if not isMoreThan_2DuiZi then
  2100. return false
  2101. end
  2102. return true, defs.CARD_TYPE.AIRPLANE_DUAD, tpLianMin.min
  2103. end
  2104. if self:isUseGodCard() and godCardCount > 0 then
  2105. local totalCardCount = #cards + #godCards
  2106. if #cards > 0 then
  2107. local temp = clone(cards)
  2108. local tpLian = self:tpLianInGodcard(temp, totalCardCount/5)
  2109. if tpLian then
  2110. dump(tpLian,'jxjx 飞机带对子总数据是')
  2111. local valueList = self:parseCard(cards)
  2112. local plane = {}
  2113. local temp = {}
  2114. local t = {} -- 所有非万能牌的手牌,整合一起,转换为具体值,不按数量
  2115. for i, v in pairs(valueList) do
  2116. if v > 0 then
  2117. table.insert(t, i)
  2118. end
  2119. end
  2120. local t1 = self:changeCardValue_Standard_To_Specific(t)
  2121. for i, v in ipairs(tpLian) do
  2122. dump(v,'jxjx 当前判断飞机带对子数据是===========>>>')
  2123. local notBePlaneTag = false -- 不能成为飞机牌标记,飞机牌包含2,小王,大王
  2124. local needGodCardCount = 0
  2125. temp = {}
  2126. for i = 1, v.feiLen do
  2127. local cCard = v.min + i - 1
  2128. local count = 0
  2129. if cCard == Value_2 or cCard == Value_Joker_Little or cCard == Value_Joker_Big then
  2130. notBePlaneTag = true
  2131. print(string.format('jxjx 飞机带对子中,飞机牌包含%d, 跳出判断', cCard))
  2132. break
  2133. end
  2134. if not valueList[cCard] then
  2135. count = 3
  2136. else
  2137. count = math.abs(3 - valueList[cCard]) -- 这里用绝对值是因为,如果飞机牌是4张,则多出的1张牌可以与万能牌组成对子当带牌使用
  2138. end
  2139. needGodCardCount = needGodCardCount + count
  2140. print(string.format('jxjx 飞机带对子,飞机牌数量判断,当前飞机牌是%d, 数量是%d, 需要补充%d张万能牌', cCard, valueList[cCard] or 0, count))
  2141. table.insert(temp, cCard)
  2142. end
  2143. if not notBePlaneTag then
  2144. dump(temp, 'jxjx 飞机带对子,当前飞机牌是')
  2145. -- 判断对子(判断非飞机头的牌,如果不是2张的牌,则需要补1张万能牌)
  2146. local xorData = self:xorTableData(t1, temp)
  2147. dump(xorData, '带牌数据有xorData,这里只算非飞机牌的,如果飞机牌是4张,则上面判断飞机牌数量已经有做处理!!!!')
  2148. for i, v in ipairs(xorData) do
  2149. local count = 0
  2150. if valueList[v] % 2 ~= 0 then
  2151. count = 1
  2152. end
  2153. needGodCardCount = needGodCardCount + count
  2154. print(string.format('jxjx 飞机带对子,带牌数量判断,当前带牌具体值是%d, 数量是%d, 需要补充%d张万能牌', v, valueList[v], count))
  2155. end
  2156. print('jxjx 飞机带对子判断needGodCardCount', needGodCardCount)
  2157. print('jxjx 飞机带对子判断godCardCount', godCardCount)
  2158. if godCardCount >= needGodCardCount then
  2159. table.insert(plane, v)
  2160. end
  2161. end
  2162. end
  2163. if #plane > 0 then
  2164. table.sort(plane, function(a, b)
  2165. return a.min < b.min
  2166. end)
  2167. return true, defs.CARD_TYPE.AIRPLANE_DUAD, plane[#plane].min, true
  2168. end
  2169. end
  2170. else
  2171. if self:isUseAllSameGodCard() then
  2172. return true, defs.CARD_TYPE.AIRPLANE_DUAD, godCards[1], true
  2173. end
  2174. end
  2175. end
  2176. return false
  2177. end
  2178. -- 飞机的判断
  2179. -- tip:主要是根据3张,4张中,通过while循环获取与传入的飞机长度feiLen相同长度的值
  2180. function PokerUtil:tpLianInNormal(la3, la4, feiLen)
  2181. local feiLen = feiLen or 0
  2182. local lc = {}
  2183. for _,v in ipairs(la3) do
  2184. table.insert(lc, v)
  2185. end
  2186. for _,v in ipairs(la4) do
  2187. table.insert(lc, v)
  2188. end
  2189. if table.nums(lc) <= 0 then
  2190. return nil
  2191. end
  2192. table.sort(lc, function (a, b)
  2193. return a < b
  2194. end)
  2195. local lenEx = 1
  2196. local feiji = {}
  2197. local lcLen = table.nums(lc)
  2198. for k,v in ipairs(lc) do
  2199. lenEx = 1
  2200. local j = k + 1
  2201. while j <= lcLen and (feiLen == 0 or lenEx < feiLen) do
  2202. if lc[j] ~= lc[j-1] + 1 then -- 判断是否是连续的
  2203. break
  2204. end
  2205. j = j + 1
  2206. lenEx = lenEx + 1
  2207. end
  2208. if lenEx == feiLen then
  2209. table.insert(feiji, {
  2210. feiLen = lenEx,
  2211. min = lc[k],
  2212. })
  2213. end
  2214. end
  2215. if table.nums(feiji) > 0 then
  2216. table.sort(feiji, function (a, b)
  2217. return b.feiLen ~= a.feiLen and b.feiLen - a.feiLen or b.min - a.min
  2218. end)
  2219. return feiji[1]
  2220. else
  2221. return nil
  2222. end
  2223. end
  2224. -- 飞机的判断,返回可组成顺子的表
  2225. -- tip 只用于万能牌
  2226. function PokerUtil:tpLianInGodcard(cards, feiLen)
  2227. local t = self:reParseCard(cards)
  2228. local temp = {}
  2229. for i, v in ipairs(t) do
  2230. for _, val in ipairs(v) do
  2231. table.insert(temp, val)
  2232. end
  2233. end
  2234. table.sort(temp, PokerUtil.sortOrder)
  2235. local feiLen = feiLen or 0
  2236. local lc = clone(temp)
  2237. local lenEx = 1
  2238. local feiji = {}
  2239. local lcLen = table.nums(lc)
  2240. for k,v in ipairs(lc) do
  2241. lenEx = 1
  2242. local j = k + 1
  2243. while j <= lcLen and (feiLen == 0 or lenEx < feiLen) do
  2244. if lc[j] ~= lc[j-1] + 1 then -- 判断是否是连续的
  2245. break
  2246. end
  2247. j = j + 1
  2248. lenEx = lenEx + 1
  2249. end
  2250. -- if lenEx == feiLen then -- 让333 *** ** 也进来,所以在外部判断是否满足3张即可,这里不做判断处理
  2251. table.insert(feiji, {
  2252. feiLen = feiLen,
  2253. min = lc[k],
  2254. })
  2255. -- end
  2256. end
  2257. if table.nums(feiji) > 0 then
  2258. return feiji
  2259. else
  2260. return nil
  2261. end
  2262. end
  2263. -- 是否是炸弹
  2264. function PokerUtil:isBomb(cards, godCards)
  2265. local tag = self:checkIsTheSameCards(cards)
  2266. local godCardCount = #godCards
  2267. if not (#cards == 0) then
  2268. if not tag then
  2269. return false
  2270. end
  2271. end
  2272. if #cards == 4 then
  2273. return true, defs.CARD_TYPE.BOMB, cards[1]
  2274. end
  2275. if self:isUseGodCard() and godCardCount > 0 then
  2276. local needGodCardCount = 4 - #cards
  2277. if #cards > 0 then
  2278. if godCardCount >= needGodCardCount then
  2279. return true, defs.CARD_TYPE.BOMB, cards[1], true
  2280. end
  2281. else
  2282. if self:isUseAllSameGodCard() then
  2283. return true, defs.CARD_TYPE.BOMB, godCards[1], true
  2284. end
  2285. end
  2286. end
  2287. return false
  2288. end
  2289. -- 是否是王炸
  2290. function PokerUtil:isKingBomb(cards, godCards)
  2291. local temp = clone(cards)
  2292. for i, v in ipairs(temp) do
  2293. if v ~= Value_Joker_Little and v ~= Value_Joker_Big then
  2294. return false
  2295. end
  2296. end
  2297. if cards[1] == Value_Joker_Little and cards[2] == Value_Joker_Big then
  2298. return true, defs.CARD_TYPE.BOMB_KING, cards[1]
  2299. end
  2300. local godCardCount = #godCards
  2301. if self:isUseGodCard() and godCardCount > 0 then
  2302. if #cards > 0 then
  2303. local needGodCardCount = 2 - #cards
  2304. if godCardCount >= needGodCardCount then
  2305. return true, defs.CARD_TYPE.BOMB_KING, cards[1], true
  2306. end
  2307. else
  2308. if self:isUseAllSameGodCard() then
  2309. return true, defs.CARD_TYPE.BOMB_KING, godCards[1], true
  2310. end
  2311. end
  2312. end
  2313. return false
  2314. end
  2315. -----------------------------------------------------------------------------------------------------------------
  2316. ---------------------------------------- 以下是配置 --------------------------------------------------------
  2317. -----------------------------------------------------------------------------------------------------------------
  2318. -- 配置
  2319. PokerUtil.Card_Max_Length = 20 -- 手牌最多的个数
  2320. PokerUtil.Less_Line = 5 -- 顺子最小长度
  2321. PokerUtil.Max_Line = 12 -- 顺子最大长度(3~A)
  2322. PokerUtil.Less_Lian_Dui = 6 -- 最小组成的连对长度
  2323. PokerUtil.Less_Plane = 6 -- 最小组成的飞机长度
  2324. PokerUtil.Card_Type_Map = {} -- 牌类型方法表
  2325. PokerUtil.Card_Tip_Map = {} -- 牌提示方法表
  2326. PokerUtil.Card_Tip_Check_Order_By_Desc = true -- 牌提示是否用倒序(查看initTypeMap方法)
  2327. -- 癞子
  2328. PokerUtil.Is_Use_God_Card = false -- 是否使用癞子牌,词穷,godCard = 癞子,神牌,万能牌
  2329. PokerUtil.God_Card_Count_Max = 0 -- 癞子牌最大数量(待用,暂没使用)
  2330. PokerUtil.God_Card_Value = 100 -- 癞子牌的标准值
  2331. PokerUtil.God_Card_Single_Value = 1 -- 如果癞子牌以单牌形式出现,转换成该值(如果不想要这个,单牌的值就是癞子值,可以赋值为nil或者0)
  2332. PokerUtil.God_Card_Is_Can_Be_All_Same = false -- 是否可以都是癞子牌(都是癞子牌。涉及部分牌提示和类型判断;若启用的话,类型判断内,min返回的是万能牌值,即使启用的话,getTip里面有部分提示是不包括判断全是手牌的,这个需注意或者待优化)
  2333. PokerUtil.God_Card_ReplaceCard_Is_Use_God_Card_Value = true -- 是否使用癞子的值来取代替代牌(开启后,替代牌的值为0x5x的值,如果为false的话,则为0x0x的值(0x0x为方块值)。之后可以看着改为定好的值,并非0x5x jxtd)
  2334. -- 获得癞子对应替代牌的方法 <- (这是替代方法),感觉之后可以把这个对应的方法直接放到牌型判断里面的返回值,就不需要配置了(jxtd)
  2335. PokerUtil.God_Card_Replace_Card_Map = {
  2336. [defs.CARD_TYPE.NULL] = nil,
  2337. [defs.CARD_TYPE.SINGLE] = 'getGodCardSingleReplace',
  2338. [defs.CARD_TYPE.DUIZI] = 'getGodCardDuiZiReplReplace',
  2339. [defs.CARD_TYPE.SANZHANG] = 'getGodCardSanZhangReplace',
  2340. [defs.CARD_TYPE.SHUNZI] = 'getGodCardShunZiReplace',
  2341. [defs.CARD_TYPE.SHUANGSHUN] = 'getGodCardLianDuiReplace',
  2342. [defs.CARD_TYPE.SANSHUN] = 'getGodCardSanShunReplace',
  2343. [defs.CARD_TYPE.SANDAIYI] = 'getGodCardSanDaiYiReplace',
  2344. [defs.CARD_TYPE.SANDAIDUI] = 'getGodCardSanDaiYiDuiReplace',
  2345. [defs.CARD_TYPE.SIDAIYI] = nil,
  2346. [defs.CARD_TYPE.SIDAIYIDUI] = nil,
  2347. [defs.CARD_TYPE.SIDAIER] = 'getGodCardSiDaiErSingleReplace',
  2348. [defs.CARD_TYPE.SIDAIERDUI] = 'getGodCardSiDaiErDuiReplace',
  2349. [defs.CARD_TYPE.AIRPLANE_SINGLE] = 'getGodCardAirPlaneSingleReplace',
  2350. [defs.CARD_TYPE.AIRPLANE_DUAD] = 'getGodCardAirPlaneDuiReplace',
  2351. [defs.CARD_TYPE.BOMB] = 'getGodCardBombReplace',
  2352. [defs.CARD_TYPE.BOMB_KING] = 'getGodCardBombKingReplace',
  2353. }
  2354. -- 牌型提示对应的方法(后面对应的是方法) <- (这是提示方法)
  2355. PokerUtil.Card_Tip_Map = {
  2356. [defs.CARD_TYPE.NULL] = nil,
  2357. [defs.CARD_TYPE.SINGLE] = 'getSingleTip',
  2358. [defs.CARD_TYPE.DUIZI] = 'getDuiZiTip',
  2359. [defs.CARD_TYPE.SANZHANG] = 'getSanZhangTip',
  2360. [defs.CARD_TYPE.SHUNZI] = 'getShunZiTip',
  2361. [defs.CARD_TYPE.SHUANGSHUN] = 'getLianDuiTip',
  2362. [defs.CARD_TYPE.SANSHUN] = 'getSanShunTip',
  2363. [defs.CARD_TYPE.SANDAIYI] = 'getSanDaiYiTip',
  2364. [defs.CARD_TYPE.SANDAIDUI] = 'getSanDaiYiDuiTip',
  2365. [defs.CARD_TYPE.SIDAIYI] = nil,
  2366. [defs.CARD_TYPE.SIDAIYIDUI] = nil,
  2367. [defs.CARD_TYPE.SIDAIER] = 'getSiDaiErSingleTip',
  2368. [defs.CARD_TYPE.SIDAIERDUI] = 'getSiDaiErDuiTip',
  2369. [defs.CARD_TYPE.AIRPLANE_SINGLE] = 'getAirPlaneSingleTip',
  2370. [defs.CARD_TYPE.AIRPLANE_DUAD] = 'getAirPlaneDuiTip',
  2371. [defs.CARD_TYPE.BOMB] = 'getBombTip',
  2372. [defs.CARD_TYPE.BOMB_KING] = 'getBombKingTip',
  2373. }
  2374. -- 初始化牌提示方法,不能用表驱动,因为子类重写时,调用的话,还是用的父类方法
  2375. -- function PokerUtil:initTipMap()
  2376. -- PokerUtil.Card_Tip_Map = {
  2377. -- [defs.CARD_TYPE.NULL] = nil,
  2378. -- [defs.CARD_TYPE.SINGLE] = self.getSingleTip,
  2379. -- [defs.CARD_TYPE.DUIZI] = self.getDuiZiTip,
  2380. -- [defs.CARD_TYPE.SANZHANG] = self.getSanZhangTip,
  2381. -- [defs.CARD_TYPE.SHUNZI] = self.getShunZiTip,
  2382. -- [defs.CARD_TYPE.SHUANGSHUN] = self.getLianDuiTip,
  2383. -- [defs.CARD_TYPE.SANSHUN] = self.getSanShunTip,
  2384. -- [defs.CARD_TYPE.SANDAIYI] = self.getSanDaiYiTip,
  2385. -- [defs.CARD_TYPE.SANDAIDUI] = self.getSanDaiYiDuiTip,
  2386. -- [defs.CARD_TYPE.SIDAIYI] = nil,
  2387. -- [defs.CARD_TYPE.SIDAIYIDUI] = nil,
  2388. -- [defs.CARD_TYPE.SIDAIER] = self.getSiDaiErSingleTip,
  2389. -- [defs.CARD_TYPE.SIDAIERDUI] = self.getSiDaiErDuiTip,
  2390. -- [defs.CARD_TYPE.AIRPLANE_SINGLE] = self.getAirPlaneSingleTip,
  2391. -- [defs.CARD_TYPE.AIRPLANE_DUAD] = self.getAirPlaneDuiTip,
  2392. -- [defs.CARD_TYPE.BOMB] = self.getBombTip,
  2393. -- [defs.CARD_TYPE.BOMB_KING] = self.getBombKingTip,
  2394. -- }
  2395. -- end
  2396. return PokerUtil