您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

2654 行
70 KiB

  1. --[[牌
  2. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, //方块 6 - KA2
  3. 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, //梅花 6 - KA2
  4. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, //红桃 6 - KA2
  5. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, //黑桃 6 - KA2
  6. 0x4B, 0x4C,//小王 大王
  7. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, //方块 6 - KA2
  8. 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, //梅花 6 - KA2
  9. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, //红桃 6 - KA2
  10. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, //黑桃 6 - KA2
  11. 0x4B, 0x4C,//小王 大王
  12. 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, //方块 6 - KA2
  13. 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, //梅花 6 - KA2
  14. 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, //红桃 6 - KA2
  15. 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, //黑桃 6 - KA2
  16. 0x4B, 0x4C,//小王 大王
  17. 0x5D,0x5D,0x5D,0x5D,0x5D //五张癞子
  18. ]]
  19. local GUI_VAL = 0x0d --鬼的牌值
  20. local ER_VAL = 0x0a --2的牌值
  21. local A_VAL = 0x09 --A的牌值
  22. local X_KING = 0x0B --小王
  23. local D_KING = 0x0C --大王
  24. function pokerParse( card )
  25. local tp = math.floor(card/16)
  26. local val = card%16
  27. -- print("---------tp : "..tp.." val : "..val)
  28. return tp, val
  29. end
  30. function pokerWRDDZPng( card )
  31. local tp , val = pokerParse(card)
  32. return string.format("wrddz_cards_%d_%d.png", tp, val)
  33. end
  34. --小牌
  35. function pokerLPng( card )
  36. local tp , val = pokerParse(card)
  37. return string.format("wrddz_lcards_%d_%d.png", tp, val)
  38. end
  39. -- 对牌进行排序
  40. function pokerSortPdkCards( cards )
  41. local tmp = {}
  42. for _,card in ipairs(cards) do
  43. local tp, val = pokerParse(card)
  44. table.insert(tmp, {tp=tp, val=val, cid=card})
  45. end
  46. table.sort(tmp, function (a, b)
  47. if a.val == b.val then
  48. return a.tp < b.tp
  49. else
  50. return a.val > b.val
  51. end
  52. end)
  53. return tmp
  54. end
  55. -- 牌的排序函数
  56. local function sortCardsFunc( a, b )
  57. return a.val < b.val
  58. end
  59. -- 获取剩余牌(parseCards)
  60. local function getLeft( src, target )
  61. local have = {}
  62. for _,v in ipairs(target) do
  63. have[tostring(v.cid)] = v
  64. end
  65. local left = {}
  66. for _,v in pairs(src) do
  67. if not have[tostring(v.cid)] then
  68. table.insert(left, v)
  69. end
  70. end
  71. return left
  72. end
  73. local zgwrDdzUtil = class("zgwrDdzUtil")
  74. -- 所有传入参数均为{tp, val, cid}结构集合
  75. function zgwrDdzUtil:ctor(param)
  76. if param.isChai==nil then
  77. param.isChai = false
  78. end
  79. if param.isFAT==nil then--four and three
  80. param.isFAT = false
  81. end
  82. self.isChai = param.isChai
  83. self.isFAT = param.isFAT
  84. end
  85. -- 对牌组按照value进行分类
  86. function zgwrDdzUtil:classifyCards( cards )
  87. local tmpCards = clone(cards)
  88. local result = {}
  89. for _,v in pairs(tmpCards) do
  90. if not result[tostring(v.val)] then
  91. result[tostring(v.val)] = {}
  92. end
  93. table.insert(result[tostring(v.val)], v)
  94. end
  95. local tmp = {}
  96. for _,v in pairs(result) do
  97. table.insert(tmp, v)
  98. end
  99. return tmp
  100. end
  101. -- 对牌组按照value进行分类 返回key-value结构
  102. function zgwrDdzUtil:classifyCardsEx( cards )
  103. local tmpCards = clone(cards)
  104. local result = {}
  105. for _,v in pairs(tmpCards) do
  106. if not result[tostring(v.val)] then
  107. result[tostring(v.val)] = {}
  108. end
  109. table.insert(result[tostring(v.val)], v)
  110. end
  111. return result
  112. end
  113. -- 检测牌的点数是否相同
  114. function zgwrDdzUtil:checkSameVal( cards )
  115. if cards and type(cards)~="table" then return false end
  116. if #cards <= 0 then return false end
  117. local targetVal = cards[1].val
  118. local result = true
  119. for _,v in pairs(cards) do
  120. if v.val ~= targetVal then
  121. result = false
  122. break
  123. end
  124. end
  125. return result
  126. end
  127. -- 检测牌组中是否带2
  128. function zgwrDdzUtil:checkOwnEr(cards)
  129. if cards and type(cards)~="table" then return false end
  130. local result = false
  131. for _,v in pairs(cards) do
  132. if v.val == ER_VAL then
  133. result = true
  134. break
  135. end
  136. end
  137. return result
  138. end
  139. -- 检测牌组中是否包含某一张牌
  140. function zgwrDdzUtil:checkOwnX( cards, card)
  141. if cards and type(cards)~="table" then return false end
  142. local result = false
  143. for _,v in pairs(cards) do
  144. if v.val == card.val then
  145. result = true
  146. break
  147. end
  148. end
  149. return result
  150. end
  151. -- 将牌解析成{tp, val ,cid}牌组
  152. function zgwrDdzUtil:parseCards( cards )
  153. local result = {}
  154. for _,v in ipairs(cards) do
  155. local tp, val = pokerParse(v)
  156. table.insert(result, {tp=tp, val=val, cid=v})
  157. end
  158. return result
  159. end
  160. -- 从分类牌组中查找到指定数量牌的集合
  161. function zgwrDdzUtil:getSameNum( classify, num )
  162. local result = {}
  163. for _,v in pairs(classify) do
  164. if #v == num then
  165. table.insert(result, v)
  166. end
  167. end
  168. return result
  169. end
  170. -- 从分类牌组中查找到指定数量牌的集合,包括大于num的牌组
  171. function zgwrDdzUtil:getSameNumEx( classify, num )
  172. local result = {}
  173. for _,v in pairs(classify) do
  174. if #v >= num then
  175. table.insert(result, v)
  176. end
  177. end
  178. return result
  179. end
  180. -- 从分类牌组中查找到指定数量牌的集合,包括大于num的牌组 key-val存储
  181. function zgwrDdzUtil:getSameNumExEx( classify, num )
  182. local result = {}
  183. for k,v in pairs(classify) do
  184. if #v >= num then
  185. result[tostring(k)] = v
  186. end
  187. end
  188. return result
  189. end
  190. --------------------------------------------------------------------------------------
  191. -- 检测牌型
  192. --------------------------------------------------------------------------------------
  193. -- 检测是否是对子
  194. function zgwrDdzUtil:checkDui( cards )
  195. if cards and type(cards)~="table" then return false end
  196. if #cards ~= 2 then return false end
  197. return self:checkSameVal(cards)
  198. end
  199. -- 检测3不带
  200. function zgwrDdzUtil:checkThree( cards )
  201. if cards and type(cards)~="table" then return false end
  202. if #cards ~= 3 then return false end
  203. return self:checkSameVal(cards)
  204. end
  205. -- 检测4张
  206. function zgwrDdzUtil:checkFour( cards )
  207. if cards and type(cards)~="table" then return false end
  208. if #cards ~= 4 then return false end
  209. return self:checkSameVal(cards)
  210. end
  211. -- 检测是否顺子,至少5张
  212. function zgwrDdzUtil:checkShunzi( cards )
  213. local LessNum = 5
  214. if cards and type(cards)~="table" then return false end
  215. if #cards < LessNum then return false end--牌中是否带2 或者牌张数不够
  216. return self:checkSZ(cards)
  217. end
  218. -- 检测顺子,至少两张
  219. function zgwrDdzUtil:checkSZ(cards)
  220. local LessNum = 2
  221. if cards and type(cards)~="table" then return false end
  222. if #cards < LessNum then return false end--牌中是否带2 或者牌张数不够
  223. local tmpCards = clone(cards)
  224. table.sort(tmpCards, sortCardsFunc)
  225. local idx = 1
  226. local result = true
  227. local classify = self:classifyCards(tmpCards)
  228. local isHaveGui,guiNum = self:checkHaveGui(classify)
  229. for i=2,#tmpCards do
  230. if tmpCards[idx].val == 12 and tmpCards[idx].val+1 == tmpCards[i].val and tmpCards[1].val == 1 then
  231. idx = idx + 1
  232. elseif tmpCards[idx].val == 13 and tmpCards[1].val == 1 then
  233. idx = idx + 1
  234. elseif tmpCards[idx].val == 3 and tmpCards[idx].val+9 == tmpCards[i].val then
  235. idx = idx + 1
  236. --[[elseif tmpCards[i].val == 13 and tmpCards[1].val ~= 1 then
  237. local needgui = tmpCards[1].val-1
  238. if guiNum >= needgui then
  239. guiNum = guiNum - needgui
  240. idx = idx + 1
  241. else
  242. result = false
  243. break
  244. end--]]
  245. elseif tmpCards[idx].val+1 ~= tmpCards[i].val and (tmpCards[i].val ~= 14) then
  246. local needgui = tmpCards[i].val - tmpCards[idx].val-1
  247. if tmpCards[i].val == 13 and tmpCards[1].val == 1 then
  248. idx = idx + 1
  249. elseif tmpCards[i].val == 12 and tmpCards[i+1] and tmpCards[i+1].val == 13 then
  250. if tmpCards[1].val == 1 then
  251. idx = idx + 1
  252. else
  253. local needgui = tmpCards[1].val - 1
  254. if guiNum >= needgui then
  255. guiNum = guiNum - needgui
  256. idx = idx + 1
  257. else
  258. result = false
  259. break
  260. end
  261. end
  262. elseif tmpCards[i].val == 12 and tmpCards[1].val == 1 and guiNum > 0 then
  263. guiNum = guiNum - 1
  264. idx = idx + 1
  265. elseif needgui < 0 then --有相等的牌,必定不是顺子
  266. result = false
  267. break
  268. elseif guiNum >= needgui then
  269. guiNum = guiNum - needgui
  270. idx = idx + 1
  271. else
  272. result = false
  273. break
  274. end
  275. else
  276. idx = idx + 1
  277. end
  278. end
  279. return result
  280. end
  281. -- 检测连对
  282. function zgwrDdzUtil:checkLianDui(cards)
  283. local LessNum = 4
  284. if cards and type(cards)~="table" then return false end
  285. if #cards < LessNum or #cards%2~=0 then return false end--牌中是否带2 或者牌张数不够
  286. local tmpCards = clone(cards)
  287. local yclassify = self:classifyCards(tmpCards)
  288. local classify = self:classifyCardsEx(tmpCards)
  289. --[[if #classify*2 ~= #tmpCards then return false end
  290. -- 确保每组牌四两张
  291. for _,v in pairs(classify) do
  292. if #v~=2 then return false end
  293. end--]]
  294. table.sort(tmpCards, sortCardsFunc)
  295. local tmp = {}
  296. --[[for i=1,#tmpCards do
  297. if i%2==1 then
  298. table.insert(tmp, tmpCards[i])
  299. end
  300. end--]]
  301. for i,v in pairs(classify) do
  302. table.insert(tmp, v[1])
  303. end
  304. return self:checkSZ(tmp)
  305. end
  306. -- 检测三带一(最后四张才能3带一?)
  307. function zgwrDdzUtil:check3And1( cards )
  308. local LessNum = 4
  309. if cards and type(cards)~="table" then return false end
  310. if #cards ~= LessNum then return false end-- 或者牌张数不够
  311. local classify = self:classifyCards(cards)
  312. local own3 = false
  313. for _,v in ipairs(classify) do
  314. if #v == 3 then
  315. own3 = true
  316. break
  317. end
  318. end
  319. return own3
  320. end
  321. -- 检测三带二
  322. function zgwrDdzUtil:check3And2( cards )
  323. local LessNum = 5
  324. if cards and type(cards)~="table" then return false end
  325. if #cards ~= LessNum then return false end--牌张数不够
  326. local classify = self:classifyCards(cards)
  327. local isHaveGui,guiNum = self:checkHaveGui(classify)
  328. local own3 = false
  329. for _,v in ipairs(classify) do
  330. if #v == 3 or (#v == 2 and guiNum == 1) or (guiNum == 2) then
  331. own3 = true
  332. break
  333. end
  334. end
  335. return own3
  336. end
  337. -- 检测四带一
  338. function zgwrDdzUtil:check4And1(cards)
  339. local LessNum = 5
  340. if cards and type(cards)~="table" then return false end
  341. if #cards ~= LessNum then return false end--或者牌张数不够
  342. local classify = self:classifyCards(cards)
  343. local own4 = false
  344. for _,v in ipairs(classify) do
  345. if #v == 4 then
  346. own4 = true
  347. break
  348. end
  349. end
  350. return own4
  351. end
  352. -- 检测四带3
  353. function zgwrDdzUtil:check4And3( cards )
  354. local LessNum = 7
  355. if cards and type(cards)~="table" then return false end
  356. if #cards ~= LessNum then return false end--或者牌张数不够
  357. local classify = self:classifyCards(cards)
  358. local own4 = false
  359. for _,v in ipairs(classify) do
  360. if #v == 4 then
  361. own4 = true
  362. break
  363. end
  364. end
  365. return own4
  366. end
  367. -- 检测 炸弹
  368. function zgwrDdzUtil:checkBomb( cards )
  369. return self:checkFour(cards)
  370. end
  371. -- 检测 是否有鬼牌 cards传已经解析过的牌
  372. function zgwrDdzUtil:checkHaveGui( cards )--返回传递的牌里是否有鬼,和鬼的张数
  373. local ishaveGui = false
  374. local guiNum = 0
  375. for i,v in pairs(cards) do
  376. if v[1].val == GUI_VAL then
  377. ishaveGui = true
  378. guiNum = #v
  379. break
  380. end
  381. end
  382. return ishaveGui,guiNum
  383. end
  384. -- 检测 是否有鬼牌 cards没有解析过
  385. function zgwrDdzUtil:checkHaveGui1( cards )--返回传递的牌里是否有鬼,和鬼的张数
  386. local ishaveGui = false
  387. local guiNum = 0
  388. local parseData = {}
  389. for _,v in ipairs(cards) do
  390. local tp, val = pokerParse(v)
  391. table.insert(parseData, {tp=tp, val=val, cid=v})
  392. end
  393. local tCards = self:classifyCards(parseData)
  394. for i,v in pairs(tCards) do
  395. if v[1].val == GUI_VAL then
  396. ishaveGui = true
  397. guiNum = #v
  398. break
  399. end
  400. end
  401. return ishaveGui,guiNum
  402. end
  403. -- 检测 是否有鬼牌 cards没有解析过
  404. function zgwrDdzUtil:checkHaveGui2( cards )--返回传递的牌里是否有鬼,和鬼的张数
  405. local ishaveGui = false
  406. local guiNum = 0
  407. for i,v in pairs(cards) do
  408. if v >= 0x51 then
  409. ishaveGui = true
  410. guiNum = guiNum + 1
  411. end
  412. end
  413. return ishaveGui,guiNum
  414. end
  415. -- 检测飞机555666 555666777等+同等数量的对牌,或者双倍单牌
  416. function zgwrDdzUtil:checkPlan( cards, shaoDai )
  417. shaoDai = shaoDai or false
  418. local LessNum = 6 -- 6+4 9+6
  419. local cNum = #cards
  420. -- print("-------------------------checkPlan num: "..cNum)
  421. if not shaoDai then--是否少带
  422. if cNum~=6 and cNum~=10 and cNum~=15 then return false end
  423. end
  424. if cards and type(cards)~="table" then return false end
  425. if #cards < LessNum then return false end--或者牌张数不够
  426. local classify = self:classifyCards(cards)
  427. local result = false
  428. local ThreeCount = 0
  429. local TowCount = 0
  430. local checkShun = {}
  431. local isHaveGui,guiNum = self:checkHaveGui(classify)
  432. if self.isChai then--区分炸弹是否可拆
  433. for _,v in ipairs(classify) do
  434. if #v >= 3 then
  435. ThreeCount = ThreeCount + 1
  436. table.insert(checkShun, v[1])
  437. end
  438. end
  439. else
  440. for _,v in ipairs(classify) do
  441. if #v == 3 then
  442. ThreeCount = ThreeCount + 1
  443. table.insert(checkShun, v[1])
  444. end
  445. if #v == 2 then
  446. TowCount = TowCount + 1
  447. end
  448. end
  449. if guiNum == 1 and ThreeCount == 1 and TowCount >= 1 then
  450. return true
  451. elseif guiNum == 2 and (ThreeCount == 1 or TowCount >= 2) then
  452. return true
  453. elseif guiNum == 3 and (ThreeCount == 1 or TowCount >= 1) then
  454. return true
  455. end
  456. end
  457. if ThreeCount <= 1 then return false end
  458. if #checkShun >= 2 then
  459. table.sort(checkShun, sortCardsFunc)
  460. end
  461. -- print("three count : " ..ThreeCount)
  462. if ThreeCount == 2 then
  463. result = (self:checkSZ(checkShun) and cNum<=10)
  464. elseif ThreeCount == 3 then
  465. result = (self:checkSZ(checkShun) and cNum<=15)
  466. if not result then--三张四张作为翅膀带出去
  467. local firstTwo = {checkShun[1], checkShun[2]}
  468. result = (self:checkSZ(firstTwo) and cNum<=10)
  469. if not result then
  470. local lastTwo = {checkShun[2], checkShun[3]}
  471. result = (self:checkSZ(lastTwo) and cNum<=10)
  472. end
  473. end
  474. else
  475. local maxLen = 1
  476. local bCount = 1
  477. local i, j=1, 2
  478. for i=1,#checkShun-1 do
  479. if checkShun[i].val + 1 == checkShun[j].val then
  480. bCount = bCount + 1
  481. if bCount>maxLen then maxLen = bCount end
  482. else
  483. if bCount>maxLen then maxLen = bCount end
  484. bCount = 1
  485. end
  486. i=i+1
  487. j=j+1
  488. end
  489. result = maxLen>=3 and cNum<=15
  490. end
  491. return result
  492. end
  493. --牌型
  494. local OUT_TYPE = {
  495. NONE = 0x00,--不适用类型
  496. SINGLE_CARD = 0x01,--单牌
  497. DUI_ZI = 0x02,--对子
  498. THREE = 0x03,--三个
  499. SHUN_ZI = 0x04,--顺子
  500. LIAN_DUI = 0x05,--连对
  501. SAN_SHUN = 0x06,--三顺
  502. THREE_AND_ONE = 0x07,--三带一
  503. THREE_AND_DUI = 0x08,--三带一对
  504. AIRPLANE_SINGLE = 0x09,--飞机(带单张)
  505. AIRPLANE_DUI = 0x0a,--飞机带对
  506. BOMB_FOUR = 0x0b,--炸弹4张
  507. TWO_SMALL_KING = 0x0c,--炸弹两小王(王炸)
  508. BIG_SMALL_KING = 0x0d,--炸弹一大王一小王(王炸)
  509. TWO_BIG_KING = 0x0e,--炸弹两大王(王炸)
  510. BOMB_EIGHT = 0x0f,--炸弹8张
  511. FOUR_SMALL_KING = 0x10,--炸弹四小王(王炸)
  512. BIG_THREE_SMALL_KING = 0x11,--炸弹一大王三小王(王炸)
  513. TWO_BIG_TWO_SMALL_KING = 0x12,--炸弹两大王两小王(王炸)
  514. THREE_BIG_SMALL_KING = 0x13,--炸弹三大王一小王(王炸)
  515. FOUR_BIG_KING = 0x14,--炸弹四大王(王炸)
  516. BOMB_TWELVE = 0x15,--炸弹12张
  517. SIX_SMALL_KING = 0x16,--炸弹六小王(王炸)
  518. THREE_BIG_THREE_SMALL_KING = 0x17,--炸弹三大王三小王(王炸)
  519. FOUR_BIG_TWO_SMALL_KING = 0x18,--炸弹四大王两小王(王炸)
  520. FIVE_BIG_SMALL_KING = 0x19,--炸弹五大王一小王(王炸)
  521. SIX_BIG_KING = 0x1a,--炸弹六大王(王炸)
  522. }
  523. zgwrDdzUtil.OUT_TYPE = OUT_TYPE
  524. function zgwrDdzUtil:getTypeString( tp )
  525. return TYPE_STRING[tp] or "TP错误"
  526. end
  527. --获取一张服务器下发的牌值装换成客户端用到的牌值
  528. function zgwrDdzUtil:getCardValue( card )
  529. local tp, val = pokerParse(card)
  530. return val
  531. end
  532. function zgwrDdzUtil:getGuiByClassifyCards( classify )
  533. for valStr,cds in pairs(classify) do
  534. if tonumber(valStr) == GUI_VAL then
  535. return cds
  536. end
  537. end
  538. return {}
  539. end
  540. --------------------------------------------------------------------------------------
  541. -- 牌型提示
  542. --------------------------------------------------------------------------------------
  543. --单张提示 cards@{{tp=, val=, cid=,}...} target@{tp=, val=, cid=,}
  544. -- fixed
  545. function zgwrDdzUtil:getSingleTip( cards, target )
  546. local target = target[1]
  547. if target.val == ER_VAL or target.val == GUI_VAL then return nil end
  548. local classify = self:classifyCardsEx(cards)
  549. local singles = {}
  550. local twos = {}
  551. local threes = {}
  552. local fours = {}
  553. for valStr,cds in pairs(classify) do
  554. if tonumber(valStr) > target.val or tonumber(valStr)==ER_VAL or tonumber(valStr)==GUI_VAL then
  555. if #cds == 1 then
  556. table.insert(singles, cds[1])
  557. elseif #cds == 2 then
  558. table.insert(twos, cds[1])
  559. table.insert(twos, cds[2])
  560. elseif #cds == 3 then
  561. table.insert(threes, cds[1])
  562. table.insert(threes, cds[2])
  563. table.insert(threes, cds[3])
  564. elseif #cds == 4 then--炸弹是否可拆决定
  565. if self.isChai then
  566. table.insert(threes, cds[1])
  567. table.insert(threes, cds[2])
  568. table.insert(threes, cds[3])
  569. table.insert(threes, cds[4])
  570. end
  571. end
  572. end
  573. end
  574. if #singles>=2 then --降序排列
  575. table.sort(singles, function ( a, b ) return a.val > b.val end)
  576. end
  577. if #twos>=2 then --升序排列
  578. table.sort(twos, function ( a, b ) return a.val < b.val end)
  579. end
  580. if #threes>=2 then --升序排列
  581. table.sort(threes, function ( a, b ) return a.val < b.val end)
  582. end
  583. for _,v in ipairs(twos) do
  584. table.insert(singles, 1, v)
  585. end
  586. for _,v in ipairs(threes) do
  587. table.insert(singles, 1, v)
  588. end
  589. return singles
  590. end
  591. -- 对子提示cards@{{tp=, val=, cid=,}...} targets@{{tp=, val=, cid=,},{tp=, val=, cid=,}}
  592. -- fixed
  593. function zgwrDdzUtil:getDoubleTip( cards, targets )
  594. local target = targets[1]
  595. if target.val >= ER_VAL then return nil end
  596. local classify = self:classifyCardsEx(cards)
  597. local isHaveGui,guiNum = self:checkHaveGui(classify)
  598. local sigle = {}
  599. local twos = {}
  600. local threes = {}
  601. local fours = {}
  602. local gui = self:getGuiByClassifyCards(classify)
  603. for valStr,cds in pairs(classify) do
  604. if tonumber(valStr) > target.val and #cds>=2 then
  605. if #cds == 2 then
  606. table.insert(twos, cds)
  607. elseif #cds == 3 then
  608. table.insert(threes, clone({cds[1], cds[2]}))
  609. elseif #cds == 4 then--炸弹是否可拆决定
  610. if self.isChai then
  611. table.insert(fours, clone({cds[1], cds[2]}))
  612. end
  613. end
  614. else
  615. if guiNum > 0 and #gui > 0 and tonumber(valStr) > target.val and tonumber(valStr) ~= GUI_VAL then
  616. table.insert(sigle, clone({cds[1], gui[1]}))
  617. end
  618. end
  619. end
  620. if #twos>=2 then --降序排列
  621. table.sort(twos, function ( a, b ) return a[1].val > b[1].val end)
  622. end
  623. if #sigle>=2 then --升序排列
  624. table.sort(sigle, function ( a, b ) return a[1].val < b[1].val end)
  625. end
  626. if #threes>=2 then --升序排列
  627. table.sort(threes, function ( a, b ) return a[1].val < b[1].val end)
  628. end
  629. if #fours>=2 then --升序排列
  630. table.sort(fours, function ( a, b ) return a[1].val < b[1].val end)
  631. end
  632. for _,v in ipairs(sigle) do
  633. table.insert(twos, 1, v)
  634. end
  635. for _,v in ipairs(threes) do
  636. table.insert(twos, 1, v)
  637. end
  638. for _,v in pairs(fours) do
  639. table.insert(twos, 1, v)
  640. end
  641. return twos
  642. end
  643. -- 三张提示
  644. -- fixed
  645. function zgwrDdzUtil:getThreeTip( cards, targets )
  646. local minVal = self:getCardsMin(targets,OUT_TYPE.THREE)
  647. local targetNum = #targets
  648. local cclassify = self:classifyCardsEx(cards)
  649. local isHaveGui,guiNum = self:checkHaveGui(cclassify)
  650. local gui = self:getGuiByClassifyCards(cclassify)
  651. if #cards < 3 then return end
  652. local valueList = {}
  653. local cardList = {}
  654. for k,v in ipairs(cards) do
  655. local value = v.val
  656. if v ~= GUI_VAL then
  657. valueList[value] = valueList[value] or 0
  658. valueList[value] = valueList[value] + 1
  659. cardList[value] = cardList[value] or {}
  660. table.insert(cardList[value], v)
  661. end
  662. end
  663. local result ={}
  664. for i = minVal + 1, 13 do
  665. local _tpIdx = i;
  666. local _tpCount = 0;
  667. local _tpReplace2 = {}
  668. local tpNotAllLai = false;
  669. local _haveLai = guiNum;
  670. valueList[_tpIdx] = valueList[_tpIdx] or 0;
  671. if valueList[_tpIdx] + _haveLai >= 3 then
  672. local _tpNum = 3 - valueList[_tpIdx];
  673. _tpNum = _tpNum >= 0 and _tpNum or 0;
  674. local lai = guiNum - _haveLai + 1
  675. for p = 1, _tpNum do
  676. table.insert(_tpReplace2,gui[lai])
  677. lai = lai + 1
  678. end
  679. for _m = 1, 3 - _tpNum do
  680. table.insert(_tpReplace2, cardList[_tpIdx][_m])
  681. tpNotAllLai = true;
  682. end
  683. _haveLai = _haveLai - _tpNum;
  684. _tpCount = _tpCount + 3
  685. _tpIdx = _tpIdx + 1
  686. if _tpCount == 3 then
  687. table.insert(result,_tpReplace2)
  688. end
  689. end
  690. end;
  691. local resultex = {}
  692. if #result > 0 then
  693. for i = #result,1,-1 do
  694. table.insert(resultex,result[i])
  695. end
  696. end
  697. return resultex
  698. --[[if #cards < #targets then return nil end
  699. local tclassify = self:classifyCards(targets)
  700. local ttarget1 = self:getSameNum(tclassify, 3)
  701. local target
  702. if next(ttarget1) ~= nil then
  703. target = ttarget1[1][1]
  704. else
  705. local ttarget2 = self:getSameNum(tclassify, 2)
  706. if guiNum == 1 then
  707. target = ttarget2[1][1]
  708. elseif guiNum == 2 then
  709. local ttarget3 = self:getSameNum(tclassify, 1)
  710. target = ttarget3[1][1]
  711. elseif guiNum == 3 then
  712. target = {["tp"] = 0,["cid"] = 14,["val"] = 14}
  713. end
  714. end
  715. local classify = self:classifyCardsEx(cards)
  716. local isHaveGui,guiNum = self:checkHaveGui(classify)
  717. local threes = {}
  718. local singles = {}
  719. local twos = {}
  720. local fours = {}
  721. local gui = self:getGuiByClassifyCards(classify)
  722. for valStr,cds in pairs(classify) do
  723. if tonumber(valStr) > target.val and #cds>=3 then
  724. if #cds == 3 then
  725. table.insert(threes, cds)
  726. elseif #cds == 4 then--炸弹是否可拆决定
  727. --if self.isChai then
  728. table.insert(threes, {cds[1], cds[2], cds[3]})
  729. --end
  730. end
  731. else
  732. if #cds == 1 then
  733. table.insert(singles, cds[1])
  734. if guiNum > 1 and #gui > 1 and tonumber(valStr) > target.val and tonumber(valStr) ~= GUI_VAL then
  735. table.insert(threes, {cds[1], gui[1], gui[2]})
  736. end
  737. elseif #cds == 2 then
  738. table.insert(twos, cds)
  739. if guiNum > 0 and #gui > 0 and tonumber(valStr) > target.val and tonumber(valStr) ~= GUI_VAL then
  740. table.insert(threes, {cds[1], cds[2], gui[1]})
  741. end
  742. elseif #cds == 4 then
  743. table.insert(fours, cds)
  744. end
  745. end
  746. end
  747. if #threes <= 0 then return nil end
  748. if #threes>=2 then --降序排列
  749. table.sort(threes, function ( a, b ) return a[1].val > b[1].val end)
  750. end
  751. return threes--]]
  752. end
  753. -- 三带二提示
  754. -- fixed
  755. function zgwrDdzUtil:getThreeAnd2Tip( cards, targets )
  756. local minVal = self:getCardsMin(targets,OUT_TYPE.THREE_AND_TWO)
  757. local targetNum = #targets
  758. local cclassify = self:classifyCardsEx(cards)
  759. local isHaveGui,guiNum = self:checkHaveGui(cclassify)
  760. local gui = self:getGuiByClassifyCards(cclassify)
  761. if #cards < 5 then return end
  762. local valueList = {}
  763. local cardList = {}
  764. for k,v in ipairs(cards) do
  765. local value = v.val
  766. if v ~= GUI_VAL then
  767. valueList[value] = valueList[value] or 0
  768. valueList[value] = valueList[value] + 1
  769. cardList[value] = cardList[value] or {}
  770. table.insert(cardList[value], v)
  771. end
  772. end
  773. local result ={}
  774. for i = minVal + 1, 13 do
  775. local _tpIdx = i;
  776. local _tpCount = 0;
  777. local _tpReplace2 = {}
  778. local tpNotAllLai = false;
  779. local _haveLai = guiNum;
  780. valueList[_tpIdx] = valueList[_tpIdx] or 0;
  781. if valueList[_tpIdx] + _haveLai >= 3 then
  782. local _tpNum = 3 - valueList[_tpIdx];
  783. _tpNum = _tpNum >= 0 and _tpNum or 0;
  784. local lai = guiNum - _haveLai + 1
  785. for p = 1, _tpNum do
  786. table.insert(_tpReplace2,gui[lai])
  787. lai = lai + 1
  788. end
  789. for _m = 1, 3 - _tpNum do
  790. table.insert(_tpReplace2, cardList[_tpIdx][_m])
  791. tpNotAllLai = true;
  792. end
  793. _haveLai = _haveLai - _tpNum;
  794. _tpCount = _tpCount + 3
  795. _tpIdx = _tpIdx + 1
  796. if _tpCount == 3 then
  797. table.insert(result,_tpReplace2)
  798. end
  799. end
  800. end;
  801. local resultex = {}
  802. if #result > 0 then
  803. for i = #result,1,-1 do
  804. table.insert(resultex,result[i])
  805. end
  806. end
  807. return resultex
  808. end
  809. -- 三带一提示 not fixed
  810. function zgwrDdzUtil:getThreeAnd1Tip(cards, targets)
  811. local tclassify = self:classifyCards(targets)
  812. local target = self:getSameNum(tclassify, 3)
  813. local cclassify = self:classifyCards(cards)
  814. local tmps = self:getSameNum(cclassify, 3)
  815. if #tmps == 0 then return nil end
  816. local result = {}
  817. for _,v in ipairs(tmps) do
  818. if v[1].val > target[1].val then
  819. table.insert(result, v)
  820. end
  821. end
  822. local tmpOnes = self:getSameNum(cclassify, 1)
  823. local ones = {}
  824. for _,v in pairs(tmpOnes) do
  825. table.insert(ones, v[1])
  826. end
  827. local twos = self:getSameNum(cclassify, 2)
  828. for _,v in ipairs(twos) do
  829. table.insert(ones, v[1])
  830. table.insert(ones, v[2])
  831. end
  832. if #ones >=1 then
  833. return {result, ones[1]}
  834. else
  835. return nil
  836. end
  837. end
  838. -- 四带一提示
  839. function zgwrDdzUtil:getFourAnd1( cards, targets )
  840. local tclassify = self:classifyCards(targets)
  841. local target = self:getSameNum(tclassify, 4)
  842. local cclassify = self:classifyCards(cards)
  843. local tmps = self:getSameNum(cclassify, 4)
  844. if #tmps == 0 then return nil end
  845. local result = {}
  846. for _,v in ipairs(tmps) do
  847. if v[1].val > target[1].val then
  848. table.insert(result, v)
  849. end
  850. end
  851. local tmpOnes = self:getSameNum(cclassify, 1)
  852. local ones = {}
  853. for _,v in pairs(tmpOnes) do
  854. table.insert(ones, v[1])
  855. end
  856. local twos = self:getSameNum(cclassify, 2)
  857. for _,v in ipairs(twos) do
  858. table.insert(ones, v[1])
  859. table.insert(ones, v[2])
  860. end
  861. local threes = self:getSameNum(cclassify, 3)
  862. for _,v in ipairs(threes) do
  863. table.insert(ones, v[1])
  864. table.insert(ones, v[2])
  865. table.insert(ones, v[3])
  866. end
  867. if #ones >= 1 then
  868. return {result, ones[1]}
  869. else--牌不够数
  870. return nil
  871. end
  872. end
  873. -- 四带三提示(前提是牌足够)
  874. -- fixed
  875. function zgwrDdzUtil:getFourAnd3( cards, targets )
  876. if #cards < #targets then return nil end
  877. local tclassify = self:classifyCards(targets)
  878. local target = self:getSameNum(tclassify, 4)[1][1]
  879. local classify = self:classifyCardsEx(cards)
  880. local threes = {}
  881. local singles = {}
  882. local twos = {}
  883. local fours = {}
  884. local targetFours = {}
  885. for valStr,cds in pairs(classify) do
  886. if tonumber(valStr) > target.val and #cds>=4 then
  887. table.insert(targetFours, cds)
  888. else
  889. if #cds == 1 then
  890. table.insert(singles, cds[1])
  891. elseif #cds == 2 then
  892. table.insert(twos, cds)
  893. elseif #cds == 3 then
  894. table.insert(threes, cds)
  895. elseif #cds == 4 then
  896. table.insert(fours, cds)
  897. end
  898. end
  899. end
  900. if #threes <= 0 then return nil end
  901. if #targetFours>=2 then --降序排列
  902. table.sort(targetFours, function ( a, b ) return a[1].val > b[1].val end)
  903. end
  904. if #singles>=2 then --升序排列
  905. table.sort(singles, function ( a, b ) return a.val < b.val end)
  906. end
  907. if #twos>=2 then --升序排列
  908. table.sort(twos, function ( a, b ) return a[1].val < b[1].val end)
  909. end
  910. if #threes>=2 then --升序排列
  911. table.sort(threes, function ( a, b ) return a[1].val < b[1].val end)
  912. end
  913. for _,v in ipairs(twos) do
  914. table.insert(singles, v[1])
  915. table.insert(singles, v[2])
  916. end
  917. for _,v in ipairs(threes) do
  918. table.insert(singles, v[1])
  919. table.insert(singles, v[2])
  920. table.insert(singles, v[3])
  921. end
  922. local result = {}
  923. if #targetFours==1 then
  924. if #singles >= 3 then
  925. table.insert(targetFours[1], singles[1])
  926. table.insert(targetFours[1], singles[2])
  927. table.insert(targetFours[1], singles[3])
  928. table.insert(result, targetFours[1])
  929. return result
  930. else
  931. return nil
  932. end
  933. else
  934. if #singles >= 3 then
  935. for _,v in ipairs(targetFours) do
  936. local cv = clone(v)
  937. table.insert(v, singles[1])
  938. table.insert(v, singles[2])
  939. table.insert(v, singles[3])
  940. table.insert(result, cv)
  941. end
  942. return result
  943. else--多个四张,玩家自己拆牌
  944. return targetFours
  945. end
  946. end
  947. end
  948. -- 检测牌组是否是连续的parseCards@sorted
  949. function zgwrDdzUtil:getSubLine( parseCards )
  950. local sub = {}
  951. local tCards = self:classifyCards(parseCards)
  952. local isHaveGui,guiNum = self:checkHaveGui(tCards)
  953. for i=#parseCards,1,-1 do
  954. if parseCards[i] and parseCards[i-1] and parseCards[i].val ~= GUI_VAL and parseCards[i-1].val ~= GUI_VAL then
  955. if parseCards[i].val-1~=parseCards[i-1].val then
  956. if guiNum > 0 then
  957. guiNum = guiNum - 1
  958. else
  959. --断开了
  960. local tmp = {}
  961. for j=#parseCards,i,-1 do
  962. table.insert(tmp, parseCards[j])
  963. end
  964. table.insert(sub, clone(tmp))
  965. for j=#parseCards,i,-1 do
  966. table.remove(parseCards, j)
  967. end
  968. end
  969. else
  970. if i == 2 then
  971. table.insert(sub, clone(parseCards))
  972. end
  973. end
  974. end
  975. end
  976. return sub
  977. end
  978. -- 从连续的牌组中获得顺子
  979. function zgwrDdzUtil:getSzTip( hands, targets )
  980. local tmpNoKey = clone(hands)
  981. table.sort(targets, sortCardsFunc)
  982. local minVal = targets[1].val
  983. local targetNum = #targets
  984. if #tmpNoKey<targetNum then return nil end
  985. local count = #tmpNoKey-targetNum
  986. if count == 0 then return {tmpNoKey} end
  987. local getMS = function ( tab, len )
  988. if #tab < len then return nil end
  989. local rst = {}
  990. for i=#tab,1,-1 do
  991. if #rst<len then
  992. table.insert(rst, 1, tab[i])
  993. else
  994. break
  995. end
  996. end
  997. return rst
  998. end
  999. local result = {}
  1000. for i=#tmpNoKey,1,-1 do
  1001. local rst = getMS(tmpNoKey, targetNum)
  1002. if rst then
  1003. table.insert(result, 1, clone(rst))
  1004. table.remove(tmpNoKey, #tmpNoKey)
  1005. else
  1006. break
  1007. end
  1008. end
  1009. return result
  1010. end
  1011. -- 顺子提示
  1012. -- fixed
  1013. function zgwrDdzUtil:getShunziTip( cards, targets )
  1014. local minVal = self:getCardsMin(targets,OUT_TYPE.SHUN_ZI)
  1015. local targetNum = #targets
  1016. local cclassify = self:classifyCardsEx(cards)
  1017. local isHaveGui,guiNum = self:checkHaveGui(cclassify)
  1018. local gui = self:getGuiByClassifyCards(cclassify)
  1019. local isHaveA = false
  1020. if targets and next(targets) ~= nil then
  1021. for i,v in pairs(targets) do
  1022. if v.val == 12 then
  1023. isHaveA = true
  1024. end
  1025. end
  1026. end
  1027. local isMinSz = (minVal == 0 and isHaveA)
  1028. local valueList = {}
  1029. local cardList = {}
  1030. for k,v in ipairs(cards) do
  1031. local value = v.val
  1032. if v ~= GUI_VAL then
  1033. valueList[value] = valueList[value] or 0
  1034. valueList[value] = valueList[value] + 1
  1035. cardList[value] = cardList[value] or {}
  1036. table.insert(cardList[value], v)
  1037. end
  1038. end
  1039. local result ={}
  1040. for i = minVal + 1, 13 - targetNum do
  1041. local _tpIdx = i;
  1042. local _tpCount = 0;
  1043. local _tpReplace2 = {}
  1044. local tpNotAllLai = false;
  1045. local _haveLai = guiNum;
  1046. while _tpCount < #cards and _tpCount < targetNum and _tpIdx <= 12 do
  1047. valueList[_tpIdx] = valueList[_tpIdx] or 0;
  1048. if (not (valueList[_tpIdx] + _haveLai >= 1)) then break end;
  1049. local _tpNum = 1 - valueList[_tpIdx];
  1050. _tpNum = _tpNum >= 0 and _tpNum or 0;
  1051. local lai = guiNum - _haveLai + 1
  1052. for p = 1, _tpNum do
  1053. table.insert(_tpReplace2,gui[lai])
  1054. lai = lai + 1
  1055. end
  1056. for _m = 1, 1 - _tpNum do
  1057. table.insert(_tpReplace2, cardList[_tpIdx][_m])
  1058. tpNotAllLai = true;
  1059. end
  1060. _haveLai = _haveLai - _tpNum;
  1061. _tpCount = _tpCount + 1;
  1062. _tpIdx = _tpIdx + 1
  1063. end
  1064. if _tpCount == targetNum then
  1065. table.insert(result,_tpReplace2)
  1066. end
  1067. end
  1068. targetNum = targetNum - 1
  1069. valueList[13] = valueList[13] or 0
  1070. if isMinSz and (valueList[13] and valueList[13] > 0) then--找一下少一张牌的然后补2
  1071. for i = minVal + 1, 13 - targetNum do
  1072. local _tpIdx = i;
  1073. local _tpCount = 0;
  1074. local _tpReplace2 = {}
  1075. local tpNotAllLai = false;
  1076. local _haveLai = guiNum;
  1077. while _tpCount < #cards and _tpCount < targetNum and _tpIdx <= 12 do
  1078. valueList[_tpIdx] = valueList[_tpIdx] or 0;
  1079. if (not (valueList[_tpIdx] + _haveLai >= 1)) then break end;
  1080. local _tpNum = 1 - valueList[_tpIdx];
  1081. _tpNum = _tpNum >= 0 and _tpNum or 0;
  1082. local lai = guiNum - _haveLai + 1
  1083. for p = 1, _tpNum do
  1084. table.insert(_tpReplace2,gui[lai])
  1085. lai = lai + 1
  1086. end
  1087. for _m = 1, 1 - _tpNum do
  1088. table.insert(_tpReplace2, cardList[_tpIdx][_m])
  1089. tpNotAllLai = true;
  1090. end
  1091. _haveLai = _haveLai - _tpNum;
  1092. _tpCount = _tpCount + 1;
  1093. _tpIdx = _tpIdx + 1
  1094. end
  1095. if _tpCount == targetNum then
  1096. if _tpReplace2[1].val == 1 or (_tpReplace2[targetNum-1].val == targetNum and _tpReplace2[targetNum].val == 14 ) then
  1097. if cardList[13] and cardList[13][1] then
  1098. table.insert(_tpReplace2, cardList[13][1])--补一张2
  1099. table.insert(result,_tpReplace2)
  1100. end
  1101. end
  1102. end
  1103. end
  1104. end
  1105. local resultex = {}
  1106. if #result > 0 then
  1107. for i = #result,1,-1 do
  1108. table.insert(resultex,result[i])
  1109. end
  1110. end
  1111. return resultex
  1112. end
  1113. -- 获取连对提示
  1114. -- fixed
  1115. function zgwrDdzUtil:getLianduiTip( cards, targets )
  1116. local minVal = self:getCardsMin(targets,OUT_TYPE.LIAN_DUI)
  1117. local targetNum = #targets
  1118. local cclassify = self:classifyCardsEx(cards)
  1119. local isHaveGui,guiNum = self:checkHaveGui(cclassify)
  1120. local gui = self:getGuiByClassifyCards(cclassify)
  1121. local valueList = {}
  1122. local cardList = {}
  1123. for k,v in ipairs(cards) do
  1124. local value = v.val
  1125. if v ~= GUI_VAL then
  1126. valueList[value] = valueList[value] or 0
  1127. valueList[value] = valueList[value] + 1
  1128. cardList[value] = cardList[value] or {}
  1129. table.insert(cardList[value], v)
  1130. end
  1131. end
  1132. local result ={}
  1133. for i = minVal + 1, 14 - targetNum/2 do
  1134. local _tpIdx = i;
  1135. local _tpCount = 0;
  1136. local _tpReplace2 = {}
  1137. local tpNotAllLai = false;
  1138. local _haveLai = guiNum;
  1139. while _tpCount < #cards and _tpCount < targetNum and _tpIdx <= 12 do
  1140. valueList[_tpIdx] = valueList[_tpIdx] or 0;
  1141. if (not (valueList[_tpIdx] + _haveLai >= 2)) then break end;
  1142. local _tpNum = 2 - valueList[_tpIdx];
  1143. _tpNum = _tpNum >= 0 and _tpNum or 0;
  1144. local lai = guiNum - _haveLai + 1
  1145. for p = 1, _tpNum do
  1146. table.insert(_tpReplace2,gui[lai])
  1147. lai = lai + 1
  1148. end
  1149. for _m = 1, 2 - _tpNum do
  1150. table.insert(_tpReplace2, cardList[_tpIdx][_m])
  1151. tpNotAllLai = true;
  1152. end
  1153. _haveLai = _haveLai - _tpNum;
  1154. _tpCount = _tpCount + 2;
  1155. _tpIdx = _tpIdx + 1
  1156. end
  1157. if _tpCount == targetNum then
  1158. table.insert(result,_tpReplace2)
  1159. end
  1160. end
  1161. if minVal == 0 and targetNum == 4 then--如果出的是aa22,则加上2233的提示
  1162. local _haveLai = guiNum;
  1163. local _tpCount = 0;
  1164. local _tpReplace2 = {}
  1165. valueList[13] = valueList[13] or 0;
  1166. if (valueList[13] + _haveLai >= 2) then
  1167. local _tpNum = 2 - valueList[13];
  1168. _tpNum = _tpNum >= 0 and _tpNum or 0;
  1169. local lai = guiNum - _haveLai + 1
  1170. for p = 1, _tpNum do
  1171. table.insert(_tpReplace2,gui[lai])
  1172. lai = lai + 1
  1173. end
  1174. for _m = 1, 2 - _tpNum do
  1175. table.insert(_tpReplace2, cardList[13][_m])
  1176. end
  1177. _haveLai = _haveLai - _tpNum;
  1178. _tpCount = _tpCount + 2;
  1179. end
  1180. valueList[1] = valueList[1] or 0;
  1181. if (valueList[1] + _haveLai >= 2) then
  1182. local _tpNum = 2 - valueList[1];
  1183. _tpNum = _tpNum >= 0 and _tpNum or 0;
  1184. local lai = guiNum - _haveLai + 1
  1185. for p = 1, _tpNum do
  1186. table.insert(_tpReplace2,gui[lai])
  1187. lai = lai + 1
  1188. end
  1189. for _m = 1, 2 - _tpNum do
  1190. table.insert(_tpReplace2, cardList[1][_m])
  1191. end
  1192. _haveLai = _haveLai - _tpNum;
  1193. _tpCount = _tpCount + 2;
  1194. end
  1195. if _tpCount == targetNum and valueList[13] > 0 and valueList[1] > 0 then
  1196. table.insert(result,_tpReplace2)
  1197. end
  1198. end
  1199. local resultex = {}
  1200. if #result > 0 then
  1201. for i = #result,1,-1 do
  1202. table.insert(resultex,result[i])
  1203. end
  1204. end
  1205. return resultex
  1206. end
  1207. -- 获取炸弹提示
  1208. function zgwrDdzUtil:getBombTip( cards, targets )
  1209. local minVal = self:getCardsMin(targets,OUT_TYPE.BOMB_FOUR)
  1210. local cclassify = self:classifyCardsEx(cards)
  1211. local isHaveGui,guiNum = self:checkHaveGui(cclassify)
  1212. local gui = self:getGuiByClassifyCards(cclassify)
  1213. local valueList = {}
  1214. local cardList = {}
  1215. for k,v in ipairs(cards) do
  1216. local value =v.val
  1217. if v ~= GUI_VAL then
  1218. valueList[value] = valueList[value] or 0
  1219. valueList[value] = valueList[value] + 1
  1220. cardList[value] = cardList[value] or {}
  1221. table.insert(cardList[value], v)
  1222. end
  1223. end
  1224. local result ={}
  1225. local _tpIndex = 1
  1226. for _i14 = minVal+1, 13 do
  1227. local _tpReplace4 = {}
  1228. valueList[_i14] = valueList[_i14] or 0
  1229. if (valueList[_i14] > 0 and valueList[_i14] + guiNum >= 4) then
  1230. local _tpNum4 = 4 - valueList[_i14];
  1231. _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0
  1232. for _l4 = 1, _tpNum4 do
  1233. table.insert(_tpReplace4,gui[_l4])
  1234. end
  1235. for _m4 = 1, 4 - _tpNum4 do
  1236. table.insert(_tpReplace4,cardList[_i14][_m4])
  1237. end
  1238. table.insert(result,_tpReplace4)
  1239. end
  1240. end
  1241. local resultex = {}
  1242. if #result > 0 then
  1243. for i = #result,1,-1 do
  1244. table.insert(resultex,result[i])
  1245. end
  1246. end
  1247. return resultex
  1248. end
  1249. -- 获取牌组中所有炸弹
  1250. function zgwrDdzUtil:getAllBomb( cards, isAaaBomb )
  1251. local parseHands = self:parseCards(cards)
  1252. local cclassify = self:classifyCardsEx(parseHands)
  1253. local isHaveGui,guiNum = self:checkHaveGui(cclassify)
  1254. local gui = self:getGuiByClassifyCards(cclassify)
  1255. local valueList = {}
  1256. local cardList = {}
  1257. for k,v in ipairs(parseHands) do
  1258. local value =v.val
  1259. if v ~= GUI_VAL then
  1260. valueList[value] = valueList[value] or 0
  1261. valueList[value] = valueList[value] + 1
  1262. cardList[value] = cardList[value] or {}
  1263. table.insert(cardList[value], v)
  1264. end
  1265. end
  1266. local result ={}
  1267. local _tpIndex = 1
  1268. for _i14 = 1, 13 do
  1269. local _tpReplace4 = {}
  1270. valueList[_i14] = valueList[_i14] or 0
  1271. if (valueList[_i14] > 0 and valueList[_i14] + guiNum >= 4) then
  1272. local _tpNum4 = 4 - valueList[_i14];
  1273. _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0
  1274. for _l4 = 1, _tpNum4 do
  1275. table.insert(_tpReplace4,gui[_l4])
  1276. end
  1277. for _m4 = 1, 4 - _tpNum4 do
  1278. table.insert(_tpReplace4,cardList[_i14][_m4])
  1279. end
  1280. table.insert(result,_tpReplace4)
  1281. end
  1282. end
  1283. return result
  1284. end
  1285. -- 获取飞机提示(手牌足够)
  1286. function zgwrDdzUtil:getPlanTip( cards, targets )
  1287. local minVal = self:getCardsMin(targets,OUT_TYPE.AIRPLANE)
  1288. local targetNum = #targets
  1289. local cclassify = self:classifyCardsEx(cards)
  1290. local isHaveGui,guiNum = self:checkHaveGui(cclassify)
  1291. local gui = self:getGuiByClassifyCards(cclassify)
  1292. local valueList = {}
  1293. local cardList = {}
  1294. for k,v in ipairs(cards) do
  1295. local value = v.val
  1296. if v ~= GUI_VAL then
  1297. valueList[value] = valueList[value] or 0
  1298. valueList[value] = valueList[value] + 1
  1299. cardList[value] = cardList[value] or {}
  1300. table.insert(cardList[value], v)
  1301. end
  1302. end
  1303. local result ={}
  1304. local needCardNum = 6
  1305. if targetNum == 9 then
  1306. needCardNum = 9
  1307. elseif targetNum == 12 then
  1308. needCardNum = 12
  1309. end
  1310. for i = minVal + 1, 14 - needCardNum/3 do
  1311. local _tpIdx = i;
  1312. local _tpCount = 0;
  1313. local _tpReplace2 = {}
  1314. local tpNotAllLai = false;
  1315. local _haveLai = guiNum;
  1316. while _tpCount < #cards and _tpCount < needCardNum and _tpIdx <= 12 do
  1317. valueList[_tpIdx] = valueList[_tpIdx] or 0;
  1318. if (not (valueList[_tpIdx] + _haveLai >= 3)) then break end;
  1319. local _tpNum = 3 - valueList[_tpIdx];
  1320. _tpNum = _tpNum >= 0 and _tpNum or 0;
  1321. local lai = guiNum - _haveLai + 1
  1322. for p = 1, _tpNum do
  1323. table.insert(_tpReplace2,gui[lai])
  1324. lai = lai + 1
  1325. end
  1326. for _m = 1, 3 - _tpNum do
  1327. table.insert(_tpReplace2, cardList[_tpIdx][_m])
  1328. tpNotAllLai = true;
  1329. end
  1330. _haveLai = _haveLai - _tpNum;
  1331. _tpCount = _tpCount + 3;
  1332. _tpIdx = _tpIdx + 1
  1333. end
  1334. if _tpCount == needCardNum or (_tpCount == 6 and needCardNum == 10) then
  1335. function checkIsHaveA2(tmptb)--判断是否有a2
  1336. if tmptb and next(tmptb) ~= nil then
  1337. local isHaveA = false
  1338. local isHave2 = false
  1339. for i,v in pairs(tmptb) do
  1340. if v.val == 12 then
  1341. isHaveA = true
  1342. elseif v.val == 13 then
  1343. isHave2 = true
  1344. end
  1345. end
  1346. return isHaveA and isHave2
  1347. end
  1348. end
  1349. if _tpCount == 6 and checkIsHaveA2(_tpReplace2) then--3顺aaa222最小
  1350. else
  1351. table.insert(result,_tpReplace2)
  1352. end
  1353. end
  1354. end
  1355. local resultex = {}
  1356. if #result > 0 then
  1357. for i = #result,1,-1 do
  1358. table.insert(resultex,result[i])
  1359. end
  1360. end
  1361. return resultex
  1362. --[[local tclassify = self:classifyCards(targets)
  1363. local target = self:getSameNum(tclassify, 3)
  1364. local cclassify = self:classifyCards(cards)
  1365. local tmps = self:getSameNumEx(cclassify, 3)
  1366. if #target > #tmps then return nil end
  1367. local tmpThree = {}
  1368. for _,v in pairs(tmps) do
  1369. if v[1].val > target[1][1].val then
  1370. while #v>3 do
  1371. table.remove(v, #v)
  1372. end
  1373. table.insert(tmpThree, v)
  1374. end
  1375. end
  1376. if #tmpThree > 1 then
  1377. table.sort(tmpThree, function ( a, b ) return a[1].val < b[1].val end)
  1378. end
  1379. local tmp = {}--一维数组
  1380. for _,v in pairs(tmpThree) do
  1381. for _,c in ipairs(v) do
  1382. table.insert(tmp, c)
  1383. end
  1384. end
  1385. if #target > #tmpThree then return nil end
  1386. if #target == 2 then--两组
  1387. if #tmpThree > 2 then
  1388. local t = {}
  1389. t = {tmpThree[1], tmpThree[2]}
  1390. tmpThree = clone(t)
  1391. end
  1392. if math.abs(tmpThree[1][1].val-tmpThree[2][1].val)==1 then
  1393. local left = getLeft(cards, tmp)
  1394. if #left<4 then
  1395. return nil
  1396. else
  1397. local tail = clone(left)
  1398. while #tail>4 do
  1399. table.remove(tail, #tail)
  1400. end
  1401. for _,v in pairs(tmpThree) do
  1402. for _,c in pairs(v) do
  1403. table.insert(tail, c)
  1404. end
  1405. end
  1406. return {tail}
  1407. end
  1408. else
  1409. return nil
  1410. end
  1411. elseif #target == 3 then--三组
  1412. if #tmpThree > 3 then
  1413. local t = {}
  1414. t = {tmpThree[1], tmpThree[2], tmpThree[3]}
  1415. tmpThree = clone(t)
  1416. end
  1417. if self:checkSZ({tmpThree[1][1], tmpThree[2][1], tmpThree[3][1]}) then
  1418. local left = getLeft(cards, tmp)
  1419. if #left<4 then
  1420. return nil
  1421. else
  1422. local tail = clone(left)
  1423. while #tail>6 do
  1424. table.remove(tail, #tail)
  1425. end
  1426. return {tmpThree, tail}
  1427. end
  1428. else
  1429. return nil
  1430. end
  1431. end
  1432. return nil --]]
  1433. end
  1434. -- 获取牌型提示
  1435. function zgwrDdzUtil:getOnlyTip( handCards, cards )
  1436. if #handCards < #cards then return nil end
  1437. local parseHands = self:parseCards(handCards)
  1438. local parseCards = self:parseCards(cards)
  1439. local tp = self:checkType(cards)
  1440. if tp >= OUT_TYPE.NONE then
  1441. return nil
  1442. end
  1443. local result = nil
  1444. if tp == OUT_TYPE.SINGLE_CARD then
  1445. result = self:getSingleTip(parseHands, parseCards)
  1446. elseif tp == OUT_TYPE.DUI_ZI then
  1447. result = self:getDoubleTip(parseHands, parseCards)
  1448. elseif tp == OUT_TYPE.THREE then
  1449. result = self:getThreeTip(parseHands, parseCards)
  1450. elseif tp == OUT_TYPE.THREE_AND_TWO or tp == OUT_TYPE.THREE_AND_DUI then
  1451. result = self:getThreeAnd2Tip(parseHands, parseCards)
  1452. elseif tp == OUT_TYPE.SHUN_ZI then
  1453. result = self:getShunziTip(parseHands, parseCards)
  1454. elseif tp == OUT_TYPE.LIAN_DUI then
  1455. result = self:getLianduiTip(parseHands, parseCards)
  1456. if result==nil then return nil end
  1457. local tmp = {}
  1458. for _,group in ipairs(result) do
  1459. local t = {}
  1460. for _,vv in ipairs(group) do
  1461. for _,v in ipairs(vv) do
  1462. table.insert(t, v)
  1463. end
  1464. end
  1465. table.insert(tmp, clone(t))
  1466. end
  1467. result = tmp
  1468. -- return tmp
  1469. elseif tp == OUT_TYPE.AIRPLANE then
  1470. result = self:getPlanTip(parseHands, parseCards)
  1471. elseif tp == OUT_TYPE.FOUR_AND_THREE then
  1472. result = self:getFourAnd3(parseHands, parseCards)
  1473. elseif tp == OUT_TYPE.BOMB then
  1474. result = self:getBombTip(parseHands, parseCards)
  1475. elseif tp == OUT_TYPE.FOUR_AND_ONE then
  1476. result = self:getFourAnd1(parseHands, parseCards)
  1477. end
  1478. if tp~= OUT_TYPE.BOMB then
  1479. local bombs = self:getAllBomb(handCards)
  1480. if #bombs==1 then
  1481. if result then
  1482. table.insert(result, bombs[1])
  1483. --[[for _,v in pairs(bombs) do
  1484. end]]--
  1485. else
  1486. result={bombs[1]}
  1487. --result = bombs[1]
  1488. end
  1489. end
  1490. end
  1491. if result and #result==1 then
  1492. return result
  1493. end
  1494. return nil
  1495. end
  1496. -- 获取只有一种牌型提示
  1497. function zgwrDdzUtil:getTip( handCards, cards )
  1498. if #handCards < #cards then return nil end
  1499. if app.room.isMustBomb and app.room.isMustBomb == 1 then return nil end
  1500. local parseHands = self:parseCards(handCards)
  1501. local parseCards = self:parseCards(cards)
  1502. local tp = self:checkType(cards)
  1503. if app.room.lastOutType and app.room.lastOutType >0 and app.room.lastOutType < OUT_TYPE.NONE then
  1504. tp = app.room.lastOutType
  1505. end
  1506. if tp >= OUT_TYPE.NONE then
  1507. return nil
  1508. end
  1509. if tp == OUT_TYPE.SINGLE_CARD then
  1510. return self:getSingleTip(parseHands, parseCards)
  1511. elseif tp == OUT_TYPE.DUI_ZI then
  1512. local result = self:getDoubleTip(parseHands, parseCards)
  1513. return result
  1514. elseif tp == OUT_TYPE.THREE then
  1515. return self:getThreeTip(parseHands, parseCards)
  1516. elseif tp == OUT_TYPE.THREE_AND_TWO or tp == OUT_TYPE.THREE_AND_DUI then
  1517. return self:getThreeAnd2Tip(parseHands, parseCards)
  1518. elseif tp == OUT_TYPE.SHUN_ZI then
  1519. local result = self:getShunziTip(parseHands, parseCards)
  1520. return result
  1521. elseif tp == OUT_TYPE.LIAN_DUI then
  1522. local result = self:getLianduiTip(parseHands, parseCards)
  1523. if result==nil then return nil end
  1524. return result
  1525. elseif tp == OUT_TYPE.AIRPLANE or tp == OUT_TYPE.AIRPLANE_TOW or tp == OUT_TYPE.AIRPLANE_DUI then
  1526. return self:getPlanTip(parseHands, parseCards)
  1527. elseif tp == OUT_TYPE.FOUR_AND_THREE then
  1528. return self:getFourAnd3(parseHands, parseCards)
  1529. elseif tp == OUT_TYPE.BOMB then
  1530. return self:getBombTip(parseHands, parseCards)
  1531. elseif tp == OUT_TYPE.FOUR_AND_ONE then
  1532. return self:getFourAnd1(parseHands, parseCards)
  1533. else
  1534. return nil
  1535. end
  1536. end
  1537. -- 第一手出牌提示
  1538. function zgwrDdzUtil:getFirstTip( handCards )
  1539. if #handCards<=0 then return nil end
  1540. local parseHands = self:parseCards(handCards)
  1541. local classify = self:classifyCardsEx(parseHands)
  1542. local singles = {}
  1543. local fours = {}
  1544. for valStr,cds in pairs(classify) do
  1545. if #cds == 1 then
  1546. table.insert(singles, cds)
  1547. elseif #cds == 2 then
  1548. table.insert(singles, cds)
  1549. elseif #cds == 3 then
  1550. table.insert(singles, cds)
  1551. elseif #cds == 4 then
  1552. table.insert(fours, cds)
  1553. end
  1554. end
  1555. if #singles > 0 then
  1556. if #singles>=2 then
  1557. table.sort(singles, function ( a, b )
  1558. return a[1].val > b[1].val
  1559. end)
  1560. end
  1561. return singles
  1562. else
  1563. if #fours>0 then
  1564. return fours
  1565. end
  1566. end
  1567. end
  1568. -- 检测最后一手牌能否一次出完
  1569. function zgwrDdzUtil:checkOnceOut( handCards )
  1570. local tp = self:checkType(handCards)
  1571. if tp == OUT_TYPE.THREE_AND_TWO then
  1572. --[[if self.isChai then --将3带2还原成4带1
  1573. local parseHands = self:parseCards(handCards)
  1574. if self:check4And1(parseHands) then
  1575. tp = OUT_TYPE.FOUR_AND_ONE
  1576. end
  1577. end--]]
  1578. end
  1579. if tp == OUT_TYPE.AIRPLANE then--还原4带3
  1580. --[[if self.isFAT then
  1581. local parseHands = self:parseCards(handCards)
  1582. if self:check4And3(parseHands) then
  1583. tp = OUT_TYPE.FOUR_AND_THREE
  1584. end
  1585. end--]]
  1586. end
  1587. print("----------------------------------once out : ", tp)
  1588. if tp and (tp < OUT_TYPE.NONE) then
  1589. return (tp==OUT_TYPE.SINGLE_CARD
  1590. or tp==OUT_TYPE.DUI_ZI
  1591. or tp==OUT_TYPE.SHUN_ZI
  1592. or tp==OUT_TYPE.THREE_AND_TWO
  1593. or tp==OUT_TYPE.THREE_AND_DUI
  1594. or tp==OUT_TYPE.THREE
  1595. or tp==OUT_TYPE.LIAN_DUI
  1596. or tp==OUT_TYPE.AIRPLANE
  1597. or tp==OUT_TYPE.AIRPLANE_DUI
  1598. or tp==OUT_TYPE.AIRPLANE_TOW), tp
  1599. else--unwork dead code
  1600. --检测是否是三个带不全
  1601. if #handCards > 4 then
  1602. return false, tp
  1603. else
  1604. --不检测三带一
  1605. --[[local parseHands = self:parseCards(handCards)
  1606. local classify = self:classifyCards(parseHands)
  1607. local tmps = self:getSameNum(classify, 3)
  1608. if #tmps>=1 then
  1609. return true, tp
  1610. else
  1611. return false, tp
  1612. end--]]
  1613. end
  1614. end
  1615. return false , tp
  1616. end
  1617. -- 判断牌是否是手牌中最大的牌
  1618. function zgwrDdzUtil:isMaxCard(handCards, card)
  1619. local targetTp, targetVal = pokerParse(card)
  1620. local parseHands = self:parseCards(handCards)
  1621. local result = true
  1622. for _,v in pairs(parseHands) do
  1623. if v.val ~= GUI_VAL and v.val > targetVal then
  1624. result = false
  1625. break
  1626. end
  1627. end
  1628. return result
  1629. end
  1630. -- 检测是否拆了炸弹
  1631. function zgwrDdzUtil:isChaiBombs( handCards, selects )
  1632. local parseSelects = self:parseCards(selects)
  1633. --检测手上是否有炸弹
  1634. local bombs = self:getAllBomb(handCards)
  1635. if #bombs > 0 then
  1636. for _,bomb in pairs(bombs) do
  1637. if self:checkOwnX(parseSelects, bomb[1]) then
  1638. local classifySelects = self:classifyCardsEx(parseSelects)
  1639. local target = classifySelects[tostring(bomb[1].val)]
  1640. if #target < 4 then
  1641. return true
  1642. end
  1643. end
  1644. end
  1645. else
  1646. return false
  1647. end
  1648. return false
  1649. end
  1650. -- 判断三带不全出牌
  1651. function zgwrDdzUtil:checkThreeOut( handCards ,targets)
  1652. local parseHands = self:parseCards(handCards)
  1653. local parseTargets = self:parseCards(targets)
  1654. local handsThree = self:getSameNumExEx(parseHands)
  1655. local targetThree = self:getSameNumExEx(parseTargets)
  1656. local handVal = nil
  1657. local targetVal = nil
  1658. for k,v in pairs(targetThree) do
  1659. targetVal = tonumber(k)
  1660. end
  1661. for k,v in pairs(handsThree) do
  1662. handVal = tonumber(k)
  1663. end
  1664. if targetVal and handVal then
  1665. return targetVal < handVal
  1666. end
  1667. return false
  1668. end
  1669. --
  1670. function zgwrDdzUtil:leftCards( handCards, targets)
  1671. local result = {}
  1672. local ts = {}
  1673. for _,group in pairs(targets) do
  1674. for _,card in pairs(group) do
  1675. table.insert(ts, card.cid)--将能出的牌汇集到一起
  1676. end
  1677. end
  1678. for _,hcid in pairs(handCards) do
  1679. local own = false
  1680. for _,tcid in pairs(ts) do
  1681. if hcid == tcid then--包含了同一张牌
  1682. own = true
  1683. end
  1684. end
  1685. if not own then
  1686. table.insert(result, hcid)
  1687. end
  1688. end
  1689. return result
  1690. end
  1691. -- 提示,只剩大于最小牌的牌
  1692. function zgwrDdzUtil:leftCardsEx( handCards, targets)
  1693. local result = {}
  1694. local ts = {}
  1695. local minVal = 100
  1696. for _,group in pairs(targets) do
  1697. for _,card in pairs(group) do
  1698. table.insert(ts, card.cid)--将能出的牌汇集到一起
  1699. if card.val < minVal then
  1700. minVal = card.val--能出牌的最小张
  1701. end
  1702. end
  1703. end
  1704. for _,hcid in pairs(handCards) do
  1705. local own = false
  1706. for _,tcid in pairs(ts) do
  1707. local _, val = pokerParse(hcid)
  1708. if hcid == tcid or val >= minVal then
  1709. own = true
  1710. end
  1711. end
  1712. if not own then
  1713. table.insert(result, hcid)
  1714. end
  1715. end
  1716. return result
  1717. end
  1718. --
  1719. function zgwrDdzUtil:leftSingleCards( handCards, targets)
  1720. local result = {}
  1721. local ts = {}
  1722. for _,card in pairs(targets) do
  1723. if card.cid == nil and type(card)=='table' and #card>0 then
  1724. for _,v in ipairs(card) do
  1725. table.insert(ts, v.cid)
  1726. end
  1727. else
  1728. table.insert(ts, card.cid)
  1729. end
  1730. end
  1731. for _,hcid in pairs(handCards) do
  1732. local own = false
  1733. for _,tcid in pairs(ts) do
  1734. if hcid == tcid then
  1735. own = true
  1736. end
  1737. end
  1738. if not own then
  1739. table.insert(result, hcid)
  1740. end
  1741. end
  1742. return result
  1743. end
  1744. --是否是AAA
  1745. function zgwrDdzUtil:isAAA( cards )
  1746. if #cards ~= 3 then return false end
  1747. local result = true
  1748. for i,v in ipairs(cards) do
  1749. local _, val = pokerParse(v)
  1750. if val ~= A_VAL then
  1751. result = false
  1752. break
  1753. end
  1754. end
  1755. return result
  1756. end
  1757. --是否有王
  1758. function zgwrDdzUtil:isHaveKing( cards )
  1759. if not cards then return false end
  1760. local result = false
  1761. for i,v in ipairs(cards) do
  1762. local _, val = pokerParse(v)
  1763. if val == X_KING or val == D_KING then
  1764. result = true
  1765. break
  1766. end
  1767. end
  1768. return result
  1769. end
  1770. --是否有小王
  1771. function zgwrDdzUtil:isHaveXKing( cards )
  1772. if not cards then return false end
  1773. local result = false
  1774. local xkingNum = 0
  1775. for i,v in ipairs(cards) do
  1776. local _, val = pokerParse(v)
  1777. if val == X_KING then
  1778. result = true
  1779. xkingNum = xkingNum + 1
  1780. end
  1781. end
  1782. return result,xkingNum
  1783. end
  1784. --是否有大王
  1785. function zgwrDdzUtil:isHaveDKing( cards )
  1786. if not cards then return false end
  1787. local result = false
  1788. local dkingNum = 0
  1789. for i,v in ipairs(cards) do
  1790. local _, val = pokerParse(v)
  1791. if val == D_KING then
  1792. result = true
  1793. dkingNum = dkingNum + 1
  1794. end
  1795. end
  1796. return result,dkingNum
  1797. end
  1798. --检查牌是否全是鬼牌
  1799. function zgwrDdzUtil:checkIsAllGui(cards)
  1800. for i,v in ipairs(cards) do
  1801. local _, val = pokerParse(v)
  1802. if val ~= GUI_VAL then
  1803. return false
  1804. end
  1805. end
  1806. return true
  1807. end
  1808. function zgwrDdzUtil:checkType(cards)
  1809. local cardsLen = table.nums(cards)
  1810. if cardsLen == 0 then
  1811. return OUT_TYPE.NONE
  1812. end
  1813. local valueList = {}
  1814. local cardList = {}
  1815. local laiCount = 0
  1816. local a = {}
  1817. for k,v in ipairs(cards) do
  1818. local value = self:getCardValue(v)
  1819. if value == GUI_VAL then
  1820. laiCount = laiCount + 1
  1821. elseif value == X_KING or value == D_KING then--小王和大王
  1822. else
  1823. valueList[value] = valueList[value] or 0
  1824. valueList[value] = valueList[value] + 1
  1825. cardList[value] = cardList[value] or {}
  1826. table.insert(cardList[value], v)
  1827. end
  1828. end
  1829. --[[if laiCount == cardsLen then
  1830. if laiCount == 1 then
  1831. return OUT_TYPE.SINGLE_CARD
  1832. elseif laiCount == 2 then
  1833. return OUT_TYPE.DUI_ZI
  1834. elseif laiCount == 3 then
  1835. return OUT_TYPE.THREE
  1836. end
  1837. end--]]
  1838. for k,v in ipairs(valueList) do
  1839. a[v] = a[v] or {}
  1840. table.insert(a[v], v)
  1841. end
  1842. local t_isHaveKing = self:isHaveKing(cards)
  1843. local typesEx = {}
  1844. --默认纯赖子不可打出
  1845. if cardsLen == 1 then
  1846. --单张
  1847. table.insert(typesEx, "单张")
  1848. return OUT_TYPE.SINGLE_CARD
  1849. elseif cardsLen == 2 and table.nums(valueList) == 1 and (not t_isHaveKing) then
  1850. --对子
  1851. table.insert(typesEx, "对子")
  1852. return OUT_TYPE.DUI_ZI
  1853. elseif cardsLen == 2 and table.nums(valueList) == 0 then
  1854. local isHaveDking,dKingNum = self:isHaveDKing(cards)
  1855. local isHaveXking,xKingNum = self:isHaveXKing(cards)
  1856. if isHaveDking and isHaveXking then
  1857. --对王
  1858. table.insert(typesEx, "对王")
  1859. return OUT_TYPE.BIG_SMALL_KING
  1860. elseif isHaveDking then
  1861. return OUT_TYPE.TWO_BIG_KING
  1862. elseif isHaveXking then
  1863. return OUT_TYPE.TWO_SMALL_KING
  1864. end
  1865. elseif cardsLen == 3 and table.nums(valueList) == 1 and (not t_isHaveKing) then
  1866. --三张
  1867. table.insert(typesEx, "三张")
  1868. return OUT_TYPE.THREE
  1869. else
  1870. if cardsLen == 4 and table.nums(valueList) == 1 and (not t_isHaveKing) then
  1871. --炸弹
  1872. table.insert(typesEx, "炸弹")
  1873. return OUT_TYPE.BOMB_FOUR
  1874. elseif cardsLen == 8 and table.nums(valueList) == 1 then
  1875. table.insert(typesEx, "炸弹")
  1876. return OUT_TYPE.BOMB_EIGHT
  1877. elseif cardsLen == 12 and table.nums(valueList) == 1 then
  1878. table.insert(typesEx, "炸弹")
  1879. return OUT_TYPE.BOMB_TWELVE
  1880. else
  1881. --4王炸
  1882. if cardsLen == 4 and table.nums(valueList) == 0 then
  1883. local isHaveDking,dKingNum = self:isHaveDKing(cards)
  1884. local isHaveXking,xKingNum = self:isHaveXKing(cards)
  1885. if isHaveDking and isHaveXking then
  1886. if xKingNum == 1 then
  1887. return OUT_TYPE.THREE_BIG_SMALL_KING
  1888. elseif xKingNum == 2 then
  1889. return OUT_TYPE.TWO_BIG_TWO_SMALL_KING
  1890. elseif xKingNum == 3 then
  1891. return OUT_TYPE.BIG_THREE_SMALL_KING
  1892. end
  1893. elseif isHaveDking then
  1894. return OUT_TYPE.FOUR_BIG_KING
  1895. elseif isHaveXking then
  1896. return OUT_TYPE.FOUR_SMALL_KING
  1897. end
  1898. elseif cardsLen == 6 and table.nums(valueList) == 0 then
  1899. local isHaveDking,dKingNum = self:isHaveDKing(cards)
  1900. local isHaveXking,xKingNum = self:isHaveXKing(cards)
  1901. if isHaveDking and isHaveXking then
  1902. if xKingNum == 1 then
  1903. return OUT_TYPE.FIVE_BIG_SMALL_KING
  1904. elseif xKingNum == 2 then
  1905. return OUT_TYPE.FOUR_BIG_TWO_SMALL_KING
  1906. elseif xKingNum == 3 then
  1907. return OUT_TYPE.THREE_BIG_THREE_SMALL_KING
  1908. end
  1909. elseif isHaveDking then
  1910. return OUT_TYPE.SIX_BIG_KING
  1911. elseif isHaveXking then
  1912. return OUT_TYPE.SIX_SMALL_KING
  1913. end
  1914. end
  1915. --如果要出的牌里面某张牌的数量大于等于4,他又不是炸弹,则组成不了任何牌型
  1916. for i,v in pairs(valueList) do
  1917. if v >= 4 then
  1918. return OUT_TYPE.NONE
  1919. end
  1920. end
  1921. local isHaveDking,dKingNum = self:isHaveDKing(cards)
  1922. local isHaveXking,xKingNum = self:isHaveXKing(cards)
  1923. if dKingNum + xKingNum >= 2 then
  1924. return OUT_TYPE.NONE
  1925. end
  1926. --三代一
  1927. if cardsLen == 4 and table.nums(valueList) <= 2 then
  1928. for i = 1, 10 do
  1929. local cardsEx = {}
  1930. local laiCountEx = laiCount
  1931. local valueCountEx = valueList[i] or 0
  1932. if valueCountEx >= 1 and valueCountEx <= 3 and valueCountEx + laiCountEx >= 3 then
  1933. local userLaiCount = 3 - valueCountEx
  1934. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  1935. for i = 1, userLaiCount do
  1936. table.insert(cardsEx, 0x0e)
  1937. end
  1938. for i = 1, 2 - userLaiCount do
  1939. table.insert(cardsEx, cardList[i])
  1940. end
  1941. --三代一
  1942. table.insert(typesEx, "三代一")
  1943. return OUT_TYPE.THREE_AND_ONE
  1944. end
  1945. end
  1946. end
  1947. --三代二
  1948. if cardsLen == 5 and table.nums(valueList) == 2 and (not t_isHaveKing) then
  1949. for i = 1, 10 do
  1950. local cardsEx = {}
  1951. local laiCountEx = laiCount
  1952. local valueCountEx = valueList[i] or 0
  1953. if valueCountEx >= 1 and valueCountEx <= 3 and valueCountEx + laiCountEx >= 3 then
  1954. local userLaiCount = 3 - valueCountEx
  1955. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  1956. for i = 1, userLaiCount do
  1957. table.insert(cardsEx, 0x0e)
  1958. end
  1959. for i = 1, 2 - userLaiCount do
  1960. table.insert(cardsEx, cardList[i])
  1961. end
  1962. --三代二
  1963. table.insert(typesEx, "三代二")
  1964. return OUT_TYPE.THREE_AND_DUI
  1965. end
  1966. end
  1967. end
  1968. --顺子
  1969. if cardsLen >= 5 then
  1970. for i = 1, 9 do
  1971. local iEx = i
  1972. local countEx = 0
  1973. local cardsEx = {}
  1974. local laiCountEx = laiCount
  1975. while iEx <= 9 and countEx < cardsLen do
  1976. local valueCountEx = valueList[iEx] or 0
  1977. if valueCountEx + laiCountEx >= 1 then
  1978. local userLaiCount = 1 - valueCountEx
  1979. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  1980. for i = 1, userLaiCount do
  1981. table.insert(cardsEx, 0x0f)
  1982. end
  1983. for i = 1, 1 - userLaiCount do
  1984. table.insert(cardsEx, cardList[i])
  1985. end
  1986. iEx = iEx + 1
  1987. countEx = countEx + 1
  1988. laiCountEx = laiCountEx - userLaiCount
  1989. else
  1990. break
  1991. end
  1992. end
  1993. if countEx == cardsLen then
  1994. --顺子
  1995. table.insert(typesEx, "顺子")
  1996. return OUT_TYPE.SHUN_ZI
  1997. end
  1998. end
  1999. end
  2000. --连对
  2001. if cardsLen % 2 == 0 and cardsLen >= 6 then
  2002. for i = 1, 9 do
  2003. local iEx = i
  2004. local countEx = 0
  2005. local cardsEx = {}
  2006. local laiCountEx = laiCount
  2007. while iEx <= 9 and countEx < cardsLen do
  2008. local valueCountEx = valueList[iEx] or 0
  2009. if valueCountEx + laiCountEx >= 2 then
  2010. local userLaiCount = 2 - valueCountEx
  2011. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2012. if userLaiCount == 2 then
  2013. break
  2014. end
  2015. for i = 1, userLaiCount do
  2016. table.insert(cardsEx, 0x0f)
  2017. end
  2018. for i = 1, 2 - userLaiCount do
  2019. table.insert(cardsEx, cardList[i])
  2020. end
  2021. iEx = iEx + 1
  2022. countEx = countEx + 2
  2023. laiCountEx = laiCountEx - userLaiCount
  2024. else
  2025. break
  2026. end
  2027. end
  2028. if countEx == cardsLen then
  2029. table.insert(typesEx, "连对")
  2030. return OUT_TYPE.LIAN_DUI
  2031. end
  2032. end
  2033. end
  2034. --三顺
  2035. if cardsLen % 3 == 0 and cardsLen >= 6 then
  2036. for i = 1, 9 do
  2037. local iEx = i
  2038. local countEx = 0
  2039. local cardsEx = {}
  2040. local laiCountEx = laiCount
  2041. while iEx <= 9 and countEx < cardsLen do
  2042. local valueCountEx = valueList[iEx] or 0
  2043. if valueCountEx + laiCountEx >= 3 then
  2044. local userLaiCount = 3 - valueCountEx
  2045. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2046. if userLaiCount == 3 then
  2047. break
  2048. end
  2049. for i = 1, userLaiCount do
  2050. table.insert(cardsEx, 0x0f)
  2051. end
  2052. for i = 1, 3 - userLaiCount do
  2053. table.insert(cardsEx, cardList[i])
  2054. end
  2055. iEx = iEx + 1
  2056. countEx = countEx + 3
  2057. laiCountEx = laiCountEx - userLaiCount
  2058. else
  2059. break
  2060. end
  2061. end
  2062. if countEx == cardsLen then
  2063. --三顺
  2064. table.insert(typesEx, "三顺")
  2065. return OUT_TYPE.SAN_SHUN
  2066. end
  2067. end
  2068. end
  2069. --飞机带单
  2070. if cardsLen % 4 == 0 and cardsLen >= 8 and table.nums(valueList) <= cardsLen / 4 * 2 then
  2071. for i = 1, 9 do
  2072. local iEx = i
  2073. local countEx = 0
  2074. local cardsEx = {}
  2075. local laiCountEx = laiCount
  2076. while iEx <= 9 and countEx < cardsLen / 4 do
  2077. local valueCountEx = valueList[iEx] or 0
  2078. if valueCountEx + laiCountEx >= 3 then
  2079. local userLaiCount = 3 - valueCountEx
  2080. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2081. for i = 1, userLaiCount do
  2082. table.insert(cardsEx, 0x0f)
  2083. end
  2084. for i = 1, 3 - userLaiCount do
  2085. table.insert(cardsEx, cardList[i])
  2086. end
  2087. iEx = iEx + 1
  2088. countEx = countEx + 1
  2089. laiCountEx = laiCountEx - userLaiCount
  2090. else
  2091. break
  2092. end
  2093. end
  2094. if countEx == cardsLen / 4 and laiCountEx < 1 then
  2095. --飞机
  2096. --[[local threeNum = 0
  2097. for i,v in pairs(valueList) do
  2098. if v >= 3 then
  2099. threeNum = threeNum + 1
  2100. end
  2101. end--]]
  2102. if countEx > 1 then
  2103. table.insert(typesEx, "飞机")
  2104. return OUT_TYPE.AIRPLANE_SINGLE
  2105. end
  2106. end
  2107. end
  2108. end
  2109. --飞机带双
  2110. if cardsLen % 5 == 0 and cardsLen >= 10 and table.nums(valueList) == cardsLen / 5 * 2 and (not t_isHaveKing) then
  2111. for i = 1, 9 do
  2112. local iEx = i
  2113. local countEx = 0
  2114. local cardsEx = {}
  2115. local laiCountEx = laiCount
  2116. while iEx <= 9 and countEx < cardsLen / 5 do
  2117. local valueCountEx = valueList[iEx] or 0
  2118. if valueCountEx + laiCountEx >= 3 then
  2119. local userLaiCount = 3 - valueCountEx
  2120. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2121. if userLaiCount == 3 then
  2122. break
  2123. end
  2124. for i = 1, userLaiCount do
  2125. table.insert(cardsEx, 0x0f)
  2126. end
  2127. for i = 1, 3 - userLaiCount do
  2128. table.insert(cardsEx, cardList[i])
  2129. end
  2130. iEx = iEx + 1
  2131. countEx = countEx + 1
  2132. laiCountEx = laiCountEx - userLaiCount
  2133. else
  2134. break
  2135. end
  2136. end
  2137. if countEx == cardsLen / 5 then
  2138. --飞机
  2139. local threeNum = 0
  2140. local singleNum = 0
  2141. for i,v in pairs(valueList) do
  2142. if v >= 3 then
  2143. threeNum = threeNum + 1
  2144. end
  2145. if v == 1 then
  2146. singleNum = singleNum + 1
  2147. end
  2148. end
  2149. if laiCountEx > 0 then
  2150. if laiCountEx == singleNum then
  2151. return OUT_TYPE.AIRPLANE_DUI
  2152. end
  2153. else
  2154. if threeNum <= cardsLen / 5 then
  2155. table.insert(typesEx, "飞机")
  2156. return OUT_TYPE.AIRPLANE_DUI
  2157. end
  2158. end
  2159. end
  2160. end
  2161. end
  2162. end
  2163. end
  2164. return OUT_TYPE.NONE
  2165. end
  2166. --检测是否是三顺
  2167. function zgwrDdzUtil:checkIsSanShun(cards)
  2168. local cardsLen = table.nums(cards)
  2169. if cardsLen == 0 then
  2170. return OUT_TYPE.NONE
  2171. end
  2172. local valueList = {}
  2173. local cardList = {}
  2174. local laiCount = 0
  2175. local a = {}
  2176. for k,v in ipairs(cards) do
  2177. local value = self:getCardValue(v)
  2178. if value == GUI_VAL then
  2179. laiCount = laiCount + 1
  2180. elseif value == X_KING or value == D_KING then--小王和大王
  2181. else
  2182. valueList[value] = valueList[value] or 0
  2183. valueList[value] = valueList[value] + 1
  2184. cardList[value] = cardList[value] or {}
  2185. table.insert(cardList[value], v)
  2186. end
  2187. end
  2188. --三顺
  2189. if cardsLen % 3 == 0 and cardsLen >= 6 then
  2190. for i = 1, 9 do
  2191. local iEx = i
  2192. local countEx = 0
  2193. local cardsEx = {}
  2194. local laiCountEx = laiCount
  2195. while iEx <= 9 and countEx < cardsLen do
  2196. local valueCountEx = valueList[iEx] or 0
  2197. if valueCountEx + laiCountEx >= 3 then
  2198. local userLaiCount = 3 - valueCountEx
  2199. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2200. for i = 1, userLaiCount do
  2201. table.insert(cardsEx, 0x0f)
  2202. end
  2203. for i = 1, 3 - userLaiCount do
  2204. table.insert(cardsEx, cardList[i])
  2205. end
  2206. iEx = iEx + 1
  2207. countEx = countEx + 3
  2208. laiCountEx = laiCountEx - userLaiCount
  2209. else
  2210. break
  2211. end
  2212. end
  2213. if countEx == cardsLen then
  2214. --三顺
  2215. return true
  2216. end
  2217. end
  2218. end
  2219. end
  2220. --根据牌类型获取最小值
  2221. function zgwrDdzUtil:getCardsMin(cards,cardtype)
  2222. local orginCards = cards
  2223. local cardsLen = table.nums(cards)
  2224. if cardsLen == 0 then
  2225. return
  2226. end
  2227. local cards = self:parseCards(cards)
  2228. local valueList = {}
  2229. local cardList = {}
  2230. local laiCount = 0
  2231. local a = {}
  2232. for k,v in ipairs(cards) do
  2233. local value = v.val
  2234. if value == GUI_VAL then
  2235. laiCount = laiCount + 1
  2236. else
  2237. valueList[value] = valueList[value] or 0
  2238. valueList[value] = valueList[value] + 1
  2239. cardList[value] = cardList[value] or {}
  2240. table.insert(cardList[value], v)
  2241. end
  2242. end
  2243. if laiCount == cardsLen then
  2244. return
  2245. end
  2246. for k,v in ipairs(valueList) do
  2247. a[v] = a[v] or {}
  2248. table.insert(a[v], v)
  2249. end
  2250. local typesEx = {}
  2251. --默认纯赖子不可打出
  2252. if cardtype == OUT_TYPE.SINGLE_CARD then
  2253. for i,v in pairs(cardList) do
  2254. return v[1].val
  2255. end
  2256. elseif cardtype == OUT_TYPE.DUI_ZI and cardsLen == 2 and table.nums(valueList) == 1 then
  2257. --对子
  2258. table.insert(typesEx, "对子")
  2259. for i,v in pairs(cardList) do
  2260. return v[1].val
  2261. end
  2262. elseif cardtype == OUT_TYPE.THREE and cardsLen == 3 and table.nums(valueList) == 1 then
  2263. --三张
  2264. table.insert(typesEx, "三张")
  2265. for i,v in pairs(cardList) do
  2266. return v[1].val
  2267. end
  2268. else
  2269. if cardtype == OUT_TYPE.BOMB_FOUR and table.nums(valueList) == 1 then
  2270. --炸弹
  2271. table.insert(typesEx, "炸弹")
  2272. for i,v in pairs(cardList) do
  2273. return v[1].val
  2274. end
  2275. elseif cardtype == OUT_TYPE.BOMB_EIGHT and table.nums(valueList) == 1 then
  2276. --炸弹
  2277. table.insert(typesEx, "炸弹")
  2278. for i,v in pairs(cardList) do
  2279. return v[1].val
  2280. end
  2281. elseif cardtype == OUT_TYPE.BOMB_TWELVE and table.nums(valueList) == 1 then
  2282. --炸弹
  2283. table.insert(typesEx, "炸弹")
  2284. for i,v in pairs(cardList) do
  2285. return v[1].val
  2286. end
  2287. else
  2288. --三代一
  2289. if cardtype == OUT_TYPE.THREE_AND_ONE then
  2290. for i = 13, 1,-1 do
  2291. local cardsEx = {}
  2292. local laiCountEx = laiCount
  2293. local valueCountEx = valueList[i] or 0
  2294. if valueCountEx >= 1 and valueCountEx <= 3 and valueCountEx + laiCountEx >= 3 then
  2295. local userLaiCount = 3 - valueCountEx
  2296. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2297. for k = 1, userLaiCount do
  2298. table.insert(cardsEx, 0x0f)
  2299. end
  2300. for k = 1, 2 - userLaiCount do
  2301. table.insert(cardsEx, cardList[k])
  2302. end
  2303. --三代一
  2304. table.insert(typesEx, "三代一")
  2305. return i
  2306. end
  2307. end
  2308. end
  2309. --三代二
  2310. if cardtype == OUT_TYPE.THREE_AND_DUI then
  2311. for i = 13, 1,-1 do
  2312. local cardsEx = {}
  2313. local laiCountEx = laiCount
  2314. local valueCountEx = valueList[i] or 0
  2315. if valueCountEx >= 1 and valueCountEx <= 3 and valueCountEx + laiCountEx >= 3 then
  2316. local userLaiCount = 3 - valueCountEx
  2317. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2318. for k = 1, userLaiCount do
  2319. table.insert(cardsEx, 0x0f)
  2320. end
  2321. for k = 1, 2 - userLaiCount do
  2322. table.insert(cardsEx, cardList[k])
  2323. end
  2324. --三代二
  2325. table.insert(typesEx, "三代二")
  2326. return i
  2327. end
  2328. end
  2329. end
  2330. --顺子
  2331. if cardtype == OUT_TYPE.SHUN_ZI and cardsLen >= 5 then
  2332. for i = 9, 1,-1 do
  2333. local iEx = i
  2334. local countEx = 0
  2335. local cardsEx = {}
  2336. local laiCountEx = laiCount
  2337. while iEx >= 1 and countEx < cardsLen do
  2338. local valueCountEx = valueList[iEx] or 0
  2339. if valueCountEx + laiCountEx >= 1 then
  2340. local userLaiCount = 1 - valueCountEx
  2341. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2342. for k = 1, userLaiCount do
  2343. table.insert(cardsEx, 0x0f)
  2344. end
  2345. for k = 1, 1 - userLaiCount do
  2346. table.insert(cardsEx, cardList[k])
  2347. end
  2348. iEx = iEx - 1
  2349. countEx = countEx + 1
  2350. laiCountEx = laiCountEx - userLaiCount
  2351. else
  2352. break
  2353. end
  2354. end
  2355. if countEx == cardsLen then
  2356. --顺子
  2357. table.insert(typesEx, "顺子")
  2358. return (i-cardsLen+1)
  2359. --[[if laiCount > 0 then
  2360. for ii=1,5 do
  2361. if valueList[ii] > 0 then
  2362. return ii
  2363. end
  2364. end
  2365. return 5
  2366. else
  2367. return i
  2368. end--]]
  2369. end
  2370. end
  2371. local isMinTime = 0
  2372. for i,v in pairs(cards) do
  2373. if v.val == 13 then
  2374. isMinTime = isMinTime + 1
  2375. return 0
  2376. elseif v.val ==1 or v.val==12 then
  2377. isMinTime = isMinTime + 1
  2378. end
  2379. end
  2380. if isMinTime >= 2 then
  2381. return 0
  2382. end
  2383. return 0
  2384. end
  2385. --连对
  2386. if cardtype == OUT_TYPE.LIAN_DUI and cardsLen % 2 == 0 and cardsLen >= 4 then
  2387. for i = 1, 9 do
  2388. local iEx = i
  2389. local countEx = 0
  2390. local cardsEx = {}
  2391. local laiCountEx = laiCount
  2392. while iEx <= 9 and countEx < cardsLen do
  2393. local valueCountEx = valueList[iEx] or 0
  2394. if valueCountEx + laiCountEx >= 2 then
  2395. local userLaiCount = 2 - valueCountEx
  2396. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2397. for k = 1, userLaiCount do
  2398. table.insert(cardsEx, 0x0f)
  2399. end
  2400. for k = 1, 2 - userLaiCount do
  2401. table.insert(cardsEx, cardList[k])
  2402. end
  2403. iEx = iEx + 1
  2404. countEx = countEx + 2
  2405. laiCountEx = laiCountEx - userLaiCount
  2406. else
  2407. break
  2408. end
  2409. end
  2410. if countEx == cardsLen then
  2411. --连对
  2412. return i
  2413. end
  2414. end
  2415. end
  2416. --三顺
  2417. if cardtype == OUT_TYPE.SAN_SHUN and cardsLen % 3 == 0 and cardsLen >= 6 then
  2418. for i = 1, 12 do
  2419. local iEx = i
  2420. local countEx = 0
  2421. local cardsEx = {}
  2422. local laiCountEx = laiCount
  2423. while iEx <= 12 and countEx < cardsLen do
  2424. local valueCountEx = valueList[iEx] or 0
  2425. if valueCountEx + laiCountEx >= 3 then
  2426. local userLaiCount = 3 - valueCountEx
  2427. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2428. for k = 1, userLaiCount do
  2429. table.insert(cardsEx, 0x0f)
  2430. end
  2431. for k = 1, 3 - userLaiCount do
  2432. table.insert(cardsEx, cardList[k])
  2433. end
  2434. iEx = iEx + 1
  2435. countEx = countEx + 3
  2436. laiCountEx = laiCountEx - userLaiCount
  2437. else
  2438. break
  2439. end
  2440. end
  2441. if countEx == cardsLen then
  2442. --三顺
  2443. table.insert(typesEx, "三顺")
  2444. return i
  2445. end
  2446. end
  2447. if cardsLen == 6 and valueList[13] and valueList[13] >= 1 and valueList[12] and valueList[12] >= 1 and cardsLen/3 == table.nums(valueList) + math.floor(laiCount/3) then--AAA222
  2448. return 0-- 三A三2
  2449. end
  2450. end
  2451. --飞机
  2452. if (cardtype >= OUT_TYPE.AIRPLANE_SINGLE and cardtype <= OUT_TYPE.AIRPLANE_DUI) then
  2453. for i = 12, 1,-1 do
  2454. local iEx = i
  2455. local countEx = 0
  2456. local cardsEx = {}
  2457. local cellNum = 4
  2458. if cardtype == OUT_TYPE.AIRPLANE_DUI then
  2459. cellNum = 5
  2460. end
  2461. local laiCountEx = laiCount
  2462. while iEx >= 1 and countEx < cardsLen / cellNum do
  2463. local valueCountEx = valueList[iEx] or 0
  2464. if valueCountEx + laiCountEx >= 3 then
  2465. local userLaiCount = 3 - valueCountEx
  2466. userLaiCount = userLaiCount > 0 and userLaiCount or 0
  2467. for k = 1, userLaiCount do
  2468. table.insert(cardsEx, 0x0f)
  2469. end
  2470. for k = 1, 3 - userLaiCount do
  2471. table.insert(cardsEx, cardList[k])
  2472. end
  2473. iEx = iEx - 1
  2474. countEx = countEx + 1
  2475. laiCountEx = laiCountEx - userLaiCount
  2476. else
  2477. break
  2478. end
  2479. end
  2480. if countEx == cardsLen / cellNum then
  2481. local issanshun = self:checkIsSanShun(orginCards)
  2482. --飞机
  2483. table.insert(typesEx, "飞机")
  2484. --if issanshun then
  2485. -- return i + 1
  2486. --else
  2487. return i
  2488. --end
  2489. end
  2490. end
  2491. end
  2492. end
  2493. end
  2494. return 1
  2495. end
  2496. return zgwrDdzUtil