You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1190 rivejä
35 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. local zgwrDdzUtil1 = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzPokerUtil"):new({isChai=nil, isFAT=nil})
  25. local DdzRoomViewConfig = require("pk_zgwrddz.luaScript.Views.Room.zgwrDdzRoomViewConfig")
  26. local ETS = DdzRoomViewConfig.EffectType
  27. local zgwrDdzUtil2 = {}
  28. --从点击的牌里面获取可以管上家牌的牌组合,没有则不提示
  29. function zgwrDdzUtil2.getOneTip(selectCards,handCards,lastCards,lastType)--选中的牌,手牌,牌桌上最后出的牌,牌桌上最后出的牌的牌型
  30. if #lastCards == 0 or lastType == 0 then--如果没有最后一手牌,自己第一个出
  31. return selectCards
  32. end
  33. if not selectCards or type(selectCards) ~= 'table' then return nil end
  34. local selectCardsNum = #selectCards
  35. if selectCardsNum == 1 then--单点一张牌
  36. local card = selectCards[1]
  37. local cval = zgwrDdzUtil1:getCardValue(card)
  38. if cval == GUI_VAL then return card end
  39. if cval == X_KING or cval == D_KING then--如果点的是王
  40. local isHaveGuil,guiNuml = zgwrDdzUtil1:checkHaveGui2(lastCards)
  41. if lastType == ETS.SINGLE_CARD then
  42. return card
  43. elseif lastType < ETS.TWO_SMALL_KING then
  44. return zgwrDdzUtil2.getTwoKingBombByCard(card,handCards)
  45. elseif lastType == ETS.TWO_SMALL_KING then
  46. if cval == X_KING then
  47. return zgwrDdzUtil2.getTwoSKingBombByCard(card,handCards,false) or zgwrDdzUtil2.getSBKingBombByCard(card,handCards) or zgwrDdzUtil2.getFourKingBombByCard(card,handCards)
  48. elseif cval == D_KING then
  49. return zgwrDdzUtil2.getSBKingBombByCard(card,handCards) or zgwrDdzUtil2.getTwoBKingBombByCard(card,handCards,true) or zgwrDdzUtil2.getFourKingBombByCard(card,handCards)
  50. end
  51. elseif lastType == ETS.BIG_SMALL_KING then
  52. if cval == X_KING then
  53. return zgwrDdzUtil2.getFourKingBombByCard(card,handCards)
  54. elseif cval == D_KING then
  55. return zgwrDdzUtil2.getTwoBKingBombByCard(card,handCards,true)
  56. end
  57. elseif lastType == ETS.TWO_BIG_KING then
  58. return zgwrDdzUtil2.getTwoBKingBombByCard(card,handCards,false) or zgwrDdzUtil2.getFourKingBombByCard(card,handCards)
  59. elseif lastType < ETS.FOUR_SMALL_KING then
  60. return zgwrDdzUtil2.getFourKingBombByCard(card,handCards)
  61. elseif lastType >= ETS.FOUR_SMALL_KING and lastType <= ETS.FOUR_BIG_KING then
  62. local tresult = zgwrDdzUtil2.getMaxFourKingBombByCard(card,handCards)
  63. if tresult then
  64. local tipType = zgwrDdzUtil1:checkType(tresult)
  65. if tipType > lastType then
  66. return tresult
  67. elseif tipType == lastType then
  68. local isHaveGui,guiNum = zgwrDdzUtil1:checkHaveGui2(tresult)
  69. if guiNum < guiNuml then
  70. return tresult
  71. else
  72. return card
  73. end
  74. else
  75. return card
  76. end
  77. end
  78. end
  79. end
  80. if lastType == ETS.SINGLE_CARD then
  81. local lval = zgwrDdzUtil1:getCardValue(lastCards[1])
  82. if cval > lval then
  83. return cval
  84. else
  85. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  86. end
  87. elseif lastType == ETS.DUI_ZI then
  88. local lval = zgwrDdzUtil1:getCardsMin(lastCards,ETS.DUI_ZI)
  89. if cval > lval then
  90. return zgwrDdzUtil2.getDuiTpsByCard(card,handCards)
  91. else
  92. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  93. end
  94. elseif lastType == ETS.THREE then
  95. local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType)
  96. if cval > lval then
  97. return zgwrDdzUtil2.getThreeTpsByCard(card,handCards)
  98. else
  99. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  100. end
  101. elseif lastType == ETS.SHUN_ZI then--顺子
  102. local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType)
  103. if cval > lval then
  104. --[[if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 3 then
  105. return card
  106. else--]]
  107. return zgwrDdzUtil2.getShunZiTpsByCard(card,handCards,#lastCards,lval)
  108. --end
  109. else
  110. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  111. end
  112. elseif lastType == ETS.LIAN_DUI then--连对
  113. local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType)
  114. if cval > lval then
  115. if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 4 then
  116. return card
  117. else
  118. return zgwrDdzUtil2.getLianDuiTpsByCard(card,handCards,#lastCards,lval)
  119. end
  120. else
  121. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  122. end
  123. elseif lastType == ETS.SAN_SHUN then--三顺
  124. local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType)
  125. if cval > lval then
  126. if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 4 then
  127. return card
  128. else
  129. return zgwrDdzUtil2.getSanShunTpsByCard(card,handCards,#lastCards,lval)
  130. end
  131. else
  132. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  133. end
  134. elseif lastType == ETS.THREE_AND_ONE then--三带一
  135. local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType)
  136. if cval > lval then
  137. if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 3 then
  138. return zgwrDdzUtil2.getSanDaiYiTpsByCard(card,handCards)
  139. elseif zgwrDdzUtil2.getCardNumByCard(card,handCards) == 2 and zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) > 0 then--癞子牌大于1
  140. return zgwrDdzUtil2.getSanDaiYiTpsByCard(card,handCards)
  141. else
  142. local three = zgwrDdzUtil2.getMinThree(handCards,lval,true)
  143. if three then
  144. table.insert(three,card)
  145. return three
  146. else
  147. return card
  148. end
  149. end
  150. else
  151. if zgwrDdzUtil2.getCardNumByCard(card,handCards) == 1 then--点击的是单张
  152. local three = zgwrDdzUtil2.getMinThree(handCards,lval,true)
  153. if three then
  154. table.insert(three,card)
  155. return three
  156. else
  157. return card
  158. end
  159. elseif zgwrDdzUtil2.getCardNumByCard(card,handCards) == 2 and zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) < 2 then
  160. local three = zgwrDdzUtil2.getMinThree(handCards,lval,true)
  161. if three then
  162. table.insert(three,card)
  163. return three
  164. else
  165. return card
  166. end
  167. else
  168. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  169. end
  170. end
  171. elseif lastType == ETS.THREE_AND_DUI then--三带一对
  172. local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType)
  173. if cval > lval then
  174. if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 3 then
  175. return zgwrDdzUtil2.getSanDaiDuiTpsByCard(card,handCards)
  176. elseif zgwrDdzUtil2.getCardNumByCard(card,handCards) == 2 and zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) > 0 then--癞子牌大于1
  177. return zgwrDdzUtil2.getSanDaiDuiTpsByCard(card,handCards)
  178. else
  179. if zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) == 1 then
  180. local three = zgwrDdzUtil2.getMinThree(handCards,lval,true)
  181. if three then
  182. table.insert(three,card)
  183. table.insert(three,0x5D)
  184. return three
  185. else
  186. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  187. end
  188. elseif zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) > 1 then
  189. return zgwrDdzUtil2.getSanDaiDuiTpsByCard(card,handCards)
  190. else
  191. return card
  192. end
  193. end
  194. else
  195. if zgwrDdzUtil2.getCardNumByCard(card,handCards) == 1 then--点击的是单张
  196. if zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) == 0 then
  197. return card
  198. elseif zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) == 1 then
  199. local three = zgwrDdzUtil2.getMinThree(handCards,lval,true)
  200. if three then
  201. table.insert(three,card)
  202. table.insert(three,0x5D)
  203. return three
  204. else
  205. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  206. end
  207. else
  208. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  209. end
  210. elseif zgwrDdzUtil2.getCardNumByCard(card,handCards) == 2 then
  211. local three = zgwrDdzUtil2.getMinThree(handCards,lval,true)
  212. if three then
  213. table.insert(three,card)
  214. table.insert(three,card)
  215. return three
  216. else
  217. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  218. end
  219. elseif zgwrDdzUtil2.getCardNumByCard(card,handCards) == 3 then
  220. if zgwrDdzUtil2.getCardNumByCard(0x5D,handCards) > 0 then
  221. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  222. else
  223. local three = zgwrDdzUtil2.getMinThree(handCards,lval,true)
  224. if three then
  225. table.insert(three,card)
  226. table.insert(three,card)
  227. return three
  228. else
  229. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  230. end
  231. end
  232. else
  233. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  234. end
  235. end
  236. elseif lastType == ETS.AIRPLANE_SINGLE then--飞机(带单张)
  237. local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType)
  238. if cval > lval then
  239. if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 4 then
  240. return card
  241. else
  242. local needNum = #lastCards - #lastCards/4
  243. local sanShun = zgwrDdzUtil2.getSanShunTpsByCard(card,handCards,needNum,lval)
  244. if type(sanShun) == 'table' then
  245. local needSigleNums = #lastCards/4
  246. local minLimit = nil
  247. for i=1,needSigleNums do
  248. local card = zgwrDdzUtil2.getMinSigle(handCards,minLimit)
  249. if card then
  250. minLimit = zgwrDdzUtil1:getCardValue(card)
  251. table.insert(sanShun,card)
  252. end
  253. end
  254. return sanShun
  255. else
  256. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  257. end
  258. end
  259. else
  260. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  261. end
  262. elseif lastType == ETS.AIRPLANE_DUI then--飞机带对
  263. local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType)
  264. if cval > lval then
  265. if zgwrDdzUtil2.getCardNumByCard(card,handCards) >= 4 then
  266. return card
  267. else
  268. local needNum = #lastCards - (#lastCards*2/5)
  269. local sanShun = zgwrDdzUtil2.getSanShunTpsByCard(card,handCards,needNum,lval)
  270. if type(sanShun) == 'table' then
  271. local needDuiNums = #lastCards/5
  272. local minLimit = nil
  273. for i=1,needDuiNums do
  274. local tcard = zgwrDdzUtil2.getMinDuiZi(handCards,minLimit)
  275. if tcard then
  276. minLimit = zgwrDdzUtil1:getCardValue(tcard[1])
  277. for i,v in pairs(tcard) do
  278. table.insert(sanShun,v)
  279. end
  280. end
  281. end
  282. return sanShun
  283. else
  284. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  285. end
  286. end
  287. else
  288. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  289. end
  290. elseif lastType == ETS.BOMB_FOUR then--炸弹4张
  291. local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType)
  292. if cval > lval then
  293. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  294. else
  295. return zgwrDdzUtil2.getEightBombByCard(card,handCards)
  296. end
  297. elseif lastType >= ETS.TWO_SMALL_KING and lastType <= ETS.TWO_BIG_KING then--双王炸
  298. return zgwrDdzUtil2.getEightBombByCard(card,handCards)
  299. elseif lastType == ETS.BOMB_EIGHT then--双王炸
  300. local lval = zgwrDdzUtil1:getCardsMin(lastCards,lastType)
  301. if cval > lval then
  302. return zgwrDdzUtil2.getEightBombByCard(card,handCards)
  303. else
  304. return zgwrDdzUtil2.getTwelveBombByCard(card,handCards)
  305. end
  306. elseif lastType >= ETS.FOUR_SMALL_KING and lastType >= ETS.FOUR_BIG_KING then--双王炸
  307. return zgwrDdzUtil2.getTwelveBombByCard(card,handCards)
  308. end
  309. elseif selectCardsNum > 1 then--选了多张牌
  310. end
  311. end
  312. --获取指定牌有多少张
  313. function zgwrDdzUtil2.getCardNumByCard(card,handCards)
  314. local valueList = {}
  315. local cardList = {}
  316. local laiCount = 0
  317. for k,v in ipairs(handCards) do
  318. local value = zgwrDdzUtil1:getCardValue(v)
  319. valueList[value] = valueList[value] or 0
  320. valueList[value] = valueList[value] + 1
  321. cardList[value] = cardList[value] or {}
  322. table.insert(cardList[value], v)
  323. if value == GUI_VAL then
  324. laiCount = laiCount + 1
  325. elseif value == X_KING or value == D_KING then--小王和大王
  326. end
  327. end
  328. local val = zgwrDdzUtil1:getCardValue(card)
  329. if valueList[val] and valueList[val] > 0 then
  330. return valueList[val]
  331. else
  332. return 0
  333. end
  334. end
  335. --根据一张牌,从手牌获取炸弹
  336. function zgwrDdzUtil2.getFourBombByCard(card,handCards)
  337. local valueList = {}
  338. local cardList = {}
  339. local laiCount = 0
  340. for k,v in ipairs(handCards) do
  341. local value = zgwrDdzUtil1:getCardValue(v)
  342. valueList[value] = valueList[value] or 0
  343. valueList[value] = valueList[value] + 1
  344. cardList[value] = cardList[value] or {}
  345. table.insert(cardList[value], v)
  346. if value == GUI_VAL then
  347. laiCount = laiCount + 1
  348. elseif value == X_KING or value == D_KING then--小王和大王
  349. end
  350. end
  351. local val = zgwrDdzUtil1:getCardValue(card)
  352. local tipresult = {}
  353. if (valueList[val] > 0 and valueList[val] + laiCount >= 4) then
  354. local _tpNum4 = 4 - valueList[val];
  355. _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0
  356. for _l4 = 1, _tpNum4 do
  357. table.insert(tipresult,cardList[GUI_VAL][_l4])
  358. end
  359. for _m4 = 1, 4 - _tpNum4 do
  360. table.insert(tipresult,cardList[val][_m4])
  361. end
  362. return tipresult
  363. end
  364. return card
  365. end
  366. --根据一张牌,从手牌获取炸弹
  367. function zgwrDdzUtil2.getEightBombByCard(card,handCards)
  368. local valueList = {}
  369. local cardList = {}
  370. local laiCount = 0
  371. for k,v in ipairs(handCards) do
  372. local value = zgwrDdzUtil1:getCardValue(v)
  373. valueList[value] = valueList[value] or 0
  374. valueList[value] = valueList[value] + 1
  375. cardList[value] = cardList[value] or {}
  376. table.insert(cardList[value], v)
  377. if value == GUI_VAL then
  378. laiCount = laiCount + 1
  379. elseif value == X_KING or value == D_KING then--小王和大王
  380. end
  381. end
  382. local val = zgwrDdzUtil1:getCardValue(card)
  383. local tipresult = {}
  384. if (valueList[val] > 0 and valueList[val] + laiCount >= 8) then
  385. local _tpNum4 = 8 - valueList[val];
  386. _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0
  387. for _l4 = 1, _tpNum4 do
  388. table.insert(tipresult,cardList[GUI_VAL][_l4])
  389. end
  390. for _m4 = 1, 8 - _tpNum4 do
  391. table.insert(tipresult,cardList[val][_m4])
  392. end
  393. return tipresult
  394. end
  395. return card
  396. end
  397. --根据一张牌,从手牌获取炸弹
  398. function zgwrDdzUtil2.getTwelveBombByCard(card,handCards)
  399. local valueList = {}
  400. local cardList = {}
  401. local laiCount = 0
  402. for k,v in ipairs(handCards) do
  403. local value = zgwrDdzUtil1:getCardValue(v)
  404. valueList[value] = valueList[value] or 0
  405. valueList[value] = valueList[value] + 1
  406. cardList[value] = cardList[value] or {}
  407. table.insert(cardList[value], v)
  408. if value == GUI_VAL then
  409. laiCount = laiCount + 1
  410. elseif value == X_KING or value == D_KING then--小王和大王
  411. end
  412. end
  413. local val = zgwrDdzUtil1:getCardValue(card)
  414. local tipresult = {}
  415. if (valueList[val] > 0 and valueList[val] + laiCount >= 12) then
  416. local _tpNum4 = 12 - valueList[val];
  417. _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0
  418. for _l4 = 1, _tpNum4 do
  419. table.insert(tipresult,cardList[GUI_VAL][_l4])
  420. end
  421. for _m4 = 1, 12 - _tpNum4 do
  422. table.insert(tipresult,cardList[val][_m4])
  423. end
  424. return tipresult
  425. end
  426. return card
  427. end
  428. function zgwrDdzUtil2.getDuiTpsByCard(card,handCards)
  429. local valueList = {}
  430. local cardList = {}
  431. local laiCount = 0
  432. for k,v in ipairs(handCards) do
  433. local value = zgwrDdzUtil1:getCardValue(v)
  434. valueList[value] = valueList[value] or 0
  435. valueList[value] = valueList[value] + 1
  436. cardList[value] = cardList[value] or {}
  437. table.insert(cardList[value], v)
  438. if value == GUI_VAL then
  439. laiCount = laiCount + 1
  440. elseif value == X_KING or value == D_KING then--小王和大王
  441. end
  442. end
  443. local val = zgwrDdzUtil1:getCardValue(card)
  444. local tipresult = {}
  445. if (valueList[val] > 0 and valueList[val] + laiCount >= 2) then
  446. local _tpNum4 = 2 - valueList[val];
  447. _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0
  448. for _l4 = 1, _tpNum4 do
  449. table.insert(tipresult,cardList[GUI_VAL][_l4])
  450. end
  451. for _m4 = 1, 2 - _tpNum4 do
  452. table.insert(tipresult,cardList[val][_m4])
  453. end
  454. return tipresult
  455. end
  456. return card
  457. end
  458. function zgwrDdzUtil2.getThreeTpsByCard(card,handCards)
  459. local valueList = {}
  460. local cardList = {}
  461. local laiCount = 0
  462. for k,v in ipairs(handCards) do
  463. local value = zgwrDdzUtil1:getCardValue(v)
  464. valueList[value] = valueList[value] or 0
  465. valueList[value] = valueList[value] + 1
  466. cardList[value] = cardList[value] or {}
  467. table.insert(cardList[value], v)
  468. if value == GUI_VAL then
  469. laiCount = laiCount + 1
  470. elseif value == X_KING or value == D_KING then--小王和大王
  471. end
  472. end
  473. local val = zgwrDdzUtil1:getCardValue(card)
  474. local tipresult = {}
  475. if (valueList[val] > 0 and valueList[val] + laiCount >= 3) then
  476. local _tpNum4 = 3 - valueList[val];
  477. _tpNum4 = _tpNum4 >= 0 and _tpNum4 or 0
  478. for _l4 = 1, _tpNum4 do
  479. table.insert(tipresult,cardList[GUI_VAL][_l4])
  480. end
  481. for _m4 = 1, 3 - _tpNum4 do
  482. table.insert(tipresult,cardList[val][_m4])
  483. end
  484. return tipresult
  485. end
  486. return card
  487. end
  488. --获取两小王炸提示
  489. function zgwrDdzUtil2.getTwoSKingBombByCard(card,handCards,isCanUseGui)
  490. local valueList = {}
  491. local cardList = {}
  492. local laiCount = 0
  493. for k,v in ipairs(handCards) do
  494. local value = zgwrDdzUtil1:getCardValue(v)
  495. valueList[value] = valueList[value] or 0
  496. valueList[value] = valueList[value] + 1
  497. cardList[value] = cardList[value] or {}
  498. table.insert(cardList[value], v)
  499. if value == GUI_VAL then
  500. laiCount = laiCount + 1
  501. elseif value == X_KING or value == D_KING then--小王和大王
  502. end
  503. end
  504. local val = zgwrDdzUtil1:getCardValue(card)
  505. valueList[X_KING] = valueList[X_KING] or 0
  506. valueList[D_KING] = valueList[D_KING] or 0
  507. valueList[GUI_VAL] = valueList[GUI_VAL] or 0
  508. local tipresult = {}
  509. if isCanUseGui and (valueList[val] > 0 and (valueList[val] + laiCount >= 2)) then
  510. table.insert(tipresult,cardList[val][1])
  511. if valueList[GUI_VAL] > 0 then
  512. table.insert(tipresult,cardList[GUI_VAL][1])
  513. elseif valueList[X_KING] and valueList[X_KING] > 1 then
  514. table.insert(tipresult,cardList[X_KING][2])
  515. end
  516. return tipresult
  517. elseif valueList[val] >= 2 then
  518. table.insert(tipresult,cardList[val][1])
  519. table.insert(tipresult,cardList[val][2])
  520. return tipresult
  521. end
  522. return nil
  523. end
  524. --获取小王大王炸提示
  525. function zgwrDdzUtil2.getSBKingBombByCard(card,handCards)
  526. local valueList = {}
  527. local cardList = {}
  528. local laiCount = 0
  529. for k,v in ipairs(handCards) do
  530. local value = zgwrDdzUtil1:getCardValue(v)
  531. valueList[value] = valueList[value] or 0
  532. valueList[value] = valueList[value] + 1
  533. cardList[value] = cardList[value] or {}
  534. table.insert(cardList[value], v)
  535. if value == GUI_VAL then
  536. laiCount = laiCount + 1
  537. elseif value == X_KING or value == D_KING then--小王和大王
  538. end
  539. end
  540. local val = zgwrDdzUtil1:getCardValue(card)
  541. valueList[D_KING] = valueList[D_KING] or 0
  542. valueList[X_KING] = valueList[X_KING] or 0
  543. local tipresult = {}
  544. if valueList[X_KING] >= 1 and valueList[D_KING] >= 1 then
  545. table.insert(tipresult,cardList[val][1])
  546. if val == X_KING then
  547. table.insert(tipresult,cardList[D_KING][1])
  548. elseif val == D_KING then
  549. table.insert(tipresult,cardList[X_KING][1])
  550. end
  551. return tipresult
  552. end
  553. return nil
  554. end
  555. --获取两大王炸提示
  556. function zgwrDdzUtil2.getTwoBKingBombByCard(card,handCards,isCanUseGui)
  557. local valueList = {}
  558. local cardList = {}
  559. local laiCount = 0
  560. for k,v in ipairs(handCards) do
  561. local value = zgwrDdzUtil1:getCardValue(v)
  562. valueList[value] = valueList[value] or 0
  563. valueList[value] = valueList[value] + 1
  564. cardList[value] = cardList[value] or {}
  565. table.insert(cardList[value], v)
  566. if value == GUI_VAL then
  567. laiCount = laiCount + 1
  568. elseif value == X_KING or value == D_KING then--小王和大王
  569. end
  570. end
  571. local val = zgwrDdzUtil1:getCardValue(card)
  572. valueList[D_KING] = valueList[D_KING] or 0
  573. valueList[X_KING] = valueList[X_KING] or 0
  574. valueList[GUI_VAL] = valueList[GUI_VAL] or 0
  575. local tipresult = {}
  576. if isCanUseGui and (valueList[val] > 0 and (valueList[val] + laiCount >= 2)) then
  577. table.insert(tipresult,cardList[val][1])
  578. if valueList[GUI_VAL] > 0 then
  579. table.insert(tipresult,cardList[GUI_VAL][1])
  580. elseif valueList[D_KING] and valueList[D_KING] > 1 then
  581. table.insert(tipresult,cardList[D_KING][2])
  582. end
  583. return tipresult
  584. elseif valueList[val] >= 2 then
  585. table.insert(tipresult,cardList[val][1])
  586. table.insert(tipresult,cardList[val][2])
  587. return tipresult
  588. end
  589. return nil
  590. end
  591. -- 获取王炸提示
  592. function zgwrDdzUtil2.getTwoKingBombByCard(card,handCards)
  593. local valueList = {}
  594. local cardList = {}
  595. local laiCount = 0
  596. for k,v in ipairs(handCards) do
  597. local value = zgwrDdzUtil1:getCardValue(v)
  598. valueList[value] = valueList[value] or 0
  599. valueList[value] = valueList[value] + 1
  600. cardList[value] = cardList[value] or {}
  601. table.insert(cardList[value], v)
  602. if value == GUI_VAL then
  603. laiCount = laiCount + 1
  604. elseif value == X_KING or value == D_KING then--小王和大王
  605. end
  606. end
  607. local val = zgwrDdzUtil1:getCardValue(card)
  608. valueList[D_KING] = valueList[D_KING] or 0
  609. valueList[X_KING] = valueList[X_KING] or 0
  610. valueList[GUI_VAL] = valueList[GUI_VAL] or 0
  611. local tipresult = {}
  612. if (valueList[val] > 0 and (valueList[X_KING] + valueList[D_KING] >= 2 or valueList[val] + laiCount >= 2)) then
  613. table.insert(tipresult,cardList[val][1])
  614. if val == X_KING then
  615. if valueList[X_KING] and valueList[X_KING] > 1 then
  616. table.insert(tipresult,cardList[X_KING][2])
  617. elseif valueList[GUI_VAL] > 0 then
  618. table.insert(tipresult,cardList[GUI_VAL][1])
  619. elseif valueList[D_KING] > 0 then
  620. table.insert(tipresult,cardList[D_KING][1])
  621. end
  622. elseif val == D_KING then
  623. if valueList[X_KING] and valueList[X_KING] > 0 then
  624. table.insert(tipresult,cardList[X_KING][1])
  625. elseif valueList[GUI_VAL] > 0 then
  626. table.insert(tipresult,cardList[GUI_VAL][1])
  627. elseif valueList[D_KING] > 1 then
  628. table.insert(tipresult,cardList[D_KING][2])
  629. end
  630. end
  631. return tipresult
  632. end
  633. return card
  634. end
  635. --获取四王炸
  636. function zgwrDdzUtil2.getFourKingBombByCard(card,handCards)
  637. local valueList = {}
  638. local cardList = {}
  639. local laiCount = 0
  640. for k,v in ipairs(handCards) do
  641. local value = zgwrDdzUtil1:getCardValue(v)
  642. valueList[value] = valueList[value] or 0
  643. valueList[value] = valueList[value] + 1
  644. cardList[value] = cardList[value] or {}
  645. table.insert(cardList[value], v)
  646. if value == GUI_VAL then
  647. laiCount = laiCount + 1
  648. elseif value == X_KING or value == D_KING then--小王和大王
  649. end
  650. end
  651. local val = zgwrDdzUtil1:getCardValue(card)
  652. valueList[D_KING] = valueList[D_KING] or 0
  653. valueList[X_KING] = valueList[X_KING] or 0
  654. valueList[GUI_VAL] = valueList[GUI_VAL] or 0
  655. local tipresult = {}
  656. local tpNum = 4
  657. if (valueList[val] > 0 and (valueList[X_KING] + valueList[D_KING] + laiCount >= 4)) then
  658. table.insert(tipresult,cardList[val][1])
  659. if val == X_KING then
  660. if valueList[X_KING] and valueList[X_KING] > 1 then
  661. for i=2,valueList[X_KING] do
  662. table.insert(tipresult,cardList[X_KING][i])
  663. if #tipresult == 4 then return tipresult end
  664. end
  665. end
  666. if valueList[GUI_VAL] > 0 then
  667. for i=1,valueList[GUI_VAL] do
  668. table.insert(tipresult,cardList[GUI_VAL][i])
  669. if #tipresult == 4 then return tipresult end
  670. end
  671. end
  672. if valueList[D_KING] > 0 then
  673. for i=1,valueList[D_KING] do
  674. table.insert(tipresult,cardList[D_KING][i])
  675. if #tipresult == 4 then return tipresult end
  676. end
  677. end
  678. elseif val == D_KING then
  679. if valueList[X_KING] and valueList[X_KING] > 0 then
  680. for i=1,valueList[X_KING] do
  681. table.insert(tipresult,cardList[X_KING][i])
  682. if #tipresult == 4 then return tipresult end
  683. end
  684. end
  685. if valueList[GUI_VAL] > 0 then
  686. for i=1,valueList[GUI_VAL] do
  687. table.insert(tipresult,cardList[GUI_VAL][i])
  688. if #tipresult == 4 then return tipresult end
  689. end
  690. end
  691. if valueList[D_KING] > 1 then
  692. for i=2,valueList[D_KING] do
  693. table.insert(tipresult,cardList[D_KING][i])
  694. if #tipresult == 4 then return tipresult end
  695. end
  696. end
  697. end
  698. return tipresult
  699. end
  700. return card
  701. end
  702. --获取最大四王炸
  703. function zgwrDdzUtil2.getMaxFourKingBombByCard(card,handCards)
  704. local valueList = {}
  705. local cardList = {}
  706. local laiCount = 0
  707. for k,v in ipairs(handCards) do
  708. local value = zgwrDdzUtil1:getCardValue(v)
  709. valueList[value] = valueList[value] or 0
  710. valueList[value] = valueList[value] + 1
  711. cardList[value] = cardList[value] or {}
  712. table.insert(cardList[value], v)
  713. if value == GUI_VAL then
  714. laiCount = laiCount + 1
  715. elseif value == X_KING or value == D_KING then--小王和大王
  716. end
  717. end
  718. local val = zgwrDdzUtil1:getCardValue(card)
  719. valueList[D_KING] = valueList[D_KING] or 0
  720. valueList[X_KING] = valueList[X_KING] or 0
  721. valueList[GUI_VAL] = valueList[GUI_VAL] or 0
  722. local tipresult = {}
  723. if (valueList[val] > 0 and (valueList[X_KING] + valueList[D_KING] + laiCount >= 4)) then
  724. table.insert(tipresult,cardList[val][1])
  725. if val == X_KING then
  726. if valueList[D_KING] > 0 then
  727. for i=1,valueList[D_KING] do
  728. table.insert(tipresult,cardList[D_KING][i])
  729. if #tipresult == 4 then return tipresult end
  730. end
  731. end
  732. if valueList[GUI_VAL] > 0 then
  733. for i=1,valueList[GUI_VAL] do
  734. table.insert(tipresult,cardList[GUI_VAL][i])
  735. if #tipresult == 4 then return tipresult end
  736. end
  737. end
  738. if valueList[X_KING] and valueList[X_KING] > 1 then
  739. for i=2,valueList[X_KING] do
  740. table.insert(tipresult,cardList[X_KING][i])
  741. if #tipresult == 4 then return tipresult end
  742. end
  743. end
  744. elseif val == D_KING then
  745. if valueList[D_KING] > 1 then
  746. for i=2,valueList[D_KING] do
  747. table.insert(tipresult,cardList[D_KING][i])
  748. if #tipresult == 4 then return tipresult end
  749. end
  750. end
  751. if valueList[GUI_VAL] > 0 then
  752. for i=1,valueList[GUI_VAL] do
  753. table.insert(tipresult,cardList[GUI_VAL][i])
  754. if #tipresult == 4 then return tipresult end
  755. end
  756. end
  757. if valueList[X_KING] and valueList[X_KING] > 0 then
  758. for i=1,valueList[X_KING] do
  759. table.insert(tipresult,cardList[X_KING][i])
  760. if #tipresult == 4 then return tipresult end
  761. end
  762. end
  763. end
  764. end
  765. return nil
  766. end
  767. function zgwrDdzUtil2.getShunZiTpsByCard(card,handCards,needNum,minVal)--选中的牌,手牌,需要的张数,最小的起始牌
  768. local valueList = {}
  769. local cardList = {}
  770. local laiCount = 0
  771. for k,v in ipairs(handCards) do
  772. local value = zgwrDdzUtil1:getCardValue(v)
  773. valueList[value] = valueList[value] or 0
  774. valueList[value] = valueList[value] + 1
  775. cardList[value] = cardList[value] or {}
  776. table.insert(cardList[value], v)
  777. if value == GUI_VAL then
  778. laiCount = laiCount + 1
  779. elseif value == X_KING or value == D_KING then--小王和大王
  780. end
  781. end
  782. local val = zgwrDdzUtil1:getCardValue(card)
  783. if val > 9 then return card end--选中的是2,不能组成顺子 返回
  784. if val > 5 or (val + needNum > 10) then--选中的牌值大于10
  785. val = 10 - needNum
  786. end
  787. if val <= minVal then
  788. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  789. end
  790. local _tpIdx = val;
  791. local _tpCount = 0;
  792. local _tpReplace2 = {}
  793. local tpNotAllLai = false;
  794. local _haveLai = laiCount;
  795. while _tpCount < #handCards and _tpCount < needNum and _tpIdx <= 10 do
  796. valueList[_tpIdx] = valueList[_tpIdx] or 0;
  797. if (not (valueList[_tpIdx] + _haveLai >= 1)) then break end;
  798. local _tpNum = 1 - valueList[_tpIdx];
  799. _tpNum = _tpNum >= 0 and _tpNum or 0;
  800. local lai = laiCount - _haveLai + 1
  801. for p = 1, _tpNum do
  802. table.insert(_tpReplace2,cardList[GUI_VAL][lai])
  803. lai = lai + 1
  804. end
  805. for _m = 1, 1 - _tpNum do
  806. table.insert(_tpReplace2, cardList[_tpIdx][_m])
  807. tpNotAllLai = true;
  808. end
  809. _haveLai = _haveLai - _tpNum;
  810. _tpCount = _tpCount + 1;
  811. _tpIdx = _tpIdx + 1
  812. end
  813. if _tpCount == needNum then
  814. return _tpReplace2
  815. else
  816. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  817. end
  818. end
  819. function zgwrDdzUtil2.getLianDuiTpsByCard(card,handCards,needNum,minVal)--选中的牌,手牌,需要的张数,最小的起始牌
  820. local valueList = {}
  821. local cardList = {}
  822. local laiCount = 0
  823. for k,v in ipairs(handCards) do
  824. local value = zgwrDdzUtil1:getCardValue(v)
  825. valueList[value] = valueList[value] or 0
  826. valueList[value] = valueList[value] + 1
  827. cardList[value] = cardList[value] or {}
  828. table.insert(cardList[value], v)
  829. if value == GUI_VAL then
  830. laiCount = laiCount + 1
  831. elseif value == X_KING or value == D_KING then--小王和大王
  832. end
  833. end
  834. local val = zgwrDdzUtil1:getCardValue(card)
  835. if val > 9 then return card end--选中的是2,不能组成顺子 返回
  836. if val > 7 or (val + needNum/2 > 10) then--选中的牌值大于Q
  837. val = 10 - needNum/2
  838. end
  839. if val <= minVal then
  840. return card
  841. end
  842. local _tpIdx = val;
  843. local _tpCount = 0;
  844. local _tpReplace2 = {}
  845. local tpNotAllLai = false;
  846. local _haveLai = laiCount;
  847. while _tpCount < #handCards and _tpCount < needNum and _tpIdx <= 9 do
  848. valueList[_tpIdx] = valueList[_tpIdx] or 0;
  849. if (not (valueList[_tpIdx] + _haveLai >= 2)) then break end;
  850. local _tpNum = 2 - valueList[_tpIdx];
  851. _tpNum = _tpNum >= 0 and _tpNum or 0;
  852. local lai = laiCount - _haveLai + 1
  853. if _tpNum >= 2 then
  854. break
  855. end
  856. for p = 1, _tpNum do
  857. table.insert(_tpReplace2,cardList[GUI_VAL][lai])
  858. lai = lai + 1
  859. end
  860. for _m = 1, 2 - _tpNum do
  861. table.insert(_tpReplace2, cardList[_tpIdx][_m])
  862. tpNotAllLai = true;
  863. end
  864. _haveLai = _haveLai - _tpNum;
  865. _tpCount = _tpCount + 2;
  866. _tpIdx = _tpIdx + 1
  867. end
  868. if _tpCount == needNum then
  869. return _tpReplace2
  870. else
  871. return zgwrDdzUtil2.getFourBombByCard(card,handCards)
  872. end
  873. end
  874. function zgwrDdzUtil2.getSanShunTpsByCard(card,handCards,needNum,minVal)--选中的牌,手牌,需要的张数,最小的起始牌
  875. local valueList = {}
  876. local cardList = {}
  877. local laiCount = 0
  878. for k,v in ipairs(handCards) do
  879. local value = zgwrDdzUtil1:getCardValue(v)
  880. valueList[value] = valueList[value] or 0
  881. valueList[value] = valueList[value] + 1
  882. cardList[value] = cardList[value] or {}
  883. table.insert(cardList[value], v)
  884. if value == GUI_VAL then
  885. laiCount = laiCount + 1
  886. elseif value == X_KING or value == D_KING then--小王和大王
  887. end
  888. end
  889. local val = zgwrDdzUtil1:getCardValue(card)
  890. if val > 9 then return card end--选中的是2,不能组成顺子 返回
  891. if val > 8 or (val + needNum/3 > 10) then--选中的牌值大于K
  892. val = 10 - needNum/3
  893. end
  894. if val <= minVal then
  895. return card
  896. end
  897. local _tpIdx = val;
  898. local _tpCount = 0;
  899. local _tpReplace2 = {}
  900. local tpNotAllLai = false;
  901. local _haveLai = laiCount;
  902. while _tpCount < #handCards and _tpCount < needNum and _tpIdx <= 9 do
  903. valueList[_tpIdx] = valueList[_tpIdx] or 0;
  904. if (not (valueList[_tpIdx] + _haveLai >= 3)) then break end;
  905. local _tpNum = 3 - valueList[_tpIdx];
  906. _tpNum = _tpNum >= 0 and _tpNum or 0;
  907. local lai = laiCount - _haveLai + 1
  908. for p = 1, _tpNum do
  909. table.insert(_tpReplace2,cardList[GUI_VAL][lai])
  910. lai = lai + 1
  911. end
  912. for _m = 1, 3 - _tpNum do
  913. table.insert(_tpReplace2, cardList[_tpIdx][_m])
  914. tpNotAllLai = true;
  915. end
  916. _haveLai = _haveLai - _tpNum;
  917. _tpCount = _tpCount + 3;
  918. _tpIdx = _tpIdx + 1
  919. end
  920. if _tpCount == needNum then
  921. return _tpReplace2
  922. else
  923. return card
  924. end
  925. end
  926. --获取最小单牌
  927. function zgwrDdzUtil2.getMinSigle(handCards,minVal,isCanChai)--是否可以拆,如果可以则从2张及以上的牌里面找
  928. local valueList = {}
  929. local cardList = {}
  930. local laiCount = 0
  931. for k,v in ipairs(handCards) do
  932. local value = zgwrDdzUtil1:getCardValue(v)
  933. valueList[value] = valueList[value] or 0
  934. valueList[value] = valueList[value] + 1
  935. cardList[value] = cardList[value] or {}
  936. table.insert(cardList[value], v)
  937. if value == GUI_VAL then
  938. laiCount = laiCount + 1
  939. elseif value == X_KING or value == D_KING then--小王和大王
  940. end
  941. end
  942. if minVal and minVal >=10 then return nil end
  943. local limit = (minVal or 0) + 1
  944. for i = limit,10 do
  945. if valueList[i] and valueList[i] == 1 then
  946. return cardList[i][1]
  947. end
  948. end
  949. if isCanChai then
  950. for i = limit,10 do
  951. if valueList[i] and valueList[i] > 1 then
  952. return cardList[i][1]
  953. end
  954. end
  955. end
  956. return nil
  957. end
  958. --获取最小对子
  959. function zgwrDdzUtil2.getMinDuiZi(handCards,minVal,isCanChai)--是否可以拆,如果可以则从3张及以上的牌里面找
  960. local valueList = {}
  961. local cardList = {}
  962. local laiCount = 0
  963. for k,v in ipairs(handCards) do
  964. local value = zgwrDdzUtil1:getCardValue(v)
  965. valueList[value] = valueList[value] or 0
  966. valueList[value] = valueList[value] + 1
  967. cardList[value] = cardList[value] or {}
  968. table.insert(cardList[value], v)
  969. if value == GUI_VAL then
  970. laiCount = laiCount + 1
  971. elseif value == X_KING or value == D_KING then--小王和大王
  972. end
  973. end
  974. if minVal and minVal >=10 then return nil end--没有比2个2还大的对牌
  975. local limit = (minVal or 0) + 1
  976. for i = limit,10 do
  977. if valueList[i] and valueList[i] == 2 then
  978. return cardList[i]
  979. end
  980. end
  981. local result = {}
  982. if isCanChai then
  983. for i = limit,10 do
  984. local isfind = false
  985. if valueList[i] and valueList[i] == 3 then
  986. isfind = true
  987. for j=1,2 do
  988. table.insert(result,cardList[i][j])
  989. end
  990. end
  991. if isfind then
  992. return result
  993. end
  994. end
  995. for i = limit,10 do
  996. local isfind = false
  997. if valueList[i] and valueList[i] >= 4 then
  998. isfind = true
  999. for j=1,2 do
  1000. table.insert(result,cardList[i][j])
  1001. end
  1002. end
  1003. if isfind then
  1004. return result
  1005. end
  1006. end
  1007. end
  1008. return nil
  1009. end
  1010. --获取最小三张
  1011. function zgwrDdzUtil2.getMinThree(handCards,minVal,isCanChai)--手牌,被限制的最小牌(即获取的三张牌至少要大于这个值),是否可以拆
  1012. local valueList = {}
  1013. local cardList = {}
  1014. local laiCount = 0
  1015. for k,v in ipairs(handCards) do
  1016. local value = zgwrDdzUtil1:getCardValue(v)
  1017. valueList[value] = valueList[value] or 0
  1018. valueList[value] = valueList[value] + 1
  1019. cardList[value] = cardList[value] or {}
  1020. table.insert(cardList[value], v)
  1021. if value == GUI_VAL then
  1022. laiCount = laiCount + 1
  1023. elseif value == X_KING or value == D_KING then--小王和大王
  1024. end
  1025. end
  1026. if minVal and minVal >=10 then return nil end--没有比三个2还大的三牌
  1027. local limit = 1
  1028. if minVal then
  1029. limit = minVal + 1
  1030. end
  1031. for i = limit,10 do
  1032. if valueList[i] and valueList[i] == 3 then
  1033. return cardList[i]
  1034. end
  1035. end
  1036. local result = {}
  1037. if isCanChai then
  1038. for i = limit,10 do
  1039. local isfind = false
  1040. if valueList[i] and valueList[i] > 3 then
  1041. isfind = true
  1042. for j=1,3 do
  1043. table.insert(result,cardList[i][j])
  1044. end
  1045. end
  1046. if isfind then
  1047. return result
  1048. end
  1049. end
  1050. end
  1051. return nil
  1052. end
  1053. --获取三带一提示
  1054. function zgwrDdzUtil2.getSanDaiYiTpsByCard(card,handCards)
  1055. local three = zgwrDdzUtil2.getThreeTpsByCard(card,handCards)
  1056. if type(three) == 'table' then
  1057. local sigle = zgwrDdzUtil2.getMinSigle(handCards)
  1058. if sigle then
  1059. table.insert(three,sigle)
  1060. end
  1061. return three
  1062. else
  1063. return card
  1064. end
  1065. end
  1066. --获取三带对提示
  1067. function zgwrDdzUtil2.getSanDaiDuiTpsByCard(card,handCards)
  1068. local three = zgwrDdzUtil2.getThreeTpsByCard(card,handCards)
  1069. if three and type(three) == 'table' then
  1070. local duiZi = zgwrDdzUtil2.getMinDuiZi(handCards)
  1071. if duiZi then
  1072. for i,v in pairs(duiZi) do
  1073. table.insert(three,v)
  1074. end
  1075. end
  1076. return three
  1077. else
  1078. return card
  1079. end
  1080. end
  1081. return zgwrDdzUtil2