Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

1520 linhas
38 KiB

  1. --[[经典16张
  2. 0x01, 0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d, //黑桃
  3. 0x12, 0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d, //红桃
  4. 0x22, 0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d, //梅花
  5. 0x32, 0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d, //方块
  6. ]]
  7. --[[15张
  8. 0x01,0x02, 0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d, //黑桃
  9. 0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d, //红桃
  10. 0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d, //梅花
  11. 0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d, //方块
  12. ]]
  13. local ER_VAL = 0x0d--2的牌值
  14. local A_VAL = 0x0c--A的牌值
  15. function pokerParse( card )
  16. local tp = math.floor(card/16)
  17. local val = card%16
  18. -- print("---------tp : "..tp.." val : "..val)
  19. return tp, val
  20. end
  21. function pokerPng( card )
  22. local tp , val = pokerParse(card)
  23. return string.format("pdk_cards_%d_%d.png", tp, val)
  24. end
  25. -- 对牌进行排序
  26. function pokerSortPdkCards( cards )
  27. local tmp = {}
  28. for _,card in ipairs(cards) do
  29. local tp, val = pokerParse(card)
  30. table.insert(tmp, {tp=tp, val=val, cid=card})
  31. end
  32. table.sort(tmp, function (a, b)
  33. if a.val == b.val then
  34. return a.tp < b.tp
  35. else
  36. return a.val > b.val
  37. end
  38. end)
  39. return tmp
  40. end
  41. -- 牌的排序函数
  42. local function sortCardsFunc( a, b )
  43. return a.val < b.val
  44. end
  45. -- 获取剩余牌(parseCards)
  46. local function getLeft( src, target )
  47. local have = {}
  48. for _,v in ipairs(target) do
  49. have[tostring(v.cid)] = v
  50. end
  51. local left = {}
  52. for _,v in pairs(src) do
  53. if not have[tostring(v.cid)] then
  54. table.insert(left, v)
  55. end
  56. end
  57. return left
  58. end
  59. local PokerUtil = class("PokerUtil")
  60. -- 所有传入参数均为{tp, val, cid}结构集合
  61. function PokerUtil:ctor(param)
  62. if param.isChai==nil then
  63. param.isChai = false
  64. end
  65. if param.isFAT==nil then--four and three
  66. param.isFAT = false
  67. end
  68. self.isChai = param.isChai
  69. self.isFAT = param.isFAT
  70. end
  71. -- 对牌组按照value进行分类
  72. function PokerUtil:classifyCards( cards )
  73. local tmpCards = clone(cards)
  74. local result = {}
  75. for _,v in pairs(tmpCards) do
  76. if not result[tostring(v.val)] then
  77. result[tostring(v.val)] = {}
  78. end
  79. table.insert(result[tostring(v.val)], v)
  80. end
  81. local tmp = {}
  82. for _,v in pairs(result) do
  83. table.insert(tmp, v)
  84. end
  85. return tmp
  86. end
  87. -- 对牌组按照value进行分类 返回key-value结构
  88. function PokerUtil:classifyCardsEx( cards )
  89. local tmpCards = clone(cards)
  90. local result = {}
  91. for _,v in pairs(tmpCards) do
  92. if not result[tostring(v.val)] then
  93. result[tostring(v.val)] = {}
  94. end
  95. table.insert(result[tostring(v.val)], v)
  96. end
  97. return result
  98. end
  99. -- 检测牌的点数是否相同
  100. function PokerUtil:checkSameVal( cards )
  101. if cards and type(cards)~="table" then return false end
  102. if #cards <= 0 then return false end
  103. local targetVal = cards[1].val
  104. local result = true
  105. for _,v in pairs(cards) do
  106. if v.val ~= targetVal then
  107. result = false
  108. break
  109. end
  110. end
  111. return result
  112. end
  113. -- 检测牌组中是否带2
  114. function PokerUtil:checkOwnEr(cards)
  115. if cards and type(cards)~="table" then return false end
  116. local result = false
  117. for _,v in pairs(cards) do
  118. if v.val == ER_VAL then
  119. result = true
  120. break
  121. end
  122. end
  123. return result
  124. end
  125. -- 检测牌组中是否包含某一张牌
  126. function PokerUtil:checkOwnX( cards, card)
  127. if cards and type(cards)~="table" then return false end
  128. local result = false
  129. for _,v in pairs(cards) do
  130. if v.val == card.val then
  131. result = true
  132. break
  133. end
  134. end
  135. return result
  136. end
  137. -- 将牌解析成{tp, val ,cid}牌组
  138. function PokerUtil:parseCards( cards )
  139. local result = {}
  140. for _,v in ipairs(cards) do
  141. local tp, val = pokerParse(v)
  142. table.insert(result, {tp=tp, val=val, cid=v})
  143. end
  144. return result
  145. end
  146. -- 从分类牌组中查找到指定数量牌的集合
  147. function PokerUtil:getSameNum( classify, num )
  148. local result = {}
  149. for _,v in pairs(classify) do
  150. if #v == num then
  151. table.insert(result, v)
  152. end
  153. end
  154. return result
  155. end
  156. -- 从分类牌组中查找到指定数量牌的集合,包括大于num的牌组
  157. function PokerUtil:getSameNumEx( classify, num )
  158. local result = {}
  159. for _,v in pairs(classify) do
  160. if #v >= num then
  161. table.insert(result, v)
  162. end
  163. end
  164. return result
  165. end
  166. -- 从分类牌组中查找到指定数量牌的集合,包括大于num的牌组 key-val存储
  167. function PokerUtil:getSameNumExEx( classify, num )
  168. local result = {}
  169. for k,v in pairs(classify) do
  170. if #v >= num then
  171. result[tostring(k)] = v
  172. end
  173. end
  174. return result
  175. end
  176. --------------------------------------------------------------------------------------
  177. -- 检测牌型
  178. --------------------------------------------------------------------------------------
  179. -- 检测是否是对子
  180. function PokerUtil:checkDui( cards )
  181. if cards and type(cards)~="table" then return false end
  182. if #cards ~= 2 then return false end
  183. return self:checkSameVal(cards)
  184. end
  185. -- 检测3不带
  186. function PokerUtil:checkThree( cards )
  187. if cards and type(cards)~="table" then return false end
  188. if #cards ~= 3 then return false end
  189. return self:checkSameVal(cards)
  190. end
  191. -- 检测4张
  192. function PokerUtil:checkFour( cards )
  193. if cards and type(cards)~="table" then return false end
  194. if #cards ~= 4 then return false end
  195. return self:checkSameVal(cards)
  196. end
  197. -- 检测是否顺子,至少5张
  198. function PokerUtil:checkShunzi( cards )
  199. local LessNum = 5
  200. if cards and type(cards)~="table" then return false end
  201. if self:checkOwnEr(cards) or #cards < LessNum then return false end--牌中是否带2 或者牌张数不够
  202. return self:checkSZ(cards)
  203. end
  204. -- 检测顺子,至少两张
  205. function PokerUtil:checkSZ(cards)
  206. local LessNum = 2
  207. if cards and type(cards)~="table" then return false end
  208. if self:checkOwnEr(cards) or #cards < LessNum then return false end--牌中是否带2 或者牌张数不够
  209. local tmpCards = clone(cards)
  210. table.sort(tmpCards, sortCardsFunc)
  211. local idx = 1
  212. local result = true
  213. for i=2,#tmpCards do
  214. if tmpCards[idx].val+1 ~= tmpCards[i].val then
  215. result = false
  216. break
  217. else
  218. idx = idx + 1
  219. end
  220. end
  221. return result
  222. end
  223. -- 检测连对
  224. function PokerUtil:checkLianDui(cards)
  225. local LessNum = 4
  226. if cards and type(cards)~="table" then return false end
  227. if self:checkOwnEr(cards) or #cards < LessNum or #cards%2~=0 then return false end--牌中是否带2 或者牌张数不够
  228. local tmpCards = clone(cards)
  229. local classify = self:classifyCards(tmpCards)
  230. if #classify*2 ~= #tmpCards then return false end
  231. -- 确保每组牌四两张
  232. for _,v in pairs(classify) do
  233. if #v~=2 then return false end
  234. end
  235. table.sort(tmpCards, sortCardsFunc)
  236. local tmp = {}
  237. for i=1,#tmpCards do
  238. if i%2==1 then
  239. table.insert(tmp, tmpCards[i])
  240. end
  241. end
  242. return self:checkSZ(tmp)
  243. end
  244. -- 检测三带一(最后四张才能3带一?)
  245. function PokerUtil:check3And1( cards )
  246. local LessNum = 4
  247. if cards and type(cards)~="table" then return false end
  248. if #cards ~= LessNum then return false end-- 或者牌张数不够
  249. local classify = self:classifyCards(cards)
  250. local own3 = false
  251. for _,v in ipairs(classify) do
  252. if #v == 3 then
  253. own3 = true
  254. break
  255. end
  256. end
  257. return own3
  258. end
  259. -- 检测三带二
  260. function PokerUtil:check3And2( cards )
  261. local LessNum = 5
  262. if cards and type(cards)~="table" then return false end
  263. if #cards ~= LessNum then return false end--牌张数不够
  264. local classify = self:classifyCards(cards)
  265. local own3 = false
  266. for _,v in ipairs(classify) do
  267. if #v == 3 then
  268. own3 = true
  269. break
  270. end
  271. end
  272. return own3
  273. end
  274. -- 检测四带一
  275. function PokerUtil:check4And1(cards)
  276. local LessNum = 5
  277. if cards and type(cards)~="table" then return false end
  278. if #cards ~= LessNum then return false end--或者牌张数不够
  279. local classify = self:classifyCards(cards)
  280. local own4 = false
  281. for _,v in ipairs(classify) do
  282. if #v == 4 then
  283. own4 = true
  284. break
  285. end
  286. end
  287. return own4
  288. end
  289. -- 检测四带2
  290. function PokerUtil:check4And2(cards)
  291. local LessNum = 6
  292. if cards and type(cards)~="table" then return false end
  293. if #cards ~= LessNum then return false end--或者牌张数不够
  294. local classify = self:classifyCards(cards)
  295. local own4 = false
  296. for _,v in ipairs(classify) do
  297. if #v == 4 then
  298. own4 = true
  299. break
  300. end
  301. end
  302. return own4
  303. end
  304. -- 检测四带3
  305. function PokerUtil:check4And3( cards )
  306. local LessNum = 7
  307. if cards and type(cards)~="table" then return false end
  308. if #cards ~= LessNum then return false end--或者牌张数不够
  309. local classify = self:classifyCards(cards)
  310. local own4 = false
  311. for _,v in ipairs(classify) do
  312. if #v == 4 then
  313. own4 = true
  314. break
  315. end
  316. end
  317. return own4
  318. end
  319. -- 检测 炸弹
  320. function PokerUtil:checkBomb( cards )
  321. return self:checkFour(cards)
  322. end
  323. -- 检测飞机555666 555666777等+同等数量的对牌,或者双倍单牌
  324. function PokerUtil:checkPlan( cards, shaoDai )
  325. shaoDai = shaoDai or true
  326. local LessNum = 6 -- 6+4 9+6
  327. local cNum = #cards
  328. -- print("-------------------------checkPlan num: "..cNum)
  329. if not shaoDai then--是否少带
  330. if cNum~=6 and cNum~=10 and cNum~=15 then return false end
  331. end
  332. if cards and type(cards)~="table" then return false end
  333. if #cards < LessNum then return false end--或者牌张数不够
  334. local classify = self:classifyCards(cards)
  335. local result = false
  336. local ThreeCount = 0
  337. local checkShun = {}
  338. if self.isChai then--区分炸弹是否可拆
  339. for _,v in ipairs(classify) do
  340. if #v >= 3 then
  341. ThreeCount = ThreeCount + 1
  342. table.insert(checkShun, v[1])
  343. end
  344. end
  345. else
  346. for _,v in ipairs(classify) do
  347. if #v == 3 then
  348. ThreeCount = ThreeCount + 1
  349. table.insert(checkShun, v[1])
  350. end
  351. end
  352. end
  353. if ThreeCount <= 1 then return false end
  354. if #checkShun >= 2 then
  355. table.sort(checkShun, sortCardsFunc)
  356. end
  357. -- print("three count : " ..ThreeCount)
  358. if ThreeCount == 2 then
  359. result = (self:checkSZ(checkShun) and cNum<=10)
  360. elseif ThreeCount == 3 then
  361. result = (self:checkSZ(checkShun) and cNum<=15)
  362. if not result then--三张四张作为翅膀带出去
  363. local firstTwo = {checkShun[1], checkShun[2]}
  364. result = (self:checkSZ(firstTwo) and cNum<=10)
  365. if not result then
  366. local lastTwo = {checkShun[2], checkShun[3]}
  367. result = (self:checkSZ(lastTwo) and cNum<=10)
  368. end
  369. end
  370. else
  371. local maxLen = 1
  372. local bCount = 1
  373. local i, j=1, 2
  374. for i=1,#checkShun-1 do
  375. if checkShun[i].val + 1 == checkShun[j].val then
  376. bCount = bCount + 1
  377. if bCount>maxLen then maxLen = bCount end
  378. else
  379. if bCount>maxLen then maxLen = bCount end
  380. bCount = 1
  381. end
  382. i=i+1
  383. j=j+1
  384. end
  385. result = (maxLen>=4 and cNum<=16) or (maxLen>=3 and cNum<=15)
  386. end
  387. return result
  388. end
  389. --牌型
  390. local OUT_TYPE = {
  391. SINGLE_CARD = 1, --//单牌
  392. DUI_ZI = 2, --//对子
  393. THREE_AND_TWO = 3, --//三带二
  394. SHUN_ZI = 4, --//顺子
  395. LIAN_DUI = 5, --//连对(至少2连对)
  396. AIRPLANE = 6, --//飞机
  397. FOUR_AND_THREE = 7, --//四带三
  398. BOMB = 8, --//炸弹
  399. FOUR_AND_ONE = 9, --//四带一
  400. THREE_AND_ONE = 10, --三带一
  401. THREE = 11, --三个
  402. FOUR_AND_TWO = 12, --//四带2
  403. NONE = 100, --不适用类型
  404. }
  405. local TYPE_STRING = {
  406. [OUT_TYPE.SINGLE_CARD] = "单牌", --//单牌
  407. [OUT_TYPE.DUI_ZI] = "对子", --//对子
  408. [OUT_TYPE.THREE_AND_TWO] = "三带二", --//三带二
  409. [OUT_TYPE.SHUN_ZI] = "顺子", --//顺子
  410. [OUT_TYPE.LIAN_DUI] = "连对", --//连对
  411. [OUT_TYPE.AIRPLANE] = "飞机", --//飞机
  412. [OUT_TYPE.FOUR_AND_THREE] = "四带三", --//四带三
  413. [OUT_TYPE.BOMB] = "炸弹", --//炸弹
  414. [OUT_TYPE.FOUR_AND_ONE] = "四带一", --//四带一
  415. [OUT_TYPE.NONE] = "错误类型", --//错误类型
  416. }
  417. PokerUtil.OUT_TYPE = OUT_TYPE
  418. function PokerUtil:getTypeString( tp )
  419. return TYPE_STRING[tp] or "TP错误"
  420. end
  421. -- 检测牌型
  422. function PokerUtil:checkType( cards )
  423. local cNum = #cards
  424. if cNum == 1 then return OUT_TYPE.SINGLE_CARD end
  425. local parseData = {}
  426. for _,v in ipairs(cards) do
  427. local tp, val = pokerParse(v)
  428. table.insert(parseData, {tp=tp, val=val, cid=v})
  429. end
  430. if #parseData >=2 then
  431. table.sort(parseData, sortCardsFunc)
  432. end
  433. if cNum == 2 then
  434. if self:checkDui(parseData) then
  435. return OUT_TYPE.DUI_ZI
  436. else
  437. return OUT_TYPE.NONE
  438. end
  439. elseif cNum == 3 then
  440. if self:checkThree(parseData) then
  441. return OUT_TYPE.THREE
  442. end
  443. return OUT_TYPE.NONE
  444. else
  445. --顺子 飞机
  446. if self:checkPlan(parseData) then
  447. if self:check4And3(parseData) and self.isFAT then
  448. return OUT_TYPE.FOUR_AND_THREE
  449. else
  450. return OUT_TYPE.AIRPLANE
  451. end
  452. elseif self:checkShunzi(parseData) then
  453. return OUT_TYPE.SHUN_ZI
  454. end
  455. if cNum%2 == 0 then--偶数张 (三带一 连对 炸弹)
  456. if self:check3And1(parseData) then
  457. return OUT_TYPE.THREE_AND_ONE
  458. elseif self:check4And2(parseData) then
  459. return OUT_TYPE.FOUR_AND_TWO
  460. elseif self:checkLianDui(parseData) then
  461. return OUT_TYPE.LIAN_DUI
  462. elseif self:checkBomb(parseData) then
  463. return OUT_TYPE.BOMB
  464. else
  465. return OUT_TYPE.NONE
  466. end
  467. else--奇数张 (三带二 顺子 四带一)
  468. if self:check3And2(parseData) then
  469. return OUT_TYPE.THREE_AND_TWO
  470. elseif self:checkShunzi(parseData) then
  471. return OUT_TYPE.SHUN_ZI
  472. elseif self:check4And1(parseData) then
  473. if self.isChai then--炸弹可拆则为3带2
  474. return OUT_TYPE.THREE_AND_TWO
  475. else
  476. return OUT_TYPE.NONE--OUT_TYPE.FOUR_AND_ONE
  477. end
  478. elseif self:check4And3(parseData) then
  479. return OUT_TYPE.FOUR_AND_THREE
  480. else
  481. return OUT_TYPE.NONE
  482. end
  483. end
  484. end
  485. end
  486. --------------------------------------------------------------------------------------
  487. -- 牌型提示
  488. --------------------------------------------------------------------------------------
  489. --单张提示 cards@{{tp=, val=, cid=,}...} target@{tp=, val=, cid=,}
  490. -- fixed
  491. function PokerUtil:getSingleTip( cards, target )
  492. local target = target[1]
  493. if target.val == ER_VAL then return nil end
  494. local classify = self:classifyCardsEx(cards)
  495. local singles = {}
  496. local twos = {}
  497. local threes = {}
  498. local fours = {}
  499. for valStr,cds in pairs(classify) do
  500. if tonumber(valStr) > target.val or tonumber(valStr)==ER_VAL then
  501. if #cds == 1 then
  502. table.insert(singles, cds[1])
  503. elseif #cds == 2 then
  504. table.insert(twos, cds[1])
  505. table.insert(twos, cds[2])
  506. elseif #cds == 3 then
  507. table.insert(threes, cds[1])
  508. table.insert(threes, cds[2])
  509. table.insert(threes, cds[3])
  510. elseif #cds == 4 then--炸弹是否可拆决定
  511. if self.isChai then
  512. table.insert(threes, cds[1])
  513. table.insert(threes, cds[2])
  514. table.insert(threes, cds[3])
  515. table.insert(threes, cds[4])
  516. end
  517. end
  518. end
  519. end
  520. if #singles>=2 then --降序排列
  521. table.sort(singles, function ( a, b ) return a.val > b.val end)
  522. end
  523. if #twos>=2 then --升序排列
  524. table.sort(twos, function ( a, b ) return a.val < b.val end)
  525. end
  526. if #threes>=2 then --升序排列
  527. table.sort(threes, function ( a, b ) return a.val < b.val end)
  528. end
  529. for _,v in ipairs(twos) do
  530. table.insert(singles, 1, v)
  531. end
  532. for _,v in ipairs(threes) do
  533. table.insert(singles, 1, v)
  534. end
  535. return singles
  536. end
  537. -- 对子提示cards@{{tp=, val=, cid=,}...} targets@{{tp=, val=, cid=,},{tp=, val=, cid=,}}
  538. -- fixed
  539. function PokerUtil:getDoubleTip( cards, targets )
  540. local target = targets[1]
  541. local classify = self:classifyCardsEx(cards)
  542. local twos = {}
  543. local threes = {}
  544. local fours = {}
  545. for valStr,cds in pairs(classify) do
  546. if tonumber(valStr) > target.val and #cds>=2 then
  547. if #cds == 2 then
  548. table.insert(twos, cds)
  549. elseif #cds == 3 then
  550. table.insert(threes, clone({cds[1], cds[2]}))
  551. elseif #cds == 4 then--炸弹是否可拆决定
  552. if self.isChai then
  553. table.insert(fours, clone({cds[1], cds[2]}))
  554. end
  555. end
  556. end
  557. end
  558. if #twos>=2 then --降序排列
  559. table.sort(twos, function ( a, b ) return a[1].val > b[1].val end)
  560. end
  561. if #threes>=2 then --升序排列
  562. table.sort(threes, function ( a, b ) return a[1].val < b[1].val end)
  563. end
  564. if #fours>=2 then --升序排列
  565. table.sort(fours, function ( a, b ) return a[1].val < b[1].val end)
  566. end
  567. for _,v in ipairs(threes) do
  568. table.insert(twos, 1, v)
  569. end
  570. for _,v in pairs(fours) do
  571. table.insert(twos, 1, v)
  572. end
  573. return twos
  574. end
  575. -- 三张提示
  576. -- fixed
  577. function PokerUtil:getThreeTip( cards, targets )
  578. if #cards < #targets then return nil end
  579. local tclassify = self:classifyCards(targets)
  580. local target = self:getSameNumEx(tclassify, 3)[1][1]--同时包含四带一
  581. local classify = self:classifyCardsEx(cards)
  582. local threes = {}
  583. local singles = {}
  584. local twos = {}
  585. local fours = {}
  586. for valStr,cds in pairs(classify) do
  587. if tonumber(valStr) > target.val and #cds>=3 then
  588. if #cds == 3 then
  589. table.insert(threes, cds)
  590. elseif #cds == 4 then--炸弹是否可拆决定
  591. if self.isChai then
  592. table.insert(threes, {cds[1], cds[2], cds[3]})
  593. end
  594. end
  595. else
  596. if #cds == 1 then
  597. table.insert(singles, cds[1])
  598. elseif #cds == 2 then
  599. table.insert(twos, cds)
  600. elseif #cds == 4 then
  601. table.insert(fours, cds)
  602. end
  603. end
  604. end
  605. if #threes <= 0 then return nil end
  606. if #threes>=2 then --降序排列
  607. table.sort(threes, function ( a, b ) return a[1].val > b[1].val end)
  608. end
  609. -- if #singles>=2 then --升序排列
  610. -- table.sort(singles, function ( a, b ) return a.val < b.val end)
  611. -- end
  612. -- if #twos>=2 then --升序排列
  613. -- table.sort(twos, function ( a, b ) return a[1].val < b[1].val end)
  614. -- end
  615. -- for _,v in ipairs(twos) do
  616. -- table.insert(singles, v[1])
  617. -- table.insert(singles, v[2])
  618. -- end
  619. -- local result = {}
  620. -- if #threes==1 then
  621. -- if #singles >= 2 then
  622. -- table.insert(threes[1], singles[1])
  623. -- table.insert(threes[1], singles[2])
  624. -- table.insert(result, threes[1])
  625. -- return result
  626. -- else
  627. -- return nil
  628. -- end
  629. -- else
  630. -- if #singles >= 2 then
  631. -- for _,v in ipairs(threes) do
  632. -- local cv = clone(v)
  633. -- table.insert(cv, singles[1])
  634. -- table.insert(cv, singles[2])
  635. -- table.insert(result, cv)
  636. -- end
  637. -- return result
  638. -- else--多个三张,玩家自己拆牌
  639. return threes
  640. -- end
  641. -- end
  642. end
  643. -- 三带二提示
  644. -- fixed
  645. function PokerUtil:getThreeAnd2Tip( cards, targets )
  646. if #cards < #targets then return nil end
  647. local tclassify = self:classifyCards(targets)
  648. local target = self:getSameNumEx(tclassify, 3)[1][1]--同时包含四带一
  649. local classify = self:classifyCardsEx(cards)
  650. local threes = {}
  651. local singles = {}
  652. local twos = {}
  653. local fours = {}
  654. for valStr,cds in pairs(classify) do
  655. if tonumber(valStr) > target.val and #cds>=3 then
  656. if #cds == 3 then
  657. table.insert(threes, cds)
  658. elseif #cds == 4 then--炸弹是否可拆决定
  659. if self.isChai then
  660. table.insert(threes, {cds[1], cds[2], cds[3]})
  661. end
  662. end
  663. else
  664. if #cds == 1 then
  665. table.insert(singles, cds[1])
  666. elseif #cds == 2 then
  667. table.insert(twos, cds)
  668. elseif #cds == 4 then
  669. table.insert(fours, cds)
  670. end
  671. end
  672. end
  673. if #threes <= 0 then return nil end
  674. if #threes>=2 then --降序排列
  675. table.sort(threes, function ( a, b ) return a[1].val > b[1].val end)
  676. end
  677. if #singles>=2 then --升序排列
  678. table.sort(singles, function ( a, b ) return a.val < b.val end)
  679. end
  680. if #twos>=2 then --升序排列
  681. table.sort(twos, function ( a, b ) return a[1].val < b[1].val end)
  682. end
  683. for _,v in ipairs(twos) do
  684. table.insert(singles, v[1])
  685. table.insert(singles, v[2])
  686. end
  687. local result = {}
  688. if #threes==1 then
  689. if #singles >= 2 then
  690. table.insert(threes[1], singles[1])
  691. table.insert(threes[1], singles[2])
  692. table.insert(result, threes[1])
  693. return result
  694. else
  695. return nil
  696. end
  697. else
  698. if #singles >= 2 then
  699. for _,v in ipairs(threes) do
  700. local cv = clone(v)
  701. table.insert(cv, singles[1])
  702. table.insert(cv, singles[2])
  703. table.insert(result, cv)
  704. end
  705. return result
  706. else--多个三张,玩家自己拆牌
  707. return threes
  708. end
  709. end
  710. end
  711. -- 三带一提示 not fixed
  712. function PokerUtil:getThreeAnd1Tip(cards, targets)
  713. local tclassify = self:classifyCards(targets)
  714. local target = self:getSameNum(tclassify, 3)
  715. local cclassify = self:classifyCards(cards)
  716. local tmps = self:getSameNum(cclassify, 3)
  717. if #tmps == 0 then return nil end
  718. local result = {}
  719. for _,v in ipairs(tmps) do
  720. if v[1].val > target[1].val then
  721. table.insert(result, v)
  722. end
  723. end
  724. local tmpOnes = self:getSameNum(cclassify, 1)
  725. local ones = {}
  726. for _,v in pairs(tmpOnes) do
  727. table.insert(ones, v[1])
  728. end
  729. local twos = self:getSameNum(cclassify, 2)
  730. for _,v in ipairs(twos) do
  731. table.insert(ones, v[1])
  732. table.insert(ones, v[2])
  733. end
  734. if #ones >=1 then
  735. return {result, ones[1]}
  736. else
  737. return nil
  738. end
  739. end
  740. -- 四带一提示
  741. function PokerUtil:getFourAnd1( cards, targets )
  742. local tclassify = self:classifyCards(targets)
  743. local target = self:getSameNum(tclassify, 4)
  744. local cclassify = self:classifyCards(cards)
  745. local tmps = self:getSameNum(cclassify, 4)
  746. if #tmps == 0 then return nil end
  747. local result = {}
  748. for _,v in ipairs(tmps) do
  749. if v[1].val > target[1].val then
  750. table.insert(result, v)
  751. end
  752. end
  753. local tmpOnes = self:getSameNum(cclassify, 1)
  754. local ones = {}
  755. for _,v in pairs(tmpOnes) do
  756. table.insert(ones, v[1])
  757. end
  758. local twos = self:getSameNum(cclassify, 2)
  759. for _,v in ipairs(twos) do
  760. table.insert(ones, v[1])
  761. table.insert(ones, v[2])
  762. end
  763. local threes = self:getSameNum(cclassify, 3)
  764. for _,v in ipairs(threes) do
  765. table.insert(ones, v[1])
  766. table.insert(ones, v[2])
  767. table.insert(ones, v[3])
  768. end
  769. if #ones >= 1 then
  770. return {result, ones[1]}
  771. else--牌不够数
  772. return nil
  773. end
  774. end
  775. -- 四带三提示(前提是牌足够)
  776. -- fixed
  777. function PokerUtil:getFourAnd3( cards, targets )
  778. if #cards < #targets then return nil end
  779. local tclassify = self:classifyCards(targets)
  780. local target = self:getSameNum(tclassify, 4)[1][1]
  781. local classify = self:classifyCardsEx(cards)
  782. local threes = {}
  783. local singles = {}
  784. local twos = {}
  785. local fours = {}
  786. local targetFours = {}
  787. for valStr,cds in pairs(classify) do
  788. if tonumber(valStr) > target.val and #cds>=4 then
  789. table.insert(targetFours, cds)
  790. else
  791. if #cds == 1 then
  792. table.insert(singles, cds[1])
  793. elseif #cds == 2 then
  794. table.insert(twos, cds)
  795. elseif #cds == 3 then
  796. table.insert(threes, cds)
  797. elseif #cds == 4 then
  798. table.insert(fours, cds)
  799. end
  800. end
  801. end
  802. if #threes <= 0 then return nil end
  803. if #targetFours>=2 then --降序排列
  804. table.sort(targetFours, function ( a, b ) return a[1].val > b[1].val end)
  805. end
  806. if #singles>=2 then --升序排列
  807. table.sort(singles, function ( a, b ) return a.val < b.val end)
  808. end
  809. if #twos>=2 then --升序排列
  810. table.sort(twos, function ( a, b ) return a[1].val < b[1].val end)
  811. end
  812. if #threes>=2 then --升序排列
  813. table.sort(threes, function ( a, b ) return a[1].val < b[1].val end)
  814. end
  815. for _,v in ipairs(twos) do
  816. table.insert(singles, v[1])
  817. table.insert(singles, v[2])
  818. end
  819. for _,v in ipairs(threes) do
  820. table.insert(singles, v[1])
  821. table.insert(singles, v[2])
  822. table.insert(singles, v[3])
  823. end
  824. local result = {}
  825. if #targetFours==1 then
  826. if #singles >= 3 then
  827. table.insert(targetFours[1], singles[1])
  828. table.insert(targetFours[1], singles[2])
  829. table.insert(targetFours[1], singles[3])
  830. table.insert(result, targetFours[1])
  831. return result
  832. else
  833. return nil
  834. end
  835. else
  836. if #singles >= 3 then
  837. for _,v in ipairs(targetFours) do
  838. local cv = clone(v)
  839. table.insert(v, singles[1])
  840. table.insert(v, singles[2])
  841. table.insert(v, singles[3])
  842. table.insert(result, cv)
  843. end
  844. return result
  845. else--多个四张,玩家自己拆牌
  846. return targetFours
  847. end
  848. end
  849. end
  850. -- 检测牌组是否是连续的parseCards@sorted
  851. function PokerUtil:getSubLine( parseCards )
  852. local sub = {}
  853. for i=#parseCards,1,-1 do
  854. if parseCards[i] and parseCards[i-1] then
  855. if parseCards[i].val-1~=parseCards[i-1].val then
  856. --断开了
  857. local tmp = {}
  858. for j=#parseCards,i,-1 do
  859. table.insert(tmp, parseCards[j])
  860. end
  861. table.insert(sub, clone(tmp))
  862. for j=#parseCards,i,-1 do
  863. table.remove(parseCards, j)
  864. end
  865. else
  866. if i == 2 then
  867. table.insert(sub, clone(parseCards))
  868. end
  869. end
  870. end
  871. end
  872. return sub
  873. end
  874. -- 从连续的牌组中获得顺子
  875. function PokerUtil:getSzTip( hands, targets )
  876. local tmpNoKey = clone(hands)
  877. table.sort(targets, sortCardsFunc)
  878. local minVal = targets[1].val
  879. local targetNum = #targets
  880. if #tmpNoKey<targetNum then return nil end
  881. local count = #tmpNoKey-targetNum
  882. if count == 0 then return {tmpNoKey} end
  883. local getMS = function ( tab, len )
  884. if #tab < len then return nil end
  885. local rst = {}
  886. for i=#tab,1,-1 do
  887. if #rst<len then
  888. table.insert(rst, 1, tab[i])
  889. else
  890. break
  891. end
  892. end
  893. return rst
  894. end
  895. local result = {}
  896. for i=#tmpNoKey,1,-1 do
  897. local rst = getMS(tmpNoKey, targetNum)
  898. if rst then
  899. table.insert(result, 1, clone(rst))
  900. table.remove(tmpNoKey, #tmpNoKey)
  901. else
  902. break
  903. end
  904. end
  905. return result
  906. end
  907. -- 顺子提示
  908. -- fixed
  909. function PokerUtil:getShunziTip( cards, targets )
  910. local classify = self:classifyCardsEx(cards)
  911. table.sort(targets, sortCardsFunc)
  912. local minVal = targets[1].val
  913. local targetNum = #targets
  914. local tmpCards = {}
  915. for valStr,cds in pairs(classify) do
  916. if tonumber(valStr)>minVal and tonumber(valStr)~=ER_VAL then
  917. if #cds == 4 then
  918. if self.isChai then
  919. table.insert(tmpCards, cds[1])
  920. end
  921. else
  922. table.insert(tmpCards, cds[1])
  923. end
  924. end
  925. end
  926. if #tmpCards>=2 then
  927. table.sort(tmpCards, sortCardsFunc)
  928. end
  929. --确保tmpCards是连续的
  930. local subLines = self:getSubLine(tmpCards)
  931. local result = {}
  932. for _,v in ipairs(subLines) do
  933. if #v >= targetNum then
  934. local rst = self:getSzTip(v, targets)
  935. if rst and #rst>0 then
  936. for _,group in ipairs(rst) do
  937. table.insert(result, group)
  938. end
  939. end
  940. end
  941. end
  942. local tmp = {}
  943. for _,v in pairs(result) do
  944. table.insert(tmp, 1, v)
  945. end
  946. return tmp
  947. end
  948. -- 获取连对提示
  949. -- fixed
  950. function PokerUtil:getLianduiTip( cards, targets )
  951. table.sort(targets, sortCardsFunc)
  952. local tclassify = self:classifyCards(targets)
  953. local target = self:getSameNum(tclassify, 2)
  954. local tmpTarget = {}
  955. for _,v in pairs(target) do
  956. table.insert(tmpTarget, v[1])
  957. end
  958. if #tmpTarget>1 then
  959. table.sort(tmpTarget, sortCardsFunc)
  960. end
  961. local cclassify = self:classifyCardsEx(cards)
  962. local tmps = {}
  963. for valStr, cds in pairs(cclassify) do
  964. if tonumber(valStr)~=ER_VAL then
  965. if #cds == 2 then
  966. tmps[valStr] = cds
  967. elseif #cds == 3 then
  968. tmps[valStr] = {cds[1], cds[2]}
  969. elseif #cds == 4 then
  970. if self.isChai then
  971. tmps[valStr] = {cds[1], cds[2]}
  972. end
  973. end
  974. end
  975. end
  976. --所有的两张的牌(key-value结构)
  977. local tmpSrc = {}
  978. for _,v in pairs(tmps) do
  979. table.insert(tmpSrc, v[1])
  980. end
  981. local tmpShunzi= self:getShunziTip(tmpSrc, tmpTarget)
  982. if #tmpShunzi > 0 then
  983. local tmpResult = {}
  984. for _,v in pairs(tmpShunzi) do
  985. local tmp = {}
  986. for _,card in pairs(v) do
  987. table.insert(tmp, clone(tmps[tostring(card.val)]))
  988. end
  989. table.insert(tmpResult, clone(tmp))
  990. end
  991. for _,group in ipairs(tmpResult) do
  992. for _,v in ipairs(group) do
  993. while #v>2 do
  994. table.remove(v, #v)
  995. end
  996. end
  997. end
  998. return tmpResult
  999. else
  1000. return nil
  1001. end
  1002. end
  1003. -- 获取炸弹提示
  1004. function PokerUtil:getBombTip( cards, targets )
  1005. local tclassify = self:classifyCards(targets)
  1006. local target = self:getSameNum(tclassify, 4)
  1007. if #target >= 1 then
  1008. target = target[1]
  1009. end
  1010. local cclassify = self:classifyCards(cards)
  1011. local tmps = self:getSameNumExEx(cclassify, 4)
  1012. local result = {}
  1013. for _,v in pairs(tmps) do
  1014. if target[1].val < v[1].val then
  1015. table.insert(result, v)
  1016. end
  1017. end
  1018. return result
  1019. end
  1020. -- 获取牌组中所有炸弹
  1021. function PokerUtil:getAllBomb( cards, isAaaBomb )
  1022. if isAaaBomb == nil then isAaaBomb = false end
  1023. if not isAaaBomb then
  1024. if #cards<4 then return {} end
  1025. end
  1026. local parseHands = self:parseCards(cards)
  1027. local cclassify = self:classifyCards(parseHands)
  1028. local tmps = self:getSameNumExEx(cclassify, 4)
  1029. local tmp = {}
  1030. if isAaaBomb then --是否拥有AAA
  1031. local tmpThrees = self:getSameNumExEx(cclassify, 3)
  1032. for _,v in pairs(tmpThrees) do
  1033. if v[1].val == A_VAL and #v == 3 then
  1034. table.insert(tmp, v)
  1035. break
  1036. end
  1037. end
  1038. end
  1039. for _,v in pairs(tmps) do
  1040. table.insert(tmp, v)
  1041. end
  1042. if #tmp>=2 then
  1043. table.sort(tmp, function (a, b)
  1044. return a[1].val > b[1].val
  1045. end)
  1046. end
  1047. return tmp
  1048. end
  1049. -- 获取飞机提示(手牌足够)
  1050. function PokerUtil:getPlanTip( cards, targets )
  1051. local tclassify = self:classifyCards(targets)
  1052. local target = self:getSameNum(tclassify, 3)
  1053. local cclassify = self:classifyCards(cards)
  1054. local tmps = self:getSameNumEx(cclassify, 3)
  1055. if #target > #tmps then return nil end
  1056. local tmpThree = {}
  1057. for _,v in pairs(tmps) do
  1058. if v[1].val > target[1][1].val then
  1059. while #v>3 do
  1060. table.remove(v, #v)
  1061. end
  1062. table.insert(tmpThree, v)
  1063. end
  1064. end
  1065. if #tmpThree > 1 then
  1066. table.sort(tmpThree, function ( a, b ) return a[1].val < b[1].val end)
  1067. end
  1068. local tmp = {}--一维数组
  1069. for _,v in pairs(tmpThree) do
  1070. for _,c in ipairs(v) do
  1071. table.insert(tmp, c)
  1072. end
  1073. end
  1074. if #target > #tmpThree then return nil end
  1075. if #target == 2 then--两组
  1076. if #tmpThree > 2 then
  1077. local t = {}
  1078. t = {tmpThree[1], tmpThree[2]}
  1079. tmpThree = clone(t)
  1080. end
  1081. if math.abs(tmpThree[1][1].val-tmpThree[2][1].val)==1 then
  1082. local left = getLeft(cards, tmp)
  1083. if #left<4 then
  1084. return nil
  1085. else
  1086. local tail = clone(left)
  1087. while #tail>4 do
  1088. table.remove(tail, #tail)
  1089. end
  1090. for _,v in pairs(tmpThree) do
  1091. for _,c in pairs(v) do
  1092. table.insert(tail, c)
  1093. end
  1094. end
  1095. return {tail}
  1096. end
  1097. else
  1098. return nil
  1099. end
  1100. elseif #target == 3 then--三组
  1101. if #tmpThree > 3 then
  1102. local t = {}
  1103. t = {tmpThree[1], tmpThree[2], tmpThree[3]}
  1104. tmpThree = clone(t)
  1105. end
  1106. if self:checkSZ({tmpThree[1][1], tmpThree[2][1], tmpThree[3][1]}) then
  1107. local left = getLeft(cards, tmp)
  1108. if #left<4 then
  1109. return nil
  1110. else
  1111. local tail = clone(left)
  1112. while #tail>6 do
  1113. table.remove(tail, #tail)
  1114. end
  1115. return {tmpThree, tail}
  1116. end
  1117. else
  1118. return nil
  1119. end
  1120. end
  1121. return nil
  1122. end
  1123. -- 获取牌型提示
  1124. function PokerUtil:getOnlyTip( handCards, cards )
  1125. if #handCards < #cards then return nil end
  1126. local parseHands = self:parseCards(handCards)
  1127. local parseCards = self:parseCards(cards)
  1128. local tp = self:checkType(cards)
  1129. if tp >= OUT_TYPE.NONE then
  1130. return nil
  1131. end
  1132. local result = nil
  1133. if tp == OUT_TYPE.SINGLE_CARD then
  1134. result = self:getSingleTip(parseHands, parseCards)
  1135. elseif tp == OUT_TYPE.DUI_ZI then
  1136. result = self:getDoubleTip(parseHands, parseCards)
  1137. elseif tp == OUT_TYPE.THREE_AND_TWO then
  1138. result = self:getThreeTip(parseHands, parseCards)
  1139. elseif tp == OUT_TYPE.SHUN_ZI then
  1140. result = self:getShunziTip(parseHands, parseCards)
  1141. elseif tp == OUT_TYPE.LIAN_DUI then
  1142. result = self:getLianduiTip(parseHands, parseCards)
  1143. if result==nil then return nil end
  1144. local tmp = {}
  1145. for _,group in ipairs(result) do
  1146. local t = {}
  1147. for _,vv in ipairs(group) do
  1148. for _,v in ipairs(vv) do
  1149. table.insert(t, v)
  1150. end
  1151. end
  1152. table.insert(tmp, clone(t))
  1153. end
  1154. result = tmp
  1155. -- return tmp
  1156. elseif tp == OUT_TYPE.AIRPLANE then
  1157. result = self:getPlanTip(parseHands, parseCards)
  1158. elseif tp == OUT_TYPE.FOUR_AND_THREE then
  1159. result = self:getFourAnd3(parseHands, parseCards)
  1160. elseif tp == OUT_TYPE.BOMB then
  1161. result = self:getBombTip(parseHands, parseCards)
  1162. elseif tp == OUT_TYPE.FOUR_AND_ONE then
  1163. result = self:getFourAnd1(parseHands, parseCards)
  1164. end
  1165. if tp~= OUT_TYPE.BOMB then
  1166. local bombs = self:getAllBomb(handCards)
  1167. if #bombs==1 then
  1168. if result then
  1169. table.insert(result, bombs[1])
  1170. --[[for _,v in pairs(bombs) do
  1171. end]]--
  1172. else
  1173. result={bombs[1]}
  1174. --result = bombs[1]
  1175. end
  1176. end
  1177. end
  1178. if result and #result==1 then
  1179. return result
  1180. end
  1181. return nil
  1182. end
  1183. -- 获取只有一种牌型提示
  1184. function PokerUtil:getTip( handCards, cards )
  1185. if #handCards < #cards then return nil end
  1186. local parseHands = self:parseCards(handCards)
  1187. local parseCards = self:parseCards(cards)
  1188. local tp = self:checkType(cards)
  1189. if tp >= OUT_TYPE.NONE then
  1190. return nil
  1191. end
  1192. if tp == OUT_TYPE.SINGLE_CARD then
  1193. return self:getSingleTip(parseHands, parseCards)
  1194. elseif tp == OUT_TYPE.DUI_ZI then
  1195. local result = self:getDoubleTip(parseHands, parseCards)
  1196. return result
  1197. elseif tp == OUT_TYPE.THREE_AND_TWO then
  1198. return self:getThreeAnd2Tip(parseHands, parseCards)
  1199. elseif tp == OUT_TYPE.SHUN_ZI then
  1200. local result = self:getShunziTip(parseHands, parseCards)
  1201. return result
  1202. elseif tp == OUT_TYPE.LIAN_DUI then
  1203. local result = self:getLianduiTip(parseHands, parseCards)
  1204. if result==nil then return nil end
  1205. local tmp = {}
  1206. for _,group in ipairs(result) do
  1207. local t = {}
  1208. for _,vv in ipairs(group) do
  1209. for _,v in ipairs(vv) do
  1210. table.insert(t, v)
  1211. end
  1212. end
  1213. table.insert(tmp, clone(t))
  1214. end
  1215. return tmp
  1216. elseif tp == OUT_TYPE.AIRPLANE then
  1217. return self:getPlanTip(parseHands, parseCards)
  1218. elseif tp == OUT_TYPE.FOUR_AND_THREE then
  1219. return self:getFourAnd3(parseHands, parseCards)
  1220. elseif tp == OUT_TYPE.BOMB then
  1221. return self:getBombTip(parseHands, parseCards)
  1222. elseif tp == OUT_TYPE.FOUR_AND_ONE then
  1223. return self:getFourAnd1(parseHands, parseCards)
  1224. else
  1225. return nil
  1226. end
  1227. end
  1228. -- 第一手出牌提示
  1229. function PokerUtil:getFirstTip( handCards )
  1230. if #handCards<=0 then return nil end
  1231. local parseHands = self:parseCards(handCards)
  1232. local classify = self:classifyCardsEx(parseHands)
  1233. local singles = {}
  1234. local fours = {}
  1235. for valStr,cds in pairs(classify) do
  1236. if #cds == 1 then
  1237. table.insert(singles, cds)
  1238. elseif #cds == 2 then
  1239. table.insert(singles, cds)
  1240. elseif #cds == 3 then
  1241. table.insert(singles, cds)
  1242. elseif #cds == 4 then
  1243. table.insert(fours, cds)
  1244. end
  1245. end
  1246. if #singles > 0 then
  1247. if #singles>=2 then
  1248. table.sort(singles, function ( a, b )
  1249. return a[1].val > b[1].val
  1250. end)
  1251. end
  1252. return singles
  1253. else
  1254. if #fours>0 then
  1255. return fours
  1256. end
  1257. end
  1258. end
  1259. -- 检测最后一手牌能否一次出完
  1260. function PokerUtil:checkOnceOut( handCards )
  1261. local tp = self:checkType(handCards)
  1262. if tp == OUT_TYPE.THREE_AND_TWO then
  1263. if self.isChai then --将3带2还原成4带1
  1264. local parseHands = self:parseCards(handCards)
  1265. if self:check4And1(parseHands) then
  1266. tp = OUT_TYPE.FOUR_AND_ONE
  1267. end
  1268. end
  1269. end
  1270. if tp == OUT_TYPE.AIRPLANE then--还原4带3
  1271. if self.isFAT then
  1272. local parseHands = self:parseCards(handCards)
  1273. if self:check4And3(parseHands) then
  1274. tp = OUT_TYPE.FOUR_AND_THREE
  1275. end
  1276. end
  1277. end
  1278. if tp == OUT_TYPE.FOUR_AND_TWO then--4带2
  1279. return false , tp
  1280. end
  1281. print("----------------------------------once out : ", tp)
  1282. if tp < OUT_TYPE.NONE then
  1283. return (tp==OUT_TYPE.SINGLE_CARD
  1284. or tp==OUT_TYPE.DUI_ZI
  1285. or tp==OUT_TYPE.SHUN_ZI
  1286. or tp==OUT_TYPE.THREE_AND_TWO
  1287. or tp==OUT_TYPE.THREE_AND_ONE
  1288. or tp==OUT_TYPE.THREE
  1289. or tp==OUT_TYPE.LIAN_DUI
  1290. or tp==OUT_TYPE.AIRPLANE), tp
  1291. else--unwork dead code
  1292. --检测是否是三个带不全
  1293. if #handCards > 4 then
  1294. return false, tp
  1295. else
  1296. local parseHands = self:parseCards(handCards)
  1297. local classify = self:classifyCards(parseHands)
  1298. local tmps = self:getSameNum(classify, 3)
  1299. if #tmps>=1 then
  1300. return true, tp
  1301. else
  1302. return false, tp
  1303. end
  1304. end
  1305. end
  1306. return false , tp
  1307. end
  1308. -- 判断牌是否是手牌中最大的牌
  1309. function PokerUtil:isMaxCard(handCards, card)
  1310. local targetTp, targetVal = pokerParse(card)
  1311. local parseHands = self:parseCards(handCards)
  1312. local result = true
  1313. for _,v in pairs(parseHands) do
  1314. if v.val > targetVal then
  1315. result = false
  1316. break
  1317. end
  1318. end
  1319. return result
  1320. end
  1321. -- 检测是否拆了炸弹
  1322. function PokerUtil:isChaiBombs( handCards, selects )
  1323. local parseSelects = self:parseCards(selects)
  1324. --检测手上是否有炸弹
  1325. local bombs = self:getAllBomb(handCards)
  1326. if #bombs > 0 then
  1327. for _,bomb in pairs(bombs) do
  1328. if self:checkOwnX(parseSelects, bomb[1]) then
  1329. local classifySelects = self:classifyCardsEx(parseSelects)
  1330. local target = classifySelects[tostring(bomb[1].val)]
  1331. if #target < 4 then
  1332. return true
  1333. end
  1334. end
  1335. end
  1336. else
  1337. return false
  1338. end
  1339. return false
  1340. end
  1341. -- 判断三带不全出牌
  1342. function PokerUtil:checkThreeOut( handCards ,targets)
  1343. local parseHands = self:parseCards(handCards)
  1344. local parseTargets = self:parseCards(targets)
  1345. local handsThree = self:getSameNumExEx(parseHands)
  1346. local targetThree = self:getSameNumExEx(parseTargets)
  1347. local handVal = nil
  1348. local targetVal = nil
  1349. for k,v in pairs(targetThree) do
  1350. targetVal = tonumber(k)
  1351. end
  1352. for k,v in pairs(handsThree) do
  1353. handVal = tonumber(k)
  1354. end
  1355. if targetVal and handVal then
  1356. return targetVal < handVal
  1357. end
  1358. return false
  1359. end
  1360. --
  1361. function PokerUtil:leftCards( handCards, targets)
  1362. local result = {}
  1363. local ts = {}
  1364. for _,group in pairs(targets) do
  1365. for _,card in pairs(group) do
  1366. table.insert(ts, card.cid)--将能出的牌汇集到一起
  1367. end
  1368. end
  1369. for _,hcid in pairs(handCards) do
  1370. local own = false
  1371. for _,tcid in pairs(ts) do
  1372. if hcid == tcid then--包含了同一张牌
  1373. own = true
  1374. end
  1375. end
  1376. if not own then
  1377. table.insert(result, hcid)
  1378. end
  1379. end
  1380. return result
  1381. end
  1382. -- 提示,只剩大于最小牌的牌
  1383. function PokerUtil:leftCardsEx( handCards, targets)
  1384. local result = {}
  1385. local ts = {}
  1386. local minVal = 100
  1387. for _,group in pairs(targets) do
  1388. for _,card in pairs(group) do
  1389. table.insert(ts, card.cid)--将能出的牌汇集到一起
  1390. if card.val < minVal then
  1391. minVal = card.val--能出牌的最小张
  1392. end
  1393. end
  1394. end
  1395. for _,hcid in pairs(handCards) do
  1396. local own = false
  1397. for _,tcid in pairs(ts) do
  1398. local _, val = pokerParse(hcid)
  1399. if hcid == tcid or val >= minVal then
  1400. own = true
  1401. end
  1402. end
  1403. if not own then
  1404. table.insert(result, hcid)
  1405. end
  1406. end
  1407. return result
  1408. end
  1409. --
  1410. function PokerUtil:leftSingleCards( handCards, targets)
  1411. local result = {}
  1412. local ts = {}
  1413. for _,card in pairs(targets) do
  1414. if card.cid == nil and type(card)=='table' and #card>0 then
  1415. for _,v in ipairs(card) do
  1416. table.insert(ts, v.cid)
  1417. end
  1418. else
  1419. table.insert(ts, card.cid)
  1420. end
  1421. end
  1422. for _,hcid in pairs(handCards) do
  1423. local own = false
  1424. for _,tcid in pairs(ts) do
  1425. if hcid == tcid then
  1426. own = true
  1427. end
  1428. end
  1429. if not own then
  1430. table.insert(result, hcid)
  1431. end
  1432. end
  1433. return result
  1434. end
  1435. --是否是AAA
  1436. function PokerUtil:isAAA( cards )
  1437. if #cards ~= 3 then return false end
  1438. local result = true
  1439. for i,v in ipairs(cards) do
  1440. local _, val = pokerParse(v)
  1441. if val ~= A_VAL then
  1442. result = false
  1443. break
  1444. end
  1445. end
  1446. return result
  1447. end
  1448. return PokerUtil