logic.js 101 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529
  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. BU: 8, // 补子
  41. ANBU: 9, // 暗补
  42. ZMBU: 10, // 自摸明补
  43. // LIANGBD:9, // TL++两张百搭和一张普通牌组成一个块
  44. // SANBD:10, // TL++三张百搭和一张普通牌组成一个块
  45. };
  46. // 椅子数
  47. const CHAIR_COUNT = 4;
  48. const CARDS_COUNT = 13;
  49. // 构造方法
  50. var Logic = function (type,gameKindTL,playerAllCount,other) {
  51. // 类型
  52. this.type = type;
  53. this.other = other;//////TL++2人3人的游戏规则
  54. this.jiangmaCount = 2;////奖码张数(抓鸟张数)
  55. this.kexuanList = [0,0,0,0];
  56. if(this.other & 1){
  57. this.kexuanList[0] = 1;//勾选了中途大四喜
  58. }
  59. if(this.other & 2){
  60. this.kexuanList[1] = 1;//勾选了中途六六顺
  61. }
  62. if(this.other & 4){
  63. this.kexuanList[2] = 1;//勾选了门清
  64. }
  65. if(this.other & 256){
  66. this.kexuanList[3] = 1;//勾选了小胡只能自摸
  67. }
  68. this.hzCount = 0;/////红中个数
  69. this.fengDingType = 0;/////封顶类型1:不封顶;2:封顶56分;3:封顶112分;
  70. if(this.other & 8){
  71. this.fengDingType = 1;
  72. }
  73. else if(this.other & 16){
  74. this.fengDingType = 2;
  75. }
  76. else if(this.other & 32){
  77. this.fengDingType = 3;
  78. }
  79. this.ZNJSType = 0;/////中鸟结算类型1:中鸟相加;2:中鸟相乘;
  80. if(this.other & 64){
  81. this.ZNJSType = 1;
  82. }
  83. else if(this.other & 128){
  84. this.ZNJSType = 2;
  85. }
  86. this.gameKindTL = 1;//1:传统;2:割索;3:疯狂
  87. if(this.other & 512){
  88. this.gameKindTL = 2;
  89. }
  90. // else if(gameKindTL == 3){
  91. // this.gameKindTL = 3;//疯狂
  92. // this.hzCount = 4;/////红中个数 疯狂模式默认为4张红中
  93. // }
  94. this.isZNZM = false;/////是否只能自摸,拉杠情况可以胡
  95. // console.warn("封顶类型1:不封顶;2:封顶56分;3:封顶112分 "+this.fengDingType)
  96. // console.warn("中鸟结算类型1:中鸟相加;2:中鸟相乘 "+this.ZNJSType)
  97. // console.warn("logic可选列表 111 "+this.kexuanList)
  98. // 七对
  99. // this.has7d = true;/////TL++因为奉化麻将当中本身就可以胡7对
  100. // 全牌
  101. var cards = _.clone(CARDS);
  102. // 添加红中红中
  103. // if (this.hzCount > 0){
  104. // for (let i = 0; i < this.hzCount; ++i) {
  105. // cards[cards.length] = 51;
  106. // }
  107. // }
  108. this.castCount = 0;
  109. this.disCount = 0;
  110. this.lastCount = cards.length;//////设置剩余牌数为了测试海底捞月
  111. this.cardsPool = cards;
  112. this.cardsyl = _.clone(cards);
  113. console.warn(" this.cardsyl "+this.cardsyl+" lastCount "+this.lastCount);
  114. //////以下变量全是TL++
  115. this.playerAllCount = playerAllCount || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
  116. this.setCardFilerIndex = 0
  117. this.baiDaCard = 0;/////TL++,拿到百搭牌
  118. // this.baiDaList = [0,0,0];/////TL++,拿到百搭牌数组
  119. // this.sbyBDList = []//////得到某人手中的百搭牌数组
  120. this.chuPaiCountTL = 0//////TL++,记录出牌的个数,为了判断天胡和地胡
  121. this.moPaiCountTL = 0//////TL++,记录出牌的个数,为了判断天胡和地胡
  122. this.lastMoPaiChairID = 0//////TL++,最后一个摸牌玩家的id
  123. this.addThisIsHu = 0//////TL++,胡牌判断时加上这张能不能胡
  124. this.isSeleCatcedCard = false//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
  125. this.currChairIDTL = 0/////当前判断胡的chairID,用于得到当前玩家的胡牌情况
  126. this.isGGMG = [false,false,false,false];//////TL++,是否刚刚直杠(明杠)用于判断是否是直杠杠开
  127. this.isGGAG = [false,false,false,false];//////TL++,是否刚刚暗杠用于判断是否暗杠杠开
  128. this.isGGFXG = [false,false,false,false];//////TL++,是否刚刚风险杠用于判断是否风险杠杠开
  129. this.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  130. this.isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1],]/////TL++,各个玩家在本轮是否点击了过胡和点击过牌时的台数
  131. this.setCardFileName = '';/////设置手牌的文件名
  132. this.cardGroupIndex = 0;////要设置的牌型种类
  133. this.isZHYZ = false;/////是不是最后1张
  134. this.isMZWF = [0,1,2,3];/////是不是满足位风
  135. /////TL++每个人满足的的起手胡胡牌类型
  136. this.everyQSHType = [
  137. [],[],[],[]
  138. ]
  139. this.canSelects = [//各个起手胡玩家可以选择的牌型
  140. [],[],[],[]
  141. ];
  142. /////TL++每个人满足的的起手胡胡牌类型操作过的牌
  143. this.everyQSHCZGList = [
  144. [],[],[],[]
  145. ]
  146. /////TL++每个人满足的的起手胡胡牌类型操作过的牌
  147. this.everyQSHCZGList2 = [
  148. [],[],[],[]
  149. ]
  150. this.qshuTypeTL = [
  151. /////分别表示起手胡牌型和台数
  152. ["四喜",2,], ///// 0 起完牌后,玩家手上已有四张一样的牌;
  153. ["板板胡",2,], ///// 1 起完牌后,玩家手上没有一张2、5、8牌;
  154. ["缺一色",2,], ///// 2 起完牌后,玩家手上筒、索、万任缺一门;
  155. ["六六顺",2,], ///// 3 起完牌后,玩家手上已有2个刻子(刻子:三个一样的牌);
  156. ["中途四喜",2,], ///// 4 玩家在牌局过程中,手中有四张相同的牌;
  157. ["中途六六顺",2,], ///// 5 起完牌后,玩家手上已有2个刻子(刻子:三个一样的牌);
  158. // ["节节高",2,], ///// 4 起完牌后,起完牌后,玩家手上有3连对且同花色;(例如2个3万,2个4万,2个5万);
  159. // ["三同",2,], ///// 5 起完牌后,玩家手上有3对点数相同的牌;(例如2个3万,2个3筒,2个3条)
  160. // ["单将一枝花",2,], ///// 6 起完牌后,玩家手上只有一张将牌(2、5、8),且这只将牌为“5”;
  161. // ["单五一枝花",2,], ///// 7 起完牌后,玩家手上只有一张将牌(2、5、8),且这只将牌为“5”;
  162. ]
  163. this.everyXiaoHuList = [
  164. [],[],[],[]
  165. ];//每个玩家的起手胡牌型用于算分
  166. /////TL++每个人满足的的大胡胡牌类型
  167. this.everyDAHType = [
  168. [],[],[],[]
  169. ]
  170. this.dahuTypeTL = [
  171. /////分别表示大胡牌型和台数
  172. // ["天胡",6,], ///// 0 单指庄家,庄家起牌后,即已经胡牌。(需要2、5、8做将)
  173. // ["地胡",6,], ///// 1 指闲家,当庄家打出第一张牌时,给闲家点炮。(需要2、5、8做将);
  174. ["七小对",7,], ///// 0 胡牌时,手上任意七对将牌(无需2、5、8做将);
  175. ["豪华七小对",7,],///// 1 手上任意七对牌,且其中有4张一样的牌(不能杠,算作2对);
  176. ["双豪华七小对",7,],///// 2 手上任意七对牌,且其中有2种4张一样的牌(不能杠,算作2对);
  177. ["三豪华七小对",7,],///// 13手上任意七对牌,且其中有3种4张一样的牌(不能杠,算作2对);
  178. ["将将胡",7,], ///// 4 玩家手上每一张牌都为2、5、8;
  179. ["全求人",7,], ///// 5 玩家通过吃、碰、杠而使得最后手中只剩下一颗牌,当摸或其他玩家打出这张牌时,即可胡牌;
  180. ["门清",7,], ///// 6 玩家没有吃、碰、杠等操作,胡牌时手上有14张牌,自己摸到的算门清别人打的不算门清;
  181. ["清一色",7,], ///// 7 玩家手中的牌全部由同一种花色(万、筒、条)组成;
  182. ["碰碰胡",7,], ///// 8 碰碰胡:玩家所有的牌均为刻子或将牌,乱将(无需2、5、8做将),可碰,可杠,可自摸;
  183. ["杠开(杠炮)",7,], ///// 9 自己杠上开花(需要2、5、8做将)
  184. ["抢杠胡",7,], ///// 10 (需要2、5、8做将);
  185. ["海底胡",7,], ///// 11 最后一张牌为海底牌。玩家选择要海底牌且通过这张海底牌胡牌,则为海底捞月,(是否需要2、5、8将根据当前牌型决定)
  186. // ["杠上炮",7,], ///// 10 单指庄家,庄家起牌后,即已经胡牌。(需要2、5、8做将)
  187. // ["海底炮",7,], ///// 11 单指庄家,庄家起牌后,即已经胡牌。(需要2、5、8做将)
  188. ]
  189. // console.warn("ppppppppppp 长度 "+cards.length+" cards "+cards);
  190. };
  191. Logic.setHCfileNameList =[/////全部设置牌型的文件名
  192. "setHandCard_tianhu",
  193. ]
  194. // 导出常量
  195. Logic.CARDS = CARDS;
  196. Logic.STYLE = STYLE;
  197. Logic.CHAIR_COUNT = CHAIR_COUNT;
  198. Logic.CARDS_COUNT = CARDS_COUNT;
  199. // 导出类
  200. module.exports = Logic;
  201. // 原型对象
  202. var proto = Logic.prototype;
  203. /////TL++为了得到百搭牌数组用于判断是否需要补花和手牌中百搭牌个数
  204. // proto.setBDList = function () {
  205. // this.baiDaList = [this.baiDaCard,this.baiDaCard,this.baiDaCard]/////TL++,拿到百搭牌
  206. // };
  207. ///////TL++在table类中出牌函数中调用,为了判断天胡和地胡
  208. proto.chuPaiTL = function () {
  209. // console.warn("111c天胡判断不正确",this.chuPaiCountTL);
  210. this.chuPaiCountTL += 1//////这个其实并不是真实的出牌个数,因为这个方法的调用在判断吃碰杠胡之前调用的
  211. }
  212. ///////TL++在table类中出牌函数中调用,为了判断天胡和地胡
  213. proto.moPaiTL = function () {
  214. // console.warn("111c天胡判断不正确",this.chuPaiCountTL);
  215. this.moPaiCountTL += 1//////TL++,记录出牌的个数,为了判断天胡和地胡 += 1
  216. }
  217. ///////TL++重置默认数据,在每局游戏开始的洗牌函数中调用
  218. proto.resetDataOnGameStart = function () {
  219. for (let i = 0; i < this.everyQSHType.length; ++i) {
  220. this.everyQSHType[i] = []
  221. }
  222. for (let i = 0; i < this.everyQSHCZGList.length; ++i) {
  223. this.everyQSHCZGList[i] = []
  224. }
  225. for (let i = 0; i < this.everyQSHCZGList2.length; ++i) {
  226. this.everyQSHCZGList2[i] = []
  227. }
  228. for (let i = 0; i < this.everyXiaoHuList.length; ++i) {
  229. this.everyXiaoHuList[i] = []
  230. }
  231. for (let i = 0; i < this.everyDAHType.length; ++i) {
  232. this.everyDAHType[i] = []
  233. }
  234. this.chuPaiCountTL = 0//////TL++出牌个数
  235. this.moPaiCountTL = 0//////TL++,记录摸牌的个数,为了判断天胡和地胡
  236. this.lastMoPaiChairID = 0//////TL++,最后一个摸牌玩家的id
  237. this.addThisIsHu = 0//////TL++,胡牌判断时加上这张能不能胡
  238. this.isSeleCatcedCard = false//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
  239. this.currChairIDTL = 0/////当前判断胡的chairID,用于得到当前玩家的花牌情况
  240. this.isGGMG = [false,false,false,false];;//////TL++,是否刚刚直杠(明杠)用于判断是否是直杠杠开
  241. this.isGGAG = [false,false,false,false];//////TL++,是否刚暗杠用于判断是否暗杠杠开
  242. this.isGGFXG = [false,false,false,false];//////TL++,是否刚刚风险杠用于判断是否风险杠杠开
  243. this.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
  244. this.isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1],]/////TL++,各个玩家在本轮是否点击了过胡和点击过牌时的台数
  245. this.isZHYZ = false;/////是不是最后1张
  246. }
  247. // 重新洗牌
  248. proto.shuffle = function () {
  249. this.castCount = 0;
  250. this.disCount = 0;
  251. this.cardsPool = _.clone(this.cardsyl);
  252. this.lastCount = this.cardsPool.length;
  253. this.cardsPool = _.shuffle(this.cardsPool);////随机打乱一个数组
  254. this.cardsPool = _.shuffle(this.cardsPool);////洗第二次牌
  255. // this.cardsPool = _.shuffle(this.cardsPool);////洗第三次牌
  256. };
  257. // 填充数组
  258. proto.fillDeep = function (array, o, isMore) {
  259. for (let i = 0; i < array.length; ++i) {
  260. if (!isMore) {
  261. array[i] = _.clone(o);
  262. } else {
  263. array[i] = _.cloneDeep(o);/////深度拷贝,就是重新分配内存空间,浅拷贝则是两个变量共用一个内存对象
  264. }
  265. }
  266. return array;
  267. };
  268. //////TL++ 深复制一个object类型的数据
  269. proto.deepCloneTL = function (obj){
  270. let objClone = Array.isArray(obj)?[]:{};
  271. if(obj && typeof obj==="object"){
  272. for(let key in obj){
  273. if(obj.hasOwnProperty(key)){
  274. //判断ojb子元素是否为对象,如果是,递归复制
  275. if(obj[key]&& typeof obj[key] ==="object"){
  276. objClone[key] = this.deepCloneTL(obj[key]);
  277. }else{
  278. //如果不是,简单复制
  279. objClone[key] = obj[key];
  280. }
  281. }
  282. }
  283. }
  284. return objClone;
  285. };
  286. // 获取类型
  287. proto.getType = function (card) {
  288. return Math.floor(card / 10);
  289. };
  290. // 获取牌值
  291. proto.getValue = function (card) {
  292. return card % 10;
  293. };
  294. // 手牌排序
  295. proto.sort = function (handCards) {
  296. return _.sortBy(handCards);///降序排序
  297. };
  298. // 删除手牌 /////TL++参数isBuHua表示是否因为补花而造成的删除牌
  299. proto.remove = function (handCards, cards) {
  300. if (typeof (cards) == 'number') {
  301. if (cards == handCards[handCards.length - 1]) {
  302. return (handCards.pop(), true);
  303. } else {
  304. let pos = handCards.indexOf(cards);
  305. if (pos == -1) return false;
  306. return (handCards.splice(pos, 1), true);
  307. }
  308. }
  309. var length = cards.length;
  310. if (length > 1 && cards[0] == cards[length - 1]) {
  311. if (cards[0] == handCards[handCards.length - 1]) {
  312. handCards.pop();
  313. length -= 1;
  314. }
  315. let pos = handCards.indexOf(cards[0]);
  316. if (pos == -1) return false;
  317. handCards.splice(pos, length);
  318. } else {
  319. for (let i = 0; i < length; ++i) {
  320. let pos = handCards.indexOf(cards[i]);
  321. if (pos == -1) return false;
  322. handCards.splice(pos, 1);
  323. }
  324. }
  325. return true;
  326. };
  327. // 调整手牌
  328. proto.adjust = function (handCards) {
  329. var length = handCards.length;
  330. if (length < 2) return false;
  331. if (handCards[length - 1] < handCards[length - 2]) {
  332. let moCard = handCards.pop();
  333. let pos = _.findIndex(handCards, (i) => (i >= moCard));
  334. if (pos == -1) handCards.push(moCard);
  335. else handCards.splice(pos, 0, moCard);
  336. }
  337. return true;
  338. };
  339. // 投骰子
  340. proto.dice = function () {
  341. return _.random(1, 6);
  342. };
  343. // 剩余牌数
  344. proto.leaveCount = function () {
  345. return this.lastCount;
  346. };
  347. //////TL++,人工设置测试牌型
  348. proto.setTestSendCardsTL = function () {
  349. this.setCardFileName = '';
  350. let fileName = "setHandCard_tianhu"
  351. if(!fileName) return;/////文件名字不存在
  352. // console.warn("设置手牌的文件名",fileName);
  353. this.setCardFileName = fileName
  354. delete require.cache[require.resolve('./setcard/' + fileName)];
  355. var SetHandCardTL = require('./setcard/' + fileName);
  356. if(!SetHandCardTL) return;
  357. //////TL++,设置手牌的文件
  358. this.setHandCardTL = new SetHandCardTL();
  359. ////console.error("洗牌之后的牌",this.cardsPool);
  360. let ccc = this.setHandCardTL.getSCFP(this.cardGroupIndex)
  361. if(ccc){//////已经设置的手牌发完了就随机发牌
  362. this.cardsPool = ccc/////设置手牌的地方 设置牌
  363. this.cardGroupIndex += 1; ////此句是否存在代表是否只发某一种牌型
  364. // SetHandCardTL.cardGroupIndex += 1; ////此句是否存在代表是否只发某一种牌型
  365. // if(SetHandCardTL.cardGroupIndex == 1) SetHandCardTL.cardGroupIndex = 0
  366. }
  367. else{
  368. this.setCardFilerIndex += 1;
  369. this.cardGroupIndex = 0;
  370. // SetHandCardTL.cardGroupIndex = 0;
  371. if(Logic.setCardFilerIndex < Logic.setHCfileNameList.length) this.setTestSendCardsTL()
  372. }
  373. }
  374. // 初始手牌
  375. proto.handCards = function (chBanker,_PJHF,_over,recordid,_ctime) {
  376. this.resetDataOnGameStart()//////TL++
  377. this.shuffle();
  378. // if(this.hzCount == 8) {
  379. // 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]
  380. // this.setTestSendCardsTL()///////设置手牌的地方,设置发牌 不需要设置的时候注释掉这个方法就可以了
  381. // this.lastCount = this.cardsPool.length;//////设置剩余牌数设置剩余牌数,测试完这句要删掉
  382. // }
  383. let dqjs = _over + 1;
  384. _PJHF.writexpJson(this.deepCloneTL(this.cardsPool),dqjs,recordid,_ctime);
  385. //// 下面这个是随机发牌但是起手发lzgs张癞子的逻辑
  386. // let lzgs = 6//癞子个数
  387. // let djg = 0;
  388. // for (let i = 0; i < this.cardsPool.length; i++) {
  389. // if(this.cardsPool[i] == 51){
  390. // let xx = this.cardsPool[djg]
  391. // this.cardsPool[djg] = 51;
  392. // this.cardsPool[i] = xx;
  393. // djg++
  394. // if(djg >= lzgs){
  395. // break
  396. // }
  397. // }
  398. // }
  399. /////TL++设置百搭牌数组
  400. // this.setBDList()
  401. var result = [];
  402. var castCount = 0;
  403. for (let i = 0; i < this.playerAllCount; ++i) {
  404. let cardCount = CARDS_COUNT;
  405. if (i == chBanker) cardCount += 1;
  406. let cards = this.cardsPool.slice(castCount, castCount + cardCount);
  407. castCount += cardCount;
  408. result.push({ cards: this.sort(cards) });
  409. }
  410. this.castCount += castCount
  411. this.lastCount -= castCount;
  412. // this.lastCount -= this.disCountTL;////因为翻出来的百搭牌不能被摸走
  413. // console.error("发的手牌",result);
  414. return result;
  415. };
  416. // 是否无牌
  417. proto.isNoCards = function () {
  418. return this.lastCount <= 0;
  419. };
  420. // 摸牌函数
  421. proto.moCard = function (isgang) {
  422. // console.error("摸排摸排--------isgang ",isgang,this.disCountTL,this.lastCount);
  423. var card = 0;
  424. if(isgang){
  425. let card1 = 0;
  426. if (this.lastCount > 1) {
  427. card1 = this.cardsPool[this.castCount++];
  428. this.lastCount -= 1;
  429. }
  430. let card2 = 0;
  431. if (this.lastCount > 0) {
  432. card2 = this.cardsPool[this.castCount++];
  433. this.lastCount -= 1;
  434. }
  435. return { card1: card1,card2: card2 };
  436. }
  437. else{
  438. if (this.lastCount > 0) {
  439. card = this.cardsPool[this.castCount++];
  440. this.lastCount -= 1;
  441. }
  442. }
  443. return { card: card };
  444. };
  445. // 是否将牌
  446. proto.isJang = function (lcard, rcard) {
  447. return lcard == rcard;
  448. };
  449. ////判断吃碰补之后是否只剩下百搭牌了,因为如果吃碰补之后只剩下百搭牌,而百搭牌又不允许打出会造成玩家无牌可出的局面
  450. proto.isCanCPB = function (handCards,opeate,type) {
  451. return true;//非疯狂没有红中不存在这个问题
  452. }
  453. // 可否碰牌
  454. proto.isPeng = function (handCards, card) {
  455. if(Array.isArray(handCards)){
  456. for (let i = 0; i < handCards.length - 1; ++i) {
  457. if (handCards[i] == card && handCards[i + 1] == card) {
  458. return true;
  459. }
  460. }
  461. }
  462. return false;
  463. };
  464. // 碰牌 TL++参数chirID为了判断圈风和位风
  465. proto.peng = function (chirID,handCards, card) {
  466. if (this.isPeng(handCards, card)) {
  467. return { style: STYLE.PENG, cards: [card, card, card], disc: [card] };
  468. }
  469. };
  470. // 吃牌,1-@**左吃, 2-*@*中吃, 3-@**右吃
  471. proto.chi = function (handCards, card, type) {
  472. var chis = this.chiAnalyze(handCards, card, type);
  473. if (chis[0]) {
  474. let res = { style: STYLE.CHI, type: type, disc: [card] };
  475. if (type == 1) {
  476. res.cards = [card, card + 1, card + 2];
  477. if (this.getValue(card) < 7) {
  478. res.disc.push(card + 3);
  479. }
  480. } else if (type == 2) {
  481. res.cards = [card - 1, card, card + 1];
  482. } else {
  483. res.cards = [card - 2, card - 1, card];
  484. if (this.getValue(card) > 3) {
  485. res.disc.push(card - 3);
  486. }
  487. }
  488. return res;
  489. }
  490. };
  491. // 杠牌,1-普通杠, 2-暗杠, 3-自摸明杠 TL++参数chirID为了判断圈风和位风
  492. proto.gang = function (chirID,handCards, card, type) {
  493. // 结果
  494. var res = null;
  495. // 明杠
  496. if (type == 1) {
  497. let gang = this.gangAnalyze(handCards, card);
  498. if (gang) {
  499. res = { style: STYLE.GANG, cards: [card, card, card] };
  500. }
  501. }
  502. // 暗杠
  503. else if (type == 2) {
  504. let anGang = this.anGangAnalyze(handCards, card);
  505. if (anGang[0]) {
  506. res = { style: STYLE.ANGANG, cards: [card, card, card] };
  507. }
  508. }
  509. return res;
  510. };
  511. // 自摸明杠,1-普通杠, 2-暗杠, 3-自摸明杠 TL++参数chirID为了判断圈风和位风
  512. proto.zmGang = function (chirID,handCards, huCards, card) {
  513. var zmGang = this.zmGangAnalyze(handCards, huCards, card);
  514. if (zmGang[0]) {
  515. return { style: STYLE.ZMGANG, cards: [card, card, card] };
  516. }
  517. };
  518. // 补牌,1-普通补, 2-暗补, 3-自摸明补 TL++参数chirID为了判断圈风和位风
  519. proto.bu = function (chirID,handCards, card, type) {
  520. // 结果
  521. var res = null;
  522. // 明补
  523. if (type == 1) {
  524. let bu = this.buAnalyze(handCards, card);
  525. if (bu) {
  526. res = { style: STYLE.BU, cards: [card, card, card] };
  527. }
  528. }
  529. // 暗补
  530. else if (type == 2) {
  531. let anBu = this.anBuAnalyze(handCards, card);
  532. if (anBu[0]) {
  533. res = { style: STYLE.ANBU, cards: [card, card, card] };
  534. }
  535. }
  536. return res;
  537. };
  538. // 自摸明补,1-普通补, 2-暗补, 3-自摸明补 TL++参数chirID为了判断圈风和位风
  539. proto.zmBu = function (chirID,handCards, huCards, card) {
  540. var zmBu = this.zmBuAnalyze(handCards, huCards, card);
  541. if (zmBu[0]) {
  542. return { style: STYLE.ZMBU, cards: [card, card, card] };
  543. }
  544. };
  545. // 吃牌分析,1-@**左吃, 2-*@*中吃, 3-@**右吃, type可以不传
  546. proto.chiAnalyze = function (handCards, card, type) {
  547. // 结果集合
  548. var result = [];
  549. // 排除风字
  550. if(!Array.isArray(handCards)) {
  551. return result;
  552. }
  553. if (handCards.length < 2 || card > 40) return result;
  554. // 查找句子
  555. var length = handCards.length;
  556. for (let i = 0; i < length; ++i) {
  557. // 牌面值
  558. let value = this.getValue(card);
  559. // @**左吃,吃类型(可以不指定)
  560. if (!type || type == 1) {
  561. if (value < 8 && i < length - 1) {
  562. if (handCards[i] == card + 1 && handCards[i + 1] == card + 2) {
  563. result.push({ type: 1, card: card });
  564. }
  565. }
  566. }
  567. // *@*中吃,吃类型(可以不指定)
  568. if (!type || type == 2) {
  569. if (value > 1 && value < 9 && i < length - 1) {
  570. if (handCards[i] == card - 1 && handCards[i + 1] != card - 1) {
  571. for (let j = i + 1; j < i + 5 && j < length; ++j) {
  572. if (handCards[j] == card + 1) {
  573. result.push({ type: 2, card: card });
  574. break;
  575. }
  576. }
  577. }
  578. }
  579. }
  580. // **@右吃,吃类型(可以不指定)
  581. if (!type || type == 3) {
  582. if (value > 2 && i < length - 1) {
  583. if (handCards[i] == card - 2 && handCards[i + 1] == card - 1) {
  584. result.push({ type: 3, card: card });
  585. }
  586. }
  587. }
  588. }
  589. return result;
  590. };
  591. // 普通杠分析,1-普通杠, 2-暗杠, 3-自摸明杠
  592. proto.gangAnalyze = function (handCards, card) {
  593. // 结果对象
  594. var result = null;
  595. var length = handCards.length;
  596. if (length < 3) return result;
  597. // 查找同牌
  598. for (let i = 0; i < length - 2; ++i) {
  599. if (handCards[i] == card && handCards[i + 1] == card && handCards[i + 2] == card) {
  600. result = { type: 1, card: card };
  601. break;
  602. }
  603. }
  604. return result;
  605. };
  606. // 暗杠分析,1-普通杠, 2-暗杠, 3-自摸明杠, card可以不传
  607. proto.anGangAnalyze = function (handCards, card) {
  608. // 结果对象
  609. var result = [];
  610. var length = handCards.length;
  611. if (length < 4) return result;
  612. // 查找同牌
  613. var moCard = handCards[length - 1];
  614. for (let i = 0; i < length - 3; ++i) {
  615. // 指定杠牌,可以不指定
  616. if (card && handCards[i] != card) continue;
  617. // 判定是否刻子
  618. if (handCards[i] == handCards[i + 1] && handCards[i] == handCards[i + 2]) {
  619. // 手上有杠牌
  620. if (handCards[i] == handCards[i + 3]) {
  621. result.push({ type: 2, card: handCards[i] });
  622. }
  623. // 刚摸到杠牌
  624. else if (handCards[i] == moCard) {
  625. result.push({ type: 2, card: moCard });
  626. }
  627. }
  628. }
  629. return result;
  630. };
  631. // 自摸杠分析,1-普通杠, 2-暗杠, 3-自摸明杠, card可以不传
  632. proto.zmGangAnalyze = function (handCards, huCards, card) {
  633. // 返回结果
  634. var result = [];
  635. // 遍历句子
  636. for (let i = 0; i < huCards.length; ++i) {
  637. if (huCards[i].style != STYLE.PENG) {
  638. continue;
  639. }
  640. let _card = huCards[i].cards[0];
  641. if (card && _card != card) continue;
  642. let pos = handCards.indexOf(_card);
  643. if (pos != -1) {
  644. result.push({ type: 3, card: _card });
  645. if (card) break;
  646. }
  647. }
  648. return result;
  649. };
  650. // 普通补分析,1-普通补, 2-暗补, 3-自摸明补
  651. proto.buAnalyze = function (handCards, card) {
  652. // 结果对象
  653. var result = null;
  654. var length = handCards.length;
  655. if (length < 3) return result;
  656. // 查找同牌
  657. for (let i = 0; i < length - 2; ++i) {
  658. if (handCards[i] == card && handCards[i + 1] == card && handCards[i + 2] == card) {
  659. result = { type: 1, card: card };
  660. break;
  661. }
  662. }
  663. return result;
  664. };
  665. // 暗补分析,1-普通补, 2-暗补, 3-自摸明补, card可以不传
  666. proto.anBuAnalyze = function (handCards, card) {
  667. // 结果对象
  668. var result = [];
  669. var length = handCards.length;
  670. if (length < 4) return result;
  671. // 查找同牌
  672. var moCard = handCards[length - 1];
  673. for (let i = 0; i < length - 3; ++i) {
  674. // 指定补牌,可以不指定
  675. if (card && handCards[i] != card) continue;
  676. // 判定是否刻子
  677. if (handCards[i] == handCards[i + 1] && handCards[i] == handCards[i + 2]) {
  678. // 手上有补牌
  679. if (handCards[i] == handCards[i + 3]) {
  680. result.push({ type: 2, card: handCards[i] });
  681. }
  682. // 刚摸到补牌
  683. else if (handCards[i] == moCard) {
  684. result.push({ type: 2, card: moCard });
  685. }
  686. }
  687. }
  688. return result;
  689. };
  690. // 自摸补分析,1-普通补, 2-暗补, 3-自摸明补, card可以不传
  691. proto.zmBuAnalyze = function (handCards, huCards, card) {
  692. // 返回结果
  693. var result = [];
  694. // 遍历句子
  695. for (let i = 0; i < huCards.length; ++i) {
  696. if (huCards[i].style != STYLE.PENG) {
  697. continue;
  698. }
  699. let _card = huCards[i].cards[0];
  700. if (card && _card != card) continue;
  701. let pos = handCards.indexOf(_card);
  702. if (pos != -1) {
  703. result.push({ type: 3, card: _card });
  704. if (card) break;
  705. }
  706. }
  707. return result;
  708. };
  709. // 分析牌型
  710. proto.parseBlock = function (card1, card2, card3) {
  711. // 刻子
  712. if (card1 && card1 == card2 && card1 == card3) {
  713. return { style: STYLE.KE, cards: [card1, card2, card3] };
  714. }
  715. // 顺子(排除风字)
  716. var cards = this.sort([card1, card2, card3]);
  717. if (cards[2] < 40) {
  718. if (cards[2] == cards[1] + 1 && cards[1] == cards[0] + 1) {
  719. return { style: STYLE.SUN, cards: cards };
  720. }
  721. }
  722. };
  723. // 得到等待数据更新类型,因为在杠后2张牌时就可能会出现2个玩家可碰或可杠或可补,
  724. // 而出现这种情况时规则是操作优先级高的玩家优先操作若相同操作时谁距离杠的玩家距离最近的玩家操作优先级高
  725. // 如ABCD4个玩家A杠后两张牌为101和102,此时B可碰101C可碰102D可胡时,若B点碰后C点碰最后D点过之后
  726. // 按照之前的逻辑就会出现B碰102(本应B碰101,由于等待碰等待数据里记录this.pengCard记录的是102),但是
  727. // 实际B不能碰102就会判碰102失败导致卡住的bug
  728. proto.getDDGXType = function (type,chairId, ddcwj,gangch, ccount,masks) {
  729. let res = 0;//0:不更新等待操作数据,1:需将之前等待操作玩家的mask置0,2:需将等待数据设置回本次修改之前的
  730. if(gangch == -1) return res;//不是杠后不会出现多个人等待同一个操作直接返回
  731. if(ddcwj == -1) return res;//此操作目前没有等待的玩家
  732. let czym = 0;//操作掩码
  733. if(type == 1) czym = 5;//判断碰
  734. else if(type == 2) czym = 9;//判断杠
  735. else if(type == 3) czym = 33;//判断补
  736. if(czym == 0) return res;//参数错误直接返回
  737. let zjjl = 0;
  738. if((gangch + 1) % ccount == chairId) zjjl = 1;
  739. else if((gangch + 2) % ccount == chairId) zjjl = 2;
  740. else if((gangch + 3) % ccount == chairId) zjjl = 3;
  741. let qtjl = 0;
  742. if((gangch + 1) % ccount == ddcwj) qtjl = 1;
  743. else if((gangch + 2) % ccount == ddcwj) qtjl = 2;
  744. else if((gangch + 3) % ccount == ddcwj) qtjl = 3;
  745. if(zjjl > qtjl){
  746. if(masks[ddcwj] == czym){
  747. res = 2;
  748. return res
  749. }
  750. else{
  751. return 0;//正常不应该走到这里来,能进这里都是有错误的
  752. }
  753. }
  754. res = 1;
  755. return res
  756. };
  757. // TL++,得到手牌中百搭牌的个数
  758. proto.getBDCount = function (cards) {
  759. ////TL++,整个for循环判断手牌中的百搭牌个数
  760. let baiDaCount = 0
  761. for (let i = 0; i < cards.length; ++i) {
  762. if(cards[i] == this.baiDaCard) baiDaCount = baiDaCount + 1
  763. }
  764. return baiDaCount
  765. }
  766. // TL++,得到手牌中百搭牌的shuzu数组
  767. // proto.getBDListZZ = function (cards) {
  768. // this.sbyBDList = []//////重置某人手牌中的百搭牌数组
  769. // ////TL++,整个for循环判断手牌中的百搭牌个数
  770. // let baiDaCount = 0
  771. // let baiDali = []
  772. // for (let i = 0; i < cards.length; ++i) {
  773. // if(cards[i] == this.baiDaCard){
  774. // baiDali[baiDaCount] = cards[i]
  775. // baiDaCount = baiDaCount + 1
  776. // }
  777. // }
  778. // return baiDali
  779. // }
  780. // TL++,得到手牌中百搭牌的index数组
  781. // proto.getBDIndexList = function (cards) {
  782. // ////TL++,整个for循环判断手牌中的百搭牌个数
  783. // let baiDali = []
  784. // for (let i = 0; i < cards.length; ++i) {
  785. // let cardTL = cards[i];
  786. // if(this.baiDaList[0] && cardTL == this.baiDaList[0]) baiDali[baiDali.length] = i;
  787. // else if(this.baiDaList[1] && cardTL == this.baiDaList[1]) baiDali[baiDali.length] = i;
  788. // else if(this.baiDaList[2] && cardTL == this.baiDaList[2]) baiDali[baiDali.length] = i;
  789. // }
  790. // return baiDali
  791. // }
  792. // // TL++,得到手牌中百搭牌的index,用于删除手牌中的百搭牌
  793. // proto.getBDIndex = function (cards) {
  794. // ////TL++,整个for循环判断手牌中的百搭牌个数
  795. // let baiDali = []
  796. // for (let i = 0; i < cards.length; ++i) {
  797. // let cardTL = cards[i];
  798. // if(this.sbyBDList[0] && cardTL == this.sbyBDList[0]) baiDali[baiDali.length] = i;
  799. // if(this.sbyBDList[1] && cardTL == this.sbyBDList[1]) baiDali[baiDali.length] = i;
  800. // if(this.sbyBDList[2] && cardTL == this.sbyBDList[2]) baiDali[baiDali.length] = i;
  801. // }
  802. // return baiDali
  803. // }
  804. // TL++,得到默认手牌中百搭牌当的数组 cards: 手牌去除百搭之后的牌
  805. proto.getBDMakeList = function (cards,isNeedAllZi) {
  806. if(cards.length == 0){
  807. ////手上就剩百搭牌的时候 需要把所有牌都当一遍
  808. let reslist = [
  809. 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
  810. 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
  811. 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
  812. ]
  813. return reslist;
  814. }
  815. ////TL++,整个for循环按照手牌情况确定百搭牌当的范围
  816. let makeList = this.deepCloneTL(cards)
  817. for (let i = 0; i < cards.length; ++i) {
  818. let cardTL = cards[i];
  819. let type = this.getType(cardTL);
  820. let vale = this.getValue(cardTL);
  821. if(type < 4){
  822. if(vale == 1){
  823. let makeValue = cardTL + 1;
  824. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  825. let makeValue2 = cardTL + 2;
  826. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  827. }
  828. else if(vale == 9){
  829. let makeValue = cardTL - 1;
  830. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  831. let makeValue2 = cardTL - 2;
  832. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  833. }
  834. else if(vale == 2){
  835. let makeValue = cardTL - 1;
  836. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  837. let makeValue2 = cardTL + 1;
  838. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  839. let makeValue3 = cardTL + 2;
  840. if(makeList.indexOf(makeValue3) == -1) makeList[makeList.length] = makeValue3;
  841. }
  842. else if(vale == 8){
  843. let makeValue = cardTL - 1;
  844. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  845. let makeValue2 = cardTL - 2;
  846. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  847. let makeValue3 = cardTL + 1;
  848. if(makeList.indexOf(makeValue3) == -1) makeList[makeList.length] = makeValue3;
  849. }
  850. else if(vale > 2 && vale < 8){
  851. let makeValue = cardTL - 1;
  852. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  853. let makeValue2 = cardTL + 1;
  854. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  855. let makeValue3 = cardTL - 2;
  856. if(makeList.indexOf(makeValue3) == -1) makeList[makeList.length] = makeValue3;
  857. let makeValue4 = cardTL + 2;
  858. if(makeList.indexOf(makeValue4) == -1) makeList[makeList.length] = makeValue4;
  859. }
  860. }
  861. }
  862. // let makeList2 = makeList.concat([41,42,43,44,51,52,53])/////给当的数组拼接字牌
  863. // var xx = [1,1,2,3,4,1,2]
  864. // var xx22 = _.uniq(xx)
  865. // console.warn("数组去重",xx,xx22);///[ 1, 1, 2, 3, 4, 1, 2 ] [ 1, 2, 3, 4 ]
  866. // xx[1] = 6
  867. // console.warn("22数组去重",xx,xx22);////[ 1, 6, 2, 3, 4, 1, 2 ] [ 1, 2, 3, 4 ]
  868. return _.uniq(makeList);
  869. }
  870. // 提取成句 card:手上的所有牌删除2张用来做将的牌之后剩下的牌 整理是否为刻子或者顺子
  871. proto._dumpFixed = function (cards, huCards) {
  872. // if(this.currChairIDTL == 0){
  873. // console.error("sscc提取成句没有百搭cards",cards);
  874. // console.error("sscc提取成ju没有百搭huCards",huCards);
  875. // }
  876. for (let i = 0; i < cards.length - 2; ++i) {
  877. let card = cards[i];
  878. if (card <= 0) continue;
  879. if (card == cards[i + 1] && card == cards[i + 2]) {
  880. huCards.push({ style: STYLE.KE, cards: [card, card, card] });
  881. cards[i] = 0; cards[i + 1] = 0; cards[i + 2] = 0;
  882. i += 2; continue;
  883. }
  884. if (card > 40 || this.getValue(card) > 7) continue;
  885. let second = -1, third = -1;
  886. for (let j = i + 1; j < cards.length; ++j) {
  887. if (cards[j] == card + 1) second = j;
  888. if (cards[j] == card + 2) third = j;
  889. if (cards[j] > card + 2) break;
  890. if (second != -1 && third != -1) break;
  891. }
  892. if (second != -1 && third != -1) {
  893. huCards.push({ style: STYLE.SUN, cards: [card, cards[second], cards[third]] });
  894. cards[i] = 0; cards[second] = 0; cards[third] = 0;
  895. }
  896. }
  897. };
  898. proto._dumpFixedc = function (cards,huCards,baidaCount) {
  899. let spkzgs = 4 - huCards.length;//手牌可组个数
  900. let spkzzh = [];//手牌可组组合(1为刻2为顺)
  901. if(spkzgs == 1) spkzzh = [[1],[2]];
  902. else if(spkzgs == 2) spkzzh = [[1,1],[1,2],[2,2],[2,1]];
  903. 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]];
  904. else if(spkzgs == 4){
  905. spkzzh = [[1,1,1,1],[1,2,1,1],[1,1,2,1],[1,1,1,2],
  906. [1,2,2,1],[1,1,2,2],[1,2,1,2],[1,2,2,2],
  907. [2,2,2,2],[2,1,2,2],[2,2,1,2],[2,2,2,1],
  908. [2,1,1,2],[2,2,1,1],[2,1,2,1],[2,1,1,1]
  909. ]
  910. }
  911. //找到目标牌
  912. var getMBCard = (cscards) => {
  913. for (let i = 0; i < cscards.length; ++i) {
  914. let card = cscards[i];
  915. if (card <= 0) continue;
  916. else return card;
  917. }
  918. return -100;
  919. };
  920. // let mbpailist = [12,15,15,15,16,17,18,25,26,27]
  921. // let islog = true;
  922. // if(mbpailist.length == cards.length){
  923. // for (let i = 0; i < cards.length; ++i) {
  924. // if(mbpailist[i] != cards[i]) islog = false;
  925. // }
  926. // }
  927. // else{
  928. // islog = false;
  929. // }
  930. // let mbpailist2 = [15,15,16,17,18,25,26,27,28,28,28]
  931. // if(islog) console.warn("_dumpFixedc 提取成句 baidaCount "+baidaCount+" cards "+cards+ " indexof "+mbpailist2.indexOf(15));
  932. // console.warn("所有的判断组合 长度 "+spkzzh.length+" spkzzh "+JSON.stringify(spkzzh) )
  933. let dqdpd = [0,0]//当前的判断
  934. for (let x = 0; x < spkzzh.length; ++x) {
  935. let copyCards = this.deepCloneTL(cards)
  936. let bdCount = baidaCount;
  937. let huCards22 = [];
  938. // console.warn("当前的判断组合 "+dqdpd+" spkzzh[x] "+spkzzh[x]+" x "+x);
  939. // if(islog && x == 5) console.warn("当前的判断组合 "+dqdpd+" spkzzh[x] "+spkzzh[x]+" x "+x);
  940. for (let y = 0; y < spkzzh[x].length; ++y) {
  941. let ckORcs = spkzzh[x][y]//成刻或成顺(1为刻2为顺)
  942. // if(islog && x == 5) console.warn("当前的判断 "+dqdpd+" ckORcs "+ckORcs);
  943. if(ckORcs == 1){
  944. let mbCard = getMBCard(copyCards);//目标card(mbCard这次应该成刻)
  945. if(mbCard > 0){
  946. let index1 = copyCards.indexOf(mbCard);
  947. if(index1 != -1) copyCards[index1] = 0;
  948. else console.error("这里不正常,都没有目标牌");
  949. let cj = [mbCard];//成句
  950. let index2 = copyCards.indexOf(mbCard);
  951. if(index2 != -1){
  952. cj[cj.length] = mbCard;
  953. copyCards[index2] = 0;
  954. }
  955. else {
  956. if(bdCount > 0){
  957. cj[cj.length] = 51;
  958. bdCount -= 1;
  959. }
  960. }
  961. let index3 = copyCards.indexOf(mbCard);
  962. if(index3 != -1){
  963. cj[cj.length] = mbCard;
  964. copyCards[index3] = 0;
  965. }
  966. else {
  967. if(bdCount > 0){
  968. cj[cj.length] = 51;
  969. bdCount -= 1;
  970. }
  971. }
  972. if(cj.length == 3){
  973. huCards22.push({ style: STYLE.KE, cards: cj });
  974. }
  975. else{
  976. //mbCard不能成刻,说明spkzzh[x]这种组合是不行的,剩下的就不用判断了
  977. // console.warn("mbCard不能成刻,说明spkzzh[x]这种组合是不行的,剩下的就不用判断了");
  978. break;
  979. }
  980. }
  981. else{
  982. //手牌全部都判断过了
  983. if(bdCount >= 3){
  984. huCards22.push({ style: STYLE.KE, cards: [51, 51, 51] });
  985. bdCount -= 3;
  986. }
  987. //因为手里最多8张百搭,最多可以有6张百搭做成2个百搭刻,所以需要两次if
  988. if(bdCount >= 3){
  989. huCards22.push({ style: STYLE.KE, cards: [51, 51, 51] });
  990. bdCount -= 3;
  991. }
  992. break;
  993. }
  994. }
  995. else if(ckORcs == 2){
  996. let mbCard = getMBCard(copyCards);//目标card(mbCard这次应该成刻)
  997. // if(islog && x == 5) console.warn("mbCard "+mbCard+" copyCards "+copyCards);
  998. if (mbCard < 40){
  999. if(mbCard > 0){
  1000. let index1 = copyCards.indexOf(mbCard);
  1001. if(index1 != -1) copyCards[index1] = 0;
  1002. else console.error("这里不正常,都没有目标牌");
  1003. let cj = [mbCard];//成句
  1004. if(this.getValue(mbCard) <= 7){
  1005. let index2 = copyCards.indexOf(mbCard+1);
  1006. if(index2 != -1){
  1007. cj[cj.length] = copyCards[index2];
  1008. copyCards[index2] = 0;
  1009. }
  1010. else {
  1011. if(bdCount > 0){
  1012. cj[cj.length] = 51;
  1013. bdCount -= 1;
  1014. }
  1015. }
  1016. let index3 = copyCards.indexOf(mbCard+2);
  1017. if(index3 != -1){
  1018. cj[cj.length] = copyCards[index3];
  1019. copyCards[index3] = 0;
  1020. }
  1021. else {
  1022. if(bdCount > 0){
  1023. cj[cj.length] = 51;
  1024. bdCount -= 1;
  1025. }
  1026. }
  1027. }
  1028. else if(this.getValue(mbCard) == 8){
  1029. let index2 = copyCards.indexOf(mbCard+1);
  1030. if(index2 != -1){
  1031. cj[cj.length] = copyCards[index2];
  1032. copyCards[index2] = 0;
  1033. }
  1034. else {
  1035. if(bdCount > 0){
  1036. cj[cj.length] = 51;
  1037. bdCount -= 1;
  1038. }
  1039. }
  1040. if(bdCount > 0){
  1041. cj[cj.length] = 51;
  1042. bdCount -= 1;
  1043. }
  1044. }
  1045. else if(this.getValue(mbCard) == 9){
  1046. if(bdCount > 1){
  1047. cj[cj.length] = 51;
  1048. cj[cj.length] = 51;
  1049. bdCount -= 2;
  1050. }
  1051. }
  1052. if(cj.length == 3){
  1053. huCards22.push({ style: STYLE.SUN, cards: cj });
  1054. }
  1055. else{
  1056. //mbCard不能成顺,说明spkzzh[x]这种组合是不行的,剩下的就不用判断了
  1057. break;
  1058. }
  1059. }
  1060. else{
  1061. //手牌全部都判断过了
  1062. if(bdCount >= 3){
  1063. huCards22.push({ style: STYLE.SUN, cards: [51, 51, 51] });
  1064. bdCount -= 3;
  1065. }
  1066. //因为手里最多8张百搭,最多可以有6张百搭做成2个百搭刻,所以需要两次if
  1067. if(bdCount >= 3){
  1068. huCards22.push({ style: STYLE.SUN, cards: [51, 51, 51] });
  1069. bdCount -= 3;
  1070. }
  1071. break;
  1072. }
  1073. }
  1074. }
  1075. // if(y < spkzzh[x].length-1) dqdpd=[x,y+1];
  1076. // else dqdpd=[x+1,0];
  1077. }
  1078. // if(islog && x == 5) console.warn("提取成句 组合 "+" spkzzh[x] "+spkzzh[x]+" huCards22 "+JSON.stringify(huCards22) );
  1079. if(huCards22.length + huCards.length == 4){
  1080. //已经可以胡牌了,其他的组合就不需要判断了
  1081. for (var i = 0; i < huCards22.length; i++) {
  1082. huCards.push(huCards22[i]);
  1083. }
  1084. break;
  1085. }
  1086. }
  1087. };
  1088. //////TL++,判断一手张牌是否为百搭牌
  1089. proto.judgeACardISBD = function (card) {
  1090. return card == this.baiDaCard;
  1091. }
  1092. // 胡牌分析 chairID(TL++这个参数) 手牌 加上这张判断能不能胡 手上的吃碰杠牌 是否自己摸上来的
  1093. proto.huAnalyze = function (chairID,handCards, card, huCards, isTouch) {
  1094. // console.error("sscc777胡牌分析card",card);
  1095. // console.error("sscc777胡牌分析handCards",handCards);
  1096. // console.error("sscc777胡牌分析huCards",huCards);
  1097. // console.error("sscc777胡牌分析isTouch",isTouch);
  1098. this.addThisIsHu = card//////TL++,胡牌判断时加上这张能不能胡
  1099. this.isSeleCatcedCard = isTouch//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
  1100. this.currChairIDTL = chairID/////当前判断胡的chairID,用于得到当前玩家的花牌情况
  1101. this.dangAfterBDListTL = [];/////7月18日+的
  1102. // console.warn("胡牌分析 isGuoHuList ",this.isGuoHuList," chairID ",chairID," isTouch ",isTouch);
  1103. // let baiDaCount22 = 0
  1104. // let bdIndexlist = []
  1105. if (!isTouch){
  1106. handCards = handCards.concat(card);/////不是自己抓的就把这张牌拼接进手牌中
  1107. }
  1108. handCards = this.sort(handCards);
  1109. let huCards2 = this.deepCloneTL(huCards)
  1110. // console.warn("判断13不搭手上百搭牌个数出错了?????",baiDaCount22,this.sbyBDList,bdIndexlist)
  1111. var huRes = { card: card, jiang: 0, huCards: [] };
  1112. // 重设将牌
  1113. var resetHuRes = (jiang) => {
  1114. huRes.jiang = jiang;
  1115. huRes.huCards = [];
  1116. for (let huCard of huCards) huRes.huCards.push(huCard);
  1117. };
  1118. // 手牌不全
  1119. var length = handCards.length;
  1120. if (length % 3 != 2) return;
  1121. let result = null
  1122. if(this.isSevenDouble(handCards)){
  1123. // console.warn("是个7对子了");
  1124. resetHuRes(-1);
  1125. result = huRes;
  1126. }
  1127. if(this.isJiangJiangHu(handCards,huCards2)){
  1128. // console.warn("是个将将胡了");
  1129. resetHuRes(-1);
  1130. result = huRes;
  1131. }
  1132. // let hucardTL = huCards//////TL++,保存碰杠牌的初始值,因为这个参数会在下面的代码中被修改掉
  1133. // console.warn("下面是计算普通胡法 "+handCards);
  1134. // 确定将牌
  1135. for (let i = 0; i < length - 1; ++i) {
  1136. if (!this.isJang(handCards[i], handCards[i + 1])) continue;
  1137. resetHuRes(handCards[i]);////设置将牌
  1138. let bcjp = handCards[i];
  1139. let cards = handCards.slice(0, i);////手牌数组的前i个元素
  1140. cards = cards.concat(handCards.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
  1141. this._dumpFixed(cards, huRes.huCards);
  1142. i += 1;/////TL++,为了减少运算
  1143. if(huRes.huCards.length >= 4){
  1144. if(this.isNeedEWBZJ(handCards,huCards2,huRes,isTouch)){
  1145. let jiangValue = this.getValue(bcjp);
  1146. if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
  1147. result = this.deepCloneTL(huRes);
  1148. // console.error("xxxxxxx需要258做将 bcjp "+bcjp+" "+handCards)
  1149. }
  1150. break
  1151. }
  1152. else{
  1153. // console.error("不需要258做将 bcjp "+bcjp+" "+handCards)
  1154. result = this.deepCloneTL(huRes);
  1155. // console.error("不需要258做将 result "+JSON.stringify(result))
  1156. }
  1157. }
  1158. }
  1159. if(result){
  1160. let copyCards = this.deepCloneTL(handCards);
  1161. // console.error("胡牌分析 判断可胡 大胡牌型111 ",chairID,copyCards);
  1162. // console.error("胡牌分析 判断可胡 大胡牌型huCards2 ",JSON.stringify(huCards2));
  1163. // console.error("胡牌分析 判断可胡 大胡牌型huRes ",JSON.stringify(huRes));
  1164. // console.error("胡牌分析 判断可胡 大胡牌型result ",JSON.stringify(result));
  1165. this.getCardTypeTL(chairID,copyCards,huCards2,result,isTouch);
  1166. // console.error("胡牌分析 可胡 大胡牌型 "+chairID+" "+this.everyDAHType[chairID]);
  1167. if(!isTouch){
  1168. // console.warn("不是此人摸牌 ",chairID,isTouch);
  1169. let pxgs = 0;
  1170. for (let x = 0; x < this.everyDAHType[chairID].length; ++x) {
  1171. if(this.everyDAHType[chairID][x] == 1) pxgs++;
  1172. }
  1173. // console.error("胡牌分析 可胡 是否过胡 "+this.isGuoHuList[chairID][0]+" 过胡牌型个数 "+this.isGuoHuList[chairID][1]+" 当前牌型个数 "+pxgs);
  1174. if(this.isGuoHuList[chairID][0] && this.isGuoHuList[chairID][1] >= pxgs){
  1175. // console.warn("此人点过胡了 ",chairID," isTouch ",(!isTouch));
  1176. return false;
  1177. }
  1178. }
  1179. }
  1180. if(!isTouch && this.kexuanList[3] == 1){
  1181. // console.error("胡牌分析 不是自己摸牌 勾选了小胡只能自摸 "+chairID+" "+this.everyDAHType[chairID]);
  1182. if(this.everyDAHType[chairID].indexOf(1) == -1){
  1183. // console.error("胡牌分析 不是自己摸牌 勾选了小胡只能自摸 没有大胡牌型 "+chairID+" "+this.everyDAHType[chairID]);
  1184. return false;
  1185. }
  1186. }
  1187. return result;
  1188. };
  1189. // // TL++胡牌提示 chairID(TL++这个参数) 手牌 手上的吃碰杠牌 这个是胡牌提示里不统计台数
  1190. proto.hutip = function (chairID,_handCards, _huCards,_allhuCards,outCards) {
  1191. // return {
  1192. // renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  1193. // kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
  1194. // };////服务端运算量太大放到前端去计算了
  1195. this.yscs = 0
  1196. // console.warn("hutip777胡牌提示handCards ",chairID,_handCards,_huCards,this.yscs);
  1197. // console.error("sscc777胡牌提示huCards",_huCards);
  1198. let hutipRes = [];
  1199. let handCards1 = _.clone(_handCards);
  1200. // if(chairID == 1) console.warn("sscc777胡牌提示handCards1 ",chairID,_handCards);
  1201. let huCards = _.clone(_huCards);
  1202. let allhuCards = _.clone(_allhuCards);////用统计胡牌提示的剩余牌
  1203. // let baiDaCount22 = this.getBDCount(_handCards);
  1204. let dangPaiList = this.getYGLDPList(handCards1);
  1205. // console.warn("hutip777胡牌提示 dangPaiList ",dangPaiList.length,dangPaiList);
  1206. // if(baiDaCount22 < this.hzCount && this.hzCount > 0 && _handCards.indexOf(this.baiDaCard) == -1 && this.baiDaCard < 60){
  1207. // dangPaiList[dangPaiList.length] = this.baiDaCard;
  1208. // }
  1209. // if(chairID == 1) console.warn("hutip777胡牌提示 dangPaiList ",dangPaiList.length,dangPaiList);
  1210. let kdcdp = 0;////可打出的牌 就是打出这个牌之后可以胡
  1211. let dczhkhdp = [];////打出kdcdp之后可以胡的牌
  1212. let yjpdgdsp = 0;////已经判断过的手牌 为了减少运算量判断过的手牌就不再判断了
  1213. // let yjpdgdzh = [];////已经判断过的组合 把28换成26 和 把26换成28 的结果是一样的所以可以剔除以减少运算
  1214. if(Array.isArray(handCards1)){
  1215. for (var i = 0; i < handCards1.length; i++) {
  1216. if(this.judgeACardISBD(handCards1[i])) continue;
  1217. kdcdp = handCards1[i];////可打出的牌
  1218. dczhkhdp = [];
  1219. if(handCards1[i] == yjpdgdsp) continue;////已经判断过的手牌 为了减少运算量判断过的手牌就不再判断了
  1220. yjpdgdsp = handCards1[i];////已经判断过的手牌 为了减少运算量判断过的手牌就不再判断了
  1221. var huResTL = [];
  1222. for (let huCard of huCards) huResTL.push(huCard);
  1223. let copyhandCards = this.deepCloneTL(_handCards)
  1224. // for (let x = 0; x < copyhandCards.length; ++x) {
  1225. // if(this.judgeACardISBD(copyhandCards[x])){
  1226. // copyhandCards[x] = 0;////剔除手里的百搭去判断抛搭
  1227. // }
  1228. // }
  1229. copyhandCards[i] = 0;///剔除手里的百搭和打出那张之后剩下的手牌去判断抛搭
  1230. let copyhandCardsqbd = _.compact(_.clone(copyhandCards));
  1231. copyhandCardsqbd = this.sort(copyhandCardsqbd);
  1232. // let ispd = this.hutipJudgePAODA(baiDaCount22,copyhandCardsqbd,dangPaiList,huResTL.length,kdcdp);////打出kdcdp之后是否抛搭
  1233. //上面是旧的算法,下面是新的算法
  1234. // let ispd = false;
  1235. // if(copyhandCardsqbd.length == 0){
  1236. // ispd = true;//手上全是百搭肯定抛搭了
  1237. // }
  1238. // else{
  1239. // if(baiDaCount22 > 0){
  1240. // ispd = this.hutipJudgePAODA2(baiDaCount22-1,copyhandCardsqbd,huResTL,kdcdp);////打出kdcdp之后是否抛搭
  1241. // }
  1242. // }
  1243. // // console.warn("打出kdcdp之后是否抛搭 ",kdcdp,ispd,this.yscs);
  1244. // if(ispd){
  1245. // ////打出kdcdp之后可以抛搭了
  1246. // let data = {
  1247. // "canTing": kdcdp,////表示打出这张牌之后可以听牌
  1248. // "youjin": 1,////打出这张牌之后是不是游金(抛搭)这个在象山麻将里面没有用
  1249. // "tpxq": dczhkhdp
  1250. // }
  1251. // hutipRes[hutipRes.length] = data;
  1252. // }
  1253. // else{
  1254. ////打出kdcdp之后不能抛搭
  1255. for (var k = 0; k < dangPaiList.length; k++) {
  1256. this.yscs++;
  1257. let handCards = _.clone(handCards1);
  1258. // console.error("222sscc777胡牌提示huCards",i,handCards[i] , dangPaiList[k],handCards);
  1259. handCards[i] = dangPaiList[k];
  1260. handCards = this.sort(handCards);
  1261. // 手牌不全
  1262. var length = handCards.length;
  1263. if (length % 3 != 2) return;
  1264. // console.warn("pandau 0ceccewcde -------开始调用 hutip33");
  1265. let huRes22 = this.hutip33(chairID,handCards, dangPaiList[k], huCards,false);
  1266. if (huRes22) {
  1267. // console.warn("胡牌提示 打出 "+kdcdp+" 如果摸到 "+dangPaiList[k]+" 可以胡");
  1268. ////打出kdcdp如果摸到dangPaiList[k]可以胡
  1269. let syzs = this.getACardSYZS(dangPaiList[k],_handCards,allhuCards,outCards);
  1270. // console.warn("111????????????????????????????????",dangPaiList[k],syzs);
  1271. dczhkhdp[dczhkhdp.length] = [dangPaiList[k],-1,syzs];////[可胡的牌,剩余张数]
  1272. }
  1273. }
  1274. // console.warn("222????????????????????????????????",dczhkhdp.length);
  1275. if(dczhkhdp.length > 0){
  1276. ////至此表示打出handCards[i]之后可以听牌
  1277. let data = {
  1278. "canTing": kdcdp,////表示打出这张牌之后可以听牌
  1279. "youjin": 0,////打出这张牌之后是不是游金(抛搭)这个在象山麻将里面没有用
  1280. "tpxq": dczhkhdp
  1281. }
  1282. hutipRes[hutipRes.length] = data;
  1283. }
  1284. }
  1285. }
  1286. // }
  1287. // console.warn("333????????????????????????????????",hutipRes);
  1288. // console.warn("222sscc777胡牌提示handCards ",chairID,_handCards,_huCards,this.yscs);
  1289. let kehuData3 = {
  1290. renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
  1291. kehuData:hutipRes/////对象数组,分别表示打哪张可胡哪几张数据
  1292. };
  1293. return kehuData3;
  1294. // return hutipRes;
  1295. };
  1296. ////TL++得到一张牌的剩余张数 用于胡牌提示提示该张的剩余张数
  1297. proto.getACardSYZS = function (card,_handCards,allhuCards,outCards) {
  1298. // console.warn("000得到一张牌的剩余张数 手牌张数",card,_handCards);
  1299. // console.warn("000得到一张牌的剩余张数 手牌张数",JSON.stringify(allhuCards));
  1300. // console.warn("000得到一张牌的剩余张数 手牌张数",JSON.stringify(outCards));
  1301. ////下面这段是适合胡牌提示里用的剩余牌数统计
  1302. let yjcxdzs = 0;////该牌已经出现的张数
  1303. for (var i = 0; i < _handCards.length; i++) {
  1304. if(card == _handCards[i]) yjcxdzs++;////该牌已经出现在自己手牌里的张数
  1305. }
  1306. // console.warn("111得到一张牌的剩余张数 手牌张数",yjcxdzs,_handCards);
  1307. for (var i = 0; i < allhuCards.length; i++) {
  1308. if(allhuCards[i].length == 0) continue;////该玩家没有碰杠牌
  1309. // console.warn("222得到一张牌的剩余张数 碰杠杠牌",card,yjcxdzs,i,JSON.stringify(_.clone(allhuCards[i])));
  1310. for (var k = 0; k < allhuCards[i].length; k++) {
  1311. let pgp = allhuCards[i][k].cards;
  1312. if(!pgp) continue;
  1313. if(allhuCards[i][k].style >= 5 && allhuCards[i][k].style <= 10 ){
  1314. if(allhuCards[i][k].cards[0] == card){
  1315. yjcxdzs+=4;//明杠暗杠自摸杠明补暗补自摸补
  1316. }
  1317. }
  1318. else{
  1319. // console.warn("得到一张牌的剩余张数 "+pgp+" card "+card);
  1320. for (var j = 0; j < pgp.length; j++) {
  1321. if(card == pgp[j]) yjcxdzs++;////该牌已经出现在自己手牌里的张数
  1322. }
  1323. }
  1324. }
  1325. }
  1326. for (var i = 0; i < outCards.length; i++) {
  1327. if(outCards[i].length == 0) continue;////该玩家没有碰杠牌
  1328. // console.warn("2得到一张牌的剩余张数 打出去的牌",card,yjcxdzs,i,JSON.stringify(_.clone(outCards[i])));
  1329. for (var k = 0; k < outCards[i].length; k++) {
  1330. if(card == outCards[i][k]) yjcxdzs++;////该牌已经出现在所有打出去牌里的张数;
  1331. }
  1332. }
  1333. let zs = 4
  1334. if(card == 51) zs = this.hzCount;
  1335. // if(this.judgeACardISBD(card)) zs = 3;
  1336. let syzs = zs - yjcxdzs;////剩余张数 = 总张数 - 已经出现的张数
  1337. // console.warn("333得到一张牌的剩余张数",card,syzs);
  1338. return syzs;
  1339. };
  1340. // //////TL++,胡牌提示判断抛搭
  1341. // proto.hutipJudgePAODA2 = function (_baidacount,_hd,_huCards,_addThisIsHu) {
  1342. // // console.warn("胡牌提示判断抛搭 _baidacount "+_baidacount+" _hd.length "+_hd.length +" _hd "+_hd);
  1343. // let cards2 = this.deepCloneTL(_hd);
  1344. // let huRes3 = { card: 0, jiang: 0, huCards: [] };
  1345. // huRes3.huCards = [];
  1346. // for (let huCard of _huCards) huRes3.huCards.push(huCard);
  1347. // this._dumpFixedc(cards2, huRes3.huCards,_baidacount);
  1348. // // console.warn("胡牌提示 判断判断抛搭 length "+huRes3.huCards.length+" huRes3.huCards "+ JSON.stringify(huRes3.huCards));
  1349. // if (huRes3.huCards.length >= 4){
  1350. // // console.warn("胡牌提示 判断判断抛搭 可以抛搭222 length "+huRes3.huCards.length+" huRes3.huCards "+ JSON.stringify(huRes3.huCards));
  1351. // return true;
  1352. // }
  1353. // // console.warn("不能抛搭");
  1354. // return false;
  1355. // }
  1356. // 胡牌分析(胡牌提示里调用) chairID(TL++这个参数) 手牌 加上这张判断能不能胡 手上的吃碰杠牌 是否自己摸上来的
  1357. proto.hutip33 = function (chairID,handCards, card, huCards, isTouch) {
  1358. // console.error("sscc777胡牌分析card",card);
  1359. // console.error("sscc777胡牌提示分析handCards",handCards);
  1360. // console.error("sscc777胡牌分析huCards",huCards);
  1361. // console.error("sscc777胡牌分析isTouch",isTouch);
  1362. // let tempres = {}///本函数的返回值
  1363. // this.addThisIsHu = card//////TL++,胡牌判断时加上这张能不能胡
  1364. // this.isSeleCatcedCard = isTouch//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
  1365. // this.currChairIDTL = chairID/////当前判断胡的chairID,用于得到当前玩家的花牌情况
  1366. // this.dangAfterBDListTL = [];/////7月18日+的
  1367. // let baiDaCount22 = 0
  1368. // let bdIndexlist = []
  1369. // handCards = this.sort(handCards);
  1370. // baiDaCount22 = this.getBDCount(handCards)
  1371. // this.sbyBDList = this.getBDListZZ(handCards)
  1372. // bdIndexlist = this.getBDIndexList(handCards)
  1373. // console.warn("判断13不搭手上百搭牌个数出错了?????",baiDaCount22,this.sbyBDList,bdIndexlist)
  1374. // 手牌不全
  1375. // var length = handCards.length;
  1376. // // console.warn("胡牌提示 length "+length+" baiDaCount22 "+baiDaCount22);
  1377. // if (length % 3 != 2) return;
  1378. let huCards2 = this.deepCloneTL(huCards)
  1379. var huRes = { card: card, jiang: 0, huCards: [] };
  1380. // 重设将牌
  1381. var resetHuRes = (jiang) => {
  1382. huRes.jiang = jiang;
  1383. huRes.huCards = [];
  1384. for (let huCard of huCards) huRes.huCards.push(huCard);
  1385. };
  1386. if(this.isSevenDouble(handCards)){
  1387. // console.warn("胡牌提示 是个7对子了");
  1388. return true;
  1389. }
  1390. if(this.isJiangJiangHu(handCards,huCards2)){
  1391. // console.warn("胡牌提示 是个将将胡了");
  1392. return true;
  1393. }
  1394. // let hucardTL = huCards//////TL++,保存碰杠牌的初始值,因为这个参数会在下面的代码中被修改掉
  1395. // 确定将牌
  1396. for (let i = 0; i < handCards.length - 1; ++i) {
  1397. if (!this.isJang(handCards[i], handCards[i + 1])) continue;
  1398. resetHuRes(handCards[i]);////设置将牌
  1399. let bcjp = handCards[i]; ///////本次的将牌 7月18日+的
  1400. let cards = handCards.slice(0, i);////手牌数组的前i个元素
  1401. cards = cards.concat(handCards.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
  1402. this._dumpFixed(cards, huRes.huCards);
  1403. i += 1;/////TL++,为了减少运算
  1404. // let tempres22 = this.outHures(huRes,handCards,hucardTL);
  1405. if(huRes.huCards.length >= 4){
  1406. if(this.isNeedEWBZJ(handCards,huCards2,huRes,true)){
  1407. let jiangValue = this.getValue(bcjp);
  1408. if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
  1409. return true;
  1410. }
  1411. }
  1412. else{
  1413. return true;
  1414. }
  1415. }
  1416. }
  1417. return false;
  1418. };
  1419. // TL++,得到和手牌有关联的牌的数组,用于判断是否听牌 cards: 13张手牌
  1420. proto.getYGLDPList = function (_cards) {
  1421. let cards = this.deepCloneTL(_cards)
  1422. cards = this.sort(cards);
  1423. let cannotList = [];
  1424. ////TL++,整个for循环按照手牌情况确定百搭牌当的范围
  1425. let makeList = this.deepCloneTL(cards)
  1426. for (let i = 0; i < cards.length; ++i) {
  1427. let cardTL = cards[i];
  1428. let type = this.getType(cardTL);
  1429. let vale = this.getValue(cardTL);
  1430. if(cardTL == cards[i+1] && cardTL == cards[i+2] && cardTL == cards[i+3]){
  1431. i += 3;
  1432. cannotList[cannotList.length] = cardTL;
  1433. }
  1434. if(type < 4){
  1435. if(vale == 1){
  1436. let makeValue = cardTL + 1;
  1437. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  1438. }
  1439. else if(vale == 9){
  1440. let makeValue = cardTL - 1;
  1441. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  1442. }
  1443. else{
  1444. let makeValue = cardTL - 1;
  1445. if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
  1446. let makeValue2 = cardTL + 1;
  1447. if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
  1448. }
  1449. }
  1450. }
  1451. // console.warn("22数组去重",xx,xx22);////[ 1, 6, 2, 3, 4, 1, 2 ] [ 1, 2, 3, 4 ]
  1452. //return _.uniq(makeList);
  1453. makeList = _.uniq(makeList);
  1454. this.remove(makeList,cannotList);
  1455. return makeList;
  1456. }
  1457. //判断是否可以杠,14张手牌去掉可以暗杠的4张牌(或者13张牌去掉可以明杠的3张牌)之后可以听牌则可以杠否则不能杠
  1458. proto.isCanGang = function (cards,_huCards,gangtype,gangcard) {
  1459. // console.error("判断是否可以杠 cards "+cards,_huCards,gangtype,gangcard);
  1460. let huCards = [];
  1461. for (let huCard of _huCards) huCards.push(huCard);
  1462. let handCards = this.deepCloneTL(cards);
  1463. handCards = this.sort(handCards);
  1464. let needDelList = [];
  1465. //1-普通杠, 2-暗杠, 3-自摸明杠
  1466. if(gangtype == 1){
  1467. needDelList[needDelList.length] = [gangcard,gangcard,gangcard]
  1468. huCards.push({ style: STYLE.GANG, cards: [gangcard,gangcard,gangcard] });
  1469. }
  1470. else if(gangtype == 2){
  1471. if(gangcard != 0){
  1472. needDelList[needDelList.length] = [gangcard,gangcard,gangcard,gangcard];
  1473. huCards.push({ style: STYLE.ANGANG, cards: [gangcard,gangcard,gangcard] });
  1474. }
  1475. else{
  1476. for (let i = 0; i < handCards.length - 3; ++i) {
  1477. let card = handCards[i];
  1478. // 判定是否刻子
  1479. if (card == handCards[i + 1] && card == handCards[i + 2] && card == handCards[i + 3]) {
  1480. needDelList[needDelList.length] = [card,card,card,card];
  1481. huCards.push({ style: STYLE.ANGANG, cards: [card,card,card] });
  1482. i+=3
  1483. }
  1484. }
  1485. }
  1486. }
  1487. else if(gangtype == 3){
  1488. needDelList[needDelList.length] = [gangcard];
  1489. }
  1490. // console.error("判断是否可以杠 needDelList "+needDelList.length,needDelList);
  1491. for (let i = 0; i < needDelList.length; ++i) {
  1492. let handCards2 = this.deepCloneTL(handCards);
  1493. this.remove(handCards2,needDelList[i]);
  1494. // console.error("判断是否可以杠 handCards2 "+handCards2+" needDelList[i] "+needDelList[i]);
  1495. if(this.checkTing(handCards2,huCards)){
  1496. // console.error("判断是否可以杠 可以杠");
  1497. return true;
  1498. }
  1499. }
  1500. return false;
  1501. }
  1502. //检查是否可以听牌
  1503. proto.checkTing = function (_cards,huCards) {
  1504. // console.error("检查是否可以听牌 length "+_cards.length+" cards "+_cards);
  1505. // console.error("检查是否可以听牌111 length "+huCards.length+" huCards "+JSON.stringify(huCards) );
  1506. if (_cards.length % 3 != 1) return;
  1507. let handCards = this.deepCloneTL(_cards)
  1508. let dangPaiList = this.getYGLDPList(handCards);
  1509. let huCards2 = this.deepCloneTL(huCards)
  1510. var huRes = { card: 0, jiang: 0, huCards: [] };
  1511. // 重设将牌
  1512. var resetHuRes = (jiang) => {
  1513. huRes.jiang = jiang;
  1514. huRes.huCards = [];
  1515. for (let huCard of huCards) huRes.huCards.push(huCard);
  1516. };
  1517. for (let n = 0; n < dangPaiList.length; ++n) {
  1518. let cards22 = this.deepCloneTL(handCards)/////百搭牌当完之后的手牌数组
  1519. cards22[cards22.length] = dangPaiList[n];
  1520. cards22 = this.sort(cards22);
  1521. if(this.isJiangJiangHu(handCards,huCards2)){
  1522. // console.error("是个将将胡了");
  1523. return true;
  1524. }
  1525. if(this.isSevenDouble(cards22)){
  1526. return true;
  1527. }
  1528. // 确定将牌
  1529. for (let i = 0; i < cards22.length - 1; ++i) {
  1530. if (!this.isJang(cards22[i], cards22[i + 1])) continue;
  1531. resetHuRes(cards22[i]);////设置将牌
  1532. let bcjp = cards22[i]; ///////本次的将牌 7月18日+的
  1533. // this.judgePAODA(1,cards22[i],dangAfterBDList);/////判断抛搭 /////7月18日以前在这里
  1534. let cards = cards22.slice(0, i);////手牌数组的前i个元素
  1535. cards = cards.concat(cards22.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
  1536. this._dumpFixed(cards, huRes.huCards);
  1537. if(huRes.huCards.length >= 4){
  1538. // if(handCards.length == 1) return true;
  1539. if(this.isNeedEWBZJ(cards22,huCards2,huRes,true)){
  1540. let jiangValue = this.getValue(bcjp);
  1541. // return (jiangValue == 2 || jiangValue == 5 || jiangValue == 8);
  1542. if((jiangValue == 2 || jiangValue == 5 || jiangValue == 8)){
  1543. // console.error("检查是否可以听牌 可以听牌111");
  1544. return true;
  1545. }
  1546. }
  1547. else{
  1548. // console.error("检查是否可以听牌 可以听牌222");
  1549. return true;
  1550. }
  1551. }
  1552. i += 1;/////TL++,为了减少运算
  1553. }
  1554. }
  1555. // console.warn("检查是否可以听牌 不能听牌");
  1556. return false;
  1557. }
  1558. //是否需要二五八做将
  1559. proto.isNeedEWBZJ = function (handCards,huCards,hures,isTouch) {
  1560. // console.error("是否需要二五八做将 isTouch "+isTouch +" handCards " +handCards+" huCards "+JSON.stringify(huCards)+" hures "+JSON.stringify(hures));
  1561. let shoupai = handCards/////手牌
  1562. let PGPai = huCards/////手上的碰杠牌
  1563. let chengju = hures/////整理好之后成句的牌(包括碰杠牌)
  1564. for (var i = 5; i < this.dahuTypeTL.length; i++) {
  1565. if( i == 5 && this.isQQR(shoupai,PGPai,chengju)){
  1566. // console.warn("不需要2,5,8做将1");
  1567. return false;
  1568. }
  1569. // else if( i == 6 && isTouch && this.isMQ(shoupai,PGPai,chengju)){
  1570. // console.warn("不需要2,5,8做将2");
  1571. // return false;
  1572. // }
  1573. else if( i == 7 && this.isQYS(shoupai,PGPai,chengju)){
  1574. // console.warn("不需要2,5,8做将3");
  1575. return false;
  1576. }
  1577. else if( i == 8 && this.isPengPengHu(shoupai,PGPai,chengju)){
  1578. // console.warn("不需要2,5,8做将4");
  1579. return false;
  1580. }
  1581. // else if( i == 9 && this.isGangKai(shoupai,PGPai,chengju)){
  1582. // console.warn("不需要2,5,8做将5");
  1583. // return false;
  1584. // }
  1585. // else if( i == 10 && this.isQiangGang(shoupai,PGPai,chengju)){
  1586. // console.warn("不需要2,5,8做将6");
  1587. // return false;
  1588. // }
  1589. // else if( i == 11 && this.isHDLY(shoupai,PGPai,chengju)){
  1590. // console.warn("不需要2,5,8做将7");
  1591. // return false;
  1592. // }
  1593. }
  1594. // console.error("是否需要二五八做将 需要 ");
  1595. return true;
  1596. }
  1597. // 是否可以出牌,别人有权限的时候不能出牌需要等待
  1598. proto.getIsCanOut = function (masks) {
  1599. let isCanOut = true;
  1600. for (let x = 0; x < masks.length; ++x) {
  1601. if(masks[x] > 0){
  1602. isCanOut = false;
  1603. break;
  1604. }
  1605. }
  1606. return isCanOut;
  1607. };
  1608. //删除起手胡牌型的操作权限
  1609. proto.getNewMask = function (oldMask) {
  1610. let list = [1,2,4,8,16,32];
  1611. let isCanOperateList = [];
  1612. for (let i = 0; i < list.length; ++i) {
  1613. // if(oldMask < list[i]) break;
  1614. if(oldMask & list[i]) isCanOperateList[isCanOperateList.length] = 1;
  1615. else isCanOperateList[isCanOperateList.length] = 0;
  1616. }
  1617. let newMask = 0;
  1618. for (let i = 0; i < isCanOperateList.length; ++i) {
  1619. if(isCanOperateList[i] == 1){
  1620. newMask |= list[i]
  1621. }
  1622. }
  1623. return newMask;
  1624. }
  1625. ////得到list1里面是否包含list2
  1626. proto.getISBH = function (_list1,list2) {
  1627. //因为运算过程中会改变_list1的值所以需要备份数据
  1628. let list1 = this.deepCloneTL(_list1);
  1629. for (let i = 0; i < list2.length; ++i) {
  1630. let pos = list1.indexOf(list2[i]);
  1631. if (pos == -1){
  1632. return false;
  1633. }
  1634. list1.splice(pos, 1);
  1635. }
  1636. return true
  1637. }
  1638. ////得到list1[[],[],[]]里面是否包含list2
  1639. proto.getISBH2 = function (_list1,list2) {
  1640. // console.warn("得到list1[[],[],[]]里面是否包含list2 "+JSON.stringify(_list1)+" list2 "+list2);
  1641. for (let i = 0; i < _list1.length; ++i) {
  1642. if(_list1[i].length == list2.length){
  1643. for (let x = 0; x < _list1[i].length; ++x) {
  1644. if(_list1[i][x] == list2[x]){
  1645. // console.warn("包含了 第i个 "+i);
  1646. return true;
  1647. }
  1648. }
  1649. }
  1650. }
  1651. // console.warn("不包含");
  1652. return false
  1653. }
  1654. //// 得到是否是起手
  1655. proto.getIsQS = function () {
  1656. let isqs = this.castCount == (this.playerAllCount*CARDS_COUNT+1);//是否起手
  1657. if(isqs){
  1658. if(this.chuPaiCountTL == 0) return true;
  1659. }
  1660. return false;
  1661. }
  1662. // 起手胡牌分析 chairID(TL++这个参数) 手牌 加上这张判断能不能胡 手上的吃碰杠牌 是否自己摸上来的
  1663. proto.qshuAnalyze = function (chairID,handCards) {
  1664. this.everyQSHType[chairID] = [];
  1665. this.canSelects[chairID] = [];
  1666. let isqs = this.getIsQS();
  1667. let shoupai = this.deepCloneTL(handCards);
  1668. // this.remove(shoupai,this.everyQSHCZGList[chairID]);
  1669. shoupai = this.sort(shoupai);
  1670. for (let i = 0; i < this.qshuTypeTL.length; ++i) {
  1671. this.everyQSHType[chairID][i] = 0;
  1672. if( i == 0 && isqs && this.isSiXi(chairID,shoupai,isqs)){
  1673. this.everyQSHType[chairID][i] = 1;
  1674. }
  1675. else if( i == 1 && isqs && this.isBanBanHu(chairID,shoupai,isqs)){
  1676. this.everyQSHType[chairID][i] = 1;
  1677. }
  1678. else if( i == 2 && isqs && this.isQueYiSe(chairID,shoupai,isqs)){
  1679. this.everyQSHType[chairID][i] = 1;
  1680. }
  1681. else if( i == 3 && isqs && this.isLiuLiuShun(chairID,shoupai,isqs)){
  1682. this.everyQSHType[chairID][i] = 1;
  1683. }
  1684. else if( i == 4 && (!isqs) && this.isSiXi(chairID,shoupai,isqs)){
  1685. this.everyQSHType[chairID][i] = 1;
  1686. }
  1687. else if( i == 5 && (!isqs) && this.isLiuLiuShun(chairID,shoupai,isqs)){
  1688. this.everyQSHType[chairID][i] = 1;
  1689. }
  1690. // else if( i == 4 && this.isJieJieGao(shoupai)){
  1691. // this.everyQSHType[chairID][i] = 1;
  1692. // }
  1693. // else if( i == 5 && this.everyQSHType[chairID][2] == 0 && this.isSanTong(shoupai)){
  1694. // //是缺一色的情况下不可能是三同
  1695. // this.everyQSHType[chairID][i] = 1;
  1696. // }
  1697. // else if( i == 6 && this.everyQSHType[chairID][1] == 0 && this.isDanJiang(shoupai)){
  1698. // //是板板胡的话不可能是单将一枝花
  1699. // this.everyQSHType[chairID][i] = 1;
  1700. // }
  1701. // else if( i == 7 && this.everyQSHType[chairID][1] == 0 && this.everyQSHType[chairID][6] == 0 && this.isDanWu(shoupai)){
  1702. // //是板板胡的话不可能是单五一枝花
  1703. // //只有一张五的情况下都满足单将一枝花和单五一枝花,这种情况算单将一枝花单五一枝花不成立
  1704. // this.everyQSHType[chairID][i] = 1;
  1705. // }
  1706. }
  1707. }
  1708. //起手的六六顺消耗过的牌起手四喜不能再次使用,中途的六六顺消耗过的牌中途四喜不能再次使用,
  1709. //起手的六六顺消耗过的牌中途四喜可以再次使用,(四喜和六六顺同理)
  1710. // 是否四喜
  1711. proto.isSiXi = function (chairID,handCards,isqs) {
  1712. // console.error("是否四喜===111 chairID "+chairID+" everyQSHCZGList "+JSON.stringify(this.everyQSHCZGList[chairID]));
  1713. // console.error("是否四喜===222 chairID "+chairID+" everyQSHCZGList2 "+JSON.stringify(this.everyQSHCZGList2[chairID]));
  1714. // console.error("是否四喜===333 chairID "+chairID+" handCards "+JSON.stringify(handCards));
  1715. if(!isqs && this.kexuanList[0] != 1) return false;//没有勾选中途大四喜
  1716. let canSelects = [];
  1717. var dcount = 0;
  1718. for (let i = 0; i < handCards.length-3; ++i) {
  1719. let card = handCards[i];
  1720. if (card == handCards[i+1] && card == handCards[i+2] && card == handCards[i+3]) {
  1721. if(!this.getISBH(this.everyQSHCZGList[chairID],[card,card,card])){
  1722. dcount += 1;
  1723. i+=3;
  1724. canSelects.push([card,card,card,card])
  1725. }
  1726. else{
  1727. // console.error("是否四喜===222 chairID isqs " + isqs)
  1728. //添加这个else是为了满足下面这个规则,如果消耗过的牌不能再次使用就不要这个else了
  1729. //起手的六六顺消耗过的牌起手四喜不能再次使用,中途的六六顺消耗过的牌中途四喜不能再次使用,
  1730. //起手的六六顺消耗过的牌中途四喜可以再次使用,(四喜和六六顺同理)
  1731. if(!isqs && !this.getISBH2(this.everyQSHCZGList2[chairID],[card,card,card,card])){
  1732. dcount += 1;
  1733. i+=3;
  1734. canSelects.push([card,card,card,card])
  1735. }
  1736. }
  1737. }
  1738. }
  1739. if(dcount >= 1){
  1740. let type = 0;
  1741. if(!isqs) type = 4;
  1742. let obj = {
  1743. type:type,
  1744. cards:canSelects
  1745. }
  1746. this.canSelects[chairID].push(obj)
  1747. return true;
  1748. }
  1749. return false;
  1750. };
  1751. // 是否板板胡
  1752. proto.isBanBanHu = function (chairID,handCards,isqs) {
  1753. if(this.everyXiaoHuList[chairID].indexOf(1) != -1) return false;
  1754. for (let i = 0; i < handCards.length; ++i) {
  1755. let card = this.getValue(handCards[i]);
  1756. if (card == 2 || card == 5 || card == 8) {
  1757. return false;
  1758. }
  1759. }
  1760. let obj = {
  1761. type:1,
  1762. cards:[]
  1763. }
  1764. this.canSelects[chairID].push(obj);
  1765. return true;
  1766. };
  1767. // 是否缺一色
  1768. proto.isQueYiSe = function (chairID,handCards,isqs) {
  1769. // console.warn("是否缺一色 chairID "+chairID+" handCards "+handCards + " isqs "+isqs);
  1770. let huaSeCount = [0,0,0,0];
  1771. for (let i = 0; i < handCards.length; ++i) {
  1772. let card = handCards[i];
  1773. if(this.getType(card) == 1 ) huaSeCount[0] = 1;
  1774. if(this.getType(card) == 2 ) huaSeCount[1] = 1;
  1775. if(this.getType(card) == 3 ) huaSeCount[2] = 1;
  1776. }
  1777. let huase = 0;
  1778. for (let n = 0; n < huaSeCount.length; ++n) {
  1779. if(huaSeCount[n] == 1) huase += 1;
  1780. }
  1781. if(huase <= 2){
  1782. let ismz = false;
  1783. let yjhgdqyscs = 0;//已经胡过的缺一色次数
  1784. for (let i = 0; i < this.everyXiaoHuList[chairID].length; ++i) {
  1785. if(this.everyXiaoHuList[chairID][i] == 2) yjhgdqyscs++
  1786. }
  1787. if(huase == 2){
  1788. if(yjhgdqyscs == 0) ismz = true;
  1789. }
  1790. else if(huase == 1){
  1791. //手上只有一种花色可以胡缺一色两次
  1792. if(yjhgdqyscs < 2) ismz = true;
  1793. }
  1794. // console.warn("缺一色==== "+ismz+" yjhgdqyscs "+yjhgdqyscs + " huase "+huase);
  1795. if(ismz){
  1796. let obj = {
  1797. type:2,
  1798. cards:[]
  1799. }
  1800. this.canSelects[chairID].push(obj);
  1801. return true;
  1802. }
  1803. }
  1804. return false;
  1805. };
  1806. // 是否六六顺
  1807. proto.isLiuLiuShun = function (chairID,handCards,isqs) {
  1808. if(!isqs && this.kexuanList[1] != 1) return false;//没有勾选中途大四喜
  1809. var keList = [];
  1810. for (let i = 0; i < handCards.length-2; ++i) {
  1811. let card = handCards[i];
  1812. if (card == handCards[i+1] && card == handCards[i+2]) {
  1813. keList.push([card,card,card])
  1814. i+=2;
  1815. }
  1816. }
  1817. if(keList.length >= 2){
  1818. let cards = [];
  1819. for (let i = 0; i < keList.length; ++i) {
  1820. for (let j = i+1; j < keList.length; ++j) {
  1821. if(!this.getISBH(this.everyQSHCZGList[chairID],keList[i]) && !this.getISBH(this.everyQSHCZGList[chairID],keList[j])){
  1822. let cc = keList[i].concat(keList[j]);
  1823. cards.push(cc);
  1824. }
  1825. }
  1826. }
  1827. if(cards.length > 0){
  1828. let type = 3;
  1829. if(!isqs) type = 5;
  1830. let obj = {
  1831. type:type,
  1832. cards:cards
  1833. }
  1834. this.canSelects[chairID].push(obj);
  1835. return true
  1836. }
  1837. return false;
  1838. }
  1839. return false;
  1840. };
  1841. // 是否节节高
  1842. // proto.isJieJieGao = function (handCards) {
  1843. // var duiziList = [];
  1844. // for (let i = 0; i < handCards.length-1; ++i) {
  1845. // let card = handCards[i];
  1846. // if (card == handCards[i+1]) {
  1847. // if(duiziList.indexOf(card) == -1){
  1848. // duiziList[duiziList.length] = card;
  1849. // }
  1850. // i+=1;
  1851. // }
  1852. // }
  1853. // for (let i = 0; i < duiziList.length; ++i) {
  1854. // let value = this.getValue(duiziList[i])
  1855. // if(value < 8 && duiziList[i]+1 == duiziList[i+ 1] && duiziList[i]+2 == duiziList[i+ 2]){
  1856. // return true
  1857. // }
  1858. // }
  1859. // return false;
  1860. // };
  1861. // // 是否三同
  1862. // proto.isSanTong = function (handCards) {
  1863. // var duiziList = [];
  1864. // for (let i = 0; i < handCards.length-1; ++i) {
  1865. // let card = handCards[i];
  1866. // if (card == handCards[i+1]) {
  1867. // if(duiziList.indexOf(card) == -1){
  1868. // duiziList[duiziList.length] = card;
  1869. // }
  1870. // i+=1;
  1871. // }
  1872. // }
  1873. // for (let i = 0; i < duiziList.length; ++i) {
  1874. // let card = handCards[i];
  1875. // let type = this.getType(duiziList[i])
  1876. // if(type < 2){
  1877. // if(duiziList.indexOf(card + 10) != -1 && duiziList.indexOf(card + 20) != -1){
  1878. // return true;
  1879. // }
  1880. // }
  1881. // else {
  1882. // return false;
  1883. // }
  1884. // }
  1885. // return false;
  1886. // };
  1887. // // 是否单将一枝花
  1888. // proto.isDanJiang = function (handCards) {
  1889. // let count = 0;
  1890. // for (let i = 0; i < handCards.length; ++i) {
  1891. // let value = this.getValue(handCards[i])
  1892. // if (value == 2 || value == 5 || value == 8) {
  1893. // count++;
  1894. // if(count >= 2) return false;
  1895. // }
  1896. // }
  1897. // return true;
  1898. // };
  1899. // // 是否单五一枝花
  1900. // proto.isDanWu = function (handCards) {
  1901. // let count1 = 0;
  1902. // let count2 = 0;
  1903. // let count3 = 0;
  1904. // for (let i = 0; i < handCards.length; ++i) {
  1905. // let value = this.getValue(handCards[i])
  1906. // if (value == 2) count1++;
  1907. // if (value == 5) count2++;
  1908. // if (value == 8) count3++;
  1909. // }
  1910. // if(count1 == 1 || count2 == 1 || count3 == 1) return true;
  1911. // };
  1912. //得到除7对和将将胡之外的大胡牌型,大胡牌型可以乱将
  1913. proto.getCardTypeTL = function (chairID,handCards, huCards,hures,isTouch) {
  1914. let shoupai = handCards/////手牌
  1915. let PGPai = huCards/////手上的碰杠牌
  1916. let chengju = hures/////整理好之后成句的牌(包括碰杠牌)
  1917. for (var i = 0; i < this.dahuTypeTL.length; i++) {
  1918. this.everyDAHType[chairID][i] = 0;
  1919. if( i == 0 && this.isSevenDouble(shoupai,PGPai,chengju)){
  1920. this.everyDAHType[chairID][i] = 1;
  1921. }
  1922. if( i == 1 && this.everyDAHType[chairID][0] == 1 && this.isHHSevenDouble(shoupai,PGPai,chengju)){
  1923. this.everyDAHType[chairID][i] = 1;
  1924. }
  1925. if( i == 2 && this.everyDAHType[chairID][0] == 1 && this.isSHHSevenDouble(shoupai,PGPai,chengju)){
  1926. this.everyDAHType[chairID][i] = 1;
  1927. }
  1928. if( i == 3 && this.everyDAHType[chairID][0] == 1 && this.isSSHHSevenDouble(shoupai,PGPai,chengju)){
  1929. this.everyDAHType[chairID][i] = 1;
  1930. }
  1931. if( i == 4 && this.isJiangJiangHu(shoupai,PGPai,chengju)){
  1932. this.everyDAHType[chairID][i] = 1;
  1933. }
  1934. if( i == 5 && this.isQQR(shoupai,PGPai,chengju)){
  1935. this.everyDAHType[chairID][i] = 1;
  1936. }
  1937. else if( i == 6 && isTouch && this.isMQ(shoupai,PGPai,chengju)){
  1938. this.everyDAHType[chairID][i] = 1;
  1939. }
  1940. else if( i == 7 && this.isQYS(shoupai,PGPai,chengju)){
  1941. this.everyDAHType[chairID][i] = 1;
  1942. }
  1943. else if( i == 8 && this.isPengPengHu(shoupai,PGPai,chengju)){
  1944. this.everyDAHType[chairID][i] = 1;
  1945. }
  1946. else if( i == 9 && this.isGangKai(shoupai,PGPai,chengju)){
  1947. this.everyDAHType[chairID][i] = 1;
  1948. }
  1949. else if( i == 10 && this.isQiangGang(shoupai,PGPai,chengju)){
  1950. this.everyDAHType[chairID][i] = 1;
  1951. }
  1952. else if( i == 11 && this.isHDLY(shoupai,PGPai,chengju)){
  1953. this.everyDAHType[chairID][i] = 1;
  1954. }
  1955. }
  1956. }
  1957. // 是否七对
  1958. proto.isSevenDouble = function (handCards,PGPai,chengju) {
  1959. if (handCards.length <= CARDS_COUNT) return false;
  1960. var dcount = 0;
  1961. var counts = {};
  1962. for (let i = 0; i < handCards.length; ++i) {
  1963. let card = handCards[i];
  1964. counts[card] = (counts[card] || 0) + 1;
  1965. if (counts[card] >= 2) {
  1966. dcount += 1;
  1967. counts[card] = 0;
  1968. }
  1969. }
  1970. // console.warn("是否是7对 ",dcount,handCards);
  1971. return (dcount >= 7);
  1972. };
  1973. // 是否豪华七对
  1974. proto.isHHSevenDouble = function (handCards,PGPai,chengju) {
  1975. if (handCards.length <= CARDS_COUNT) return false;
  1976. var dcount = 0;
  1977. for (let i = 0; i < handCards.length-3; ++i) {
  1978. let card = handCards[i];
  1979. if (card == handCards[i+1] && card == handCards[i+2] && card == handCards[i+3]) {
  1980. dcount += 1;
  1981. i+=3;
  1982. }
  1983. }
  1984. // console.warn("是否是豪华七对 "+dcount);
  1985. return (dcount >= 1);
  1986. };
  1987. // 是否双豪华七对
  1988. proto.isSHHSevenDouble = function (handCards,PGPai,chengju) {
  1989. if (handCards.length <= CARDS_COUNT) return false;
  1990. var dcount = 0;
  1991. for (let i = 0; i < handCards.length-3; ++i) {
  1992. let card = handCards[i];
  1993. if (card == handCards[i+1] && card == handCards[i+2] && card == handCards[i+3]) {
  1994. dcount += 1;
  1995. i+=3;
  1996. }
  1997. }
  1998. return (dcount >= 2);
  1999. };
  2000. // 是否三豪华七对
  2001. proto.isSSHHSevenDouble = function (handCards,PGPai,chengju) {
  2002. if (handCards.length <= CARDS_COUNT) return false;
  2003. var dcount = 0;
  2004. for (let i = 0; i < handCards.length-3; ++i) {
  2005. let card = handCards[i];
  2006. if (card == handCards[i+1] && card == handCards[i+2] && card == handCards[i+3]) {
  2007. dcount += 1;
  2008. i+=3;
  2009. }
  2010. }
  2011. return (dcount >= 3);
  2012. };
  2013. // 是否将将胡
  2014. proto.isJiangJiangHu = function (handCards,PGPai,chengju) {
  2015. for (let i = 0; i < handCards.length; ++i) {
  2016. let value = this.getValue(handCards[i]);
  2017. if (value == 2 || value == 5 || value == 8) continue;
  2018. else return false;
  2019. }
  2020. ////上面是统计手牌2,5,8,下面是统计碰杠牌的2,5,8
  2021. if(PGPai && PGPai.length > 0){
  2022. for (let i = 0; i < PGPai.length; ++i) {
  2023. if(!PGPai[i]) continue;
  2024. let pgcardlist = PGPai[i].cards;
  2025. if(!pgcardlist) continue;
  2026. for (let j = 0; j < pgcardlist.length; ++j) {
  2027. let card2 = pgcardlist[j];
  2028. let value = this.getValue(card2);
  2029. if (value == 2 || value == 5 || value == 8) continue;
  2030. else return false;
  2031. }
  2032. }
  2033. }
  2034. return true;
  2035. }
  2036. //是否 "全求人",
  2037. proto.isQQR = function (shoupai,PGPai,chengju) {
  2038. // console.warn("判断全求人 shoupai "+shoupai);
  2039. return shoupai.length == 2 && shoupai[0] == shoupai[1];
  2040. }
  2041. //是否 "门清",
  2042. proto.isMQ = function (shoupai,PGPai,chengju) {
  2043. if(this.kexuanList[2] != 1) return false;
  2044. return shoupai.length == (CARDS_COUNT+1) && PGPai.length == 0
  2045. }
  2046. //是否 "清一色",
  2047. proto.isQYS = function (shoupai,PGPai,chengju) {
  2048. let huaSe= 0;
  2049. for (let n = 0; n < shoupai.length; ++n) {
  2050. let card = shoupai[n];
  2051. if(huaSe == 0){
  2052. huaSe = this.getType(card);
  2053. }
  2054. else{
  2055. if(this.getType(card) != huaSe){
  2056. return false;
  2057. }
  2058. }
  2059. }
  2060. ////上面是统计手牌花色种类,下面是统计碰杠牌的花色
  2061. if(PGPai && PGPai.length > 0){
  2062. for (let i = 0; i < PGPai.length; ++i) {
  2063. if(!PGPai[i]) continue;
  2064. let pgcardlist = PGPai[i].cards;
  2065. if(!pgcardlist) continue;
  2066. let card2 = pgcardlist[0];
  2067. if(this.getType(card2) != huaSe){
  2068. return false;
  2069. }
  2070. }
  2071. }
  2072. return true;
  2073. };
  2074. // 是否碰碰胡
  2075. proto.isPengPengHu = function (shoupai,PGPai,chengju) {
  2076. // console.warn("是否碰碰胡000 shoupai "+shoupai+" PGPai "+JSON.stringify(PGPai));
  2077. // console.warn("是否碰碰胡111 chengju "+JSON.stringify(chengju));
  2078. let cjlist = chengju.huCards
  2079. if(!cjlist) return false;/////七对的话没有chengju,所以直接返回false
  2080. // console.warn("是否碰碰胡222 "+JSON.stringify(chengju));
  2081. let keOrGangCount = 0;
  2082. for (let i = 0; i < cjlist.length; ++i) {
  2083. if(cjlist[i].style >= 3 && cjlist[i].style <= 10) keOrGangCount += 1;
  2084. }
  2085. // return keOrGangCount == 4 && chengju.jiang > 0;
  2086. if(keOrGangCount == 4 && chengju.jiang > 0) return true;
  2087. let huCards2 = this.deepCloneTL(PGPai)
  2088. // console.warn("判断13不搭手上百搭牌个数出错了?????",baiDaCount22,this.sbyBDList,bdIndexlist)
  2089. var huRes = { card: 0, jiang: 0, huCards: [] };
  2090. // 重设将牌
  2091. var resetHuRes = (jiang) => {
  2092. huRes.jiang = jiang;
  2093. huRes.huCards = [];
  2094. for (let huCard of huCards2) huRes.huCards.push(huCard);
  2095. };
  2096. for (let i = 0; i < shoupai.length - 1; ++i) {
  2097. let handCards = this.deepCloneTL(shoupai)
  2098. if (!this.isJang(handCards[i], handCards[i + 1])) continue;
  2099. // console.warn("判断13不搭手上百搭牌个数出错了?????000 ",JSON.stringify(huRes))
  2100. resetHuRes(handCards[i]);////设置将牌
  2101. // console.warn("判断13不搭手上百搭牌个数出错了?????111 ",JSON.stringify(huRes))
  2102. let bcjp = handCards[i];
  2103. let cards = handCards.slice(0, i);////手牌数组的前i个元素
  2104. cards = cards.concat(handCards.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
  2105. this._dumpFixed(cards, huRes.huCards);
  2106. // console.warn("判断13不搭手上百搭牌个数出错了?????222 ",JSON.stringify(huRes))
  2107. i += 1;/////TL++,为了减少运算
  2108. if(huRes.huCards.length == 4){
  2109. let keOrGangCount = 0;
  2110. for (let j = 0; j < huRes.huCards.length; ++j) {
  2111. if(huRes.huCards[j].style >= 3 && huRes.huCards[j].style <= 10) keOrGangCount += 1;
  2112. }
  2113. // console.warn("是否碰碰胡333 "+JSON.stringify(huRes)+" keOrGangCount "+keOrGangCount);
  2114. if(keOrGangCount == 4 && huRes.jiang > 0) return true;
  2115. }
  2116. }
  2117. return false;
  2118. };
  2119. //是否杠开
  2120. proto.isGangKai = function (shoupai,PGPai,chengju) {
  2121. // console.warn("是否杠开 ",this.currChairIDTL,JSON.stringify(this.isGGMG),JSON.stringify(this.isGGAG),JSON.stringify(this.isGGFXG));
  2122. // if(this.isSeleCatcedCard){
  2123. // if(this.isGGMG[this.currChairIDTL] || this.isGGAG[this.currChairIDTL] || this.isGGFXG[this.currChairIDTL]){
  2124. // return true;/////普通杠开
  2125. // }
  2126. // }
  2127. ////上面是判断刚开的方法,下面是可以杠开和杠炮都判断,因为杠开和杠炮不能同时存在
  2128. for (var i = 0; i < this.isGGMG.length; i++) {
  2129. if(this.isGGMG[i]) return true;
  2130. }
  2131. for (var i = 0; i < this.isGGAG.length; i++) {
  2132. if(this.isGGAG[i]) return true;
  2133. }
  2134. for (var i = 0; i < this.isGGFXG.length; i++) {
  2135. if(this.isGGFXG[i]) return true;
  2136. }
  2137. return false;
  2138. }
  2139. //是否抢杠胡
  2140. proto.isQiangGang = function (shoupai,PGPai,chengju) {
  2141. return this.isLaGang
  2142. }
  2143. //是否海底捞月
  2144. proto.isHDLY = function (shoupai,PGPai,chengju) {
  2145. // console.error("是否海底捞月 "+" this.isZHYZ "+this.isZHYZ+" this.lastCount "+this.lastCount);
  2146. return (this.isZHYZ && this.lastCount == 0)
  2147. }
  2148. // 获得奖码列表和计算奖码分数函数
  2149. proto.getJiangmaInfo = function () {
  2150. // console.warn("获得奖码列表函数 奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中 "+this.jiangmaType)
  2151. let jiangmaList = []
  2152. let jmzs = this.jiangmaCount;//奖码张数
  2153. let castC1 = this.castCount;//已经消耗的
  2154. let lastC1 = this.lastCount;
  2155. for (var i = 0; i < jmzs; i++) {
  2156. let card = 0;
  2157. if (lastC1 > 0) {
  2158. card = this.cardsPool[castC1++];
  2159. lastC1 -= 1;
  2160. }
  2161. if(card > 0) jiangmaList[i] = card;
  2162. else break;
  2163. }
  2164. let startNum1 = 0;/////骰子1的点数
  2165. let startNum2 = 0;/////骰子2的点数
  2166. if(jiangmaList.length < jmzs){
  2167. //抓鸟牌时牌堆剩余牌张数不足的时候通过掷骰子来凑数
  2168. startNum1 = this.dice();/////骰子1的点数
  2169. startNum2 = this.dice();/////骰子2的点数
  2170. }
  2171. // console.warn("获得奖码列表函数 奖码列表 ",jiangmaList," 长度 ",jiangmaList.length," addThisIsHu ",this.addThisIsHu)
  2172. //下面是计算奖码分数
  2173. let mafen = 0;
  2174. return { jiangmaList:jiangmaList,mafen:mafen,startNum1:startNum1,startNum2:startNum2}
  2175. };
  2176. //得到本局的各个玩家的中鸟个数
  2177. proto.getBJGWJZBGS = function (chairId,jiangmaList,diceNum1,diceNum2,lead,yjList) {
  2178. // console.warn("每个玩家中鸟个数 chairId " , chairId,jiangmaList,diceNum1,diceNum2,lead,JSON.stringify(yjList));
  2179. let tzdsfbqk = [0,0,0,0];//点数分布情况
  2180. if(jiangmaList.length == 0){
  2181. let dices = diceNum1;
  2182. if(dices == 1 || dices == 5) tzdsfbqk[0]++;
  2183. else if(dices == 2 || dices == 6) tzdsfbqk[1]++;
  2184. else if(dices == 3) tzdsfbqk[2]++;
  2185. else if(dices == 4) tzdsfbqk[3]++;
  2186. let dices2 = diceNum2;
  2187. if(dices2 == 1 || dices2 == 5) tzdsfbqk[0]++;
  2188. else if(dices2 == 2 || dices2 == 6) tzdsfbqk[1]++;
  2189. else if(dices2 == 3) tzdsfbqk[2]++;
  2190. else if(dices2 == 4) tzdsfbqk[3]++;
  2191. }
  2192. else if(jiangmaList.length == 1){
  2193. let dices = diceNum1+diceNum2;
  2194. if(dices == 5 || dices == 9) tzdsfbqk[0]++;
  2195. else if(dices == 2 || dices == 6 || dices == 10) tzdsfbqk[1]++;
  2196. else if(dices == 3 || dices == 7 || dices == 11) tzdsfbqk[2]++;
  2197. else if(dices == 4 || dices == 8 || dices == 12) tzdsfbqk[3]++;
  2198. let cardValue = this.getValue(jiangmaList[0])
  2199. if(cardValue == 1 || cardValue == 5 || cardValue == 9) tzdsfbqk[0]++;
  2200. else if(cardValue == 2 || cardValue == 6) tzdsfbqk[1]++;
  2201. else if(cardValue == 3 || cardValue == 7) tzdsfbqk[2]++;
  2202. else if(cardValue == 4 || cardValue == 8) tzdsfbqk[3]++;
  2203. }
  2204. else if(jiangmaList.length == 2){
  2205. for (var i = 0; i < jiangmaList.length; i++) {
  2206. let cardValue = this.getValue(jiangmaList[i])
  2207. if(cardValue == 1 || cardValue == 5 || cardValue == 9) tzdsfbqk[0]++;
  2208. else if(cardValue == 2 || cardValue == 6) tzdsfbqk[1]++;
  2209. else if(cardValue == 3 || cardValue == 7) tzdsfbqk[2]++;
  2210. else if(cardValue == 4 || cardValue == 8) tzdsfbqk[3]++;
  2211. }
  2212. }
  2213. // let result = [];
  2214. // if(this.playerAllCount == 2) result = [0,0];
  2215. // else if(this.playerAllCount == 3) result = [0,0,0];
  2216. // else if(this.playerAllCount == 4) result = [0,0,0,0];
  2217. // let cell = this.qshuTypeTL[qshType][1] || 0;
  2218. // console.warn("每个玩家中鸟个数000==== tzdsfbqk " + tzdsfbqk);
  2219. let everyZNGS = [0,0,0,0];//每个玩家中鸟个数
  2220. if(this.playerAllCount == 2){
  2221. if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
  2222. else if(chairId == 1) everyZNGS = [tzdsfbqk[1],tzdsfbqk[0],tzdsfbqk[2],tzdsfbqk[3]];
  2223. }
  2224. else if(this.playerAllCount == 3){
  2225. if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
  2226. else if(chairId == 1) everyZNGS = [tzdsfbqk[2],tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[3]];
  2227. else if(chairId == 2) everyZNGS = [tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[0],tzdsfbqk[3]];
  2228. }
  2229. else if(this.playerAllCount == 4){
  2230. if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
  2231. else if(chairId == 1) everyZNGS = [tzdsfbqk[3],tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2]];
  2232. else if(chairId == 2) everyZNGS = [tzdsfbqk[2],tzdsfbqk[3],tzdsfbqk[0],tzdsfbqk[1]];
  2233. else if(chairId == 3) everyZNGS = [tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3],tzdsfbqk[0]];
  2234. }
  2235. // console.warn("每个玩家中鸟个数111==== everyZNGS " + everyZNGS);
  2236. if(lead != -1){
  2237. for (var i = 0; i < everyZNGS.length; i++) {
  2238. if(chairId == lead){
  2239. //自己是抓鸟者又是点炮者,说明自己是一炮多响了
  2240. //一炮多响的时候,不是赢家也不是点炮者不中鸟
  2241. if (yjList.indexOf(i) == -1 && i != lead) everyZNGS[i] = 0;
  2242. }
  2243. else{
  2244. //正常的点炮,不是点炮者也不是赢家就不中鸟了
  2245. if(i != chairId && i != lead) everyZNGS[i] = 0;
  2246. }
  2247. }
  2248. }
  2249. // console.warn("每个玩家中鸟个数222==== everyZNGS " + everyZNGS);
  2250. return everyZNGS;
  2251. }
  2252. //得到起手胡牌型的总分
  2253. proto.getQSHFen = function (chairID) {
  2254. // console.error("得到起手胡牌型的总分 "+chairID+" "+this.everyXiaoHuList[chairID]+" cd "+this.everyXiaoHuList[chairID].length);
  2255. let count = 0;
  2256. for (var i = 0; i < this.everyXiaoHuList[chairID].length; i++) {
  2257. let zl = this.everyXiaoHuList[chairID][i];
  2258. count+=this.qshuTypeTL[zl][1];
  2259. }
  2260. return count;
  2261. };
  2262. //得到本次起手/中途胡牌型的各个玩家的输赢
  2263. proto.getBCQSHSY = function (chairId,qshType,diceNum1,diceNum2) {
  2264. let result = [];
  2265. if(this.playerAllCount == 2) result = [0,0];
  2266. else if(this.playerAllCount == 3) result = [0,0,0];
  2267. else if(this.playerAllCount == 4) result = [0,0,0,0];
  2268. let cell = this.qshuTypeTL[qshType][1] || 0;
  2269. let dices = [diceNum1,diceNum2];
  2270. let tzdsfbqk = [0,0,0,0];//骰子点数分布情况
  2271. for (var i = 0; i < dices.length; i++) {
  2272. if(dices[i] == 1 || dices[i] == 5) tzdsfbqk[0]++;
  2273. else if(dices[i] == 2 || dices[i] == 6) tzdsfbqk[1]++;
  2274. else if(dices[i] == 3) tzdsfbqk[2]++;
  2275. else if(dices[i] == 4) tzdsfbqk[3]++;
  2276. }
  2277. let everyZNGS = [0,0,0,0];//每个玩家中鸟个数
  2278. if(this.playerAllCount == 2){
  2279. if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
  2280. else if(chairId == 1) everyZNGS = [tzdsfbqk[1],tzdsfbqk[0],tzdsfbqk[2],tzdsfbqk[3]];
  2281. }
  2282. else if(this.playerAllCount == 3){
  2283. if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
  2284. else if(chairId == 1) everyZNGS = [tzdsfbqk[2],tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[3]];
  2285. else if(chairId == 2) everyZNGS = [tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[0],tzdsfbqk[3]];
  2286. }
  2287. else if(this.playerAllCount == 4){
  2288. if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
  2289. else if(chairId == 1) everyZNGS = [tzdsfbqk[3],tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2]];
  2290. else if(chairId == 2) everyZNGS = [tzdsfbqk[2],tzdsfbqk[3],tzdsfbqk[0],tzdsfbqk[1]];
  2291. else if(chairId == 3) everyZNGS = [tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3],tzdsfbqk[0]];
  2292. }
  2293. let bsList = [1,2,4];//分表表示中0,1,2鸟输1,2,4倍
  2294. for (let i = 0; i < this.playerAllCount; ++i) {
  2295. if(i == chairId) continue;
  2296. let gs = everyZNGS[i]+everyZNGS[chairId];
  2297. let sy = bsList[gs] * cell;
  2298. result[i] -= sy;
  2299. result[chairId] += sy;
  2300. }
  2301. // console.warn("每个玩家中鸟个数==== tzdsfbqk "+tzdsfbqk + " everyZNGS " + everyZNGS+" result "+result);
  2302. // for (var i = 0; i < result.length; i++) {
  2303. // if(everyZNGS[i] == 0) result = cell;
  2304. // else if(everyZNGS[i] == 1) result = cell*2;
  2305. // else if(everyZNGS[i] == 2) result = cell*4;
  2306. // }
  2307. return result;
  2308. }
  2309. //得到大胡牌型的总分
  2310. proto.getDaHuFen = function (chairID) {
  2311. let count = 0;
  2312. for (var i = 0; i < this.everyDAHType[chairID].length; i++) {
  2313. if(this.everyDAHType[chairID][i] == 1) count+=this.dahuTypeTL[i][1];
  2314. }
  2315. if(count == 0) count = 2;
  2316. return count;
  2317. };
  2318. //得到大胡牌型的总分2
  2319. proto.getDaHuFen2 = function (chairID,typeList) {
  2320. let count = 0;
  2321. for (var i = 0; i < typeList.length; i++) {
  2322. if(typeList[i] == 1) count+=this.dahuTypeTL[i][1];
  2323. }
  2324. if(count == 0) count = 2;
  2325. return count;
  2326. };
  2327. //得到点炮者
  2328. proto.getLead = function (chairID,lead,yjList) {
  2329. let res = -100;
  2330. if(chairID != -1){
  2331. let yjgs = yjList.length
  2332. if(yjgs > 1){
  2333. res = chairID;
  2334. }
  2335. else if(yjgs == 1){
  2336. if(yjList[0] == chairID){
  2337. res = -1;
  2338. }
  2339. else{
  2340. res = chairID;
  2341. }
  2342. }
  2343. else if(yjgs == 0){
  2344. res = -1;
  2345. }
  2346. }
  2347. if(res == -100) res = lead;
  2348. return res;
  2349. }