| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209 |
- 'use strict';
- //// 为什么选择 Lodash ?
- //// Lodash 通过降低 array、number、objects、string 等等的使用难度从而让 JavaScript 变得更简单。
- //// Lodash 的模块化方法 非常适用于:
- //// 遍历 array、object 和 string
- //// 对值进行操作和检测
- //// 创建符合功能的函数
- var _ = require('lodash');
- var quick = require('quick-pomelo');
- var logger = quick.logger.getLogger('fhmj', __filename);
- // 所有牌
- const CARDS = [
- 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
- 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
- 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
- // 51, // 中
- 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
- 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
- 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
- // 51, // 中
- 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
- 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
- 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
- // 51, // 中
- 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
- 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
- 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
- // 51, // 中
- ];
- // 块类型
- const STYLE = {
- NULL: 0, // 无效
- CHI: 1, // 吃牌
- SUN: 2, // 顺序
- PENG: 3, // 碰子
- KE: 4, // 刻子
- GANG: 5, // 杠子
- ANGANG: 6, // 暗杠
- ZMGANG: 7, // 自摸明杠
- BU: 8, // 补子
- ANBU: 9, // 暗补
- ZMBU: 10, // 自摸明补
- // LIANGBD:9, // TL++两张百搭和一张普通牌组成一个块
- // SANBD:10, // TL++三张百搭和一张普通牌组成一个块
- };
- // 椅子数
- const CHAIR_COUNT = 4;
- const CARDS_COUNT = 13;
- // 构造方法
- var Logic = function (type,gameKindTL,playerAllCount,other) {
- // 类型
- this.type = type;
- this.other = other;//////TL++2人3人的游戏规则
- this.jiangmaCount = 2;////奖码张数(抓鸟张数)
- this.kexuanList = [0,0,0,0];
- if(this.other & 1){
- this.kexuanList[0] = 1;//勾选了中途大四喜
- }
- if(this.other & 2){
- this.kexuanList[1] = 1;//勾选了中途六六顺
- }
- if(this.other & 4){
- this.kexuanList[2] = 1;//勾选了门清
- }
- if(this.other & 256){
- this.kexuanList[3] = 1;//勾选了小胡只能自摸
- }
- this.hzCount = 0;/////红中个数
- this.fengDingType = 0;/////封顶类型1:不封顶;2:封顶56分;3:封顶112分;
- if(this.other & 8){
- this.fengDingType = 1;
- }
- else if(this.other & 16){
- this.fengDingType = 2;
- }
- else if(this.other & 32){
- this.fengDingType = 3;
- }
- this.ZNJSType = 0;/////中鸟结算类型1:中鸟相加;2:中鸟相乘;
- if(this.other & 64){
- this.ZNJSType = 1;
- }
- else if(this.other & 128){
- this.ZNJSType = 2;
- }
- this.gameKindTL = 1;//1:传统;2:割索;3:疯狂
- if(this.other & 512){
- this.gameKindTL = 2;
- }
- else if(gameKindTL == 3){
- this.gameKindTL = 3;//疯狂
- this.hzCount = 4;/////红中个数 疯狂模式默认为4张红中
- }
- this.isZNZM = false;/////是否只能自摸,拉杠情况可以胡
- // console.warn("封顶类型1:不封顶;2:封顶56分;3:封顶112分 "+this.fengDingType)
- // console.warn("中鸟结算类型1:中鸟相加;2:中鸟相乘 "+this.ZNJSType)
- // console.warn("logicfk可选列表 ffffkkkk222 "+this.kexuanList)
- // 七对
- // this.has7d = true;/////TL++因为奉化麻将当中本身就可以胡7对
- // 全牌
- var cards = _.clone(CARDS);
- // 添加红中红中
- if (this.hzCount > 0){
- for (let i = 0; i < this.hzCount; ++i) {
- cards[cards.length] = 51;
- }
- }
-
- this.castCount = 0;
- this.disCount = 0;
- this.lastCount = cards.length;//////设置剩余牌数为了测试海底捞月
- this.cardsPool = cards;
- this.cardsyl = _.clone(cards);
- // console.warn(" this.cardsyl "+this.cardsyl+" lastCount "+this.lastCount);
- //////以下变量全是TL++
- this.playerAllCount = playerAllCount || 4;////游戏人数 = 2表示2人局 = 3表示3人局 = 4表示4人局
- this.setCardFilerIndex = 0
- this.baiDaCard = 51;/////TL++,拿到百搭牌
- this.baiDaList = [0,0,0];/////TL++,拿到百搭牌数组
- this.sbyBDList = []//////得到某人手中的百搭牌数组
-
- this.chuPaiCountTL = 0//////TL++,记录出牌的个数,为了判断天胡和地胡
- this.moPaiCountTL = 0//////TL++,记录出牌的个数,为了判断天胡和地胡
- this.lastMoPaiChairID = 0//////TL++,最后一个摸牌玩家的id
-
- this.addThisIsHu = 0//////TL++,胡牌判断时加上这张能不能胡
- this.isSeleCatcedCard = false//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
- this.currChairIDTL = 0/////当前判断胡的chairID,用于得到当前玩家的胡牌情况
- this.isGGMG = [false,false,false,false];//////TL++,是否刚刚直杠(明杠)用于判断是否是直杠杠开
- this.isGGAG = [false,false,false,false];//////TL++,是否刚刚暗杠用于判断是否暗杠杠开
- this.isGGFXG = [false,false,false,false];//////TL++,是否刚刚风险杠用于判断是否风险杠杠开
- this.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- this.isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1],]/////TL++,各个玩家在本轮是否点击了过胡和点击过牌时的台数
- this.setCardFileName = '';/////设置手牌的文件名
- this.cardGroupIndex = 0;////要设置的牌型种类
-
- this.isZHYZ = false;/////是不是最后1张
- this.isMZWF = [0,1,2,3];/////是不是满足位风
- /////TL++每个人满足的的起手胡胡牌类型
- this.everyQSHType = [
- [],[],[],[]
- ]
- this.canSelects = [//各个起手胡玩家可以选择的牌型
- [],[],[],[]
- ];
- /////TL++每个人满足的的起手胡胡牌类型操作过的牌
- this.everyQSHCZGList = [
- [],[],[],[]
- ]
- /////TL++每个人满足的的起手胡胡牌类型操作过的牌
- this.everyQSHCZGList2 = [
- [],[],[],[]
- ]
- this.qshuTypeTL = [
- /////分别表示起手胡牌型和台数
- ["四喜",2,], ///// 0 起完牌后,玩家手上已有四张一样的牌;
- ["板板胡",2,], ///// 1 起完牌后,玩家手上没有一张2、5、8牌;
- ["缺一色",2,], ///// 2 起完牌后,玩家手上筒、索、万任缺一门;
- ["六六顺",2,], ///// 3 起完牌后,玩家手上已有2个刻子(刻子:三个一样的牌);
- ["中途四喜",2,], ///// 4 玩家在牌局过程中,手中有四张相同的牌;
- ["中途六六顺",2,], ///// 5 起完牌后,玩家手上已有2个刻子(刻子:三个一样的牌);
- // ["节节高",2,], ///// 4 起完牌后,起完牌后,玩家手上有3连对且同花色;(例如2个3万,2个4万,2个5万);
- // ["三同",2,], ///// 5 起完牌后,玩家手上有3对点数相同的牌;(例如2个3万,2个3筒,2个3条)
- // ["单将一枝花",2,], ///// 6 起完牌后,玩家手上只有一张将牌(2、5、8),且这只将牌为“5”;
- // ["单五一枝花",2,], ///// 7 起完牌后,玩家手上只有一张将牌(2、5、8),且这只将牌为“5”;
- ]
- this.everyXiaoHuList = [
- [],[],[],[]
- ];//每个玩家的起手胡牌型用于算分
- /////TL++每个人满足的的大胡胡牌类型
- this.everyDAHType = [
- [],[],[],[]
- ]
- this.dahuTypeTL = [
- /////分别表示大胡牌型和台数
- // ["天胡",6,], ///// 0 单指庄家,庄家起牌后,即已经胡牌。(需要2、5、8做将)
- // ["地胡",6,], ///// 1 指闲家,当庄家打出第一张牌时,给闲家点炮。(需要2、5、8做将);
- ["七小对",7,], ///// 0 胡牌时,手上任意七对将牌(无需2、5、8做将);
- ["豪华七小对",7,],///// 1 手上任意七对牌,且其中有4张一样的牌(不能杠,算作2对);
- ["双豪华七小对",7,],///// 2 手上任意七对牌,且其中有2种4张一样的牌(不能杠,算作2对);
- ["三豪华七小对",7,],///// 13手上任意七对牌,且其中有3种4张一样的牌(不能杠,算作2对);
- ["将将胡",7,], ///// 4 玩家手上每一张牌都为2、5、8;
- ["全求人",7,], ///// 5 玩家通过吃、碰、杠而使得最后手中只剩下一颗牌,当摸或其他玩家打出这张牌时,即可胡牌;
- ["门清",7,], ///// 6 玩家没有吃、碰、杠等操作,胡牌时手上有14张牌,自己摸到的算门清别人打的不算门清;
- ["清一色",7,], ///// 7 玩家手中的牌全部由同一种花色(万、筒、条)组成;
- ["碰碰胡",7,], ///// 8 碰碰胡:玩家所有的牌均为刻子或将牌,乱将(无需2、5、8做将),可碰,可杠,可自摸;
- ["杠开(杠炮)",7,], ///// 9 自己杠上开花(需要2、5、8做将)
- ["抢杠胡",7,], ///// 10 (需要2、5、8做将);
- ["海底胡",7,], ///// 11 最后一张牌为海底牌。玩家选择要海底牌且通过这张海底牌胡牌,则为海底捞月,(是否需要2、5、8将根据当前牌型决定)
- ["天胡",7,], ///// 12 单指庄家,庄家起牌后,就有4个红中
- // ["杠上炮",7,], ///// 10 单指庄家,庄家起牌后,即已经胡牌。(需要2、5、8做将)
- // ["海底炮",7,], ///// 11 单指庄家,庄家起牌后,即已经胡牌。(需要2、5、8做将)
- ]
- // console.warn("ppppppppppp 长度 "+cards.length+" cards "+cards);
- };
- Logic.setHCfileNameList =[/////全部设置牌型的文件名
- "setHandCard_tianhu",
- ]
- // 导出常量
- Logic.CARDS = CARDS;
- Logic.STYLE = STYLE;
- Logic.CHAIR_COUNT = CHAIR_COUNT;
- Logic.CARDS_COUNT = CARDS_COUNT;
- // 导出类
- module.exports = Logic;
- // 原型对象
- var proto = Logic.prototype;
- /////TL++为了得到百搭牌数组用于判断是否需要补花和手牌中百搭牌个数
- proto.setBDList = function () {
- this.baiDaList = [this.baiDaCard,this.baiDaCard,this.baiDaCard]/////TL++,拿到百搭牌
- };
- ///////TL++在table类中出牌函数中调用,为了判断天胡和地胡
- proto.chuPaiTL = function () {
- // console.warn("111c天胡判断不正确",this.chuPaiCountTL);
- this.chuPaiCountTL += 1//////这个其实并不是真实的出牌个数,因为这个方法的调用在判断吃碰杠胡之前调用的
- }
- ///////TL++在table类中出牌函数中调用,为了判断天胡和地胡
- proto.moPaiTL = function () {
- // console.warn("111c天胡判断不正确",this.chuPaiCountTL);
- this.moPaiCountTL += 1//////TL++,记录出牌的个数,为了判断天胡和地胡 += 1
- }
-
- ///////TL++重置默认数据,在每局游戏开始的洗牌函数中调用
- proto.resetDataOnGameStart = function () {
- for (let i = 0; i < this.everyQSHType.length; ++i) {
- this.everyQSHType[i] = []
- }
- for (let i = 0; i < this.everyQSHCZGList.length; ++i) {
- this.everyQSHCZGList[i] = []
- }
- for (let i = 0; i < this.everyQSHCZGList2.length; ++i) {
- this.everyQSHCZGList2[i] = []
- }
- for (let i = 0; i < this.everyXiaoHuList.length; ++i) {
- this.everyXiaoHuList[i] = []
- }
- for (let i = 0; i < this.everyDAHType.length; ++i) {
- this.everyDAHType[i] = []
- }
- this.chuPaiCountTL = 0//////TL++出牌个数
- this.moPaiCountTL = 0//////TL++,记录摸牌的个数,为了判断天胡和地胡
- this.lastMoPaiChairID = 0//////TL++,最后一个摸牌玩家的id
- this.addThisIsHu = 0//////TL++,胡牌判断时加上这张能不能胡
- this.isSeleCatcedCard = false//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
- this.currChairIDTL = 0/////当前判断胡的chairID,用于得到当前玩家的花牌情况
- this.isGGMG = [false,false,false,false];;//////TL++,是否刚刚直杠(明杠)用于判断是否是直杠杠开
- this.isGGAG = [false,false,false,false];//////TL++,是否刚暗杠用于判断是否暗杠杠开
- this.isGGFXG = [false,false,false,false];//////TL++,是否刚刚风险杠用于判断是否风险杠杠开
- this.isLaGang = false;//////TL++,是否刚刚被拉杠用于判断是否被拉杠胡
- this.isGuoHuList = [[false,-1],[false,-1],[false,-1],[false,-1],]/////TL++,各个玩家在本轮是否点击了过胡和点击过牌时的台数
- this.isZHYZ = false;/////是不是最后1张
- }
- // 重新洗牌
- proto.shuffle = function () {
- this.castCount = 0;
- this.disCount = 0;
- this.cardsPool = _.clone(this.cardsyl);
- this.lastCount = this.cardsPool.length;
- this.cardsPool = _.shuffle(this.cardsPool);////随机打乱一个数组
- this.cardsPool = _.shuffle(this.cardsPool);////洗第二次牌
- // this.cardsPool = _.shuffle(this.cardsPool);////洗第三次牌
- };
- // 填充数组
- proto.fillDeep = function (array, o, isMore) {
- for (let i = 0; i < array.length; ++i) {
- if (!isMore) {
- array[i] = _.clone(o);
- } else {
- array[i] = _.cloneDeep(o);/////深度拷贝,就是重新分配内存空间,浅拷贝则是两个变量共用一个内存对象
- }
- }
- return array;
- };
- //////TL++ 深复制一个object类型的数据
- proto.deepCloneTL = function (obj){
- let objClone = Array.isArray(obj)?[]:{};
- if(obj && typeof obj==="object"){
- for(let key in obj){
- if(obj.hasOwnProperty(key)){
- //判断ojb子元素是否为对象,如果是,递归复制
- if(obj[key]&& typeof obj[key] ==="object"){
- objClone[key] = this.deepCloneTL(obj[key]);
- }else{
- //如果不是,简单复制
- objClone[key] = obj[key];
- }
- }
- }
- }
- return objClone;
- };
- // 获取类型
- proto.getType = function (card) {
- return Math.floor(card / 10);
- };
- // 获取牌值
- proto.getValue = function (card) {
- return card % 10;
- };
- // 手牌排序
- proto.sort = function (handCards) {
- return _.sortBy(handCards);///降序排序
- };
- // 删除手牌 /////TL++参数isBuHua表示是否因为补花而造成的删除牌
- proto.remove = function (handCards, cards) {
- if (typeof (cards) == 'number') {
- if (cards == handCards[handCards.length - 1]) {
- return (handCards.pop(), true);
- } else {
- let pos = handCards.indexOf(cards);
- if (pos == -1) return false;
- return (handCards.splice(pos, 1), true);
- }
- }
- var length = cards.length;
- if (length > 1 && cards[0] == cards[length - 1]) {
- if (cards[0] == handCards[handCards.length - 1]) {
- handCards.pop();
- length -= 1;
- }
- let pos = handCards.indexOf(cards[0]);
- if (pos == -1) return false;
- handCards.splice(pos, length);
- } else {
- for (let i = 0; i < length; ++i) {
- let pos = handCards.indexOf(cards[i]);
- if (pos == -1) return false;
- handCards.splice(pos, 1);
- }
- }
- return true;
- };
- // 调整手牌
- proto.adjust = function (handCards) {
- var length = handCards.length;
- if (length < 2) return false;
- if (handCards[length - 1] < handCards[length - 2]) {
- let moCard = handCards.pop();
- let pos = _.findIndex(handCards, (i) => (i >= moCard));
- if (pos == -1) handCards.push(moCard);
- else handCards.splice(pos, 0, moCard);
- }
- return true;
- };
- // 投骰子
- proto.dice = function () {
- return _.random(1, 6);
- };
- // 剩余牌数
- proto.leaveCount = function () {
-
- return this.lastCount;
- };
- //////TL++,人工设置测试牌型
- proto.setTestSendCardsTL = function () {
- this.setCardFileName = '';
- let fileName = "setHandCard_tianhu"
- if(!fileName) return;/////文件名字不存在
- // console.warn("设置手牌的文件名",fileName);
- this.setCardFileName = fileName
- delete require.cache[require.resolve('./setcard/' + fileName)];
- var SetHandCardTL = require('./setcard/' + fileName);
- if(!SetHandCardTL) return;
- //////TL++,设置手牌的文件
- this.setHandCardTL = new SetHandCardTL();
-
- ////console.error("洗牌之后的牌",this.cardsPool);
- let ccc = this.setHandCardTL.getSCFP(this.cardGroupIndex)
- if(ccc){//////已经设置的手牌发完了就随机发牌
- this.cardsPool = ccc/////设置手牌的地方 设置牌
- this.cardGroupIndex += 1; ////此句是否存在代表是否只发某一种牌型
- // SetHandCardTL.cardGroupIndex += 1; ////此句是否存在代表是否只发某一种牌型
- // if(SetHandCardTL.cardGroupIndex == 1) SetHandCardTL.cardGroupIndex = 0
- }
- else{
- this.setCardFilerIndex += 1;
- this.cardGroupIndex = 0;
- // SetHandCardTL.cardGroupIndex = 0;
- if(Logic.setCardFilerIndex < Logic.setHCfileNameList.length) this.setTestSendCardsTL()
- }
- }
- // 初始手牌
- proto.handCards = function (chBanker,_PJHF,_over,recordid,_ctime) {
- this.resetDataOnGameStart()//////TL++
- this.shuffle();
- // if(this.hzCount == 8) {
- // 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]
- // this.setTestSendCardsTL()///////设置手牌的地方,设置发牌 不需要设置的时候注释掉这个方法就可以了
- // this.lastCount = this.cardsPool.length;//////设置剩余牌数设置剩余牌数,测试完这句要删掉
- // }
- let dqjs = _over + 1;
- _PJHF.writexpJson(this.deepCloneTL(this.cardsPool),dqjs,recordid,_ctime);
-
- //// 下面这个是随机发牌但是起手发lzgs张癞子的逻辑
- // let lzgs = 2//癞子个数
- // let djg = 0;
- // for (let i = 0; i < this.cardsPool.length; i++) {
- // if(this.cardsPool[i] == 51){
- // let xx = this.cardsPool[djg]
- // this.cardsPool[djg] = 51;
- // this.cardsPool[i] = xx;
- // djg++
- // if(djg >= lzgs){
- // break
- // }
- // }
- // }
- /////TL++设置百搭牌数组
- this.setBDList()
- var result = [];
- var castCount = 0;
- for (let i = 0; i < this.playerAllCount; ++i) {
- let cardCount = CARDS_COUNT;
- if (i == chBanker) cardCount += 1;
- let cards = this.cardsPool.slice(castCount, castCount + cardCount);
- castCount += cardCount;
- result.push({ cards: this.sort(cards) });
- }
- this.castCount += castCount
- this.lastCount -= castCount;
- // this.lastCount -= this.disCountTL;////因为翻出来的百搭牌不能被摸走
- // console.error("发的手牌",result);
- return result;
- };
- // 是否无牌
- proto.isNoCards = function () {
- return this.lastCount <= 0;
- };
- // 摸牌函数
- proto.moCard = function (isgang) {
- // console.error("摸排摸排--------isgang ",isgang,this.disCountTL,this.lastCount);
- var card = 0;
- if(isgang){
- let card1 = 0;
- if (this.lastCount > 1) {
- card1 = this.cardsPool[this.castCount++];
- this.lastCount -= 1;
- }
- let card2 = 0;
- if (this.lastCount > 0) {
- card2 = this.cardsPool[this.castCount++];
- this.lastCount -= 1;
- }
- return { card1: card1,card2: card2 };
- }
- else{
- if (this.lastCount > 0) {
- card = this.cardsPool[this.castCount++];
- this.lastCount -= 1;
- }
- }
- return { card: card };
- };
- // 是否将牌
- proto.isJang = function (lcard, rcard) {
- return lcard == rcard;
- };
- ////判断吃碰补之后是否只剩下百搭牌了,因为如果吃碰补之后只剩下百搭牌,而百搭牌又不允许打出会造成玩家无牌可出的局面
- proto.isCanCPB = function (handCards,opeate,type) {
- // console.warn("判断吃碰补之后是否只剩下百搭牌了 length "+handCards.length +" handCards "+JSON.stringify(handCards)+" opeate "+opeate+" type "+type);
- let length = handCards.length;
- let baiDaCount22 = this.getBDCount(handCards)
- let needCost = 0;//进行操作需要消耗的张数
- if(opeate == STYLE.CHI || opeate == STYLE.PENG) needCost = 2;
- else if(opeate == STYLE.BU || opeate == STYLE.GANG){
- //补牌,1-普通补, 2-暗补, 3-自摸补
- //1-普通杠, 2-暗杠, 3-自摸明杠
- if(type == 1) needCost = 3;
- else if(type == 2) needCost = 4;
- else if(type == 3) needCost = 1;
- }
- // console.warn("判断吃碰补之后是否只剩下百搭牌了 length "+length +" baiDaCount22 "+baiDaCount22+" needCost "+needCost);
- return (length - needCost - baiDaCount22 > 0);
- }
- // 可否碰牌
- proto.isPeng = function (handCards, card) {
- if(card == 51) return false;
- for (let i = 0; i < handCards.length - 1; ++i) {
- if (handCards[i] == card && handCards[i + 1] == card) {
- return true;
- }
- }
- return false;
- };
- // 碰牌 TL++参数chirID为了判断圈风和位风
- proto.peng = function (chirID,handCards, card) {
- if (this.isPeng(handCards, card)) {
- return { style: STYLE.PENG, cards: [card, card, card], disc: [card] };
- }
- };
- // 吃牌,1-@**左吃, 2-*@*中吃, 3-@**右吃
- proto.chi = function (handCards, card, type) {
- var chis = this.chiAnalyze(handCards, card, type);
- if (chis[0]) {
- let res = { style: STYLE.CHI, type: type, disc: [card] };
- if (type == 1) {
- res.cards = [card, card + 1, card + 2];
- if (this.getValue(card) < 7) {
- res.disc.push(card + 3);
- }
- } else if (type == 2) {
- res.cards = [card - 1, card, card + 1];
- } else {
- res.cards = [card - 2, card - 1, card];
- if (this.getValue(card) > 3) {
- res.disc.push(card - 3);
- }
- }
- return res;
- }
- };
- // 杠牌,1-普通杠, 2-暗杠, 3-自摸明杠 TL++参数chirID为了判断圈风和位风
- proto.gang = function (chirID,handCards, card, type) {
- // 结果
- var res = null;
- // 明杠
- if (type == 1) {
- let gang = this.gangAnalyze(handCards, card);
- if (gang) {
- res = { style: STYLE.GANG, cards: [card, card, card] };
- }
- }
- // 暗杠
- else if (type == 2) {
- let anGang = this.anGangAnalyze(handCards, card);
- if (anGang[0]) {
- res = { style: STYLE.ANGANG, cards: [card, card, card] };
- }
- }
- return res;
- };
- // 自摸明杠,1-普通杠, 2-暗杠, 3-自摸明杠 TL++参数chirID为了判断圈风和位风
- proto.zmGang = function (chirID,handCards, huCards, card) {
- var zmGang = this.zmGangAnalyze(handCards, huCards, card);
- if (zmGang[0]) {
- return { style: STYLE.ZMGANG, cards: [card, card, card] };
- }
- };
- // 补牌,1-普通补, 2-暗补, 3-自摸明补 TL++参数chirID为了判断圈风和位风
- proto.bu = function (chirID,handCards, card, type) {
- // 结果
- var res = null;
- // 明补
- if (type == 1) {
- let bu = this.buAnalyze(handCards, card);
- if (bu) {
- res = { style: STYLE.BU, cards: [card, card, card] };
- }
- }
- // 暗补
- else if (type == 2) {
- let anBu = this.anBuAnalyze(handCards, card);
- if (anBu[0]) {
- res = { style: STYLE.ANBU, cards: [card, card, card] };
- }
- }
- return res;
- };
- // 自摸明补,1-普通补, 2-暗补, 3-自摸明补 TL++参数chirID为了判断圈风和位风
- proto.zmBu = function (chirID,handCards, huCards, card) {
- var zmBu = this.zmBuAnalyze(handCards, huCards, card);
- if (zmBu[0]) {
- return { style: STYLE.ZMBU, cards: [card, card, card] };
- }
- };
- // 吃牌分析,1-@**左吃, 2-*@*中吃, 3-@**右吃, type可以不传
- proto.chiAnalyze = function (handCards, card, type) {
- // 结果集合
- var result = [];
- if(card == 51) return result;
- // 排除风字
- if (handCards.length < 2 || card > 40) return result;
- // 查找句子
- var length = handCards.length;
- for (let i = 0; i < length; ++i) {
- // 牌面值
- let value = this.getValue(card);
- // @**左吃,吃类型(可以不指定)
- if (!type || type == 1) {
- if (value < 8 && i < length - 1) {
- if (handCards[i] == card + 1 && handCards[i + 1] == card + 2) {
- result.push({ type: 1, card: card });
- }
- }
- }
- // *@*中吃,吃类型(可以不指定)
- if (!type || type == 2) {
- if (value > 1 && value < 9 && i < length - 1) {
- if (handCards[i] == card - 1 && handCards[i + 1] != card - 1) {
- for (let j = i + 1; j < i + 5 && j < length; ++j) {
- if (handCards[j] == card + 1) {
- result.push({ type: 2, card: card });
- break;
- }
- }
- }
- }
- }
- // **@右吃,吃类型(可以不指定)
- if (!type || type == 3) {
- if (value > 2 && i < length - 1) {
- if (handCards[i] == card - 2 && handCards[i + 1] == card - 1) {
- result.push({ type: 3, card: card });
- }
- }
- }
- }
- return result;
- };
- // 普通杠分析,1-普通杠, 2-暗杠, 3-自摸明杠
- proto.gangAnalyze = function (handCards, card) {
- // 结果对象
- var result = null;
- if(card == 51) return result;//红中不能碰杠
- var length = handCards.length;
- if (length < 3) return result;
- // 查找同牌
- for (let i = 0; i < length - 2; ++i) {
- if (handCards[i] == card && handCards[i + 1] == card && handCards[i + 2] == card) {
- result = { type: 1, card: card };
- break;
- }
- }
- return result;
- };
- // 暗杠分析,1-普通杠, 2-暗杠, 3-自摸明杠, card可以不传
- proto.anGangAnalyze = function (handCards, card) {
- // 结果对象
- var result = [];
- var length = handCards.length;
- if (length < 4) return result;
- // 查找同牌
- var moCard = handCards[length - 1];
- for (let i = 0; i < length - 3; ++i) {
- // 指定杠牌,可以不指定
- if (card && handCards[i] != card) continue;
- // 判定是否刻子
- if (handCards[i] == handCards[i + 1] && handCards[i] == handCards[i + 2]) {
- // 手上有杠牌
- if (handCards[i] == handCards[i + 3]) {
- if(handCards[i] != 51){
- result.push({ type: 2, card: handCards[i] });
- }
- }
- // 刚摸到杠牌
- else if (handCards[i] == moCard) {
- if(handCards[i] != 51){
- result.push({ type: 2, card: moCard });
- }
- }
- }
- }
- return result;
- };
- // 自摸杠分析,1-普通杠, 2-暗杠, 3-自摸明杠, card可以不传
- proto.zmGangAnalyze = function (handCards, huCards, card) {
- // 返回结果
- var result = [];
- if(card == 51) return result;//红中不能碰杠
- // 遍历句子
- for (let i = 0; i < huCards.length; ++i) {
- if (huCards[i].style != STYLE.PENG) {
- continue;
- }
- let _card = huCards[i].cards[0];
- if (card && _card != card) continue;
- let pos = handCards.indexOf(_card);
- if (pos != -1) {
- result.push({ type: 3, card: _card });
- if (card) break;
- }
- }
- return result;
- };
- // 普通补分析,1-普通补, 2-暗补, 3-自摸明补
- proto.buAnalyze = function (handCards, card) {
- // 结果对象
- var result = null;
- if(card == 51) return result;//红中不能碰杠
- var length = handCards.length;
- if (length < 3) return result;
- // 查找同牌
- for (let i = 0; i < length - 2; ++i) {
- if (handCards[i] == card && handCards[i + 1] == card && handCards[i + 2] == card) {
- result = { type: 1, card: card };
- break;
- }
- }
- return result;
- };
- // 暗补分析,1-普通补, 2-暗补, 3-自摸明补, card可以不传
- proto.anBuAnalyze = function (handCards, card) {
- // 结果对象
- var result = [];
- if(card == 51) return result;//红中不能碰杠
- var length = handCards.length;
- if (length < 4) return result;
- // 查找同牌
- var moCard = handCards[length - 1];
- for (let i = 0; i < length - 3; ++i) {
- // 指定补牌,可以不指定
- if (card && handCards[i] != card) continue;
- // 判定是否刻子
- if (handCards[i] == handCards[i + 1] && handCards[i] == handCards[i + 2]) {
- // 手上有补牌
- if (handCards[i] == handCards[i + 3]) {
- if(handCards[i] != 51){
- result.push({ type: 2, card: handCards[i] });
- }
- }
- // 刚摸到补牌
- else if (handCards[i] == moCard) {
- if(handCards[i] != 51){
- result.push({ type: 2, card: moCard });
- }
- }
- }
- }
- return result;
- };
- // 自摸补分析,1-普通补, 2-暗补, 3-自摸明补, card可以不传
- proto.zmBuAnalyze = function (handCards, huCards, card) {
- // 返回结果
- var result = [];
- if(card == 51) return result;//红中不能碰杠
- // 遍历句子
- for (let i = 0; i < huCards.length; ++i) {
- if (huCards[i].style != STYLE.PENG) {
- continue;
- }
- let _card = huCards[i].cards[0];
- if (card && _card != card) continue;
- let pos = handCards.indexOf(_card);
- if (pos != -1) {
- result.push({ type: 3, card: _card });
- if (card) break;
- }
- }
- return result;
- };
- // 分析牌型
- proto.parseBlock = function (card1, card2, card3) {
- // 刻子
- if (card1 && card1 == card2 && card1 == card3) {
- return { style: STYLE.KE, cards: [card1, card2, card3] };
- }
- // 顺子(排除风字)
- var cards = this.sort([card1, card2, card3]);
- if (cards[2] < 40) {
- if (cards[2] == cards[1] + 1 && cards[1] == cards[0] + 1) {
- return { style: STYLE.SUN, cards: cards };
- }
- }
- };
- // 得到等待数据更新类型,因为在杠后2张牌时就可能会出现2个玩家可碰或可杠或可补,
- // 而出现这种情况时规则是操作优先级高的玩家优先操作若相同操作时谁距离杠的玩家距离最近的玩家操作优先级高
- // 如ABCD4个玩家A杠后两张牌为101和102,此时B可碰101C可碰102D可胡时,若B点碰后C点碰最后D点过之后
- // 按照之前的逻辑就会出现B碰102(本应B碰101,由于等待碰等待数据里记录this.pengCard记录的是102),但是
- // 实际B不能碰102就会判碰102失败导致卡住的bug
- proto.getDDGXType = function (type,chairId, ddcwj,gangch, ccount,masks) {
- let res = 0;//0:不更新等待操作数据,1:需将之前等待操作玩家的mask置0,2:需将等待数据设置回本次修改之前的
- if(gangch == -1) return res;//不是杠后不会出现多个人等待同一个操作直接返回
- if(ddcwj == -1) return res;//此操作目前没有等待的玩家
- let czym = 0;//操作掩码
- if(type == 1) czym = 5;//判断碰
- else if(type == 2) czym = 9;//判断杠
- else if(type == 3) czym = 33;//判断补
- if(czym == 0) return res;//参数错误直接返回
- let zjjl = 0;
- if((gangch + 1) % ccount == chairId) zjjl = 1;
- else if((gangch + 2) % ccount == chairId) zjjl = 2;
- else if((gangch + 3) % ccount == chairId) zjjl = 3;
- let qtjl = 0;
- if((gangch + 1) % ccount == ddcwj) qtjl = 1;
- else if((gangch + 2) % ccount == ddcwj) qtjl = 2;
- else if((gangch + 3) % ccount == ddcwj) qtjl = 3;
- if(zjjl > qtjl){
- if(masks[ddcwj] == czym){
- res = 2;
- return res
- }
- else{
- return 0;//正常不应该走到这里来,能进这里都是有错误的
- }
- }
- res = 1;
- return res
- };
- // TL++,得到手牌中百搭牌的个数
- proto.getBDCount = function (cards) {
- ////TL++,整个for循环判断手牌中的百搭牌个数
- let baiDaCount = 0
- for (let i = 0; i < cards.length; ++i) {
- if(cards[i] == this.baiDaCard) baiDaCount = baiDaCount + 1
- }
- return baiDaCount
- }
- //// TL++,得到手牌中百搭牌的shuzu数组
- proto.getBDListZZ = function (cards) {
- this.sbyBDList = []//////重置某人手牌中的百搭牌数组
- ////TL++,整个for循环判断手牌中的百搭牌个数
- let baiDaCount = 0
- let baiDali = []
- for (let i = 0; i < cards.length; ++i) {
- if(cards[i] == this.baiDaCard){
- baiDali[baiDaCount] = cards[i]
- baiDaCount = baiDaCount + 1
- }
- }
- return baiDali
- }
- ////TL++,得到手牌中百搭牌的index数组
- proto.getBDIndexList = function (cards) {
- ////TL++,整个for循环判断手牌中的百搭牌个数
- let baiDali = []
- for (let i = 0; i < cards.length; ++i) {
- let cardTL = cards[i];
- if(this.baiDaList[0] && cardTL == this.baiDaList[0]) baiDali[baiDali.length] = i;
- else if(this.baiDaList[1] && cardTL == this.baiDaList[1]) baiDali[baiDali.length] = i;
- else if(this.baiDaList[2] && cardTL == this.baiDaList[2]) baiDali[baiDali.length] = i;
- }
- return baiDali
- }
- // TL++,得到手牌中百搭牌的index,用于删除手牌中的百搭牌
- proto.getBDIndex = function (cards) {
- ////TL++,整个for循环判断手牌中的百搭牌个数
- let baiDali = []
- for (let i = 0; i < cards.length; ++i) {
- let cardTL = cards[i];
- if(this.sbyBDList[0] && cardTL == this.sbyBDList[0]) baiDali[baiDali.length] = i;
- if(this.sbyBDList[1] && cardTL == this.sbyBDList[1]) baiDali[baiDali.length] = i;
- if(this.sbyBDList[2] && cardTL == this.sbyBDList[2]) baiDali[baiDali.length] = i;
- if(this.sbyBDList[3] && cardTL == this.sbyBDList[3]) baiDali[baiDali.length] = i;
- }
- return baiDali
- }
- // TL++,得到默认手牌中百搭牌当的数组 cards: 手牌去除百搭之后的牌
- proto.getBDMakeList = function (cards,isNeedAllZi) {
- if(cards.length == 0){
- ////手上就剩百搭牌的时候 需要把所有牌都当一遍
- let reslist = [
- 11, 12, 13, 14, 15, 16, 17, 18, 19, // 筒
- 21, 22, 23, 24, 25, 26, 27, 28, 29, // 万
- 31, 32, 33, 34, 35, 36, 37, 38, 39, // 条
- ]
- return reslist;
- }
- ////TL++,整个for循环按照手牌情况确定百搭牌当的范围
- let makeList = this.deepCloneTL(cards)
- for (let i = 0; i < cards.length; ++i) {
- let cardTL = cards[i];
- let type = this.getType(cardTL);
- let vale = this.getValue(cardTL);
- if(type < 4){
- if(vale == 1){
- let makeValue = cardTL + 1;
- if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
- let makeValue2 = cardTL + 2;
- if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
- }
- else if(vale == 9){
- let makeValue = cardTL - 1;
- if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
- let makeValue2 = cardTL - 2;
- if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
- }
- else if(vale == 2){
- let makeValue = cardTL - 1;
- if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
- let makeValue2 = cardTL + 1;
- if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
- let makeValue3 = cardTL + 2;
- if(makeList.indexOf(makeValue3) == -1) makeList[makeList.length] = makeValue3;
- }
- else if(vale == 8){
- let makeValue = cardTL - 1;
- if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
- let makeValue2 = cardTL - 2;
- if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
- let makeValue3 = cardTL + 1;
- if(makeList.indexOf(makeValue3) == -1) makeList[makeList.length] = makeValue3;
- }
- else if(vale > 2 && vale < 8){
- let makeValue = cardTL - 1;
- if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
- let makeValue2 = cardTL + 1;
- if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
- let makeValue3 = cardTL - 2;
- if(makeList.indexOf(makeValue3) == -1) makeList[makeList.length] = makeValue3;
- let makeValue4 = cardTL + 2;
- if(makeList.indexOf(makeValue4) == -1) makeList[makeList.length] = makeValue4;
- }
- }
- }
- // let makeList2 = makeList.concat([41,42,43,44,51,52,53])/////给当的数组拼接字牌
- // var xx = [1,1,2,3,4,1,2]
- // var xx22 = _.uniq(xx)
- // console.warn("数组去重",xx,xx22);///[ 1, 1, 2, 3, 4, 1, 2 ] [ 1, 2, 3, 4 ]
- // xx[1] = 6
- // console.warn("22数组去重",xx,xx22);////[ 1, 6, 2, 3, 4, 1, 2 ] [ 1, 2, 3, 4 ]
- let ewbList = [12,15,18,22,25,28,32,35,38];
- for (let i = 0; i < ewbList.length; ++i) {
- if(makeList.indexOf(ewbList[i]) == -1) makeList[makeList.length] = ewbList[i];
- }
- return _.uniq(makeList);
- }
- // 提取成句 card:手上的所有牌删除2张用来做将的牌之后剩下的牌 整理是否为刻子或者顺子
- proto._dumpFixed = function (cards, huCards) {
- // if(this.currChairIDTL == 0){
- // console.error("sscc提取成句没有百搭cards",cards);
- // console.error("sscc提取成ju没有百搭huCards",huCards);
- // }
- for (let i = 0; i < cards.length - 2; ++i) {
- let card = cards[i];
- if (card <= 0) continue;
- if (card == cards[i + 1] && card == cards[i + 2]) {
- huCards.push({ style: STYLE.KE, cards: [card, card, card] });
- cards[i] = 0; cards[i + 1] = 0; cards[i + 2] = 0;
- i += 2; continue;
- }
- if (card > 40 || this.getValue(card) > 7) continue;
- let second = -1, third = -1;
- for (let j = i + 1; j < cards.length; ++j) {
- if (cards[j] == card + 1) second = j;
- if (cards[j] == card + 2) third = j;
- if (cards[j] > card + 2) break;
- if (second != -1 && third != -1) break;
- }
- if (second != -1 && third != -1) {
- huCards.push({ style: STYLE.SUN, cards: [card, cards[second], cards[third]] });
- cards[i] = 0; cards[second] = 0; cards[third] = 0;
- }
- }
- };
- proto._dumpFixedc = function (cards,huCards,baidaCount) {
- let spkzgs = 4 - huCards.length;//手牌可组个数
- let spkzzh = [];//手牌可组组合(1为刻2为顺)
- if(spkzgs == 1) spkzzh = [[1],[2]];
- else if(spkzgs == 2) spkzzh = [[1,1],[1,2],[2,2],[2,1]];
- 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]];
- else if(spkzgs == 4){
- spkzzh = [[1,1,1,1],[1,2,1,1],[1,1,2,1],[1,1,1,2],
- [1,2,2,1],[1,1,2,2],[1,2,1,2],[1,2,2,2],
- [2,2,2,2],[2,1,2,2],[2,2,1,2],[2,2,2,1],
- [2,1,1,2],[2,2,1,1],[2,1,2,1],[2,1,1,1]
- ]
- }
- //找到目标牌
- var getMBCard = (cscards) => {
- for (let i = 0; i < cscards.length; ++i) {
- let card = cscards[i];
- if (card <= 0) continue;
- else return card;
- }
- return -100;
- };
-
- // let mbpailist = [12,15,15,15,16,17,18,25,26,27]
- // let islog = true;
- // if(mbpailist.length == cards.length){
- // for (let i = 0; i < cards.length; ++i) {
- // if(mbpailist[i] != cards[i]) islog = false;
- // }
- // }
- // else{
- // islog = false;
- // }
- // let mbpailist2 = [15,15,16,17,18,25,26,27,28,28,28]
- // if(islog) console.warn("_dumpFixedc 提取成句 baidaCount "+baidaCount+" cards "+cards+ " indexof "+mbpailist2.indexOf(15));
- // console.warn("所有的判断组合 长度 "+spkzzh.length+" spkzzh "+JSON.stringify(spkzzh) )
- let dqdpd = [0,0]//当前的判断
- for (let x = 0; x < spkzzh.length; ++x) {
- let copyCards = this.deepCloneTL(cards)
- let bdCount = baidaCount;
- let huCards22 = [];
- // console.warn("当前的判断组合 "+dqdpd+" spkzzh[x] "+spkzzh[x]+" x "+x);
- // if(islog && x == 5) console.warn("当前的判断组合 "+dqdpd+" spkzzh[x] "+spkzzh[x]+" x "+x);
- for (let y = 0; y < spkzzh[x].length; ++y) {
- let ckORcs = spkzzh[x][y]//成刻或成顺(1为刻2为顺)
- // if(islog && x == 5) console.warn("当前的判断 "+dqdpd+" ckORcs "+ckORcs);
- if(ckORcs == 1){
- let mbCard = getMBCard(copyCards);//目标card(mbCard这次应该成刻)
- if(mbCard > 0){
- let index1 = copyCards.indexOf(mbCard);
- if(index1 != -1) copyCards[index1] = 0;
- else console.error("这里不正常,都没有目标牌");
- let cj = [mbCard];//成句
- let index2 = copyCards.indexOf(mbCard);
- if(index2 != -1){
- cj[cj.length] = mbCard;
- copyCards[index2] = 0;
- }
- else {
- if(bdCount > 0){
- cj[cj.length] = 51;
- bdCount -= 1;
- }
-
- }
- let index3 = copyCards.indexOf(mbCard);
- if(index3 != -1){
- cj[cj.length] = mbCard;
- copyCards[index3] = 0;
- }
- else {
- if(bdCount > 0){
- cj[cj.length] = 51;
- bdCount -= 1;
- }
-
- }
- if(cj.length == 3){
- huCards22.push({ style: STYLE.KE, cards: cj });
- }
- else{
- //mbCard不能成刻,说明spkzzh[x]这种组合是不行的,剩下的就不用判断了
- // console.warn("mbCard不能成刻,说明spkzzh[x]这种组合是不行的,剩下的就不用判断了");
- break;
- }
- }
- else{
- //手牌全部都判断过了
- if(bdCount >= 3){
- huCards22.push({ style: STYLE.KE, cards: [51, 51, 51] });
- bdCount -= 3;
- }
- //因为手里最多8张百搭,最多可以有6张百搭做成2个百搭刻,所以需要两次if
- if(bdCount >= 3){
- huCards22.push({ style: STYLE.KE, cards: [51, 51, 51] });
- bdCount -= 3;
- }
- break;
- }
- }
- else if(ckORcs == 2){
- let mbCard = getMBCard(copyCards);//目标card(mbCard这次应该成刻)
- // if(islog && x == 5) console.warn("mbCard "+mbCard+" copyCards "+copyCards);
- if (mbCard < 40){
- if(mbCard > 0){
- let index1 = copyCards.indexOf(mbCard);
- if(index1 != -1) copyCards[index1] = 0;
- else console.error("这里不正常,都没有目标牌");
- let cj = [mbCard];//成句
- if(this.getValue(mbCard) <= 7){
- let index2 = copyCards.indexOf(mbCard+1);
- if(index2 != -1){
- cj[cj.length] = copyCards[index2];
- copyCards[index2] = 0;
- }
- else {
- if(bdCount > 0){
- cj[cj.length] = 51;
- bdCount -= 1;
- }
-
- }
- let index3 = copyCards.indexOf(mbCard+2);
- if(index3 != -1){
- cj[cj.length] = copyCards[index3];
- copyCards[index3] = 0;
- }
- else {
- if(bdCount > 0){
- cj[cj.length] = 51;
- bdCount -= 1;
- }
-
- }
- }
- else if(this.getValue(mbCard) == 8){
- let index2 = copyCards.indexOf(mbCard+1);
- if(index2 != -1){
- cj[cj.length] = copyCards[index2];
- copyCards[index2] = 0;
- }
- else {
- if(bdCount > 0){
- cj[cj.length] = 51;
- bdCount -= 1;
- }
-
- }
- if(bdCount > 0){
- cj[cj.length] = 51;
- bdCount -= 1;
- }
- }
- else if(this.getValue(mbCard) == 9){
- if(bdCount > 1){
- cj[cj.length] = 51;
- cj[cj.length] = 51;
- bdCount -= 2;
- }
- }
- if(cj.length == 3){
- huCards22.push({ style: STYLE.SUN, cards: cj });
- }
- else{
- //mbCard不能成顺,说明spkzzh[x]这种组合是不行的,剩下的就不用判断了
- break;
- }
- }
- else{
- //手牌全部都判断过了
- if(bdCount >= 3){
- huCards22.push({ style: STYLE.SUN, cards: [51, 51, 51] });
- bdCount -= 3;
- }
- //因为手里最多8张百搭,最多可以有6张百搭做成2个百搭刻,所以需要两次if
- if(bdCount >= 3){
- huCards22.push({ style: STYLE.SUN, cards: [51, 51, 51] });
- bdCount -= 3;
- }
- break;
- }
- }
- }
- // if(y < spkzzh[x].length-1) dqdpd=[x,y+1];
- // else dqdpd=[x+1,0];
- }
- // if(islog && x == 5) console.warn("提取成句 组合 "+" spkzzh[x] "+spkzzh[x]+" huCards22 "+JSON.stringify(huCards22) );
- if(huCards22.length + huCards.length == 4){
- //已经可以胡牌了,其他的组合就不需要判断了
- for (var i = 0; i < huCards22.length; i++) {
- huCards.push(huCards22[i]);
- }
- break;
- }
- }
- };
- //////TL++,判断一手张牌是否为百搭牌
- proto.judgeACardISBD = function (card) {
- return card == this.baiDaCard;
- }
- // 胡牌分析 chairID(TL++这个参数) 手牌 加上这张判断能不能胡 手上的吃碰杠牌 是否自己摸上来的
- proto.huAnalyze = function (chairID,handCards, card, huCards, isTouch) {
- // console.error("sscc777胡牌分析card",card);
- // console.error("sscc777胡牌分析handCards",handCards);
- // console.error("sscc777胡牌分析huCards",huCards);
- // console.error("sscc777胡牌分析isTouch",isTouch);
- this.addThisIsHu = card//////TL++,胡牌判断时加上这张能不能胡
- this.isSeleCatcedCard = isTouch//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
- this.currChairIDTL = chairID/////当前判断胡的chairID,用于得到当前玩家的花牌情况
- this.dangAfterBDListTL = [];/////7月18日+的
- // console.warn("胡牌分析 isGuoHuList ",this.isGuoHuList," chairID ",chairID," isTouch ",isTouch);
-
- let baiDaCount22 = 0
- let bdIndexlist = []
- if (!isTouch){
- // baiDaCount22 = this.getBDCount(handCards)
- // this.sbyBDList = this.getBDListZZ(handCards)
- handCards = handCards.concat(card);/////不是自己抓的就把这张牌拼接进手牌中
- // handCards = this.sort(handCards);
- // bdIndexlist = this.getBDIndexList(handCards)
- }
- else{
- // handCards = this.sort(handCards);
- // baiDaCount22 = this.getBDCount(handCards)
- // this.sbyBDList = this.getBDListZZ(handCards)
- // bdIndexlist = this.getBDIndexList(handCards)
- }
- handCards = this.sort(handCards);
- //由于杠后两张牌里面的红中是按照百搭算的,而且红中不能打出,所以把找红中放在判断isTouch外面了
- baiDaCount22 = this.getBDCount(handCards)
- this.sbyBDList = this.getBDListZZ(handCards)
- bdIndexlist = this.getBDIndexList(handCards)
- let huCards2 = this.deepCloneTL(huCards)
- // console.warn("判断13不搭手上百搭牌个数出错了?????",baiDaCount22,this.sbyBDList,bdIndexlist)
- var huRes = { card: card, jiang: 0, huCards: [] };
- // 重设将牌
- var resetHuRes = (jiang) => {
- huRes.jiang = jiang;
- huRes.huCards = [];
- for (let huCard of huCards) huRes.huCards.push(huCard);
- };
- // 手牌不全
- var length = handCards.length;
- if (length % 3 != 2) return;
- let result = null
- if(this.isSevenDouble(handCards)){
- // console.warn("是个7对子了");
- resetHuRes(-1);
- result = huRes;
- }
- if(this.isJiangJiangHu(handCards,huCards2)){
- // console.warn("是个将将胡了");
- resetHuRes(-1);
- result = huRes;
- }
- if(this.isTianHu(handCards,huCards2)){
- // console.warn("是个天胡了");
- resetHuRes(-1);
- result = huRes;
- }
- // let hucardTL = huCards//////TL++,保存碰杠牌的初始值,因为这个参数会在下面的代码中被修改掉
- let tempAllTai = -1/////临时总台数
- let tempres = {}///临时成句
- if(result){
- let copyCards = this.deepCloneTL(handCards);
- this.getCardTypeTL(chairID,copyCards,huCards2,result,isTouch);
- for (let x = 0; x < this.everyDAHType[chairID].length; ++x) {
- if(this.everyDAHType[chairID][x] == 1) tempAllTai++;
- }
- }
- // console.warn("下面是计算普通胡法 "+handCards);
- if(baiDaCount22 == 0){/////没有百搭的时候
- // 确定将牌
- for (let i = 0; i < length - 1; ++i) {
- if (!this.isJang(handCards[i], handCards[i + 1])) continue;
- resetHuRes(handCards[i]);////设置将牌
- let bcjp = handCards[i];
- let cards = handCards.slice(0, i);////手牌数组的前i个元素
- cards = cards.concat(handCards.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
- this._dumpFixed(cards, huRes.huCards);
- i += 1;/////TL++,为了减少运算
- if(huRes.huCards.length >= 4){
- let temresult = null;
- if(this.isNeedEWBZJ(handCards,huCards2,huRes,isTouch)){
- let jiangValue = this.getValue(bcjp);
- if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
- temresult = this.deepCloneTL(huRes);
- }
- }
- else{
- // console.error("不需要258做将 bcjp "+bcjp+" "+handCards)
- temresult = this.deepCloneTL(huRes);
- // console.error("不需要258做将 temresult "+JSON.stringify(temresult))
- }
- if(temresult){
- let copyCards = this.deepCloneTL(handCards);
- this.getCardTypeTL(chairID,copyCards,huCards2,temresult,isTouch);
- let pxgs = 0;//牌型个数
- for (let x = 0; x < this.everyDAHType[chairID].length; ++x) {
- if(this.everyDAHType[chairID][x] == 1) pxgs++;
- }
- if(pxgs > tempAllTai){
- result = this.deepCloneTL(temresult);
- tempAllTai = pxgs;
- }
- }
- }
- }
- }
- else{/////有百搭的时候
- let card2 = []//////用于存放手牌中将所有百搭牌去掉之后的手牌
- let ccchandCards = this.deepCloneTL(handCards)
- for (let xx = 0; xx < this.sbyBDList.length; ++xx){
- card2 = ccchandCards.slice(0,bdIndexlist[xx] - xx)////得到数组中的前bdIndexlist[xx] 个元素
- card2 = card2.concat(ccchandCards.slice(bdIndexlist[xx]+1 - xx))////得到数组中的最后bdIndexlist[xx] +1 个元素
- ccchandCards = card2
- // console.error("有百搭删除掉百搭牌",card2);
- }
- // console.warn("删除百搭之后的手牌111 card2 ",card2);
- // console.warn("删除百搭之后的手牌222 handCards ",handCards);
- let bdzs = this.sbyBDList.length;/////百搭张数
- let copyhandCards = this.deepCloneTL(card2)
- var huResTL = [];
- for (let huCard of huCards) huResTL.push(huCard);
- // console.warn("去掉百搭之后的手牌 copyhandCards "+copyhandCards);
- if(copyhandCards.length == 0) {
- result = this.deepCloneTL(huRes);
- let copyCards = this.deepCloneTL(handCards);
- this.getCardTypeTL(chairID,copyCards,huCards2,result,isTouch);
- }
- else if(copyhandCards.length > 0) {
- //下面的for循环是用手牌的两张牌做将牌看能不能胡牌
- for (let i = 0; i < copyhandCards.length - 1; ++i) {
- let cards22 = this.deepCloneTL(copyhandCards)
- if (!this.isJang(cards22[i], cards22[i + 1])) continue;
- let bcjp = handCards[i];
- let huRes3 = { card: card, jiang: 0, huCards: [] };
- // 重设将牌
- huRes3.jiang = cards22[i];
- huRes3.huCards = [];
- for (let huCard of huCards) huRes3.huCards.push(huCard);
-
- let cards2 = cards22.slice(0, i);////手牌数组的前i个元素
- cards2 = cards2.concat(cards22.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
-
- this._dumpFixedc(cards2, huRes3.huCards,bdzs);
- // console.warn("判胡 2张手牌做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
- if (huRes3.huCards.length >= 4){
- let temresult = null;
- if(this.isNeedEWBZJ(handCards,huCards2,huRes3,isTouch)){
- let jiangValue = this.getValue(bcjp);
- if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
- temresult = this.deepCloneTL(huRes3);
- }
- }
- else{
- // console.error("不需要258做将 bcjp "+bcjp+" "+handCards)
- temresult = this.deepCloneTL(huRes3);
- // console.error("不需要258做将 temresult "+JSON.stringify(temresult))
- }
- if(temresult){
- let copyCards = this.deepCloneTL(handCards);
- this.getCardTypeTL(chairID,copyCards,huCards2,temresult,isTouch);
- let pxgs = 0;//牌型个数
- for (let x = 0; x < this.everyDAHType[chairID].length; ++x) {
- if(this.everyDAHType[chairID][x] == 1) pxgs++;
- }
- // console.error("可以胡牌了111 pxgs "+pxgs+ " temresult "+JSON.stringify(temresult));
- if(pxgs > tempAllTai){
- result = this.deepCloneTL(temresult);
- tempAllTai = pxgs;
- }
- }
- }
- i += 1;/////TL++,为了减少运算
- }
- //下面的for循环是用一张手牌和一张百搭牌做将牌看能不能胡牌
- if(bdzs >= 1){
- let bcjp = 0;///////本次的将牌
- for (let i = 0; i < copyhandCards.length; ++i) {
- let cards22 = this.deepCloneTL(copyhandCards);
- if(cards22[i] == bcjp) continue;
-
- let huRes3 = { card: card, jiang: 0, huCards: [] };
- // 重设将牌
- huRes3.jiang = cards22[i];
- huRes3.huCards = [];
- for (let huCard of huCards) huRes3.huCards.push(huCard);
- bcjp = cards22[i]; ///////本次的将牌
-
- let cards2 = cards22.slice(0, i);////手牌数组的前i个元素
- cards2 = cards2.concat(cards22.slice(i + 1));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
- // console.warn("判胡 1张手牌做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
- this._dumpFixedc(cards2, huRes3.huCards,bdzs-1);
- if (huRes3.huCards.length >= 4){
- // return huRes3;
- let temresult = null;
- if(this.isNeedEWBZJ(handCards,huCards2,huRes3,isTouch)){
- // console.error("需要258做将 bcjp "+bcjp)
- let jiangValue = this.getValue(bcjp);
- if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
- temresult = this.deepCloneTL(huRes3);
- }
- }
- else{
- // console.error("不需要258做将 bcjp "+bcjp+" "+handCards)
- temresult = this.deepCloneTL(huRes3);
- // console.error("不需要258做将 temresult "+JSON.stringify(temresult))
- }
- if(temresult){
- // console.error("可胡 temresult "+JSON.stringify(temresult))
- let copyCards = this.deepCloneTL(handCards);
- this.getCardTypeTL(chairID,copyCards,huCards2,temresult,isTouch);
- let pxgs = 0;//牌型个数
- for (let x = 0; x < this.everyDAHType[chairID].length; ++x) {
- if(this.everyDAHType[chairID][x] == 1) pxgs++;
- }
- // console.error("可以胡牌了222 pxgs "+pxgs+ " temresult "+JSON.stringify(temresult));
- if(pxgs > tempAllTai){
- result = this.deepCloneTL(temresult);
- tempAllTai = pxgs;
- }
- }
- }
- }
- }
- //下面的for循环是用2张百搭牌做将牌看能不能胡牌
- if(bdzs >= 2){
- let cards22 = this.deepCloneTL(copyhandCards);
- let huRes3 = { card: card, jiang: 0, huCards: [] };
- // 重设将牌
- huRes3.jiang = 51;
- huRes3.huCards = [];
- for (let huCard of huCards) huRes3.huCards.push(huCard);
- // console.warn("判胡 2张红中做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
- this._dumpFixedc(cards22, huRes3.huCards,bdzs-2);
- if (huRes3.huCards.length >= 4){
- let temresult = null;
- temresult = this.deepCloneTL(huRes3);
- let copyCards = this.deepCloneTL(handCards);
- this.getCardTypeTL(chairID,copyCards,huCards2,temresult,isTouch);
- let pxgs = 0;//牌型个数
- for (let x = 0; x < this.everyDAHType[chairID].length; ++x) {
- if(this.everyDAHType[chairID][x] == 1) pxgs++;
- }
- // console.error("可以胡牌了222 pxgs "+pxgs+ " temresult "+JSON.stringify(temresult));
- if(pxgs > tempAllTai){
- result = this.deepCloneTL(temresult);
- tempAllTai = pxgs;
- }
- }
- }
- }
- }
- if(result){
- let copyCards = this.deepCloneTL(handCards);
- // console.error("胡牌分析 判断可胡 大胡牌型111 ",chairID,copyCards);
- // console.error("胡牌分析 判断可胡 大胡牌型huCards2 ",JSON.stringify(huCards2));
- // console.error("胡牌分析 判断可胡 大胡牌型huRes ",JSON.stringify(huRes));
- // console.error("胡牌分析 判断可胡 大胡牌型result ",JSON.stringify(result));
- this.getCardTypeTL(chairID,copyCards,huCards2,result,isTouch);
- // console.error("胡牌分析 可胡 大胡牌型 "+chairID+" "+this.everyDAHType[chairID]);
-
- if(!isTouch){
- // console.warn("不是此人摸牌 ",chairID,isTouch);
- let pxgs = 0;
- for (let x = 0; x < this.everyDAHType[chairID].length; ++x) {
- if(this.everyDAHType[chairID][x] == 1) pxgs++;
- }
- // console.error("胡牌分析 可胡 是否过胡 "+this.isGuoHuList[chairID][0]+" 过胡牌型个数 "+this.isGuoHuList[chairID][1]+" 当前牌型个数 "+pxgs);
- if(this.isGuoHuList[chairID][0] && this.isGuoHuList[chairID][1] >= pxgs){
- // console.warn("此人点过胡了 ",chairID," isTouch ",(!isTouch));
- return false;
- }
- }
- }
- if(!isTouch && this.kexuanList[3] == 1){
- // console.error("胡牌分析 不是自己摸牌 勾选了小胡只能自摸 "+chairID+" "+this.everyDAHType[chairID]);
- if(this.everyDAHType[chairID].indexOf(1) == -1){
- // console.error("胡牌分析 不是自己摸牌 勾选了小胡只能自摸 没有大胡牌型 "+chairID+" "+this.everyDAHType[chairID]);
- return false;
- }
- }
- return result;
- };
- // // TL++胡牌提示 chairID(TL++这个参数) 手牌 手上的吃碰杠牌 这个是胡牌提示里不统计台数
- proto.hutip = function (chairID,_handCards, _huCards,_allhuCards,outCards) {
- // return {
- // renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- // kehuData:[]/////对象数组,分别表示打哪张可胡哪几张数据
- // };////服务端运算量太大放到前端去计算了
- this.yscs = 0
- // console.warn("hutip777胡牌提示handCards ",chairID,_handCards,_huCards,this.yscs);
- // console.error("sscc777胡牌提示huCards",_huCards);
- let hutipRes = [];
- let handCards1 = _.clone(_handCards);
- // if(chairID == 1) console.warn("sscc777胡牌提示handCards1 ",chairID,_handCards);
- let huCards = _.clone(_huCards);
- let allhuCards = _.clone(_allhuCards);////用统计胡牌提示的剩余牌
- let baiDaCount22 = this.getBDCount(_handCards);
- let dangPaiList = this.getBDMakeList(handCards1);
- // let dangPaiList = this.getYGLDPList(handCards1);
-
- // console.warn("hutip777胡牌提示 dangPaiList ",dangPaiList.length,JSON.stringify(dangPaiList));
- // console.warn("hutip777胡牌提示 dangPaiList2 ",dangPaiList2.length,JSON.stringify(dangPaiList2));
-
- if(baiDaCount22 < this.hzCount && this.hzCount > 0 && _handCards.indexOf(this.baiDaCard) == -1 && this.baiDaCard < 60){
- dangPaiList[dangPaiList.length] = this.baiDaCard;
- }
- // if(chairID == 1) console.warn("hutip777胡牌提示 dangPaiList ",dangPaiList.length,dangPaiList);
- let kdcdp = 0;////可打出的牌 就是打出这个牌之后可以胡
- let dczhkhdp = [];////打出kdcdp之后可以胡的牌
- let yjpdgdsp = 0;////已经判断过的手牌 为了减少运算量判断过的手牌就不再判断了
- // let yjpdgdzh = [];////已经判断过的组合 把28换成26 和 把26换成28 的结果是一样的所以可以剔除以减少运算
- for (var i = 0; i < handCards1.length; i++) {
- if(this.judgeACardISBD(handCards1[i])) continue;
- kdcdp = handCards1[i];////可打出的牌
- dczhkhdp = [];
- if(handCards1[i] == yjpdgdsp) continue;////已经判断过的手牌 为了减少运算量判断过的手牌就不再判断了
- yjpdgdsp = handCards1[i];////已经判断过的手牌 为了减少运算量判断过的手牌就不再判断了
-
- var huResTL = [];
- for (let huCard of huCards) huResTL.push(huCard);
- let copyhandCards = this.deepCloneTL(_handCards)
- for (let x = 0; x < copyhandCards.length; ++x) {
- if(this.judgeACardISBD(copyhandCards[x])){
- copyhandCards[x] = 0;////剔除手里的百搭去判断抛搭
- }
- }
- copyhandCards[i] = 0;///剔除手里的百搭和打出那张之后剩下的手牌去判断抛搭
- let copyhandCardsqbd = _.compact(_.clone(copyhandCards));
- copyhandCardsqbd = this.sort(copyhandCardsqbd);
- // let ispd = this.hutipJudgePAODA(baiDaCount22,copyhandCardsqbd,dangPaiList,huResTL.length,kdcdp);////打出kdcdp之后是否抛搭
- //上面是旧的算法,下面是新的算法
- let ispd = false;
- if(copyhandCardsqbd.length == 0){
- ispd = true;//手上全是百搭肯定抛搭了
- }
- else{
- if(baiDaCount22 > 0){
- ispd = this.hutipJudgePAODA2(baiDaCount22-1,copyhandCardsqbd,huResTL,kdcdp,huCards,handCards1);////打出kdcdp之后是否抛搭
- }
- }
- // console.warn("打出kdcdp之后是否抛搭 ",kdcdp,ispd,this.yscs);
- if(ispd){
- ////打出kdcdp之后可以抛搭了
- let data = {
- "canTing": kdcdp,////表示打出这张牌之后可以听牌
- "youjin": 1,////打出这张牌之后是不是游金(抛搭)这个在象山麻将里面没有用
- "tpxq": dczhkhdp
- }
- hutipRes[hutipRes.length] = data;
- }
- else{
- ////打出kdcdp之后不能抛搭
- for (var k = 0; k < dangPaiList.length; k++) {
- this.yscs++;
- let handCards = _.clone(handCards1);
- // console.error("222sscc777胡牌提示huCards",i,handCards[i] , dangPaiList[k],handCards);
- handCards[i] = dangPaiList[k];
-
- handCards = this.sort(handCards);
- // 手牌不全
- var length = handCards.length;
- if (length % 3 != 2) return;
- // console.warn("pandau 0ceccewcde -------开始调用 hutip33");
- let huRes22 = this.hutip33(chairID,handCards, dangPaiList[k], huCards,false);
- if (huRes22) {
- // console.warn("胡牌提示 打出 "+kdcdp+" 如果摸到 "+dangPaiList[k]+" 可以胡");
- ////打出kdcdp如果摸到dangPaiList[k]可以胡
- let syzs = this.getACardSYZS(dangPaiList[k],_handCards,allhuCards,outCards);
- // console.warn("111????????????????????????????????",dangPaiList[k],syzs);
- dczhkhdp[dczhkhdp.length] = [dangPaiList[k],-1,syzs];////[可胡的牌,剩余张数]
- }
- }
- // console.warn("222????????????????????????????????",dczhkhdp.length);
- if(dczhkhdp.length > 0){
- ////至此表示打出handCards[i]之后可以听牌
- let data = {
- "canTing": kdcdp,////表示打出这张牌之后可以听牌
- "youjin": 0,////打出这张牌之后是不是游金(抛搭)这个在象山麻将里面没有用
- "tpxq": dczhkhdp
- }
- hutipRes[hutipRes.length] = data;
- }
- }
- }
- // console.warn("333????????????????????????????????",hutipRes);
- // console.warn("222sscc777胡牌提示handCards ",chairID,_handCards,_huCards,this.yscs);
- let kehuData3 = {
- renyi:0,//////是否可胡任意牌,0表示不满足1表示满足
- kehuData:hutipRes/////对象数组,分别表示打哪张可胡哪几张数据
- };
- return kehuData3;
- // return hutipRes;
- };
- ////TL++得到一张牌的剩余张数 用于胡牌提示提示该张的剩余张数
- proto.getACardSYZS = function (card,_handCards,allhuCards,outCards) {
- // console.warn("000得到一张牌的剩余张数 手牌张数",card,_handCards);
- // console.warn("000得到一张牌的剩余张数 手牌张数",JSON.stringify(allhuCards));
- // console.warn("000得到一张牌的剩余张数 手牌张数",JSON.stringify(outCards));
- ////下面这段是适合胡牌提示里用的剩余牌数统计
- let yjcxdzs = 0;////该牌已经出现的张数
- for (var i = 0; i < _handCards.length; i++) {
- if(card == _handCards[i]) yjcxdzs++;////该牌已经出现在自己手牌里的张数
- }
- // console.warn("111得到一张牌的剩余张数 手牌张数",yjcxdzs,_handCards);
- for (var i = 0; i < allhuCards.length; i++) {
- if(allhuCards[i].length == 0) continue;////该玩家没有碰杠牌
- // console.warn("222得到一张牌的剩余张数 碰杠杠牌",card,yjcxdzs,i,JSON.stringify(_.clone(allhuCards[i])));
- for (var k = 0; k < allhuCards[i].length; k++) {
- let pgp = allhuCards[i][k].cards;
- if(!pgp) continue;
- if(allhuCards[i][k].style >= 5 && allhuCards[i][k].style <= 10 ){
- if(allhuCards[i][k].cards[0] == card){
- yjcxdzs+=4;//明杠暗杠自摸杠明补暗补自摸补
- }
- }
- else{
- // console.warn("得到一张牌的剩余张数 "+pgp+" card "+card);
- for (var j = 0; j < pgp.length; j++) {
- if(card == pgp[j]) yjcxdzs++;////该牌已经出现在自己手牌里的张数
- }
- }
- }
- }
- for (var i = 0; i < outCards.length; i++) {
- if(outCards[i].length == 0) continue;////该玩家没有碰杠牌
- // console.warn("2得到一张牌的剩余张数 打出去的牌",card,yjcxdzs,i,JSON.stringify(_.clone(outCards[i])));
- for (var k = 0; k < outCards[i].length; k++) {
- if(card == outCards[i][k]) yjcxdzs++;////该牌已经出现在所有打出去牌里的张数;
- }
- }
- let zs = 4
- if(card == 51) zs = this.hzCount;
- // if(this.judgeACardISBD(card)) zs = 3;
- let syzs = zs - yjcxdzs;////剩余张数 = 总张数 - 已经出现的张数
- // console.warn("333得到一张牌的剩余张数",card,syzs);
- return syzs;
- };
- // //////TL++,胡牌提示判断抛搭
- proto.hutipJudgePAODA2 = function (_baidacount,_hd,_huCards,_addThisIsHu,_huCards2,_handCards1) {
- // console.warn("胡牌提示判断抛搭 _baidacount "+_baidacount+" _hd.length "+_hd.length +" _hd "+_hd);
- // console.warn("胡牌提示判断抛搭 _addThisIsHu "+_addThisIsHu+" _huCards "+JSON.stringify(_huCards) +" _huCards2 "+JSON.stringify(_huCards2)+" _handCards1 "+_handCards1);
- let cards2 = this.deepCloneTL(_hd);
- //是否七对抛搭
- if(cards2.length+_baidacount+1 == CARDS_COUNT){
- var dcount = 0;
- var counts = {};
- for (let i = 0; i < cards2.length; ++i) {
- let card = cards2[i];
- counts[card] = (counts[card] || 0) + 1;
- if (counts[card] >= 2) {
- dcount += 1;
- counts[card] = 0;
- }
- }
- // console.warn("七对抛搭了 ???? dcount "+dcount+" _baidacount "+_baidacount );
- if(dcount + _baidacount >= 6) {
- // console.warn("七对抛搭了 dcount "+dcount);
- return true;
- }
- }
- // console.warn("至此七对没有抛搭");
- let huRes3 = { card: 0, jiang: 0, huCards: [] };
- huRes3.huCards = [];
- for (let huCard of _huCards) huRes3.huCards.push(huCard);
- this._dumpFixedc(cards2, huRes3.huCards,_baidacount);
- // console.warn("胡牌提示 判断判断抛搭 length "+huRes3.huCards.length+" huRes3.huCards "+ JSON.stringify(huRes3.huCards));
- if (huRes3.huCards.length >= 4){
- // console.warn("胡牌提示 判断判断抛搭 可以抛搭222 length "+huRes3.huCards.length+" huRes3.huCards "+ JSON.stringify(huRes3.huCards));
- // console.warn("胡牌提示 判断判断抛搭 huRes3 "+ JSON.stringify(huRes3));
- // return true;
- let handCards = this.deepCloneTL(_handCards1);
- let huCards2 = this.deepCloneTL(_huCards2);
- if(this.isNeedEWBZJ(handCards,huCards2,huRes3,true)) {
- // console.warn("胡牌提示===================抛搭 ")
- for (let i = 0; i < huRes3.huCards.length; ++i) {
- let hrcItem = huRes3.huCards[i].cards;
- if(hrcItem[0] == hrcItem[1] && hrcItem.indexOf(51) != -1){
- let jiangValue = this.getValue(hrcItem[0]);
- if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
- //如果成句中存在比如35,35,51这种组合,可以让35做将,
- //让腾出来的51和已经去掉的51再加上任何一张牌组成一个城成句,这样也能抛搭
- return true;
- }
- }
- }
- return false;
- }
- else return true;
- }
- // console.warn("不能抛搭");
- return false;
- }
- // 胡牌分析(胡牌提示里调用) chairID(TL++这个参数) 手牌 加上这张判断能不能胡 手上的吃碰杠牌 是否自己摸上来的
- proto.hutip33 = function (chairID,handCards, card, huCards, isTouch) {
- // console.error("sscc777胡牌分析card",card);
- // console.error("sscc777胡牌提示分析handCards",handCards);
- // console.error("sscc777胡牌分析huCards",huCards);
- // console.error("sscc777胡牌分析isTouch",isTouch);
- // let tempres = {}///本函数的返回值
- // this.addThisIsHu = card//////TL++,胡牌判断时加上这张能不能胡
- // this.isSeleCatcedCard = isTouch//////判断能否胡牌的那张牌是自己抓的还是别人打出来的
- // this.currChairIDTL = chairID/////当前判断胡的chairID,用于得到当前玩家的花牌情况
- // this.dangAfterBDListTL = [];/////7月18日+的
-
- let baiDaCount22 = 0
- let bdIndexlist = []
-
- handCards = this.sort(handCards);
- baiDaCount22 = this.getBDCount(handCards)
- this.sbyBDList = this.getBDListZZ(handCards)
- bdIndexlist = this.getBDIndexList(handCards)
- // console.warn("判断13不搭手上百搭牌个数出错了?????",baiDaCount22,this.sbyBDList,bdIndexlist)
- // 手牌不全
- // var length = handCards.length;
- // // console.warn("胡牌提示 length "+length+" baiDaCount22 "+baiDaCount22);
- // if (length % 3 != 2) return;
- let huCards2 = this.deepCloneTL(huCards)
-
- if(this.isSevenDouble(handCards)){
- // console.warn("胡牌提示 是个7对子了");
- return true;
- }
- if(this.isJiangJiangHu(handCards,huCards2)){
- // console.warn("胡牌提示 是个将将胡了");
- return true;
- }
- // let hucardTL = huCards//////TL++,保存碰杠牌的初始值,因为这个参数会在下面的代码中被修改掉
- // 确定将牌
- var length = handCards.length;
- // console.warn("胡牌提示 length "+length+" baiDaCount22 "+baiDaCount22);
- if (length % 3 != 2) return;
- if(baiDaCount22 == 0){/////没有百搭的时候
- var huRes = { card: card, jiang: 0, huCards: [] };
- // 重设将牌
- var resetHuRes = (jiang) => {
- huRes.jiang = jiang;
- huRes.huCards = [];
- for (let huCard of huCards) huRes.huCards.push(huCard);
- };
- for (let i = 0; i < handCards.length - 1; ++i) {
- if (!this.isJang(handCards[i], handCards[i + 1])) continue;
- resetHuRes(handCards[i]);////设置将牌
- let bcjp = handCards[i]; ///////本次的将牌 7月18日+的
- let cards = handCards.slice(0, i);////手牌数组的前i个元素
- cards = cards.concat(handCards.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
- this._dumpFixed(cards, huRes.huCards);
- i += 1;/////TL++,为了减少运算
- // let tempres22 = this.outHures(huRes,handCards,hucardTL);
- if(huRes.huCards.length >= 4){
- if(this.isNeedEWBZJ(handCards,huCards2,huRes,true)){
- let jiangValue = this.getValue(bcjp);
- if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
- return true;
- }
- }
- else{
- return true;
- }
- }
- }
- }
- else{/////有百搭的时候
- let card2 = []//////用于存放手牌中将所有百搭牌去掉之后的手牌
- let ccchandCards = this.deepCloneTL(handCards)
- for (let xx = 0; xx < this.sbyBDList.length; ++xx){
- card2 = ccchandCards.slice(0,bdIndexlist[xx] - xx)////得到数组中的前bdIndexlist[xx] 个元素
- card2 = card2.concat(ccchandCards.slice(bdIndexlist[xx]+1 - xx))////得到数组中的最后bdIndexlist[xx] +1 个元素
- ccchandCards = card2
- // console.error("有百搭删除掉百搭牌",card2);
- }
- let bdzs = this.sbyBDList.length;/////百搭张数
- let copyhandCards = this.deepCloneTL(card2)
- var huResTL = [];
- for (let huCard of huCards) huResTL.push(huCard);
- // console.warn("去掉百搭之后的手牌 copyhandCards "+copyhandCards);
- if(copyhandCards.length == 0) {
- result = this.deepCloneTL(huRes);
- let copyCards = this.deepCloneTL(handCards);
- this.getCardTypeTL(chairID,copyCards,huCards2,result,isTouch);
- }
- else if(copyhandCards.length > 0) {
- //下面的for循环是用手牌的两张牌做将牌看能不能胡牌
- for (let i = 0; i < copyhandCards.length - 1; ++i) {
- let cards22 = this.deepCloneTL(copyhandCards)
- if (!this.isJang(cards22[i], cards22[i + 1])) continue;
- let bcjp = handCards[i];
- let huRes3 = { card: card, jiang: 0, huCards: [] };
- // 重设将牌
- huRes3.jiang = cards22[i];
- huRes3.huCards = [];
- for (let huCard of huCards) huRes3.huCards.push(huCard);
-
- let cards2 = cards22.slice(0, i);////手牌数组的前i个元素
- cards2 = cards2.concat(cards22.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
-
- this._dumpFixedc(cards2, huRes3.huCards,bdzs);
- // console.warn("判胡 2张手牌做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
- if (huRes3.huCards.length >= 4){
- if(this.isNeedEWBZJ(handCards,huCards2,huRes3,isTouch)){
- let jiangValue = this.getValue(bcjp);
- if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
- return true;
- }
- }
- else{
- return true;
- }
- }
- i += 1;/////TL++,为了减少运算
- }
- //下面的for循环是用一张手牌和一张百搭牌做将牌看能不能胡牌
- if(bdzs >= 1){
- let bcjp = 0;///////本次的将牌
- for (let i = 0; i < copyhandCards.length; ++i) {
- let cards22 = this.deepCloneTL(copyhandCards);
- if(cards22[i] == bcjp) continue;
-
- let huRes3 = { card: card, jiang: 0, huCards: [] };
- // 重设将牌
- huRes3.jiang = cards22[i];
- huRes3.huCards = [];
- for (let huCard of huCards) huRes3.huCards.push(huCard);
- bcjp = cards22[i]; ///////本次的将牌
-
- let cards2 = cards22.slice(0, i);////手牌数组的前i个元素
- cards2 = cards2.concat(cards22.slice(i + 1));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
- // console.warn("判胡 1张手牌做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
- this._dumpFixedc(cards2, huRes3.huCards,bdzs-1);
- if (huRes3.huCards.length >= 4){
- if(this.isNeedEWBZJ(handCards,huCards2,huRes3,isTouch)){
- let jiangValue = this.getValue(bcjp);
- if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
- return true;
- }
- }
- else{
- return true;
- }
- }
- }
- }
- //下面的for循环是用2张百搭牌做将牌看能不能胡牌
- if(bdzs >= 2){
- let cards22 = this.deepCloneTL(copyhandCards);
- let huRes3 = { card: card, jiang: 0, huCards: [] };
- // 重设将牌
- huRes3.jiang = 51;
- huRes3.huCards = [];
- for (let huCard of huCards) huRes3.huCards.push(huCard);
- // console.warn("判胡 2张红中做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
- this._dumpFixedc(cards22, huRes3.huCards,bdzs-2);
- if (huRes3.huCards.length >= 4){
- return true;
- }
- }
- }
- }
- return false;
-
- };
- // TL++,得到和手牌有关联的牌的数组,用于判断是否听牌 cards: 13张手牌
- proto.getYGLDPList = function (_cards) {
- let cards = this.deepCloneTL(_cards)
- cards = this.sort(cards);
- let cannotList = [];
- ////TL++,整个for循环按照手牌情况确定百搭牌当的范围
- let makeList = this.deepCloneTL(cards)
- for (let i = 0; i < cards.length; ++i) {
- let cardTL = cards[i];
- let type = this.getType(cardTL);
- let vale = this.getValue(cardTL);
- if(cardTL == cards[i+1] && cardTL == cards[i+2] && cardTL == cards[i+3]){
- i += 3;
- cannotList[cannotList.length] = cardTL;
- }
- if(type < 4){
- if(vale == 1){
- let makeValue = cardTL + 1;
- if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
- }
- else if(vale == 9){
- let makeValue = cardTL - 1;
- if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
- }
- else{
- let makeValue = cardTL - 1;
- if(makeList.indexOf(makeValue) == -1) makeList[makeList.length] = makeValue;
- let makeValue2 = cardTL + 1;
- if(makeList.indexOf(makeValue2) == -1) makeList[makeList.length] = makeValue2;
- }
- }
- }
- // console.warn("22数组去重",xx,xx22);////[ 1, 6, 2, 3, 4, 1, 2 ] [ 1, 2, 3, 4 ]
- //return _.uniq(makeList);
- makeList = _.uniq(makeList);
- let ewbList = [12,15,18,22,25,28,32,35,38];
- for (let i = 0; i < ewbList.length; ++i) {
- if(makeList.indexOf(ewbList[i]) == -1) makeList[makeList.length] = ewbList[i];
- }
- this.remove(makeList,cannotList);
- return makeList;
- }
- //判断是否可以杠,14张手牌去掉可以暗杠的4张牌(或者13张牌去掉可以明杠的3张牌)之后可以听牌则可以杠否则不能杠
- proto.isCanGang = function (cards,_huCards,gangtype,gangcard) {
- // console.error("判断是否可以杠 cards "+cards,_huCards,gangtype,gangcard);
- let huCards = [];
- for (let huCard of _huCards) huCards.push(huCard);
- let handCards = this.deepCloneTL(cards);
- handCards = this.sort(handCards);
- let needDelList = [];
- //1-普通杠, 2-暗杠, 3-自摸明杠
- if(gangtype == 1){
- needDelList[needDelList.length] = [gangcard,gangcard,gangcard]
- huCards.push({ style: STYLE.GANG, cards: [gangcard,gangcard,gangcard] });
- }
- else if(gangtype == 2){
- if(gangcard != 0){
- needDelList[needDelList.length] = [gangcard,gangcard,gangcard,gangcard];
- huCards.push({ style: STYLE.ANGANG, cards: [gangcard,gangcard,gangcard] });
- }
- else{
- for (let i = 0; i < handCards.length - 3; ++i) {
- let card = handCards[i];
- // 判定是否刻子
- if (card == handCards[i + 1] && card == handCards[i + 2] && card == handCards[i + 3]) {
- needDelList[needDelList.length] = [card,card,card,card];
- huCards.push({ style: STYLE.ANGANG, cards: [card,card,card] });
- i+=3
- }
- }
- }
-
- }
- else if(gangtype == 3){
- needDelList[needDelList.length] = [gangcard];
- }
- // console.error("判断是否可以杠 needDelList "+needDelList.length,needDelList);
- for (let i = 0; i < needDelList.length; ++i) {
- let handCards2 = this.deepCloneTL(handCards);
- this.remove(handCards2,needDelList[i]);
- // console.error("判断是否可以杠 handCards2 "+handCards2+" needDelList[i] "+needDelList[i]);
- if(this.checkTing(handCards2,huCards)){
- // console.error("判断是否可以杠 可以杠");
- return true;
- }
- }
- return false;
- }
- //检查是否可以听牌
- proto.checkTing = function (_cards,huCards) {
- // console.error("检查是否可以听牌 length "+_cards.length+" cards "+_cards);
- // console.error("检查是否可以听牌111 length "+huCards.length+" huCards "+JSON.stringify(huCards) );
- if (_cards.length % 3 != 1) return;
- let handCards = this.deepCloneTL(_cards)
- let dangPaiList = this.getBDMakeList(handCards);
- // let dangPaiList = this.getYGLDPList(handCards);
- let huCards2 = this.deepCloneTL(huCards)
-
-
- for (let n = 0; n < dangPaiList.length; ++n) {
- var huRes = { card: 0, jiang: 0, huCards: [] };
- // 重设将牌
- var resetHuRes = (jiang) => {
- huRes.jiang = jiang;
- huRes.huCards = [];
- for (let huCard of huCards) huRes.huCards.push(huCard);
- };
- let cards22 = this.deepCloneTL(handCards)/////百搭牌当完之后的手牌数组
- cards22[cards22.length] = dangPaiList[n];
- cards22 = this.sort(cards22);
- let baiDaCount22 = 0
- let bdIndexlist = []
- baiDaCount22 = this.getBDCount(cards22)
- this.sbyBDList = this.getBDListZZ(cards22)
- bdIndexlist = this.getBDIndexList(cards22)
- if(this.isJiangJiangHu(handCards,huCards2)){
- // console.error("是个将将胡了");
- return true;
- }
- if(this.isSevenDouble(cards22)){
- return true;
- }
- if(baiDaCount22 == 0){/////没有百搭的时候
- // 确定将牌
- for (let i = 0; i < cards22.length - 1; ++i) {
- if (!this.isJang(cards22[i], cards22[i + 1])) continue;
- resetHuRes(cards22[i]);////设置将牌
- let bcjp = cards22[i]; ///////本次的将牌 7月18日+的
- // this.judgePAODA(1,cards22[i],dangAfterBDList);/////判断抛搭 /////7月18日以前在这里
- let cards = cards22.slice(0, i);////手牌数组的前i个元素
-
- cards = cards.concat(cards22.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
- this._dumpFixed(cards, huRes.huCards);
- if(huRes.huCards.length >= 4){
- // if(handCards.length == 1) return true;
- if(this.isNeedEWBZJ(cards22,huCards2,huRes,true)){
- let jiangValue = this.getValue(bcjp);
- // return (jiangValue == 2 || jiangValue == 5 || jiangValue == 8);
- if((jiangValue == 2 || jiangValue == 5 || jiangValue == 8)){
- // console.error("检查是否可以听牌 可以听牌111");
- return true;
- }
- }
- else{
- // console.error("检查是否可以听牌 可以听牌222");
- return true;
- }
- }
- i += 1;/////TL++,为了减少运算
- }
- }
- else{/////有百搭的时候
- let card2 = []//////用于存放手牌中将所有百搭牌去掉之后的手牌
- let ccchandCards = this.deepCloneTL(cards22)
- for (let xx = 0; xx < this.sbyBDList.length; ++xx){
- card2 = ccchandCards.slice(0,bdIndexlist[xx] - xx)////得到数组中的前bdIndexlist[xx] 个元素
- card2 = card2.concat(ccchandCards.slice(bdIndexlist[xx]+1 - xx))////得到数组中的最后bdIndexlist[xx] +1 个元素
- ccchandCards = card2
- }
- let bdzs = this.sbyBDList.length;/////百搭张数
- // console.error("有百搭删除掉百搭牌",bdzs,JSON.stringify(card2));
- let copyhandCards = this.deepCloneTL(card2)
- var huResTL = [];
- for (let huCard of huCards) huResTL.push(huCard);
- // console.warn("去掉百搭之后的手牌 copyhandCards "+copyhandCards);
- if(copyhandCards.length == 0) {
- result = this.deepCloneTL(huRes);
- let copyCards = this.deepCloneTL(cards22);
- this.getCardTypeTL(chairID,copyCards,huCards2,result,isTouch);
- }
- else if(copyhandCards.length > 0) {
- //下面的for循环是用手牌的两张牌做将牌看能不能胡牌
- for (let i = 0; i < copyhandCards.length - 1; ++i) {
- let cards2t = this.deepCloneTL(copyhandCards)
- if (!this.isJang(cards2t[i], cards2t[i + 1])) continue;
- let bcjp = cards22[i];
- let huRes3 = { card: dangPaiList[n], jiang: bcjp, huCards: [] };
- // 重设将牌
- huRes3.jiang = cards2t[i];
- huRes3.huCards = [];
- for (let huCard of huCards) huRes3.huCards.push(huCard);
-
- let cards2 = cards2t.slice(0, i);////手牌数组的前i个元素
- cards2 = cards2.concat(cards2t.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
-
- this._dumpFixedc(cards2, huRes3.huCards,bdzs);
- // console.warn("判胡 2张手牌做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
- if (huRes3.huCards.length >= 4){
- if(this.isNeedEWBZJ(cards22,huCards2,huRes3,false)){
- let jiangValue = this.getValue(bcjp);
- if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
- return true;
- }
- }
- else{
- return true;
- }
- }
- i += 1;/////TL++,为了减少运算
- }
- //下面的for循环是用一张手牌和一张百搭牌做将牌看能不能胡牌
- if(bdzs >= 1){
- let bcjp = 0;///////本次的将牌
- for (let i = 0; i < copyhandCards.length; ++i) {
- let cards2t = this.deepCloneTL(copyhandCards);
- if(cards2t[i] == bcjp) continue;
-
- let huRes3 = { card: dangPaiList[n], jiang: bcjp, huCards: [] };
- // 重设将牌
- huRes3.jiang = cards2t[i];
- huRes3.huCards = [];
- for (let huCard of huCards) huRes3.huCards.push(huCard);
- bcjp = cards22[i]; ///////本次的将牌
-
- let cards2 = cards2t.slice(0, i);////手牌数组的前i个元素
- cards2 = cards2.concat(cards2t.slice(i + 1));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
- // console.warn("判胡 1张手牌做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
- this._dumpFixedc(cards2, huRes3.huCards,bdzs-1);
- if (huRes3.huCards.length >= 4){
- if(this.isNeedEWBZJ(cards22,huCards2,huRes3,false)){
- let jiangValue = this.getValue(bcjp);
- if(jiangValue == 2 || jiangValue == 5 || jiangValue == 8){
- return true;
- }
- }
- else{
- return true;
- }
- }
- }
- }
- //下面的for循环是用2张百搭牌做将牌看能不能胡牌
- if(bdzs >= 2){
- let cards22 = this.deepCloneTL(copyhandCards);
- let huRes3 = { card: dangPaiList[n], jiang: 0, huCards: [] };
- // 重设将牌
- huRes3.jiang = 51;
- huRes3.huCards = [];
- for (let huCard of huCards) huRes3.huCards.push(huCard);
- // console.warn("判胡 2张红中做将length "+huRes3.huCards.length+" jiang "+huRes3.jiang+" huRes3.huCards "+JSON.stringify(huRes3.huCards));
- this._dumpFixedc(cards22, huRes3.huCards,bdzs-2);
- if (huRes3.huCards.length >= 4){
- return true;
- }
- }
- }
- }
- }
- // console.warn("检查是否可以听牌 不能听牌");
- return false;
- }
- //是否需要二五八做将
- proto.isNeedEWBZJ = function (handCards,huCards,hures,isTouch) {
- // console.error("是否需要二五八做将 isTouch "+isTouch +" handCards " +handCards+" huCards "+JSON.stringify(huCards)+" hures "+JSON.stringify(hures));
- let shoupai = handCards/////手牌
- let PGPai = huCards/////手上的碰杠牌
- let chengju = hures/////整理好之后成句的牌(包括碰杠牌)
- for (var i = 5; i < this.dahuTypeTL.length; i++) {
- if( i == 5 && this.isQQR(shoupai,PGPai,chengju)){
- // console.warn("不需要2,5,8做将1");
- return false;
- }
- // else if( i == 6 && isTouch && this.isMQ(shoupai,PGPai,chengju)){
- // console.warn("不需要2,5,8做将2");
- // return false;
- // }
- else if( i == 7 && this.isQYS(shoupai,PGPai,chengju)){
- // console.warn("不需要2,5,8做将3");
- return false;
- }
- else if( i == 8 && this.isPengPengHu(shoupai,PGPai,chengju)){
- // console.warn("不需要2,5,8做将4");
- return false;
- }
- else if( i == 12 && this.isTianHu(shoupai,PGPai,chengju)){
- // console.warn("不需要2,5,8做将4");
- return false;
- }
- // else if( i == 9 && this.isGangKai(shoupai,PGPai,chengju)){
- // console.warn("不需要2,5,8做将5");
- // return false;
- // }
- // else if( i == 10 && this.isQiangGang(shoupai,PGPai,chengju)){
- // console.warn("不需要2,5,8做将6");
- // return false;
- // }
- // else if( i == 11 && this.isHDLY(shoupai,PGPai,chengju)){
- // console.warn("不需要2,5,8做将7");
- // return false;
- // }
- }
- // console.error("是否需要二五八做将 需要 ");
- return true;
- }
- // 是否可以出牌,别人有权限的时候不能出牌需要等待
- proto.getIsCanOut = function (masks) {
- let isCanOut = true;
- for (let x = 0; x < masks.length; ++x) {
- if(masks[x] > 0){
- isCanOut = false;
- break;
- }
- }
- return isCanOut;
- };
- //删除起手胡牌型的操作权限
- proto.getNewMask = function (oldMask) {
- let list = [1,2,4,8,16,32];
- let isCanOperateList = [];
- for (let i = 0; i < list.length; ++i) {
- // if(oldMask < list[i]) break;
- if(oldMask & list[i]) isCanOperateList[isCanOperateList.length] = 1;
- else isCanOperateList[isCanOperateList.length] = 0;
- }
- let newMask = 0;
- for (let i = 0; i < isCanOperateList.length; ++i) {
- if(isCanOperateList[i] == 1){
- newMask |= list[i]
- }
- }
- return newMask;
- }
- ////得到list1里面是否包含list2
- proto.getISBH = function (_list1,list2) {
- //因为运算过程中会改变_list1的值所以需要备份数据
- let list1 = this.deepCloneTL(_list1);
- for (let i = 0; i < list2.length; ++i) {
- let pos = list1.indexOf(list2[i]);
- if (pos == -1){
- return false;
- }
- list1.splice(pos, 1);
- }
- return true
- }
- ////得到list1[[],[],[]]里面是否包含list2
- proto.getISBH2 = function (_list1,list2) {
- // console.warn("得到list1[[],[],[]]里面是否包含list2 "+JSON.stringify(_list1)+" list2 "+list2);
- for (let i = 0; i < _list1.length; ++i) {
- if(_list1[i].length == list2.length){
- for (let x = 0; x < _list1[i].length; ++x) {
- if(_list1[i][x] == list2[x]){
- // console.warn("包含了 第i个 "+i);
- return true;
- }
- }
- }
- }
- // console.warn("不包含");
- return false
- }
- //// 得到是否是起手
- proto.getIsQS = function () {
- let isqs = this.castCount == (this.playerAllCount*CARDS_COUNT+1);//是否起手
- if(isqs){
- if(this.chuPaiCountTL == 0) return true;
- }
- return false;
- }
- // 起手胡牌分析 chairID(TL++这个参数) 手牌 加上这张判断能不能胡 手上的吃碰杠牌 是否自己摸上来的
- proto.qshuAnalyze = function (chairID,handCards) {
- this.everyQSHType[chairID] = [];
- this.canSelects[chairID] = [];
- let isqs = this.getIsQS();
- let shoupai = this.deepCloneTL(handCards);
- // this.remove(shoupai,this.everyQSHCZGList[chairID]);
- shoupai = this.sort(shoupai);
- for (let i = 0; i < this.qshuTypeTL.length; ++i) {
- this.everyQSHType[chairID][i] = 0;
- if( i == 0 && isqs && this.isSiXi(chairID,shoupai,isqs)){
- this.everyQSHType[chairID][i] = 1;
- }
- else if( i == 1 && isqs && this.isBanBanHu(chairID,shoupai,isqs)){
- this.everyQSHType[chairID][i] = 1;
- }
- else if( i == 2 && isqs && this.isQueYiSe(chairID,shoupai,isqs)){
- this.everyQSHType[chairID][i] = 1;
- }
- else if( i == 3 && isqs && this.isLiuLiuShun(chairID,shoupai,isqs)){
- this.everyQSHType[chairID][i] = 1;
- }
- else if( i == 4 && (!isqs) && this.isSiXi(chairID,shoupai,isqs)){
- this.everyQSHType[chairID][i] = 1;
- }
- else if( i == 5 && (!isqs) && this.isLiuLiuShun(chairID,shoupai,isqs)){
- this.everyQSHType[chairID][i] = 1;
- }
- // else if( i == 4 && this.isJieJieGao(shoupai)){
- // this.everyQSHType[chairID][i] = 1;
- // }
- // else if( i == 5 && this.everyQSHType[chairID][2] == 0 && this.isSanTong(shoupai)){
- // //是缺一色的情况下不可能是三同
- // this.everyQSHType[chairID][i] = 1;
- // }
- // else if( i == 6 && this.everyQSHType[chairID][1] == 0 && this.isDanJiang(shoupai)){
- // //是板板胡的话不可能是单将一枝花
- // this.everyQSHType[chairID][i] = 1;
- // }
- // else if( i == 7 && this.everyQSHType[chairID][1] == 0 && this.everyQSHType[chairID][6] == 0 && this.isDanWu(shoupai)){
- // //是板板胡的话不可能是单五一枝花
- // //只有一张五的情况下都满足单将一枝花和单五一枝花,这种情况算单将一枝花单五一枝花不成立
- // this.everyQSHType[chairID][i] = 1;
- // }
- }
- }
- //起手的六六顺消耗过的牌起手四喜不能再次使用,中途的六六顺消耗过的牌中途四喜不能再次使用,
- //起手的六六顺消耗过的牌中途四喜可以再次使用,(四喜和六六顺同理)
- // 是否四喜
- proto.isSiXi = function (chairID,handCards,isqs) {
- // console.error("是否四喜===111 chairID "+chairID+" everyQSHCZGList "+JSON.stringify(this.everyQSHCZGList[chairID]));
- // console.error("是否四喜===222 chairID "+chairID+" everyQSHCZGList2 "+JSON.stringify(this.everyQSHCZGList2[chairID]));
- // console.error("是否四喜===333 chairID "+chairID+" handCards "+JSON.stringify(handCards));
- if(!isqs && this.kexuanList[0] != 1) return false;//没有勾选中途大四喜
- let canSelects = [];
- var dcount = 0;
- for (let i = 0; i < handCards.length-3; ++i) {
- let card = handCards[i];
- if (card == handCards[i+1] && card == handCards[i+2] && card == handCards[i+3]) {
- if(!this.getISBH(this.everyQSHCZGList[chairID],[card,card,card])){
- dcount += 1;
- i+=3;
- canSelects.push([card,card,card,card])
- }
- else{
- // console.error("是否四喜===222 chairID isqs " + isqs)
- //添加这个else是为了满足下面这个规则,如果消耗过的牌不能再次使用就不要这个else了
- //起手的六六顺消耗过的牌起手四喜不能再次使用,中途的六六顺消耗过的牌中途四喜不能再次使用,
- //起手的六六顺消耗过的牌中途四喜可以再次使用,(四喜和六六顺同理)
- if(!isqs && !this.getISBH2(this.everyQSHCZGList2[chairID],[card,card,card,card])){
- dcount += 1;
- i+=3;
- canSelects.push([card,card,card,card])
- }
- }
- }
- }
- if(dcount >= 1){
- let type = 0;
- if(!isqs) type = 4;
- let obj = {
- type:type,
- cards:canSelects
- }
- this.canSelects[chairID].push(obj)
- return true;
- }
- return false;
- };
- // 是否板板胡
- proto.isBanBanHu = function (chairID,handCards,isqs) {
- if(this.everyXiaoHuList[chairID].indexOf(1) != -1) return false;
- for (let i = 0; i < handCards.length; ++i) {
- let card = this.getValue(handCards[i]);
- if (card == 2 || card == 5 || card == 8) {
- return false;
- }
- }
- let obj = {
- type:1,
- cards:[]
- }
- this.canSelects[chairID].push(obj);
- return true;
- };
- // 是否缺一色
- proto.isQueYiSe = function (chairID,handCards,isqs) {
- // console.warn("是否缺一色 chairID "+chairID+" handCards "+handCards + " isqs "+isqs);
- let huaSeCount = [0,0,0,0];
- for (let i = 0; i < handCards.length; ++i) {
- let card = handCards[i];
- if(this.getType(card) == 1 ) huaSeCount[0] = 1;
- if(this.getType(card) == 2 ) huaSeCount[1] = 1;
- if(this.getType(card) == 3 ) huaSeCount[2] = 1;
- }
- let huase = 0;
- for (let n = 0; n < huaSeCount.length; ++n) {
- if(huaSeCount[n] == 1) huase += 1;
- }
-
- if(huase <= 2){
- let ismz = false;
- let yjhgdqyscs = 0;//已经胡过的缺一色次数
- for (let i = 0; i < this.everyXiaoHuList[chairID].length; ++i) {
- if(this.everyXiaoHuList[chairID][i] == 2) yjhgdqyscs++
- }
- if(huase == 2){
- if(yjhgdqyscs == 0) ismz = true;
- }
- else if(huase == 1){
- //手上只有一种花色可以胡缺一色两次
- if(yjhgdqyscs < 2) ismz = true;
- }
- // console.warn("缺一色==== "+ismz+" yjhgdqyscs "+yjhgdqyscs + " huase "+huase);
- if(ismz){
- let obj = {
- type:2,
- cards:[]
- }
- this.canSelects[chairID].push(obj);
- return true;
- }
- }
- return false;
- };
- // 是否六六顺
- proto.isLiuLiuShun = function (chairID,handCards,isqs) {
- if(!isqs && this.kexuanList[1] != 1) return false;//没有勾选中途大四喜
- var keList = [];
- for (let i = 0; i < handCards.length-2; ++i) {
- let card = handCards[i];
- if (card == handCards[i+1] && card == handCards[i+2]) {
- keList.push([card,card,card])
- i+=2;
- }
- }
- if(keList.length >= 2){
- let cards = [];
- for (let i = 0; i < keList.length; ++i) {
- for (let j = i+1; j < keList.length; ++j) {
- if(!this.getISBH(this.everyQSHCZGList[chairID],keList[i]) && !this.getISBH(this.everyQSHCZGList[chairID],keList[j])){
- let cc = keList[i].concat(keList[j]);
- cards.push(cc);
- }
- }
- }
- if(cards.length > 0){
- let type = 3;
- if(!isqs) type = 5;
- let obj = {
- type:type,
- cards:cards
- }
- this.canSelects[chairID].push(obj);
- return true
- }
- return false;
- }
- return false;
- };
- // 是否节节高
- // proto.isJieJieGao = function (handCards) {
- // var duiziList = [];
- // for (let i = 0; i < handCards.length-1; ++i) {
- // let card = handCards[i];
- // if (card == handCards[i+1]) {
- // if(duiziList.indexOf(card) == -1){
- // duiziList[duiziList.length] = card;
- // }
- // i+=1;
- // }
- // }
- // for (let i = 0; i < duiziList.length; ++i) {
- // let value = this.getValue(duiziList[i])
- // if(value < 8 && duiziList[i]+1 == duiziList[i+ 1] && duiziList[i]+2 == duiziList[i+ 2]){
- // return true
- // }
- // }
- // return false;
- // };
- // // 是否三同
- // proto.isSanTong = function (handCards) {
- // var duiziList = [];
- // for (let i = 0; i < handCards.length-1; ++i) {
- // let card = handCards[i];
- // if (card == handCards[i+1]) {
- // if(duiziList.indexOf(card) == -1){
- // duiziList[duiziList.length] = card;
- // }
- // i+=1;
- // }
- // }
- // for (let i = 0; i < duiziList.length; ++i) {
- // let card = handCards[i];
- // let type = this.getType(duiziList[i])
- // if(type < 2){
- // if(duiziList.indexOf(card + 10) != -1 && duiziList.indexOf(card + 20) != -1){
- // return true;
- // }
- // }
- // else {
- // return false;
- // }
- // }
- // return false;
- // };
- // // 是否单将一枝花
- // proto.isDanJiang = function (handCards) {
- // let count = 0;
- // for (let i = 0; i < handCards.length; ++i) {
- // let value = this.getValue(handCards[i])
- // if (value == 2 || value == 5 || value == 8) {
- // count++;
- // if(count >= 2) return false;
- // }
- // }
- // return true;
- // };
- // // 是否单五一枝花
- // proto.isDanWu = function (handCards) {
- // let count1 = 0;
- // let count2 = 0;
- // let count3 = 0;
- // for (let i = 0; i < handCards.length; ++i) {
- // let value = this.getValue(handCards[i])
- // if (value == 2) count1++;
- // if (value == 5) count2++;
- // if (value == 8) count3++;
- // }
- // if(count1 == 1 || count2 == 1 || count3 == 1) return true;
- // };
- //得到除7对和将将胡之外的大胡牌型,大胡牌型可以乱将
- proto.getCardTypeTL = function (chairID,handCards, huCards,hures,isTouch) {
- // console.warn("得到除7对和将将胡之外的大胡牌型,大胡牌型可以乱将 "+this.dahuTypeTL.length);
- let shoupai = handCards/////手牌
- let PGPai = huCards/////手上的碰杠牌
- let chengju = hures/////整理好之后成句的牌(包括碰杠牌)
- for (var i = 0; i < this.dahuTypeTL.length; i++) {
- this.everyDAHType[chairID][i] = 0;
- if( i == 0 && this.isSevenDouble(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- if( i == 1 && this.everyDAHType[chairID][0] == 1 && this.isHHSevenDouble(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- if( i == 2 && this.everyDAHType[chairID][0] == 1 && this.isSHHSevenDouble(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- if( i == 3 && this.everyDAHType[chairID][0] == 1 && this.isSSHHSevenDouble(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- if( i == 4 && this.isJiangJiangHu(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- if( i == 5 && this.isQQR(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- else if( i == 6 && isTouch && this.isMQ(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- else if( i == 7 && this.isQYS(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- else if( i == 8 && this.isPengPengHu(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- else if( i == 9 && this.isGangKai(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- else if( i == 10 && this.isQiangGang(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- else if( i == 11 && this.isHDLY(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- else if( i == 12 && this.isTianHu(shoupai,PGPai,chengju)){
- this.everyDAHType[chairID][i] = 1;
- }
- }
- }
- // 是否七对
- proto.isSevenDouble = function (handCards,PGPai,chengju) {
- if (handCards.length <= CARDS_COUNT) return false;
- let baiDaCount22 = this.sbyBDList.length////TL++
- var dcount = 0;
- var counts = {};
- for (let i = 0; i < handCards.length; ++i) {
- let card = handCards[i];
- if(this.judgeACardISBD(card)) continue;/////百搭牌不做基础牌进行判断
- counts[card] = (counts[card] || 0) + 1;
- if (counts[card] >= 2) {
- dcount += 1;
- counts[card] = 0;
- }
- }
- // console.warn("是否是7对 ",baiDaCount22,dcount,handCards);
- return (dcount + baiDaCount22 >= 7);
- };
- // 是否豪华七对
- proto.isHHSevenDouble = function (handCards,PGPai,chengju) {
- if (handCards.length <= CARDS_COUNT) return false;
- let baiDaCount22 = this.sbyBDList.length////TL++
- var gcount = 0;
- for (let i = 0; i < handCards.length-3; ++i) {
- let card = handCards[i];
- if(this.judgeACardISBD(card)) continue;/////百搭牌不做基础牌进行判断
- if (card == handCards[i+1] && card == handCards[i+2] && card == handCards[i+3]) {
- gcount += 1;
- i+=3;
- }
- }
- // console.warn("是否是豪华七对 "+gcount+" baiDaCount22 "+baiDaCount22+" handCards "+JSON.stringify(handCards));
- if(gcount >= 1){
- return true;
- }
- if(baiDaCount22 >= 1){
- var kcount = 0;
- for (let i = 0; i < handCards.length-2; ++i) {
- let card = handCards[i];
- if(this.judgeACardISBD(card)) continue;/////百搭牌不做基础牌进行判断
- if (card == handCards[i+1] && card == handCards[i+2]) {
- kcount += 1;
- i+=2;
- }
- }
- // console.warn("是否是豪华七对 有百搭111 kcount "+kcount);
- if(kcount >= 1) return true;
- //至此手上只有对子和单牌
- var dcount = 0;
- var counts = {};
- for (let i = 0; i < handCards.length; ++i) {
- let card = handCards[i];
- if(this.judgeACardISBD(card)) continue;/////百搭牌不做基础牌进行判断
- counts[card] = (counts[card] || 0) + 1;
- if (counts[card] >= 2) {
- dcount += 1;
- counts[card] = 0;
- }
- }
- // console.warn("是否是豪华七对 dcount "+dcount+" kcount "+kcount)
- if(dcount == 5 && baiDaCount22 >= 3) return true;//5对+4百搭 或者5对1单3百搭
- else if(dcount == 6 && baiDaCount22 == 2) return true;
- }
- return false;
- };
- // 是否双豪华七对
- proto.isSHHSevenDouble = function (handCards,PGPai,chengju) {
- if (handCards.length <= CARDS_COUNT) return false;
- let baiDaCount22 = this.sbyBDList.length////TL++
- var gcount = 0;
- for (let i = 0; i < handCards.length-3; ++i) {
- let card = handCards[i];
- if(this.judgeACardISBD(card)) continue;/////百搭牌不做基础牌进行判断
- if (card == handCards[i+1] && card == handCards[i+2] && card == handCards[i+3]) {
- gcount += 1;
- i+=3;
- }
- }
- if(gcount >= 2) return true;
- if(baiDaCount22 >= 1){
- gcount = 0;
- var kcount = 0;
- var dcount = 0;
- for (let i = 0; i < handCards.length-1; ++i) {
- let card = handCards[i];
- if(this.judgeACardISBD(card)) continue;/////百搭牌不做基础牌进行判断
- if (handCards[i+2] && handCards[i+3] && card == handCards[i+1] && card == handCards[i+2] && card == handCards[i+3]) {
- gcount += 1;
- i+=3;
- }
- if (handCards[i+2] && card == handCards[i+1] && card == handCards[i+2]) {
- kcount += 1;
- i+=2;
- }
- else if (card == handCards[i+1]) {
- dcount += 1;
- i+=1;
- }
- }
- // console.warn("是否是双豪华七对 有百搭111 gcount "+gcount+" kcount "+kcount+" dcount "+dcount);
- if(gcount == 0){
- if(kcount == 0){
- //无杠无刻情况下只能是5对+4百搭 组成双豪华七对
- if(dcount == 5 && baiDaCount22 == 4) return true;
- }
- else if(kcount == 1){
- //无杠1刻情况下 1刻4对3百搭 组成双豪华七对
- if(dcount == 4 && baiDaCount22 == 3) return true;
- //无杠1刻情况下 1刻3对1单牌4百搭 组成双豪华七对
- else if(dcount == 3 && baiDaCount22 == 4) return true;
- }
- else if(kcount == 2){
- //无杠2刻情况下 2刻3对2百搭 组成双豪华七对
- if(dcount == 3 && baiDaCount22 == 2) return true;
- //无杠2刻情况下 2刻2对1单3百搭 组成双豪华七对
- else if(dcount == 2 && baiDaCount22 == 3) return true;
- //无杠2刻情况下 2刻2对4百搭 组成双豪华七对
- else if(dcount == 2 && baiDaCount22 == 4) return true;
- }
- else if(kcount == 3){
- //无杠3刻情况下 3刻1对3百搭 组成双豪华七对
- if(dcount == 1 && baiDaCount22 == 3) return true;
- //无杠3刻情况下 3刻0对1单4百搭 组成双豪华七对
- else if(dcount == 0 && baiDaCount22 == 4) return true;
- }
- }
- if(gcount == 1){
- if(kcount == 0){
- //1杠无刻情况下 1杠0刻4对2百搭 组成双豪华七对
- if(dcount == 4 && baiDaCount22 == 2) return true;
- //1杠无刻情况下 1杠0刻3对4百搭 组成双豪华七对
- else if(dcount == 3 && baiDaCount22 == 4) return true;
- }
- else if(kcount == 1){
- //1杠1刻情况下 1杠1刻3对1百搭 组成双豪华七对
- if(dcount == 3 && baiDaCount22 == 1) return true;
- //1杠1刻情况下 1杠1刻2对1单2百搭 组成双豪华七对
- else if(dcount == 2 && baiDaCount22 == 2) return true;
- //1杠1刻情况下 1杠1刻2对3百搭 组成双豪华七对
- else if(dcount == 2 && baiDaCount22 == 3) return true;
- //1杠1刻情况下 1杠1刻1对2单3百搭 组成双豪华七对
- else if(dcount == 1 && baiDaCount22 == 3) return true;
- //1杠1刻情况下 1杠1刻0对3单牌4百搭 组成双豪华七对
- else if(dcount == 0 && baiDaCount22 == 4) return true;
- }
- else if(kcount == 2){
- //1杠2刻情况下 1杠2刻1对2百搭 组成双豪华七对
- if(dcount == 1 && baiDaCount22 == 2) return true;
- //1杠2刻情况下 1杠2刻0对1单3百搭 组成双豪华七对
- else if(dcount == 0 && baiDaCount22 == 3) return true;
- //1杠2刻情况下 1杠2刻0对0单4百搭 组成双豪华七对
- else if(dcount == 0 && baiDaCount22 == 4) return true;
- }
- }
- }
- return false;
- };
- // 是否三豪华七对
- proto.isSSHHSevenDouble = function (handCards,PGPai,chengju) {
- if (handCards.length <= CARDS_COUNT) return false;
- let baiDaCount22 = this.sbyBDList.length////TL++
- var gcount = 0;
- for (let i = 0; i < handCards.length-3; ++i) {
- let card = handCards[i];
- if (card == handCards[i+1] && card == handCards[i+2] && card == handCards[i+3]) {
- gcount += 1;
- i+=3;
- }
- }
- if(gcount >= 3) return true;
- if(baiDaCount22 >= 1){
- gcount = 0;
- var kcount = 0;
- var dcount = 0;
- for (let i = 0; i < handCards.length-1; ++i) {
- let card = handCards[i];
- if(this.judgeACardISBD(card)) continue;/////百搭牌不做基础牌进行判断
- if (handCards[i+2] && handCards[i+3] && card == handCards[i+1] && card == handCards[i+2] && card == handCards[i+3]) {
- gcount += 1;
- i+=3;
- }
- if (handCards[i+2] && card == handCards[i+1] && card == handCards[i+2]) {
- kcount += 1;
- i+=2;
- }
- else if (card == handCards[i+1]) {
- dcount += 1;
- i+=1;
- }
- }
- // console.warn("是否是三豪华七对 有百搭111 gcount "+gcount+" kcount "+kcount+" dcount "+dcount);
- if(gcount == 0){
- if(kcount == 2){
- //无杠2刻情况下 2刻2对4百搭 组成三豪华七对
- if(dcount == 2 && baiDaCount22 == 4) return true;
- }
- else if(kcount == 3){
- //无杠3刻情况下 3刻1对3百搭 组成三豪华七对
- if(dcount == 1 && baiDaCount22 == 3) return true;
- //无杠3刻情况下 3刻0对1单4百搭 组成三豪华七对
- else if(dcount == 0 && baiDaCount22 == 4) return true;
- }
- }
- if(gcount == 1){
- if(kcount == 0){
- //1杠无刻情况下 1杠0刻3对4百搭 组成三豪华七对
- if(dcount == 3 && baiDaCount22 == 4) return true;
- }
- else if(kcount == 1){
- //1杠1刻情况下 1杠1刻2对3百搭 组成三豪华七对
- if(dcount == 2 && baiDaCount22 == 3) return true;
- //1杠1刻情况下 1杠1刻1对1单牌4百搭 组成三豪华七对
- else if(dcount == 1 && baiDaCount22 == 4) return true;
- }
- else if(kcount == 2){
- //1杠2刻情况下 1杠2刻1对2百搭 组成三豪华七对
- if(dcount == 1 && baiDaCount22 == 2) return true;
- //1杠2刻情况下 1杠2刻0对1单3百搭 组成三豪华七对
- else if(dcount == 0 && baiDaCount22 == 3) return true;
- //1杠2刻情况下 1杠2刻0对0单4百搭 组成三豪华七对
- else if(dcount == 0 && baiDaCount22 == 4) return true;
- }
- }
- if(gcount == 2){
- if(kcount == 0){
- //2杠无刻情况下 2杠0刻1对1单3百搭 组成三豪华七对
- if(dcount == 1 && baiDaCount22 == 3) return true;
- //2杠无刻情况下 2杠0刻1对4百搭 组成三豪华七对
- else if(dcount == 1 && baiDaCount22 == 4) return true;
- }
- else if(kcount == 1){
- //2杠1刻情况下 2杠1刻1对1百搭 组成三豪华七对
- if(dcount == 1 && baiDaCount22 == 1) return true;
- //2杠1刻情况下 2杠1刻1对1单2百搭 组成三豪华七对
- else if(dcount == 1 && baiDaCount22 == 2) return true;
- //2杠1刻情况下 2杠1刻0对0单牌3百搭 组成三豪华七对
- else if(dcount == 0 && baiDaCount22 == 3) return true;
- }
- }
- }
- return false;
- };
- // 是否将将胡
- proto.isJiangJiangHu = function (handCards,PGPai,chengju) {
- for (let i = 0; i < handCards.length; ++i) {
- if(this.judgeACardISBD(handCards[i])) continue;/////百搭牌不做基础牌进行判断
- let value = this.getValue(handCards[i]);
- if (value == 2 || value == 5 || value == 8) continue;
- else return false;
- }
- ////上面是统计手牌2,5,8,下面是统计碰杠牌的2,5,8
- if(PGPai && PGPai.length > 0){
- for (let i = 0; i < PGPai.length; ++i) {
- if(!PGPai[i]) continue;
- let pgcardlist = PGPai[i].cards;
- if(!pgcardlist) continue;
- for (let j = 0; j < pgcardlist.length; ++j) {
- let card2 = pgcardlist[j];
- let value = this.getValue(card2);
- if (value == 2 || value == 5 || value == 8) continue;
- else return false;
- }
- }
- }
- return true;
- }
- //是否 "全求人",
- proto.isQQR = function (shoupai,PGPai,chengju) {
- // console.warn("判断全求人 shoupai "+shoupai);
- if(shoupai.length == 2){
- if(shoupai[0] == shoupai[1]) return true;
- if(shoupai.indexOf(51) != -1) return true;
- }
- return false;
- }
- //是否 "门清",
- proto.isMQ = function (shoupai,PGPai,chengju) {
- if(this.kexuanList[2] != 1) return false;
- return shoupai.length == (CARDS_COUNT+1) && PGPai.length == 0
- }
- //是否 "清一色",
- proto.isQYS = function (shoupai,PGPai,chengju) {
- let huaSe= 0;
- for (let n = 0; n < shoupai.length; ++n) {
- let card = shoupai[n];
- if(this.judgeACardISBD(card)) continue;
- if(huaSe == 0){
- huaSe = this.getType(card);
- }
- else{
- if(this.getType(card) != huaSe){
- return false;
- }
- }
- }
- ////上面是统计手牌花色种类,下面是统计碰杠牌的花色
- if(PGPai && PGPai.length > 0){
- for (let i = 0; i < PGPai.length; ++i) {
- if(!PGPai[i]) continue;
- let pgcardlist = PGPai[i].cards;
- if(!pgcardlist) continue;
- let card2 = pgcardlist[0];
- if(this.judgeACardISBD(card2)) continue;
- if(this.getType(card2) != huaSe){
- return false;
- }
- }
- }
- return true;
- };
- // 是否碰碰胡
- proto.isPengPengHu = function (shoupai,PGPai,chengju) {
- // console.warn("是否碰碰胡000 shoupai "+shoupai+" PGPai "+JSON.stringify(PGPai));
- // console.warn("是否碰碰胡111 chengju "+JSON.stringify(chengju));
- let cjlist = chengju.huCards
- if(!cjlist) return false;/////七对的话没有chengju,所以直接返回false
- // console.warn("是否碰碰胡222 "+JSON.stringify(chengju));
- let keOrGangCount = 0;
- for (let i = 0; i < cjlist.length; ++i) {
- if(cjlist[i].style >= 3 && cjlist[i].style <= 10) keOrGangCount += 1;
- }
- return keOrGangCount == 4 && chengju.jiang > 0;
-
- // if(keOrGangCount == 4 && chengju.jiang > 0) return true;
- // let huCards2 = this.deepCloneTL(PGPai)
- // // console.warn("判断13不搭手上百搭牌个数出错了?????",baiDaCount22,this.sbyBDList,bdIndexlist)
- // var huRes = { card: 0, jiang: 0, huCards: [] };
- // // 重设将牌
- // var resetHuRes = (jiang) => {
- // huRes.jiang = jiang;
- // huRes.huCards = [];
- // for (let huCard of huCards2) huRes.huCards.push(huCard);
- // };
- // for (let i = 0; i < shoupai.length - 1; ++i) {
- // let handCards = this.deepCloneTL(shoupai)
- // if (!this.isJang(handCards[i], handCards[i + 1])) continue;
- // // console.warn("判断13不搭手上百搭牌个数出错了?????000 ",JSON.stringify(huRes))
- // resetHuRes(handCards[i]);////设置将牌
- // // console.warn("判断13不搭手上百搭牌个数出错了?????111 ",JSON.stringify(huRes))
- // let bcjp = handCards[i];
- // let cards = handCards.slice(0, i);////手牌数组的前i个元素
- // cards = cards.concat(handCards.slice(i + 2));////给数组cards拼接上手牌的第 i+2 个以后的全部数组元素 这句是将手牌删除2张将牌之后得到的牌
- // this._dumpFixed(cards, huRes.huCards);
- // // console.warn("判断13不搭手上百搭牌个数出错了?????222 ",JSON.stringify(huRes))
- // i += 1;/////TL++,为了减少运算
- // if(huRes.huCards.length == 4){
- // let keOrGangCount = 0;
- // for (let j = 0; j < huRes.huCards.length; ++j) {
- // if(huRes.huCards[j].style >= 3 && huRes.huCards[j].style <= 10) keOrGangCount += 1;
- // }
- // // console.warn("是否碰碰胡333 "+JSON.stringify(huRes)+" keOrGangCount "+keOrGangCount);
- // if(keOrGangCount == 4 && huRes.jiang > 0) return true;
- // }
- // }
- // return false;
- };
- //是否杠开
- proto.isGangKai = function (shoupai,PGPai,chengju) {
- // console.warn("是否杠开 ",this.currChairIDTL,JSON.stringify(this.isGGMG),JSON.stringify(this.isGGAG),JSON.stringify(this.isGGFXG));
- // if(this.isSeleCatcedCard){
- // if(this.isGGMG[this.currChairIDTL] || this.isGGAG[this.currChairIDTL] || this.isGGFXG[this.currChairIDTL]){
- // return true;/////普通杠开
- // }
- // }
- ////上面是判断刚开的方法,下面是可以杠开和杠炮都判断,因为杠开和杠炮不能同时存在
- for (var i = 0; i < this.isGGMG.length; i++) {
- if(this.isGGMG[i]) return true;
- }
- for (var i = 0; i < this.isGGAG.length; i++) {
- if(this.isGGAG[i]) return true;
- }
- for (var i = 0; i < this.isGGFXG.length; i++) {
- if(this.isGGFXG[i]) return true;
- }
- return false;
- }
- //是否抢杠胡
- proto.isQiangGang = function (shoupai,PGPai,chengju) {
- return this.isLaGang
- }
- //是否海底捞月
- proto.isHDLY = function (shoupai,PGPai,chengju) {
- // console.error("是否海底捞月 "+" this.isZHYZ "+this.isZHYZ+" this.lastCount "+this.lastCount);
- return (this.isZHYZ && this.lastCount == 0)
- }
- //是否天胡
- proto.isTianHu = function (shoupai,PGPai,chengju) {
- // console.error("是否天胡 "+" chuPaiCountTL "+this.chuPaiCountTL+" this.sbyBDList.length "+this.sbyBDList.length);
- return this.chuPaiCountTL == 0 && this.getBDCount(shoupai) == 4;
- }
- // 获得奖码列表和计算奖码分数函数
- proto.getJiangmaInfo = function () {
- // console.warn("获得奖码列表函数 奖码类型:-1:不奖码,1:159奖码,2:摸几奖几,3:一码全中 "+this.jiangmaType)
- let jiangmaList = []
- let jmzs = this.jiangmaCount;//奖码张数
-
- let castC1 = this.castCount;//已经消耗的
- let lastC1 = this.lastCount;
- for (var i = 0; i < jmzs; i++) {
- let card = 0;
- if (lastC1 > 0) {
- card = this.cardsPool[castC1++];
- lastC1 -= 1;
- }
- if(card > 0) jiangmaList[i] = card;
- else break;
- }
- let startNum1 = 0;/////骰子1的点数
- let startNum2 = 0;/////骰子2的点数
- if(jiangmaList.length < jmzs){
- //抓鸟牌时牌堆剩余牌张数不足的时候通过掷骰子来凑数
- startNum1 = this.dice();/////骰子1的点数
- startNum2 = this.dice();/////骰子2的点数
- }
- // console.warn("获得奖码列表函数 奖码列表 ",jiangmaList," 长度 ",jiangmaList.length," addThisIsHu ",this.addThisIsHu)
-
- //下面是计算奖码分数
- let mafen = 0;
-
- return { jiangmaList:jiangmaList,mafen:mafen,startNum1:startNum1,startNum2:startNum2}
- };
- //得到本局的各个玩家的中鸟个数
- proto.getBJGWJZBGS = function (chairId,jiangmaList,diceNum1,diceNum2,lead,yjList) {
- // console.warn("每个玩家中鸟个数 chairId " , chairId,jiangmaList,diceNum1,diceNum2,lead,JSON.stringify(yjList));
- let tzdsfbqk = [0,0,0,0];//点数分布情况
- if(jiangmaList.length == 0){
- let dices = diceNum1;
- if(dices == 1 || dices == 5) tzdsfbqk[0]++;
- else if(dices == 2 || dices == 6) tzdsfbqk[1]++;
- else if(dices == 3) tzdsfbqk[2]++;
- else if(dices == 4) tzdsfbqk[3]++;
- let dices2 = diceNum2;
- if(dices2 == 1 || dices2 == 5) tzdsfbqk[0]++;
- else if(dices2 == 2 || dices2 == 6) tzdsfbqk[1]++;
- else if(dices2 == 3) tzdsfbqk[2]++;
- else if(dices2 == 4) tzdsfbqk[3]++;
- }
- else if(jiangmaList.length == 1){
- let dices = diceNum1+diceNum2;
- if(dices == 5 || dices == 9) tzdsfbqk[0]++;
- else if(dices == 2 || dices == 6 || dices == 10) tzdsfbqk[1]++;
- else if(dices == 3 || dices == 7 || dices == 11) tzdsfbqk[2]++;
- else if(dices == 4 || dices == 8 || dices == 12) tzdsfbqk[3]++;
- let cardValue = this.getValue(jiangmaList[0])
- if(cardValue == 1 || cardValue == 5 || cardValue == 9) tzdsfbqk[0]++;
- else if(cardValue == 2 || cardValue == 6) tzdsfbqk[1]++;
- else if(cardValue == 3 || cardValue == 7) tzdsfbqk[2]++;
- else if(cardValue == 4 || cardValue == 8) tzdsfbqk[3]++;
- }
- else if(jiangmaList.length == 2){
- for (var i = 0; i < jiangmaList.length; i++) {
- let cardValue = this.getValue(jiangmaList[i])
- if(cardValue == 1 || cardValue == 5 || cardValue == 9) tzdsfbqk[0]++;
- else if(cardValue == 2 || cardValue == 6) tzdsfbqk[1]++;
- else if(cardValue == 3 || cardValue == 7) tzdsfbqk[2]++;
- else if(cardValue == 4 || cardValue == 8) tzdsfbqk[3]++;
- }
- }
- // let result = [];
- // if(this.playerAllCount == 2) result = [0,0];
- // else if(this.playerAllCount == 3) result = [0,0,0];
- // else if(this.playerAllCount == 4) result = [0,0,0,0];
- // let cell = this.qshuTypeTL[qshType][1] || 0;
- // console.warn("每个玩家中鸟个数000==== tzdsfbqk " + tzdsfbqk);
- let everyZNGS = [0,0,0,0];//每个玩家中鸟个数
- if(this.playerAllCount == 2){
- if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
- else if(chairId == 1) everyZNGS = [tzdsfbqk[1],tzdsfbqk[0],tzdsfbqk[2],tzdsfbqk[3]];
- }
- else if(this.playerAllCount == 3){
- if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
- else if(chairId == 1) everyZNGS = [tzdsfbqk[2],tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[3]];
- else if(chairId == 2) everyZNGS = [tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[0],tzdsfbqk[3]];
- }
- else if(this.playerAllCount == 4){
- if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
- else if(chairId == 1) everyZNGS = [tzdsfbqk[3],tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2]];
- else if(chairId == 2) everyZNGS = [tzdsfbqk[2],tzdsfbqk[3],tzdsfbqk[0],tzdsfbqk[1]];
- else if(chairId == 3) everyZNGS = [tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3],tzdsfbqk[0]];
- }
- // console.warn("每个玩家中鸟个数111==== everyZNGS " + everyZNGS);
- if(lead != -1){
- for (var i = 0; i < everyZNGS.length; i++) {
- if(chairId == lead){
- //自己是抓鸟者又是点炮者,说明自己是一炮多响了
- //一炮多响的时候,不是赢家也不是点炮者不中鸟
- if (yjList.indexOf(i) == -1 && i != lead) everyZNGS[i] = 0;
- }
- else{
- //正常的点炮,不是点炮者也不是赢家就不中鸟了
- if(i != chairId && i != lead) everyZNGS[i] = 0;
- }
- }
- }
- // console.warn("每个玩家中鸟个数222==== everyZNGS " + everyZNGS);
- return everyZNGS;
- }
- //得到起手胡牌型的总分
- proto.getQSHFen = function (chairID) {
- // console.error("得到起手胡牌型的总分 "+chairID+" "+this.everyXiaoHuList[chairID]+" cd "+this.everyXiaoHuList[chairID].length);
- let count = 0;
- for (var i = 0; i < this.everyXiaoHuList[chairID].length; i++) {
- let zl = this.everyXiaoHuList[chairID][i];
- count+=this.qshuTypeTL[zl][1];
- }
- return count;
- };
- //得到本次起手/中途胡牌型的各个玩家的输赢
- proto.getBCQSHSY = function (chairId,qshType,diceNum1,diceNum2) {
- let result = [];
- if(this.playerAllCount == 2) result = [0,0];
- else if(this.playerAllCount == 3) result = [0,0,0];
- else if(this.playerAllCount == 4) result = [0,0,0,0];
- let cell = this.qshuTypeTL[qshType][1] || 0;
- let dices = [diceNum1,diceNum2];
- let tzdsfbqk = [0,0,0,0];//骰子点数分布情况
- for (var i = 0; i < dices.length; i++) {
- if(dices[i] == 1 || dices[i] == 5) tzdsfbqk[0]++;
- else if(dices[i] == 2 || dices[i] == 6) tzdsfbqk[1]++;
- else if(dices[i] == 3) tzdsfbqk[2]++;
- else if(dices[i] == 4) tzdsfbqk[3]++;
- }
- let everyZNGS = [0,0,0,0];//每个玩家中鸟个数
- if(this.playerAllCount == 2){
- if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
- else if(chairId == 1) everyZNGS = [tzdsfbqk[1],tzdsfbqk[0],tzdsfbqk[2],tzdsfbqk[3]];
- }
- else if(this.playerAllCount == 3){
- if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
- else if(chairId == 1) everyZNGS = [tzdsfbqk[2],tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[3]];
- else if(chairId == 2) everyZNGS = [tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[0],tzdsfbqk[3]];
- }
- else if(this.playerAllCount == 4){
- if(chairId == 0) everyZNGS = [tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3]];
- else if(chairId == 1) everyZNGS = [tzdsfbqk[3],tzdsfbqk[0],tzdsfbqk[1],tzdsfbqk[2]];
- else if(chairId == 2) everyZNGS = [tzdsfbqk[2],tzdsfbqk[3],tzdsfbqk[0],tzdsfbqk[1]];
- else if(chairId == 3) everyZNGS = [tzdsfbqk[1],tzdsfbqk[2],tzdsfbqk[3],tzdsfbqk[0]];
- }
- let bsList = [1,2,4];//分表表示中0,1,2鸟输1,2,4倍
- for (let i = 0; i < this.playerAllCount; ++i) {
- if(i == chairId) continue;
- let gs = everyZNGS[i]+everyZNGS[chairId];
- let sy = bsList[gs] * cell;
- result[i] -= sy;
- result[chairId] += sy;
- }
- // console.warn("每个玩家中鸟个数==== tzdsfbqk "+tzdsfbqk + " everyZNGS " + everyZNGS+" result "+result);
- // for (var i = 0; i < result.length; i++) {
- // if(everyZNGS[i] == 0) result = cell;
- // else if(everyZNGS[i] == 1) result = cell*2;
- // else if(everyZNGS[i] == 2) result = cell*4;
- // }
- return result;
- }
- //得到大胡牌型的总分
- proto.getDaHuFen = function (chairID) {
- let count = 0;
- for (var i = 0; i < this.everyDAHType[chairID].length; i++) {
- if(this.everyDAHType[chairID][i] == 1) count+=this.dahuTypeTL[i][1];
- }
- if(count == 0) count = 2;
- return count;
- };
- //得到大胡牌型的总分2
- proto.getDaHuFen2 = function (chairID,typeList) {
- let count = 0;
- for (var i = 0; i < typeList.length; i++) {
- if(typeList[i] == 1) count+=this.dahuTypeTL[i][1];
- }
- if(count == 0) count = 2;
- return count;
- };
- //得到点炮者
- proto.getLead = function (chairID,lead,yjList) {
- let res = -100;
- if(chairID != -1){
- let yjgs = yjList.length
- if(yjgs > 1){
- res = chairID;
- }
- else if(yjgs == 1){
- if(yjList[0] == chairID){
- res = -1;
- }
- else{
- res = chairID;
- }
- }
- else if(yjgs == 0){
- res = -1;
- }
- }
- if(res == -100) res = lead;
- return res;
- }
|