logic.js 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. 'use strict';
  2. //// 为什么选择 Lodash ?
  3. //// Lodash 通过降低 array、number、objects、string 等等的使用难度从而让 JavaScript 变得更简单。
  4. //// Lodash 的模块化方法 非常适用于:
  5. //// 遍历 array、object 和 string
  6. //// 对值进行操作和检测
  7. //// 创建符合功能的函数
  8. var _ = require('lodash');
  9. var quick = require('quick-pomelo');
  10. var logger = quick.logger.getLogger('fhmj', __filename);
  11. // 所有牌
  12. const CARDS = [
  13. 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
  14. 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
  15. 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
  16. // 51, // 中
  17. 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
  18. 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
  19. 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
  20. // 51, // 中
  21. 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
  22. 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
  23. 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
  24. // 51, // 中
  25. 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
  26. 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
  27. 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
  28. // 51, // 中
  29. ];
  30. // 块类型
  31. const STYLE = {
  32. NULL: 0, // 无效
  33. CHI: 1, // 吃牌
  34. SUN: 2, // 顺序
  35. PENG: 3, // 碰子
  36. KE: 4, // 刻子
  37. GANG: 5, // 杠子
  38. ANGANG: 6, // 暗杠
  39. ZMGANG: 7, // 自摸明杠
  40. BUDA:8, // TL++不搭
  41. // LIANGBD:9, // TL++两张百搭和一张普通牌组成一个块
  42. // SANBD:10, // TL++三张百搭和一张普通牌组成一个块
  43. };
  44. // 椅子数
  45. const CHAIR_COUNT = 4;
  46. const CARDS_COUNT = 13;
  47. // 构造方法
  48. var Logic = function (type,gameKindTL,playerAllCount,other) {
  49. // 类型
  50. this.type = type;
  51. this.other = other;//////TL++2人3人的游戏规则
  52. this.jiangmaType = -1;////奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中
  53. this.jiangmaCount = -1;////奖码张数
  54. if(this.other & 1){
  55. this.jiangmaType = 1;
  56. if(this.other & 8) this.jiangmaCount = 2;
  57. else if(this.other & 16) this.jiangmaCount = 4;
  58. else if(this.other & 32) this.jiangmaCount = 6;
  59. }
  60. else if(this.other & 2){
  61. this.jiangmaType = 2;
  62. this.jiangmaCount = 0;
  63. }
  64. else if(this.other & 4){
  65. this.jiangmaType = 3;
  66. this.jiangmaCount = 1;
  67. }
  68. this.hzCount = 0;/////红中个数
  69. if(this.other & 64) this.hzCount = 8;
  70. else if(this.other & 1024) this.hzCount = 6;
  71. else if(this.other & 2048) this.hzCount = 8;
  72. this.isQGHJM = false;/////是否抢杠胡奖码
  73. if(this.other & 128) this.isQGHJM = true;
  74. this.isHZHG = false;/////是否荒庄荒杠
  75. if(this.other & 256) this.isHZHG = true;
  76. this.isWGHZJYM = false;/////无红中胡加一码
  77. if(this.other & 512) this.isWGHZJYM = true;
  78. this.isZNZM = this.type == 2;/////是否只能自摸,拉杠情况可以胡
  79. // console.warn("logic 奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中 "+this.jiangmaType)
  80. // console.warn("logic 奖码张数 "+this.jiangmaCount)
  81. // console.warn("logic 是否红中赖子 "+this.isHZLZ)
  82. // console.warn("logic 是否抢杠胡奖码 "+this.isQGHJM)
  83. // console.warn("logic 是否荒庄荒杠 "+this.isHZHG)
  84. // console.warn("logic 无红中胡加一码 "+this.isWGHZJYM)
  85. // console.warn("logic 是否只能自摸 "+this.isZNZM)
  86. // 七对
  87. // this.has7d = true;/////TL++因为奉化麻将当中本身就可以胡7对
  88. // 全牌
  89. var cards = _.clone(CARDS);
  90. // 添加红中红中
  91. if (this.hzCount > 0){
  92. for (let i = 0; i < this.hzCount; ++i) {
  93. cards[cards.length] = 51;
  94. }
  95. }
  96. this.castCount = 0;
  97. this.disCount = 0;
  98. this.lastCount = cards.length;//////设置剩余牌数为了测试海底捞月
  99. this.cardsPool = cards;
  100. this.cardsyl = _.clone(cards);
  101. //////以下变量全是TL++
  102. this.gameKindTL = gameKindTL || 1;////平搓还是冲刺 = 1代表平搓 = 2代表冲刺
  103. this.playerAllCount = playerAllCount || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  104. this.setCardFilerIndex = 0
  105. this.baiDaCard = 51;/////TL++,拿到百搭牌
  106. this.baiDaList = [0,0,0];/////TL++,拿到百搭牌数组
  107. this.sbyBDList = []//////得到某人手中的百搭牌数组
  108. this.chuPaiCountTL = 0//////TL++,记录出牌的个数,为了判断天胡和地胡
  109. this.moPaiCountTL = 0//////TL++,记录出牌的个数,为了判断天胡和地胡
  110. this.lastMoPaiChairID = 0//////TL++,最后一个摸牌玩家的id
  111. this.addThisIsHu = 0//////TL++,胡牌判断时加上这张能不能胡
  112. this.isSeleCatcedCard = false//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
  113. this.currChairIDTL = 0/////当前判断胡的chairID,用于得到当前玩家的胡牌情况
  114. this.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  115. this.isGuoHuList = [[false,0],[false,0],[false,0],[false,0],]/////TL++,各个玩家在本轮是否点击了过胡和点击过牌时的台数
  116. this.setCardFileName = '';/////设置手牌的文件名
  117. this.cardGroupIndex = 0;////要设置的牌型种类
  118. this.isZHYZ = false;/////是不是最后1张
  119. this.isMZWF = [0,1,2,3];/////是不是满足位风
  120. // console.warn("ppppppppppp 长度 "+cards.length+" cards "+cards);
  121. };
  122. Logic.setHCfileNameList =[/////全部设置牌型的文件名
  123. "setHandCard_tianhu",
  124. ]
  125. // 导出常量
  126. Logic.CARDS = CARDS;
  127. Logic.STYLE = STYLE;
  128. Logic.CHAIR_COUNT = CHAIR_COUNT;
  129. Logic.CARDS_COUNT = CARDS_COUNT;
  130. // 导出类
  131. module.exports = Logic;
  132. // 原型对象
  133. var proto = Logic.prototype;
  134. /////TL++为了得到百搭牌数组用于判断是否需要补花和手牌中百搭牌个数
  135. proto.setBDList = function () {
  136. this.baiDaList = [this.baiDaCard,this.baiDaCard,this.baiDaCard]/////TL++,拿到百搭牌
  137. };
  138. ///////TL++在table类中出牌函数中调用,为了判断天胡和地胡
  139. proto.chuPaiTL = function () {
  140. // console.warn("111c天胡判断不正确",this.chuPaiCountTL);
  141. this.chuPaiCountTL += 1//////这个其实并不是真实的出牌个数,因为这个方法的调用在判断吃碰杠胡之前调用的
  142. }
  143. ///////TL++在table类中出牌函数中调用,为了判断天胡和地胡
  144. proto.moPaiTL = function () {
  145. // console.warn("111c天胡判断不正确",this.chuPaiCountTL);
  146. this.moPaiCountTL += 1//////TL++,记录出牌的个数,为了判断天胡和地胡 += 1
  147. }
  148. ///////TL++重置默认数据,在每局游戏开始的洗牌函数中调用
  149. proto.resetDataOnGameStart = function () {
  150. this.chuPaiCountTL = 0//////TL++出牌个数
  151. this.moPaiCountTL = 0//////TL++,记录摸牌的个数,为了判断天胡和地胡
  152. this.lastMoPaiChairID = 0//////TL++,最后一个摸牌玩家的id
  153. this.addThisIsHu = 0//////TL++,胡牌判断时加上这张能不能胡
  154. this.isSeleCatcedCard = false//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
  155. this.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  156. this.isGuoHuList = [[false,0],[false,0],[false,0],[false,0],]/////TL++,各个玩家在本轮是否点击了过胡和点击过牌时的台数
  157. this.isZHYZ = false;/////是不是最后1张
  158. }
  159. // 重新洗牌
  160. proto.shuffle = function () {
  161. this.castCount = 0;
  162. this.disCount = 0;
  163. this.cardsPool = _.clone(this.cardsyl);
  164. this.lastCount = this.cardsPool.length;
  165. this.cardsPool = _.shuffle(this.cardsPool);////随机打乱一个数组
  166. this.cardsPool = _.shuffle(this.cardsPool);////洗第二次牌
  167. // this.cardsPool = _.shuffle(this.cardsPool);////洗第三次牌
  168. };
  169. // 填充数组
  170. proto.fillDeep = function (array, o, isMore) {
  171. for (let i = 0; i < array.length; ++i) {
  172. if (!isMore) {
  173. array[i] = _.clone(o);
  174. } else {
  175. array[i] = _.cloneDeep(o);/////深度拷贝,就是重新分配内存空间,浅拷贝则是两个变量共用一个内存对象
  176. }
  177. }
  178. return array;
  179. };
  180. //////TL++ 深复制一个object类型的数据
  181. proto.deepCloneTL = function (obj){
  182. let objClone = Array.isArray(obj)?[]:{};
  183. if(obj && typeof obj==="object"){
  184. for(let key in obj){
  185. if(obj.hasOwnProperty(key)){
  186. //判断ojb子元素是否为对象,如果是,递归复制
  187. if(obj[key]&& typeof obj[key] ==="object"){
  188. objClone[key] = this.deepCloneTL(obj[key]);
  189. }else{
  190. //如果不是,简单复制
  191. objClone[key] = obj[key];
  192. }
  193. }
  194. }
  195. }
  196. return objClone;
  197. };
  198. // 获取类型
  199. proto.getType = function (card) {
  200. return Math.floor(card / 10);
  201. };
  202. // 获取牌值
  203. proto.getValue = function (card) {
  204. return card % 10;
  205. };
  206. // 手牌排序
  207. proto.sort = function (handCards) {
  208. return _.sortBy(handCards);///降序排序
  209. };
  210. // 删除手牌 /////TL++参数isBuHua表示是否因为补花而造成的删除牌
  211. proto.remove = function (handCards, cards) {
  212. if (typeof (cards) == 'number') {
  213. if (cards == handCards[handCards.length - 1]) {
  214. return (handCards.pop(), true);
  215. } else {
  216. let pos = handCards.indexOf(cards);
  217. if (pos == -1) return false;
  218. return (handCards.splice(pos, 1), true);
  219. }
  220. }
  221. var length = cards.length;
  222. if (length > 1 && cards[0] == cards[length - 1]) {
  223. if (cards[0] == handCards[handCards.length - 1]) {
  224. handCards.pop();
  225. length -= 1;
  226. }
  227. let pos = handCards.indexOf(cards[0]);
  228. if (pos == -1) return false;
  229. handCards.splice(pos, length);
  230. } else {
  231. for (let i = 0; i < length; ++i) {
  232. let pos = handCards.indexOf(cards[i]);
  233. if (pos == -1) return false;
  234. handCards.splice(pos, 1);
  235. }
  236. }
  237. return true;
  238. };
  239. // 调整手牌
  240. proto.adjust = function (handCards) {
  241. var length = handCards.length;
  242. if (length < 2) return false;
  243. if (handCards[length - 1] < handCards[length - 2]) {
  244. let moCard = handCards.pop();
  245. let pos = _.findIndex(handCards, (i) => (i >= moCard));
  246. if (pos == -1) handCards.push(moCard);
  247. else handCards.splice(pos, 0, moCard);
  248. }
  249. return true;
  250. };
  251. // 投骰子
  252. proto.dice = function () {
  253. return _.random(1, 6);
  254. };
  255. // 剩余牌数
  256. proto.leaveCount = function () {
  257. return this.lastCount;
  258. };
  259. //////TL++,人工设置测试牌型
  260. proto.setTestSendCardsTL = function () {
  261. this.setCardFileName = '';
  262. let fileName = "setHandCard_tianhu"
  263. if(!fileName) return;/////文件名字不存在
  264. // console.warn("设置手牌的文件名",fileName);
  265. this.setCardFileName = fileName
  266. var SetHandCardTL = require('./setcard/' + fileName);
  267. if(!SetHandCardTL) return;
  268. //////TL++,设置手牌的文件
  269. this.setHandCardTL = new SetHandCardTL();
  270. ////console.error("洗牌之后的牌",this.cardsPool);
  271. let ccc = this.setHandCardTL.getSCFP(this.cardGroupIndex)
  272. if(ccc){//////已经设置的手牌发完了就随机发牌
  273. this.cardsPool = ccc/////设置手牌的地方 设置牌
  274. this.cardGroupIndex += 1; ////此句是否存在代表是否只发某一种牌型
  275. // SetHandCardTL.cardGroupIndex += 1; ////此句是否存在代表是否只发某一种牌型
  276. // if(SetHandCardTL.cardGroupIndex == 1) SetHandCardTL.cardGroupIndex = 0
  277. }
  278. else{
  279. this.setCardFilerIndex += 1;
  280. this.cardGroupIndex = 0;
  281. // SetHandCardTL.cardGroupIndex = 0;
  282. if(Logic.setCardFilerIndex < Logic.setHCfileNameList.length) this.setTestSendCardsTL()
  283. }
  284. }
  285. // 初始手牌
  286. proto.handCards = function (chBanker,_PJHF,_over,recordid,_ctime) {
  287. this.resetDataOnGameStart()//////TL++
  288. this.shuffle();
  289. // if(this.hzCount == 8) {
  290. // // this.cardsPool = [21,51,33,33,15,26,24,29,26,35,14,29,17,11,19,14,13,38,29,35,23,51,17,51,27,19,33,28,22,21,17,51,21,13,38,34,39,39,38,34,26,14,36,33,37,39,19,27,17,37,12,24,28,31,32,22,11,23,12,15,25,29,34,36,16,36,18,12,21,11,32,13,11,22,19,38,24,15,35,32,16,27,39,37,31,18,51,28,16,51,25,27,32,16,51,14,31,18,51,35,15,26,23,28,22,34,12,36,31,25,23,37,13,25,18,24]
  291. // this.setTestSendCardsTL()///////设置手牌的地方,设置发牌 不需要设置的时候注释掉这个方法就可以了
  292. // this.lastCount = this.cardsPool.length;//////设置剩余牌数设置剩余牌数,测试完这句要删掉
  293. // }
  294. let dqjs = _over + 1;
  295. _PJHF.writexpJson(this.deepCloneTL(this.cardsPool),dqjs,recordid,_ctime);
  296. //// 下面这个是随机发牌但是起手发lzgs张癞子的逻辑
  297. // let lzgs = 6//癞子个数
  298. // let djg = 0;
  299. // for (let i = 0; i < this.cardsPool.length; i++) {
  300. // if(this.cardsPool[i] == 51){
  301. // let xx = this.cardsPool[djg]
  302. // this.cardsPool[djg] = 51;
  303. // this.cardsPool[i] = xx;
  304. // djg++
  305. // if(djg >= lzgs){
  306. // break
  307. // }
  308. // }
  309. // }
  310. /////TL++设置百搭牌数组
  311. this.setBDList()
  312. var result = [];
  313. var castCount = 0;
  314. for (let i = 0; i < this.playerAllCount; ++i) {
  315. let cardCount = CARDS_COUNT;
  316. if (i == chBanker) cardCount += 1;
  317. let cards = this.cardsPool.slice(castCount, castCount + cardCount);
  318. castCount += cardCount;
  319. result.push({ cards: this.sort(cards) });
  320. }
  321. this.castCount += castCount
  322. this.lastCount -= castCount;
  323. // this.lastCount -= this.disCountTL;////因为翻出来的百搭牌不能被摸走
  324. // console.error("发的手牌",result);
  325. return result;
  326. };
  327. // 是否无牌
  328. proto.isNoCards = function () {
  329. return this.lastCount <= 0;
  330. };
  331. // 摸牌函数
  332. proto.moCard = function (isgang) {
  333. // console.error("摸排摸排---------",isgang,this.disCountTL,this.lastCount);
  334. var card = 0;
  335. if (this.lastCount > 0) {
  336. card = this.cardsPool[this.castCount++];
  337. this.lastCount -= 1;
  338. }
  339. return { card: card };
  340. };
  341. // 是否将牌
  342. proto.isJang = function (lcard, rcard) {
  343. return lcard == rcard;
  344. };
  345. // 可否碰牌
  346. proto.isPeng = function (handCards, card) {
  347. if(card == 51) return false;
  348. for (let i = 0; i < handCards.length - 1; ++i) {
  349. if (handCards[i] == card && handCards[i + 1] == card) {
  350. return true;
  351. }
  352. }
  353. return false;
  354. };
  355. // 碰牌 TL++参数chirID为了判断圈风和位风
  356. proto.peng = function (chirID,handCards, card) {
  357. if (this.isPeng(handCards, card)) {
  358. return { style: STYLE.PENG, cards: [card, card, card], disc: [card] };
  359. }
  360. };
  361. // 吃牌,1-@**左吃, 2-*@*中吃, 3-@**右吃
  362. proto.chi = function (handCards, card, type) {
  363. var chis = this.chiAnalyze(handCards, card, type);
  364. if (chis[0]) {
  365. let res = { style: STYLE.CHI, type: type, disc: [card] };
  366. if (type == 1) {
  367. res.cards = [card, card + 1, card + 2];
  368. if (this.getValue(card) < 7) {
  369. res.disc.push(card + 3);
  370. }
  371. } else if (type == 2) {
  372. res.cards = [card - 1, card, card + 1];
  373. } else {
  374. res.cards = [card - 2, card - 1, card];
  375. if (this.getValue(card) > 3) {
  376. res.disc.push(card - 3);
  377. }
  378. }
  379. return res;
  380. }
  381. };
  382. // 杠牌,1-普通杠, 2-暗杠, 3-自摸明杠 TL++参数chirID为了判断圈风和位风
  383. proto.gang = function (chirID,handCards, card, type) {
  384. // 结果
  385. var res = null;
  386. // 明杠
  387. if (type == 1) {
  388. let gang = this.gangAnalyze(handCards, card);
  389. if (gang) {
  390. res = { style: STYLE.GANG, cards: [card, card, card] };
  391. }
  392. }
  393. // 暗杠
  394. else if (type == 2) {
  395. let anGang = this.anGangAnalyze(handCards, card);
  396. if (anGang[0]) {
  397. res = { style: STYLE.ANGANG, cards: [card, card, card] };
  398. }
  399. }
  400. return res;
  401. };
  402. // 自摸明杠,1-普通杠, 2-暗杠, 3-自摸明杠 TL++参数chirID为了判断圈风和位风
  403. proto.zmGang = function (chirID,handCards, huCards, card) {
  404. var zmGang = this.zmGangAnalyze(handCards, huCards, card);
  405. if (zmGang[0]) {
  406. return { style: STYLE.ZMGANG, cards: [card, card, card] };
  407. }
  408. };
  409. // 吃牌分析,1-@**左吃, 2-*@*中吃, 3-@**右吃, type可以不传
  410. proto.chiAnalyze = function (handCards, card, type) {
  411. // 结果集合
  412. var result = [];
  413. // 排除风字
  414. if (handCards.length < 2 || card > 40) return result;
  415. // 查找句子
  416. var length = handCards.length;
  417. for (let i = 0; i < length; ++i) {
  418. // 牌面值
  419. let value = this.getValue(card);
  420. // @**左吃,吃类型(可以不指定)
  421. if (!type || type == 1) {
  422. if (value < 8 && i < length - 1) {
  423. if (handCards[i] == card + 1 && handCards[i + 1] == card + 2) {
  424. result.push({ type: 1, card: card });
  425. }
  426. }
  427. }
  428. // *@*中吃,吃类型(可以不指定)
  429. if (!type || type == 2) {
  430. if (value > 1 && value < 9 && i < length - 1) {
  431. if (handCards[i] == card - 1 && handCards[i + 1] != card - 1) {
  432. for (let j = i + 1; j < i + 5 && j < length; ++j) {
  433. if (handCards[j] == card + 1) {
  434. result.push({ type: 2, card: card });
  435. break;
  436. }
  437. }
  438. }
  439. }
  440. }
  441. // **@右吃,吃类型(可以不指定)
  442. if (!type || type == 3) {
  443. if (value > 2 && i < length - 1) {
  444. if (handCards[i] == card - 2 && handCards[i + 1] == card - 1) {
  445. result.push({ type: 3, card: card });
  446. }
  447. }
  448. }
  449. }
  450. return result;
  451. };
  452. // 普通杠分析,1-普通杠, 2-暗杠, 3-自摸明杠
  453. proto.gangAnalyze = function (handCards, card) {
  454. // 结果对象
  455. var result = null;
  456. if(card == 51 || this.lastCount <= 0) return result;//红中不能碰杠
  457. var length = handCards.length;
  458. if (length < 3) return result;
  459. // 查找同牌
  460. for (let i = 0; i < length - 2; ++i) {
  461. if (handCards[i] == card && handCards[i + 1] == card && handCards[i + 2] == card) {
  462. result = { type: 1, card: card };
  463. break;
  464. }
  465. }
  466. return result;
  467. };
  468. // 暗杠分析,1-普通杠, 2-暗杠, 3-自摸明杠, card可以不传
  469. proto.anGangAnalyze = function (handCards, card) {
  470. // 结果对象
  471. var result = [];
  472. if(this.lastCount <= 0) return result;//红中不能碰杠
  473. var length = handCards.length;
  474. if (length < 4) return result;
  475. // 查找同牌
  476. var moCard = handCards[length - 1];
  477. for (let i = 0; i < length - 3; ++i) {
  478. // 指定杠牌,可以不指定
  479. if (card && handCards[i] != card) continue;
  480. // 判定是否刻子
  481. if (handCards[i] == handCards[i + 1] && handCards[i] == handCards[i + 2]) {
  482. // 手上有杠牌
  483. if (handCards[i] == handCards[i + 3]) {
  484. if(handCards[i] != 51){
  485. result.push({ type: 2, card: handCards[i] });
  486. }
  487. }
  488. // 刚摸到杠牌
  489. else if (handCards[i] == moCard) {
  490. if(handCards[i] != 51){
  491. result.push({ type: 2, card: moCard });
  492. }
  493. }
  494. }
  495. }
  496. return result;
  497. };
  498. // 自摸杠分析,1-普通杠, 2-暗杠, 3-自摸明杠, card可以不传
  499. proto.zmGangAnalyze = function (handCards, huCards, card) {
  500. // 返回结果
  501. var result = [];
  502. if(card == 51 || this.lastCount <= 0) return result;//红中不能碰杠
  503. // 遍历句子
  504. for (let i = 0; i < huCards.length; ++i) {
  505. if (huCards[i].style != STYLE.PENG) {
  506. continue;
  507. }
  508. let _card = huCards[i].cards[0];
  509. if (card && _card != card) continue;
  510. let pos = handCards.indexOf(_card);
  511. if (pos != -1) {
  512. result.push({ type: 3, card: _card });
  513. if (card) break;
  514. }
  515. }
  516. return result;
  517. };
  518. // 分析牌型
  519. proto.parseBlock = function (card1, card2, card3) {
  520. // 刻子
  521. if (card1 && card1 == card2 && card1 == card3) {
  522. return { style: STYLE.KE, cards: [card1, card2, card3] };
  523. }
  524. // 顺子(排除风字)
  525. var cards = this.sort([card1, card2, card3]);
  526. if (cards[2] < 40) {
  527. if (cards[2] == cards[1] + 1 && cards[1] == cards[0] + 1) {
  528. return { style: STYLE.SUN, cards: cards };
  529. }
  530. }
  531. };
  532. // TL++,得到手牌中百搭牌的个数
  533. proto.getBDCount = function (cards) {
  534. ////TL++,整个for循环判断手牌中的百搭牌个数
  535. let baiDaCount = 0
  536. for (let i = 0; i < cards.length; ++i) {
  537. if(cards[i] == this.baiDaCard) baiDaCount = baiDaCount + 1
  538. }
  539. return baiDaCount
  540. }
  541. // TL++,得到手牌中百搭牌的shuzu数组
  542. proto.getBDListZZ = function (cards) {
  543. this.sbyBDList = []//////重置某人手牌中的百搭牌数组
  544. ////TL++,整个for循环判断手牌中的百搭牌个数
  545. let baiDaCount = 0
  546. let baiDali = []
  547. for (let i = 0; i < cards.length; ++i) {
  548. if(cards[i] == this.baiDaCard){
  549. baiDali[baiDaCount] = cards[i]
  550. baiDaCount = baiDaCount + 1
  551. }
  552. }
  553. return baiDali
  554. }
  555. // TL++,得到手牌中百搭牌的index数组
  556. proto.getBDIndexList = function (cards) {
  557. ////TL++,整个for循环判断手牌中的百搭牌个数
  558. let baiDali = []
  559. for (let i = 0; i < cards.length; ++i) {
  560. let cardTL = cards[i];
  561. if(this.baiDaList[0] && cardTL == this.baiDaList[0]) baiDali[baiDali.length] = i;
  562. else if(this.baiDaList[1] && cardTL == this.baiDaList[1]) baiDali[baiDali.length] = i;
  563. else if(this.baiDaList[2] && cardTL == this.baiDaList[2]) baiDali[baiDali.length] = i;
  564. }
  565. return baiDali
  566. }
  567. // TL++,得到手牌中百搭牌的index,用于删除手牌中的百搭牌
  568. proto.getBDIndex = function (cards) {
  569. ////TL++,整个for循环判断手牌中的百搭牌个数
  570. let baiDali = []
  571. for (let i = 0; i < cards.length; ++i) {
  572. let cardTL = cards[i];
  573. if(this.sbyBDList[0] && cardTL == this.sbyBDList[0]) baiDali[baiDali.length] = i;
  574. if(this.sbyBDList[1] && cardTL == this.sbyBDList[1]) baiDali[baiDali.length] = i;
  575. if(this.sbyBDList[2] && cardTL == this.sbyBDList[2]) baiDali[baiDali.length] = i;
  576. }
  577. return baiDali
  578. }
  579. // TL++,得到默认手牌中百搭牌当的数组 cards: 手牌去除百搭之后的牌
  580. proto.getBDMakeList = function (cards,isNeedAllZi) {
  581. if(cards.length == 0){
  582. ////手上就剩百搭牌的时候 需要把所有牌都当一遍
  583. let reslist = [
  584. 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
  585. 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
  586. 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
  587. ]
  588. return reslist;
  589. }
  590. ////TL++,整个for循环按照手牌情况确定百搭牌当的范围
  591. let makeList = this.deepCloneTL(cards)
  592. for (let i = 0; i < cards.length; ++i) {
  593. let cardTL = cards[i];
  594. let type = this.getType(cardTL);
  595. let vale = this.getValue(cardTL);
  596. if(type < 4){
  597. if(vale == 1){
  598. let makeValue = cardTL + 1;
  599. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  600. let makeValue2 = cardTL + 2;
  601. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  602. }
  603. else if(vale == 9){
  604. let makeValue = cardTL - 1;
  605. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  606. let makeValue2 = cardTL - 2;
  607. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  608. }
  609. else if(vale == 2){
  610. let makeValue = cardTL - 1;
  611. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  612. let makeValue2 = cardTL + 1;
  613. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  614. let makeValue3 = cardTL + 2;
  615. if(makeList.indexOf(makeValue3) == -1) makeList[makeList.length] = makeValue3;
  616. }
  617. else if(vale == 8){
  618. let makeValue = cardTL - 1;
  619. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  620. let makeValue2 = cardTL - 2;
  621. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  622. let makeValue3 = cardTL + 1;
  623. if(makeList.indexOf(makeValue3) == -1) makeList[makeList.length] = makeValue3;
  624. }
  625. else if(vale > 2 && vale < 8){
  626. let makeValue = cardTL - 1;
  627. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  628. let makeValue2 = cardTL + 1;
  629. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  630. let makeValue3 = cardTL - 2;
  631. if(makeList.indexOf(makeValue3) == -1) makeList[makeList.length] = makeValue3;
  632. let makeValue4 = cardTL + 2;
  633. if(makeList.indexOf(makeValue4) == -1) makeList[makeList.length] = makeValue4;
  634. }
  635. }
  636. }
  637. // let makeList2 = makeList.concat([41,42,43,44,51,52,53])/////给当的数组拼接字牌
  638. // var xx = [1,1,2,3,4,1,2]
  639. // var xx22 = _.uniq(xx)
  640. // console.warn("数组去重",xx,xx22);///[ 1, 1, 2, 3, 4, 1, 2 ] [ 1, 2, 3, 4 ]
  641. // xx[1] = 6
  642. // console.warn("22数组去重",xx,xx22);////[ 1, 6, 2, 3, 4, 1, 2 ] [ 1, 2, 3, 4 ]
  643. return _.uniq(makeList);
  644. }
  645. // 提取成句 card:手上的所有牌删除2张用来做将的牌之后剩下的牌 整理是否为刻子或者顺子
  646. proto._dumpFixed = function (cards, huCards) {
  647. // if(this.currChairIDTL == 0){
  648. // console.error("sscc提取成句没有百搭cards",cards);
  649. // console.error("sscc提取成ju没有百搭huCards",huCards);
  650. // }
  651. for (let i = 0; i < cards.length - 2; ++i) {
  652. let card = cards[i];
  653. if (card <= 0) continue;
  654. if (card == cards[i + 1] && card == cards[i + 2]) {
  655. huCards.push({ style: STYLE.KE, cards: [card, card, card] });
  656. cards[i] = 0; cards[i + 1] = 0; cards[i + 2] = 0;
  657. i += 2; continue;
  658. }
  659. if (card > 40 || this.getValue(card) > 7) continue;
  660. let second = -1, third = -1;
  661. for (let j = i + 1; j < cards.length; ++j) {
  662. if (cards[j] == card + 1) second = j;
  663. if (cards[j] == card + 2) third = j;
  664. if (cards[j] > card + 2) break;
  665. if (second != -1 && third != -1) break;
  666. }
  667. if (second != -1 && third != -1) {
  668. huCards.push({ style: STYLE.SUN, cards: [card, cards[second], cards[third]] });
  669. cards[i] = 0; cards[second] = 0; cards[third] = 0;
  670. }
  671. }
  672. };
  673. proto._dumpFixedc = function (cards,huCards,baidaCount) {
  674. let spkzgs = 4 - huCards.length;//手牌可组个数
  675. let spkzzh = [];//手牌可组组合(1为刻2为顺)
  676. if(spkzgs == 1) spkzzh = [[1],[2]];
  677. else if(spkzgs == 2) spkzzh = [[1,1],[1,2],[2,2],[2,1]];
  678. else if(spkzgs == 3) spkzzh = [[1,1,1],[1,2,1],[1,1,2],[1,2,2],[2,2,2],[2,1,2],[2,2,1],[2,1,1]];
  679. else if(spkzgs == 4){
  680. spkzzh = [[1,1,1,1],[1,2,1,1],[1,1,2,1],[1,1,1,2],
  681. [1,2,2,1],[1,1,2,2],[1,2,1,2],[1,2,2,2],
  682. [2,2,2,2],[2,1,2,2],[2,2,1,2],[2,2,2,1],
  683. [2,1,1,2],[2,2,1,1],[2,1,2,1],[2,1,1,1]
  684. ]
  685. }
  686. //找到目标牌
  687. var getMBCard = (cscards) => {
  688. for (let i = 0; i < cscards.length; ++i) {
  689. let card = cscards[i];
  690. if (card <= 0) continue;
  691. else return card;
  692. }
  693. return -100;
  694. };
  695. // let mbpailist = [12,15,15,15,16,17,18,25,26,27]
  696. // let islog = true;
  697. // if(mbpailist.length == cards.length){
  698. // for (let i = 0; i < cards.length; ++i) {
  699. // if(mbpailist[i] != cards[i]) islog = false;
  700. // }
  701. // }
  702. // else{
  703. // islog = false;
  704. // }
  705. // let mbpailist2 = [15,15,16,17,18,25,26,27,28,28,28]
  706. // if(islog) console.warn("_dumpFixedc 提取成句 baidaCount "+baidaCount+" cards "+cards+ " indexof "+mbpailist2.indexOf(15));
  707. let dqdpd = [0,0]//当前的判断
  708. for (let x = 0; x < spkzzh.length; ++x) {
  709. let copyCards = this.deepCloneTL(cards)
  710. let bdCount = baidaCount;
  711. let huCards22 = [];
  712. // if(islog && x == 5) console.warn("当前的判断组合 "+dqdpd+" spkzzh[x] "+spkzzh[x]+" x "+x);
  713. for (let y = 0; y < spkzzh[x].length; ++y) {
  714. let ckORcs = spkzzh[x][y]//成刻或成顺(1为刻2为顺)
  715. // if(islog && x == 5) console.warn("当前的判断 "+dqdpd+" ckORcs "+ckORcs);
  716. if(ckORcs == 1){
  717. let mbCard = getMBCard(copyCards);//目标card(mbCard这次应该成刻)
  718. if(mbCard > 0){
  719. let index1 = copyCards.indexOf(mbCard);
  720. if(index1 != -1) copyCards[index1] = 0;
  721. else console.error("这里不正常,都没有目标牌");
  722. let cj = [mbCard];//成句
  723. let index2 = copyCards.indexOf(mbCard);
  724. if(index2 != -1){
  725. cj[cj.length] = mbCard;
  726. copyCards[index2] = 0;
  727. }
  728. else {
  729. if(bdCount > 0){
  730. cj[cj.length] = 51;
  731. bdCount -= 1;
  732. }
  733. }
  734. let index3 = copyCards.indexOf(mbCard);
  735. if(index3 != -1){
  736. cj[cj.length] = mbCard;
  737. copyCards[index3] = 0;
  738. }
  739. else {
  740. if(bdCount > 0){
  741. cj[cj.length] = 51;
  742. bdCount -= 1;
  743. }
  744. }
  745. if(cj.length == 3){
  746. huCards22.push({ style: STYLE.KE, cards: cj });
  747. }
  748. else{
  749. //mbCard不能成刻,说明spkzzh[x]这种组合是不行的,剩下的就不用判断了
  750. break;
  751. }
  752. }
  753. else{
  754. //手牌全部都判断过了
  755. if(bdCount >= 3){
  756. huCards22.push({ style: STYLE.KE, cards: [51, 51, 51] });
  757. bdCount -= 3;
  758. }
  759. //因为手里最多8张百搭,最多可以有6张百搭做成2个百搭刻,所以需要两次if
  760. if(bdCount >= 3){
  761. huCards22.push({ style: STYLE.KE, cards: [51, 51, 51] });
  762. bdCount -= 3;
  763. }
  764. break;
  765. }
  766. }
  767. else if(ckORcs == 2){
  768. let mbCard = getMBCard(copyCards);//目标card(mbCard这次应该成刻)
  769. // if(islog && x == 5) console.warn("mbCard "+mbCard+" copyCards "+copyCards);
  770. if (mbCard < 40){
  771. if(mbCard > 0){
  772. let index1 = copyCards.indexOf(mbCard);
  773. if(index1 != -1) copyCards[index1] = 0;
  774. else console.error("这里不正常,都没有目标牌");
  775. let cj = [mbCard];//成句
  776. if(this.getValue(mbCard) <= 7){
  777. let index2 = copyCards.indexOf(mbCard+1);
  778. if(index2 != -1){
  779. cj[cj.length] = copyCards[index2];
  780. copyCards[index2] = 0;
  781. }
  782. else {
  783. if(bdCount > 0){
  784. cj[cj.length] = 51;
  785. bdCount -= 1;
  786. }
  787. }
  788. let index3 = copyCards.indexOf(mbCard+2);
  789. if(index3 != -1){
  790. cj[cj.length] = copyCards[index3];
  791. copyCards[index3] = 0;
  792. }
  793. else {
  794. if(bdCount > 0){
  795. cj[cj.length] = 51;
  796. bdCount -= 1;
  797. }
  798. }
  799. }
  800. else if(this.getValue(mbCard) == 8){
  801. let index2 = copyCards.indexOf(mbCard+1);
  802. if(index2 != -1){
  803. cj[cj.length] = copyCards[index2];
  804. copyCards[index2] = 0;
  805. }
  806. else {
  807. if(bdCount > 0){
  808. cj[cj.length] = 51;
  809. bdCount -= 1;
  810. }
  811. }
  812. if(bdCount > 0){
  813. cj[cj.length] = 51;
  814. bdCount -= 1;
  815. }
  816. }
  817. else if(this.getValue(mbCard) == 9){
  818. if(bdCount > 1){
  819. cj[cj.length] = 51;
  820. cj[cj.length] = 51;
  821. bdCount -= 2;
  822. }
  823. }
  824. if(cj.length == 3){
  825. huCards22.push({ style: STYLE.SUN, cards: cj });
  826. }
  827. else{
  828. //mbCard不能成顺,说明spkzzh[x]这种组合是不行的,剩下的就不用判断了
  829. break;
  830. }
  831. }
  832. else{
  833. //手牌全部都判断过了
  834. if(bdCount >= 3){
  835. huCards22.push({ style: STYLE.SUN, cards: [51, 51, 51] });
  836. bdCount -= 3;
  837. }
  838. //因为手里最多8张百搭,最多可以有6张百搭做成2个百搭刻,所以需要两次if
  839. if(bdCount >= 3){
  840. huCards22.push({ style: STYLE.SUN, cards: [51, 51, 51] });
  841. bdCount -= 3;
  842. }
  843. break;
  844. }
  845. }
  846. }
  847. // if(y < spkzzh[x].length-1) dqdpd=[x,y+1];
  848. // else dqdpd=[x+1,0];
  849. }
  850. // if(islog && x == 5) console.warn("提取成句 组合 "+" spkzzh[x] "+spkzzh[x]+" huCards22 "+JSON.stringify(huCards22) );
  851. if(huCards22.length + huCards.length == 4){
  852. //已经可以胡牌了,其他的组合就不需要判断了
  853. for (var i = 0; i < huCards22.length; i++) {
  854. huCards.push(huCards22[i]);
  855. }
  856. break;
  857. }
  858. }
  859. };
  860. //////TL++,判断一手张牌是否为百搭牌
  861. proto.judgeACardISBD = function (card) {
  862. return card == this.baiDaCard;
  863. }
  864. // 胡牌分析 chairID(TL++这个参数) 手牌 加上这张判断能不能胡 手上的吃碰杠牌 是否自己摸上来的
  865. proto.huAnalyze = function (chairID,handCards, card, huCards, isTouch) {
  866. // console.error("sscc777胡牌分析card",card);
  867. // console.error("sscc777胡牌分析handCards",handCards);
  868. // console.error("sscc777胡牌分析huCards",huCards);
  869. // console.error("sscc777胡牌分析isTouch",isTouch);
  870. // this.isHanDa = false;//////TL++,是否还搭(百搭牌用作原牌型,不累计)
  871. this.isPaoDa = false/////TL++,当前是不是抛搭,因为是抛搭的话不能打倒胡(吃胡)
  872. this.isQiDui = false;//////TL++,是否7对
  873. let tempAllTai = 0/////临时总台数
  874. let tempres = {}///本函数的返回值
  875. this.addThisIsHu = card//////TL++,胡牌判断时加上这张能不能胡
  876. this.isSeleCatcedCard = isTouch//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
  877. this.currChairIDTL = chairID/////当前判断胡的chairID,用于得到当前玩家的花牌情况
  878. this.dangAfterBDListTL = [];/////7月18日+的
  879. // console.warn("胡牌分析 isGuoHuList ",this.isGuoHuList," chairID ",chairID," isTouch ",isTouch);
  880. if(this.isGuoHuList[chairID][0]){
  881. // console.warn("此人点过胡了 ",chairID," isTouch ",(!isTouch));
  882. if(!isTouch){
  883. // console.warn("不是此人摸牌 ",chairID,isTouch);
  884. return false;
  885. }
  886. }
  887. let baiDaCount22 = 0
  888. let bdIndexlist = []
  889. if (!isTouch){
  890. baiDaCount22 = this.getBDCount(handCards)
  891. this.sbyBDList = this.getBDListZZ(handCards)
  892. handCards = handCards.concat(card);/////不是自己抓的就把这张牌拼接进手牌中
  893. handCards = this.sort(handCards);
  894. bdIndexlist = this.getBDIndexList(handCards)
  895. }
  896. else{
  897. handCards = this.sort(handCards);
  898. baiDaCount22 = this.getBDCount(handCards)
  899. this.sbyBDList = this.getBDListZZ(handCards)
  900. bdIndexlist = this.getBDIndexList(handCards)
  901. }
  902. // console.warn("判断13不搭手上百搭牌个数出错了?????",baiDaCount22,this.sbyBDList,bdIndexlist)
  903. handCards = this.sort(handCards);
  904. var huRes = { card: card, jiang: 0, huCards: [] };
  905. // 重设将牌
  906. var resetHuRes = (jiang) => {
  907. huRes.jiang = jiang;
  908. huRes.huCards = [];
  909. for (let huCard of huCards) huRes.huCards.push(huCard);
  910. };
  911. // 手牌不全
  912. var length = handCards.length;
  913. if (length % 3 != 2) return;
  914. let hucardTL = huCards//////TL++,保存碰杠牌的初始值,因为这个参数会在下面的代码中被修改掉
  915. if(baiDaCount22 == 4 && this.hzCount == 4){
  916. //选择4红中规则的时候,手里有4张红中的话可以直接胡,6红中8红中不可直接胡
  917. // tempres = huCards
  918. return huRes;
  919. }
  920. if(baiDaCount22 == 0){/////没有百搭的时候
  921. // 确定将牌
  922. for (let i = 0; i < length - 1; ++i) {
  923. if (!this.isJang(handCards[i], handCards[i + 1])) continue;
  924. resetHuRes(handCards[i]);////设置将牌
  925. let cards = handCards.slice(0, i);////手牌数组的前i个元素
  926. cards = cards.concat(handCards.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
  927. this._dumpFixed(cards, huRes.huCards);
  928. i += 1;/////TL++,为了减少运算
  929. if(huRes.huCards.length >= 4){
  930. return huRes;
  931. }
  932. }
  933. }
  934. else{/////有百搭的时候
  935. let card2 = []//////用于存放手牌中将所有百搭牌去掉之后的手牌
  936. for (let xx = 0; xx < this.sbyBDList.length; ++xx){
  937. card2 = handCards.slice(0,bdIndexlist[xx] - xx)////得到数组中的前bdIndexlist[xx] 个元素
  938. card2 = card2.concat(handCards.slice(bdIndexlist[xx]+1 - xx))////得到数组中的最后bdIndexlist[xx] +1 个元素
  939. handCards = card2
  940. // console.error("有百搭删除掉百搭牌",handCards,card2);
  941. }
  942. // console.warn("删除百搭之后的手牌222",handCards);
  943. let bdzs = this.sbyBDList.length;/////百搭张数
  944. let copyhandCards = this.deepCloneTL(handCards)
  945. var huResTL = [];
  946. for (let huCard of huCards) huResTL.push(huCard);
  947. // console.warn("去掉百搭之后的手牌 copyhandCards "+copyhandCards);
  948. if(copyhandCards.length == 0) return huRes;
  949. //下面的for循环是用手牌的两张牌做将牌看能不能胡牌
  950. for (let i = 0; i < copyhandCards.length - 1; ++i) {
  951. let cards22 = this.deepCloneTL(copyhandCards)
  952. if (!this.isJang(cards22[i], cards22[i + 1])) continue;
  953. let huRes3 = { card: card, jiang: 0, huCards: [] };
  954. // 重设将牌
  955. huRes3.jiang = cards22[i];
  956. huRes3.huCards = [];
  957. for (let huCard of huCards) huRes3.huCards.push(huCard);
  958. let cards2 = cards22.slice(0, i);////手牌数组的前i个元素
  959. cards2 = cards2.concat(cards22.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
  960. this._dumpFixedc(cards2, huRes3.huCards,bdzs);
  961. // console.warn("判胡 2张手牌做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
  962. if (huRes3.huCards.length >= 4){
  963. return huRes3;
  964. }
  965. i += 1;/////TL++,为了减少运算
  966. }
  967. //下面的for循环是用一张手牌和一张百搭牌做将牌看能不能胡牌
  968. let bcjp = 0;///////本次的将牌
  969. for (let i = 0; i < copyhandCards.length; ++i) {
  970. let cards22 = this.deepCloneTL(copyhandCards);
  971. if(cards22[i] == bcjp) continue;
  972. let huRes3 = { card: card, jiang: 0, huCards: [] };
  973. // 重设将牌
  974. huRes3.jiang = cards22[i];
  975. huRes3.huCards = [];
  976. for (let huCard of huCards) huRes3.huCards.push(huCard);
  977. bcjp = cards22[i]; ///////本次的将牌
  978. let cards2 = cards22.slice(0, i);////手牌数组的前i个元素
  979. cards2 = cards2.concat(cards22.slice(i + 1));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
  980. // console.warn("判胡 1张手牌做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
  981. this._dumpFixedc(cards2, huRes3.huCards,bdzs-1);
  982. if (huRes3.huCards.length >= 4){
  983. return huRes3;
  984. }
  985. }
  986. }
  987. };
  988. // // TL++胡牌提示 chairID(TL++这个参数) 手牌 手上的吃碰杠牌 这个是胡牌提示里不统计台数
  989. proto.hutip = function (chairID,_handCards, _huCards,_allhuCards,outCards) {
  990. // return {
  991. // renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  992. // kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  993. // };////服务端运算量太大放到前端去计算了
  994. this.yscs = 0
  995. // console.warn("hutip777胡牌提示handCards ",chairID,_handCards,_huCards,this.yscs);
  996. // console.error("sscc777胡牌提示huCards",_huCards);
  997. let hutipRes = [];
  998. let handCards1 = _.clone(_handCards);
  999. // if(chairID == 1) console.warn("sscc777胡牌提示handCards1 ",chairID,_handCards);
  1000. let huCards = _.clone(_huCards);
  1001. let allhuCards = _.clone(_allhuCards);////用统计胡牌提示的剩余牌
  1002. let baiDaCount22 = this.getBDCount(_handCards);
  1003. let dangPaiList = this.getBDMakeList(handCards1);
  1004. if(baiDaCount22 == 4 && this.hzCount == 4){
  1005. //选择4红中规则的时候,手里有4张红中的话可以直接胡,6红中8红中不可直接胡
  1006. let kehuData2 = {
  1007. renyi:1,//////是否可胡任意牌,0表示不满足1表示满足
  1008. kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  1009. };
  1010. return kehuData2;
  1011. }
  1012. if(baiDaCount22 < this.hzCount && this.hzCount > 0 && _handCards.indexOf(this.baiDaCard) == -1 && this.baiDaCard < 60){
  1013. dangPaiList[dangPaiList.length] = this.baiDaCard;
  1014. }
  1015. // if(chairID == 1) console.warn("hutip777胡牌提示 dangPaiList ",dangPaiList.length,dangPaiList);
  1016. let kdcdp = 0;////可打出的牌 就是打出这个牌之后可以胡
  1017. let dczhkhdp = [];////打出kdcdp之后可以胡的牌
  1018. let yjpdgdsp = 0;////已经判断过的手牌 为了减少运算量判断过的手牌就不再判断了
  1019. // let yjpdgdzh = [];////已经判断过的组合 把28换成26 和 把26换成28 的结果是一样的所以可以剔除以减少运算
  1020. for (var i = 0; i < handCards1.length; i++) {
  1021. if(this.judgeACardISBD(handCards1[i])) continue;
  1022. kdcdp = handCards1[i];////可打出的牌
  1023. dczhkhdp = [];
  1024. if(handCards1[i] == yjpdgdsp) continue;////已经判断过的手牌 为了减少运算量判断过的手牌就不再判断了
  1025. yjpdgdsp = handCards1[i];////已经判断过的手牌 为了减少运算量判断过的手牌就不再判断了
  1026. var huResTL = [];
  1027. for (let huCard of huCards) huResTL.push(huCard);
  1028. let copyhandCards = this.deepCloneTL(_handCards)
  1029. for (let x = 0; x < copyhandCards.length; ++x) {
  1030. if(this.judgeACardISBD(copyhandCards[x])){
  1031. copyhandCards[x] = 0;////剔除手里的百搭去判断抛搭
  1032. }
  1033. }
  1034. copyhandCards[i] = 0;///剔除手里的百搭和打出那张之后剩下的手牌去判断抛搭
  1035. let copyhandCardsqbd = _.compact(_.clone(copyhandCards));
  1036. copyhandCardsqbd = this.sort(copyhandCardsqbd);
  1037. // let ispd = this.hutipJudgePAODA(baiDaCount22,copyhandCardsqbd,dangPaiList,huResTL.length,kdcdp);////打出kdcdp之后是否抛搭
  1038. //上面是旧的算法,下面是新的算法
  1039. let ispd = false;
  1040. if(copyhandCardsqbd.length == 0){
  1041. ispd = true;//手上全是百搭肯定抛搭了
  1042. }
  1043. else{
  1044. if(baiDaCount22 > 0){
  1045. ispd = this.hutipJudgePAODA2(baiDaCount22-1,copyhandCardsqbd,huResTL,kdcdp);////打出kdcdp之后是否抛搭
  1046. }
  1047. }
  1048. // console.warn("打出kdcdp之后是否抛搭 ",kdcdp,ispd,this.yscs);
  1049. if(ispd){
  1050. ////打出kdcdp之后可以抛搭了
  1051. let data = {
  1052. "canTing": kdcdp,////表示打出这张牌之后可以听牌
  1053. "youjin": 1,////打出这张牌之后是不是游金(抛搭)这个在象山麻将里面没有用
  1054. "tpxq": dczhkhdp
  1055. }
  1056. hutipRes[hutipRes.length] = data;
  1057. }
  1058. else{
  1059. ////打出kdcdp之后不能抛搭
  1060. for (var k = 0; k < dangPaiList.length; k++) {
  1061. this.yscs++;
  1062. let handCards = _.clone(handCards1);
  1063. // console.error("222sscc777胡牌提示huCards",i,handCards[i] , dangPaiList[k],handCards);
  1064. handCards[i] = dangPaiList[k];
  1065. handCards = this.sort(handCards);
  1066. // 手牌不全
  1067. var length = handCards.length;
  1068. if (length % 3 != 2) return;
  1069. // console.warn("pandau 0ceccewcde -------开始调用 hutip33");
  1070. let huRes22 = this.hutip33(chairID,handCards, dangPaiList[k], huCards,false);
  1071. if (huRes22) {
  1072. // console.warn("胡牌提示 打出 "+kdcdp+" 如果摸到 "+dangPaiList[k]+" 可以胡");
  1073. ////打出kdcdp如果摸到dangPaiList[k]可以胡
  1074. let syzs = this.getACardSYZS(dangPaiList[k],_handCards,allhuCards,outCards);
  1075. // console.warn("111????????????????????????????????",dangPaiList[k],syzs);
  1076. dczhkhdp[dczhkhdp.length] = [dangPaiList[k],-1,syzs];////[可胡的牌,剩余张数]
  1077. }
  1078. }
  1079. // console.warn("222????????????????????????????????",dczhkhdp.length);
  1080. if(dczhkhdp.length > 0){
  1081. ////至此表示打出handCards[i]之后可以听牌
  1082. let data = {
  1083. "canTing": kdcdp,////表示打出这张牌之后可以听牌
  1084. "youjin": 0,////打出这张牌之后是不是游金(抛搭)这个在象山麻将里面没有用
  1085. "tpxq": dczhkhdp
  1086. }
  1087. hutipRes[hutipRes.length] = data;
  1088. }
  1089. }
  1090. }
  1091. // console.warn("333????????????????????????????????",hutipRes);
  1092. // console.warn("222sscc777胡牌提示handCards ",chairID,_handCards,_huCards,this.yscs);
  1093. let kehuData3 = {
  1094. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  1095. kehuData:hutipRes/////对象数组,分别表示打哪张可胡哪几张数据
  1096. };
  1097. return kehuData3;
  1098. // return hutipRes;
  1099. };
  1100. ////TL++得到一张牌的剩余张数 用于胡牌提示提示该张的剩余张数
  1101. proto.getACardSYZS = function (card,_handCards,allhuCards,outCards) {
  1102. ////下面这段是适合胡牌提示里用的剩余牌数统计
  1103. let yjcxdzs = 0;////该牌已经出现的张数
  1104. for (var i = 0; i < _handCards.length; i++) {
  1105. if(card == _handCards[i]) yjcxdzs++;////该牌已经出现在自己手牌里的张数
  1106. }
  1107. // console.warn("111得到一张牌的剩余张数 手牌张数",yjcxdzs,_handCards);
  1108. for (var i = 0; i < allhuCards.length; i++) {
  1109. if(allhuCards[i].length == 0) continue;////该玩家没有碰杠牌
  1110. // console.warn("222得到一张牌的剩余张数 碰杠杠牌",card,yjcxdzs,i,JSON.stringify(_.clone(allhuCards[i])));
  1111. for (var k = 0; k < allhuCards[i].length; k++) {
  1112. let pgp = allhuCards[i][k].cards;
  1113. if(!pgp) continue;
  1114. for (var j = 0; j < pgp.length; j++) {
  1115. if(card == pgp[j]) yjcxdzs++;////该牌已经出现在自己手牌里的张数
  1116. }
  1117. }
  1118. }
  1119. for (var i = 0; i < outCards.length; i++) {
  1120. if(outCards[i].length == 0) continue;////该玩家没有碰杠牌
  1121. // console.warn("2得到一张牌的剩余张数 打出去的牌",card,yjcxdzs,i,JSON.stringify(_.clone(outCards[i])));
  1122. for (var k = 0; k < outCards[i].length; k++) {
  1123. if(card == outCards[i][k]) yjcxdzs++;////该牌已经出现在所有打出去牌里的张数;
  1124. }
  1125. }
  1126. let zs = 4
  1127. if(card == 51) zs = this.hzCount;
  1128. // if(this.judgeACardISBD(card)) zs = 3;
  1129. let syzs = zs - yjcxdzs;////剩余张数 = 总张数 - 已经出现的张数
  1130. // console.warn("333得到一张牌的剩余张数",card,syzs);
  1131. return syzs;
  1132. };
  1133. //////TL++,胡牌提示判断抛搭
  1134. proto.hutipJudgePAODA2 = function (_baidacount,_hd,_huCards,_addThisIsHu) {
  1135. // console.warn("胡牌提示判断抛搭 _baidacount "+_baidacount+" _hd.length "+_hd.length +" _hd "+_hd);
  1136. let cards2 = this.deepCloneTL(_hd);
  1137. let huRes3 = { card: 0, jiang: 0, huCards: [] };
  1138. huRes3.huCards = [];
  1139. for (let huCard of _huCards) huRes3.huCards.push(huCard);
  1140. this._dumpFixedc(cards2, huRes3.huCards,_baidacount);
  1141. // console.warn("胡牌提示 判断判断抛搭 length "+huRes3.huCards.length+" huRes3.huCards "+ JSON.stringify(huRes3.huCards));
  1142. if (huRes3.huCards.length >= 4){
  1143. // console.warn("胡牌提示 判断判断抛搭 可以抛搭222 length "+huRes3.huCards.length+" huRes3.huCards "+ JSON.stringify(huRes3.huCards));
  1144. return true;
  1145. }
  1146. // console.warn("不能抛搭");
  1147. return false;
  1148. }
  1149. // 胡牌分析 chairID(TL++这个参数) 手牌 加上这张判断能不能胡 手上的吃碰杠牌 是否自己摸上来的
  1150. proto.hutip33 = function (chairID,handCards, card, huCards, isTouch) {
  1151. // console.error("sscc777胡牌分析card",card);
  1152. // console.error("sscc777胡牌分析handCards",handCards);
  1153. // console.error("sscc777胡牌分析huCards",huCards);
  1154. // console.error("sscc777胡牌分析isTouch",isTouch);
  1155. let tempres = {}///本函数的返回值
  1156. this.addThisIsHu = card//////TL++,胡牌判断时加上这张能不能胡
  1157. this.isSeleCatcedCard = isTouch//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
  1158. this.currChairIDTL = chairID/////当前判断胡的chairID,用于得到当前玩家的花牌情况
  1159. this.dangAfterBDListTL = [];/////7月18日+的
  1160. let baiDaCount22 = 0
  1161. let bdIndexlist = []
  1162. handCards = this.sort(handCards);
  1163. baiDaCount22 = this.getBDCount(handCards)
  1164. this.sbyBDList = this.getBDListZZ(handCards)
  1165. bdIndexlist = this.getBDIndexList(handCards)
  1166. // console.warn("判断13不搭手上百搭牌个数出错了?????",baiDaCount22,this.sbyBDList,bdIndexlist)
  1167. // 手牌不全
  1168. var length = handCards.length;
  1169. // console.warn("胡牌提示 length "+length+" baiDaCount22 "+baiDaCount22);
  1170. if (length % 3 != 2) return;
  1171. if(baiDaCount22 == 0){/////没有百搭的时候
  1172. var huRes = { card: card, jiang: 0, huCards: [] };
  1173. // 重设将牌
  1174. var resetHuRes = (jiang) => {
  1175. huRes.jiang = jiang;
  1176. huRes.huCards = [];
  1177. for (let huCard of huCards) huRes.huCards.push(huCard);
  1178. };
  1179. // let hucardTL = huCards//////TL++,保存碰杠牌的初始值,因为这个参数会在下面的代码中被修改掉
  1180. // 确定将牌
  1181. for (let i = 0; i < length - 1; ++i) {
  1182. if (!this.isJang(handCards[i], handCards[i + 1])) continue;
  1183. resetHuRes(handCards[i]);////设置将牌
  1184. let cards = handCards.slice(0, i);////手牌数组的前i个元素
  1185. cards = cards.concat(handCards.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
  1186. this._dumpFixed(cards, huRes.huCards);
  1187. i += 1;/////TL++,为了减少运算
  1188. // let tempres22 = this.outHures(huRes,handCards,hucardTL);
  1189. if(huRes.huCards.length >= 4){
  1190. return true;
  1191. }
  1192. }
  1193. }
  1194. else{/////有百搭的时候
  1195. let card2 = []//////用于存放手牌中将所有百搭牌去掉之后的手牌
  1196. for (let xx = 0; xx < this.sbyBDList.length; ++xx){
  1197. card2 = handCards.slice(0,bdIndexlist[xx] - xx)////得到数组中的前bdIndexlist[xx] 个元素
  1198. card2 = card2.concat(handCards.slice(bdIndexlist[xx]+1 - xx))////得到数组中的最后bdIndexlist[xx] +1 个元素
  1199. handCards = card2
  1200. // console.error("有百搭删除掉百搭牌",handCards,card2);
  1201. }
  1202. // console.warn("胡牌提示 删除百搭之后的手牌222",handCards);
  1203. let bdzs = this.sbyBDList.length;/////百搭张数
  1204. let copyhandCards = this.deepCloneTL(handCards)
  1205. // console.warn("去掉百搭之后的手牌 copyhandCards "+copyhandCards);
  1206. if(copyhandCards.length == 0) return true;
  1207. //下面的for循环是用手牌的两张牌做将牌看能不能胡牌
  1208. for (let i = 0; i < copyhandCards.length - 1; ++i) {
  1209. let cards22 = this.deepCloneTL(copyhandCards)
  1210. if (!this.isJang(cards22[i], cards22[i + 1])) continue;
  1211. let huRes3 = { card: card, jiang: 0, huCards: [] };
  1212. // 重设将牌
  1213. huRes3.jiang = cards22[i];
  1214. huRes3.huCards = [];
  1215. for (let huCard of huCards) huRes3.huCards.push(huCard);
  1216. let cards2 = cards22.slice(0, i);////手牌数组的前i个元素
  1217. cards2 = cards2.concat(cards22.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
  1218. this._dumpFixedc(cards2, huRes3.huCards,bdzs);
  1219. if (huRes3.huCards.length >= 4){
  1220. // console.warn("胡牌提示 判断结果222 length "+huRes3.huCards.length+" huRes3.huCards "+ JSON.stringify(huRes3.huCards));
  1221. return true;
  1222. }
  1223. i += 1;/////TL++,为了减少运算
  1224. }
  1225. //下面的for循环是用一张手牌和一张百搭牌做将牌看能不能胡牌
  1226. let bcjp = 0;///////本次的将牌
  1227. for (let i = 0; i < copyhandCards.length; ++i) {
  1228. let cards22 = this.deepCloneTL(copyhandCards);
  1229. if(cards22[i] == bcjp) continue;
  1230. let huRes3 = { card: card, jiang: 0, huCards: [] };
  1231. // 重设将牌
  1232. huRes3.jiang = cards22[i];
  1233. huRes3.huCards = [];
  1234. for (let huCard of huCards) huRes3.huCards.push(huCard);
  1235. bcjp = cards22[i]; ///////本次的将牌
  1236. let cards2 = cards22.slice(0, i);////手牌数组的前i个元素
  1237. cards2 = cards2.concat(cards22.slice(i + 1));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
  1238. this._dumpFixedc(cards2, huRes3.huCards,bdzs-1);
  1239. // console.warn("胡牌提示 判断结果233 length "+huRes3.huCards.length+" huRes3.huCards "+ JSON.stringify(huRes3.huCards));
  1240. if (huRes3.huCards.length >= 4){
  1241. return true;
  1242. }
  1243. }
  1244. }
  1245. return false;
  1246. };
  1247. // 获得奖码列表和计算奖码分数函数
  1248. proto.getJiangmaInfo = function (isMZJYM) {
  1249. // console.warn("获得奖码列表函数 奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中 "+this.jiangmaType)
  1250. let jiangmaList = []
  1251. let jmzs = 0;//奖码张数
  1252. if(this.jiangmaType == 2){
  1253. //摸几奖几
  1254. jmzs = this.getValue(this.addThisIsHu);//胡的那张牌的牌值
  1255. if(this.addThisIsHu == 51) jmzs = 10;
  1256. }
  1257. else{
  1258. //159奖码 一码全中
  1259. jmzs = this.jiangmaCount;
  1260. if(isMZJYM ){
  1261. //满足无红中加1码
  1262. jmzs++;
  1263. }
  1264. }
  1265. if(this.isLaGang){
  1266. // console.warn("现在 是 拉杠胡了");
  1267. if(!this.isQGHJM){
  1268. //没有选择抢杠胡奖码
  1269. jmzs = 0;
  1270. // console.warn("现在 是 拉杠胡了 选则了抢杠胡不奖码 现在不奖码");
  1271. }
  1272. }
  1273. else{
  1274. // console.warn("现在 不是 拉杠胡了");
  1275. }
  1276. let castC1 = this.castCount;//已经消耗的
  1277. let lastC1 = this.lastCount;
  1278. for (var i = 0; i < jmzs; i++) {
  1279. let card = 0;
  1280. if (lastC1 > 0) {
  1281. card = this.cardsPool[castC1++];
  1282. lastC1 -= 1;
  1283. }
  1284. if(card > 0) jiangmaList[i] = card;
  1285. else break;
  1286. }
  1287. // console.warn("获得奖码列表函数 奖码列表 ",jiangmaList," 长度 ",jiangmaList.length," addThisIsHu ",this.addThisIsHu)
  1288. //下面是计算奖码分数
  1289. let mafen = 0;
  1290. if(this.jiangmaType == 1 || this.jiangmaType == 2){
  1291. //159奖码 摸几奖几
  1292. let count = 0
  1293. for (var i = 0; i < jiangmaList.length; i++) {
  1294. let pz = this.getValue(jiangmaList[i]);//牌值
  1295. if (pz == 1 || pz == 5 || pz == 9 || jiangmaList[i] == 51 ){
  1296. count++
  1297. }
  1298. }
  1299. mafen = 2 * count;
  1300. }
  1301. else if(this.jiangmaType == 3){
  1302. //一码全中
  1303. let count = this.getValue(jiangmaList[0]);
  1304. if(jiangmaList[0] == 51) count = 10;
  1305. mafen = count;
  1306. }
  1307. // console.warn("获得奖码分数 mafen ",mafen)
  1308. return { jiangmaList:jiangmaList,mafen:mafen}
  1309. };