var module_CardInfo = function(_number,_type,_level,_tag){ this.idList = []; this.count = 0; this.number = _number; this.type = _type; this.level = _level; this.tag = _tag; } module_CardInfo.prototype.addIdToList = function(_id){ this.idList.push(_id); this.count = this.idList.length; } module_CardInfo.prototype.delIdFromList=function(_id){ var index = this.idList.indexOf(_id); if(index>-1){ this.idList.splice(index,1); this.count = this.idList.length; return true; }else{ return false; } } module_CardInfo.prototype.getFromIdList=function(){ if(this.idList.length>0){ var id = this.idList.splice(index,1); this.count = this.idList.length; return id; }else{ return null; } } module_CardInfo.prototype.getTag = function(){ return this.tag; } module_CardInfo.prototype.setTag = function(_tag){ this.tag = _tag; } //class module_CardInfo{ //constructor (_number,_type,_level,_tag){ //this.idList = []; //this.count = 0; //this.number = _number; //this.type = _type; //this.level = _level; //this.tag = _tag; //} //addIdToList (_id){ //this.idList.push(_id); //this.count = this.idList.length; //} //delIdFromList (_id){ //var index = this.idList.indexOf(_id); //if(index>-1){ //this.idList.splice(index,1); //this.count = this.idList.length; //return true; //}else{ //return false; //} //} //getFromIdList (){ //if(this.idList.length>0){ //var id = this.idList.splice(index,1); //this.count = this.idList.length; //return id; //}else{ //return null; //} //} //getTag (){ //return this.tag; //} //setTag (_tag){ //this.tag = _tag; //} //} var module_algorithm = module_algorithm || {}; //初始化牌 module_algorithm.allCards = []; //发牌临时数据 //module_algorithm.dealTemp = []; //module_algorithm.initDealTemp = function(){ //} module_algorithm.prototypeList = []; module_algorithm.initCards = function(){ this.allCards = []; var dealTemp = []; var _dealCards = function(){ } for (var i = 1; i <= module_const.pairs; i++){ //四种花色 for (var j = 1; j <= 4; j++){ for (var k = 1; k <= 13; k++){ //牌id var id = (i - 1) * 54 + (j - 1) * 13 + k - 1; //分值 var score = 0; //发牌状态 var dealowner = 0; //特殊处理 switch (k) { case 5: score = 5; break; case 10: score = 10; break; case 13: score = 10; break; } var new_card = module_card.new(id,score); this.dealCards(new_card); this.allCards.push(new_card); } } var new_card = module_card.new((i - 1) * 54 + 53 - 1,0); //小王 this.dealCards(new_card); this.allCards.push(new_card); //大王 new_card = module_card.new((i - 1) * 54 + 54 - 1,0); this.dealCards(new_card); this.allCards.push(new_card); } } //id转化为数值 module_algorithm.convertIdToNumber = function(_cardId){ if (_cardId % 54 == 52){ //小王 return 53; } if (_cardId % 54 == 53){ //大王 return 54; } return module_rule.card_order.order[(_cardId % 54) % 13]; } //id转为花色 module_algorithm.convertIdToFlower = function(_cardId){ if (_cardId % 54 == 52){ //小王 return 5; } if (_cardId % 54 == 53){ //大王 return 5; } return parseInt((_cardId % 54) / 13) + 1; } //id转为编码 module_algorithm.convertIdToCode = function(_cardId){ if (_cardId % 54 == 52){ //小王 return 5305; } if (_cardId % 54 == 53){ //大王 return 5405; } var flower = this.convertIdToFlower(_cardId); var number = this.convertIdToNumber(_cardId); var code = number * 100 + flower; return code; } //发牌 module_algorithm.dealCards = function(o_card){ } //打乱排序 module_algorithm.mixUpCardList = function(_cardList){ var cd_list = [].concat(_cardList); while(cd_list.length==0){ } } //牌列表排序(从大到小排序) module_algorithm.orderCardsById = function(_cardList){ var cardListTemp = [].concat(_cardList); if (cardListTemp){ for (var i = 0; i < cardListTemp.length; i++) { for (var j = i + 1; j < cardListTemp.length; j++) { var i_code = this.convertIdToCode(cardListTemp[i]); var j_code = this.convertIdToCode(cardListTemp[j]); if (i_code < j_code) { var tmp = cardListTemp[j]; cardListTemp[j] = cardListTemp[i]; cardListTemp[i] = tmp; } } } } return cardListTemp; } //得出510K解析牌型 module_algorithm.get510KCardObjectList = function(_cardList){ try{ if(!_cardList){ return []; } if(_cardList.length == 0){ return []; } _cardList = module_algorithm.orderCardsById(_cardList); var cardObjListTemp = module_card.convertIdListToObjectList(_cardList); module_algorithm.prototypeList = ['link510K']; //for(var key in module_rule.card_prototype){ //module_algorithm.prototypeList.push(key); //} var num = -1; var cardInfoList = []; var result = []; var restRardInfoList = []; var restRardInfoListTemp = []; var resultList = []; var m=0; //for(var m=0;m= 2){ if(cardInfoList[cardInfoList.length - 1].level + 1 == cardInfoList[cardInfoList.length - 2].level){ cardInfoList[cardInfoList.length - 1].setTag(module_const.TAG.beg); }else{ } } for(var i = cardInfoList.length - 2;i >= 0;i--){ if(cardInfoList[i + 1].level + 1 == cardInfoList[i].level){ if(i == 0){//为最后一位 cardInfoList[i].setTag(module_const.TAG.end); }else{ cardInfoList[i].setTag(module_const.TAG.mid); } if(cardInfoList[i + 1].getTag() == module_const.TAG.sde){ cardInfoList[i + 1].setTag(module_const.TAG.beg); } }else{ if(cardInfoList[i+1].getTag() == module_const.TAG.mid || cardInfoList[i+1].getTag() == module_const.TAG.beg){ cardInfoList[i + 1].setTag(module_const.TAG.end); } } } result.push(cardInfoList); result.push(restRardInfoListTemp); resultList.push(result); } return resultList; //} }catch(e){ var _msg = {}; _msg._cardList = _cardList; _msg.func = "module_algorithm.get510KCardObjectList"; _msg.spyzuobiao = spyzuobiao; _msg.chshoupai = chshoupai; _msg.zshu = zshu; _msg.bijiao = bijiao; _msg = JSON.stringify(_msg); module_util.submitError(_msg,e.stack); } } //获得牌列表信息 module_algorithm.getCardListInfo = function(_cardList){ try{ if(!_cardList){ return []; } if(_cardList.length == 0){ return []; } _cardList = module_algorithm.orderCardsById(_cardList); var cardObjListTemp = module_card.convertIdListToObjectList(_cardList); module_algorithm.prototypeList = ['link']; //for(var key in module_rule.card_prototype){ //module_algorithm.prototypeList.push(key); //} var num = -1; var cardInfoList = []; var result = []; var restRardInfoList = []; var restRardInfoListTemp = []; var resultList = []; var m=0; //for(var m=0;m= 2){ if(cardInfoList[cardInfoList.length - 1].level + 1 == cardInfoList[cardInfoList.length - 2].level){ cardInfoList[cardInfoList.length - 1].setTag(module_const.TAG.beg); }else{ } } for(var i = cardInfoList.length - 2;i >= 0;i--){ if(cardInfoList[i + 1].level + 1 == cardInfoList[i].level){ if(i == 0){//为最后一位 cardInfoList[i].setTag(module_const.TAG.end); }else{ cardInfoList[i].setTag(module_const.TAG.mid); } if(cardInfoList[i + 1].getTag() == module_const.TAG.sde){ cardInfoList[i + 1].setTag(module_const.TAG.beg); } }else{ if(cardInfoList[i+1].getTag() == module_const.TAG.mid || cardInfoList[i+1].getTag() == module_const.TAG.beg){ cardInfoList[i + 1].setTag(module_const.TAG.end); } } } result.push(cardInfoList); result.push(restRardInfoListTemp); resultList.push(result); } return resultList; //} }catch(e){ var _msg = {}; _msg._cardList = _cardList; _msg.func = "module_algorithm.getCardListInfo"; _msg.spyzuobiao = spyzuobiao; _msg.chshoupai = chshoupai; _msg.zshu = zshu; _msg.bijiao = bijiao; _msg = JSON.stringify(_msg); module_util.submitError(_msg,e.stack); } } var module_CardType = function(_number,_type,_level){ //constructor (_number,_type,_level){ this.idList = []; this.count = 0; this.type = _type; this.level = _level; //} } module_CardType.prototype.addIdToList = function(_id){ this.idList.push(_id); this.count = this.idList.length; } module_CardType.prototype.delIdFromList = function(_id){ var index = this.idList.indexOf(_id); if(index>-1){ this.idList.splice(index,1); this.count = this.idList.length; return true; }else{ return false; } } //class module_CardType{ //constructor (_number,_type,_level){ //this.idList = []; //this.count = 0; //this.type = _type; //this.level = _level; //} //addIdToList (_id){ //this.idList.push(_id); //this.count = this.idList.length; //} //delIdFromList (_id){ //var index = this.idList.indexOf(_id); //if(index>-1){ //this.idList.splice(index,1); //this.count = this.idList.length; //return true; //}else{ //return false; //} //} //} var module_Analyses = function(_type,_level,_linkCount){ //constructor (_type,_level,_linkCount = 1){ this.idList = []; this.count = 0; this.type = _type; this.level = _level; this.linkCount = _linkCount; //} } module_Analyses.prototype.addIdToList = function(_id){ this.idList.push(_id); this.count = this.idList.length; } module_Analyses.prototype.delIdFromList = function(_id){ var index = this.idList.indexOf(_id); if(index>-1){ this.idList.splice(index,1); this.count = this.idList.length; return true; }else{ return false; } } module_Analyses.prototype.addIdListToList = function(_idList){ for(var i=0;i<_idList.length;i++){ this.idList.push(_idList[i]); } this.count = this.idList.length; } //class module_Analyses{ //constructor (_type,_level,_linkCount = 1){ //this.idList = []; //this.count = 0; //this.type = _type; //this.level = _level; //this.linkCount = _linkCount; //} //addIdToList (_id){ //this.idList.push(_id); //this.count = this.idList.length; //} //delIdFromList (_id){ //var index = this.idList.indexOf(_id); //if(index>-1){ //this.idList.splice(index,1); //this.count = this.idList.length; //return true; //}else{ //return false; //} //} //addIdListToList (_idList){ //for(var i=0;i<_idList.length;i++){ //this.idList.push(_idList[i]); //} //this.count = this.idList.length; //} //} //排列表是否为合法牌型如果符合返回牌型,不符合返回null (只判断单种牌型) module_algorithm.legalCardsType = function(_cardInfoList,_bTemp/*是否手中已经无牌*/){ try{ var _cardInfo = _cardInfoList[0]; var _restCards = _cardInfoList[1]; var _restCardsSum = _cardInfoList[1].length; var _infoLength = _cardInfo.length; var result = []; var alyTemp = null; var addSum = 0; //cardInfo可以额外带的牌数量 switch(_infoLength){ case 0: return null; break; case 1: switch(_cardInfo[0].count){ case 1: alyTemp = new module_Analyses(CARDTYPE.cone,_cardInfo[0].level,1); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; //return alyTemp; break; case 2: alyTemp = new module_Analyses(CARDTYPE.ctwo,_cardInfo[0].level,1); //alyTemp.addIdListToList(_cardInfo[0].idList); //return alyTemp; break; case 3: alyTemp = new module_Analyses(CARDTYPE.cthree,_cardInfo[0].level,1); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 2; //return alyTemp; break; case 4: if(_restCardsSum==0){ alyTemp = new module_Analyses(CARDTYPE.cboom4,_cardInfo[0].level,1); addSum = 0; }else{ alyTemp = new module_Analyses(CARDTYPE.cthree,_cardInfo[0].level,1); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 1; } //return alyTemp; break; case 5: alyTemp = new module_Analyses(CARDTYPE.cboom5,_cardInfo[0].level,1); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; //return alyTemp; break; case 6: alyTemp = new module_Analyses(CARDTYPE.cboom6,_cardInfo[0].level,1); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; //return alyTemp; break; case 7: alyTemp = new module_Analyses(CARDTYPE.cboom7,_cardInfo[0].level,1); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; //return alyTemp; break; case 8: alyTemp = new module_Analyses(CARDTYPE.cboom8,_cardInfo[0].level,1); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; //return alyTemp; break; } break; default: //特殊牌型(510K) if(_infoLength == 3){ var spK105 = [0,0,0];//K510的个数 if(_cardInfo[0].number == 13){ spK105[0] = _cardInfo[0].count; } if(_cardInfo[1].number == 10){ spK105[1] = _cardInfo[1].count; } if(_cardInfo[2].number == 5){ spK105[2] = _cardInfo[2].count; } //单个510K if(spK105[0] == 1 && spK105[1] == 1 && spK105[2] == 1){ alyTemp = new module_Analyses(CARDTYPE.cboom510K1,_cardInfo[0].level,1); addSum = 0; for(var k=0;k<_cardInfo.length;k++){ alyTemp.addIdListToList(_cardInfo[k].idList); } return alyTemp; } //多个510K var min510K = spK105[0]; for(var k=0;k<3;k++){ spK105[k] < min510K ? min510K = spK105[k] : min510K; } switch(min510K){ case 3: alyTemp = new module_Analyses(CARDTYPE.cboom510K3,_cardInfo[0].level,1); addSum = 0; for(var k=0;k<_cardInfo.length;k++){ alyTemp.addIdListToList(_cardInfo[k].idList); } return alyTemp; break; case 4: alyTemp = new module_Analyses(CARDTYPE.cboom510K4,_cardInfo[0].level,1); addSum = 0; for(var k=0;k<_cardInfo.length;k++){ alyTemp.addIdListToList(_cardInfo[k].idList); } return alyTemp; break; case 5: alyTemp = new module_Analyses(CARDTYPE.cboom510K5,_cardInfo[0].level,1); addSum = 0; for(var k=0;k<_cardInfo.length;k++){ alyTemp.addIdListToList(_cardInfo[k].idList); } return alyTemp; break; } } var linkIndex = -1; var linkCount = 0; var sdeTemp = false; var linkIndexTemp = -1; var linkCountTemp = 0; for(var i=0;i<_cardInfo.length;i++){ if(i!=_cardInfo.length-1){ if(_cardInfo[i].level - _cardInfo[i+1].level != 1){//连续 sdeTemp = true; } } linkIndexTemp = -1; linkCountTemp = 0; for(j=i+1;j<_cardInfo.length;j++){ if(_cardInfo[i].count>=3){// linkIndexTemp == -1 ? linkIndexTemp = i : linkIndexTemp; linkCountTemp == 0 ? linkCountTemp = 1 : linkCountTemp; if(_cardInfo[i].level - _cardInfo[j].level == j-i && _cardInfo[j].count >= 3){//连续 linkCountTemp++; if(linkCount < linkCountTemp){ linkIndex = linkIndexTemp; linkCount = linkCountTemp; } }else{ //linkCountTemp++; if(linkCount < linkCountTemp){ linkIndex = linkIndexTemp; linkCount = linkCountTemp; } break; //continue; } }else{ //linkIndexTemp = -1; //linkCountTemp = 0; break; } } if(i==_cardInfo.length-1){ if(_cardInfo[i].count>=3){// linkIndexTemp = i; linkCountTemp = 0; if(_cardInfo[i].count >= 3){//连续 linkCountTemp++; if(linkCount < linkCountTemp){ linkIndex = linkIndexTemp; linkCount = linkCountTemp; } }else{ } }else{ //linkIndexTemp = -1; //linkCountTemp = 0; } } } //console.log("sdeTemp: "+sdeTemp); //console.log("linkIndex:"+linkIndex); //console.log("linkCount:"+linkCount); if(sdeTemp){//有单牌位 if(linkIndex == -1){ return null; }else{ var sdeSum = 0;//单牌数量 for(var i=0;i<_cardInfo.length;i++){ if(i>=linkIndex && i<=linkCount+linkIndex-1){ sdeSum += (_cardInfo[i].count - 3); }else{ sdeSum += _cardInfo[i].count; } } addSum = linkCount*2 - sdeSum; switch(linkCount){ case 1: alyTemp = new module_Analyses(CARDTYPE.cthree,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //for(var k=0;k<_cardInfo.length;k++){ //alyTemp.addIdListToList(_cardInfo[k].idList); //} break; case 2: alyTemp = new module_Analyses(CARDTYPE.ctrblink2,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 3: alyTemp = new module_Analyses(CARDTYPE.ctrblink3,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 4: alyTemp = new module_Analyses(CARDTYPE.ctrblink4,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 5: alyTemp = new module_Analyses(CARDTYPE.ctrblink5,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 6: alyTemp = new module_Analyses(CARDTYPE.ctrblink6,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 7: alyTemp = new module_Analyses(CARDTYPE.ctrblink7,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 8: alyTemp = new module_Analyses(CARDTYPE.ctrblink8,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 9: alyTemp = new module_Analyses(CARDTYPE.ctrblink9,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 10: alyTemp = new module_Analyses(CARDTYPE.ctrblink10,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 11: alyTemp = new module_Analyses(CARDTYPE.ctrblink11,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 12: alyTemp = new module_Analyses(CARDTYPE.ctrblink12,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; default: return null; break; } } }else{ if(linkIndex == -1){ if(_cardInfo[0].type == 2){//为大小王 var jokersum = 0; for(var i=0;i<_cardInfo.length;i++){ jokersum += _cardInfo[i].count; } if(jokersum == 3){ alyTemp = new module_Analyses(CARDTYPE.cboomjoker3,_cardInfo[_cardInfo.length - 1].level,1); addSum = 0; for(var k=0;k<_cardInfo.length;k++){ alyTemp.addIdListToList(_cardInfo[k].idList); } return alyTemp; } if(jokersum == 4){ alyTemp = new module_Analyses(CARDTYPE.cboomjoker4,_cardInfo[_cardInfo.length - 1].level,1); addSum = 0; for(var k=0;k<_cardInfo.length;k++){ alyTemp.addIdListToList(_cardInfo[k].idList); } return alyTemp; } return null; } var linkType = _cardInfo[0].count; for(var i=0;i<_cardInfo.length;i++){ if(linkType != _cardInfo[i].count){ //return null;(33345)这种牌型 return null; } } switch(linkType){ case 1://单顺 switch(_cardInfo.length){ case 5: alyTemp = new module_Analyses(CARDTYPE.csgllink5,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 6: alyTemp = new module_Analyses(CARDTYPE.csgllink6,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 7: alyTemp = new module_Analyses(CARDTYPE.csgllink7,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 8: alyTemp = new module_Analyses(CARDTYPE.csgllink8,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 9: alyTemp = new module_Analyses(CARDTYPE.csgllink9,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 10: alyTemp = new module_Analyses(CARDTYPE.csgllink10,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 11: alyTemp = new module_Analyses(CARDTYPE.csgllink11,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 12: alyTemp = new module_Analyses(CARDTYPE.csgllink12,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; default: return null; break; } break; case 2://双顺 switch(_cardInfo.length){ case 2: alyTemp = new module_Analyses(CARDTYPE.cdbllink2,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 3: alyTemp = new module_Analyses(CARDTYPE.cdbllink3,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 4: alyTemp = new module_Analyses(CARDTYPE.cdbllink4,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 5: alyTemp = new module_Analyses(CARDTYPE.cdbllink5,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 6: alyTemp = new module_Analyses(CARDTYPE.cdbllink6,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 7: alyTemp = new module_Analyses(CARDTYPE.cdbllink7,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 8: alyTemp = new module_Analyses(CARDTYPE.cdbllink8,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 9: alyTemp = new module_Analyses(CARDTYPE.cdbllink9,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 10: alyTemp = new module_Analyses(CARDTYPE.cdbllink10,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 11: alyTemp = new module_Analyses(CARDTYPE.cdbllink11,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; case 12: alyTemp = new module_Analyses(CARDTYPE.cdbllink12,_cardInfo[_cardInfo.length - 1].level,_cardInfo.length); //alyTemp.addIdListToList(_cardInfo[0].idList); addSum = 0; break; default: return null; break; } break; } }else{ var sdeSum = 0;//单牌数量 for(var i=0;i<_cardInfo.length;i++){ if(i>=linkIndex && i<=linkCount+linkIndex-1){ sdeSum += (_cardInfo[i].count - 3); }else{ sdeSum += _cardInfo[i].count; } } addSum = linkCount*2 - sdeSum; switch(linkCount){ case 1: alyTemp = new module_Analyses(CARDTYPE.cthree,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //for(var k=0;k<_cardInfo.length;k++){ //alyTemp.addIdListToList(_cardInfo[k].idList); //} break; case 2: alyTemp = new module_Analyses(CARDTYPE.ctrblink2,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 3: alyTemp = new module_Analyses(CARDTYPE.ctrblink3,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 4: alyTemp = new module_Analyses(CARDTYPE.ctrblink4,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 5: alyTemp = new module_Analyses(CARDTYPE.ctrblink5,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 6: alyTemp = new module_Analyses(CARDTYPE.ctrblink6,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 7: alyTemp = new module_Analyses(CARDTYPE.ctrblink7,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 8: alyTemp = new module_Analyses(CARDTYPE.ctrblink8,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 9: alyTemp = new module_Analyses(CARDTYPE.ctrblink9,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 10: alyTemp = new module_Analyses(CARDTYPE.ctrblink10,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 11: alyTemp = new module_Analyses(CARDTYPE.ctrblink11,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; case 12: alyTemp = new module_Analyses(CARDTYPE.ctrblink12,_cardInfo[linkIndex + linkCount - 1].level,linkCount); //alyTemp.addIdListToList(_cardInfo[0].idList); break; default: return null; break; } } } break; } for(var k=0;k<_cardInfo.length;k++){ alyTemp.addIdListToList(_cardInfo[k].idList); } if(_bTemp){//为最后一手牌 if(addSum >= _restCardsSum){ for(var i=0;i<_restCardsSum;i++){ alyTemp.addIdToList(_restCards[i].id); } return alyTemp; }else{ return null; } }else{ if(addSum == _restCardsSum){ for(var i=0;i<_restCardsSum;i++){ alyTemp.addIdToList(_restCards[i].id); } return alyTemp; }else{ return null; } } return null; }catch(e){ var _msg = {}; //_msg.data = _cardList; _msg.func = "module_algorithm.legalCardsType"; _msg.spyzuobiao = spyzuobiao; _msg.chshoupai = chshoupai; _msg.zshu = zshu; _msg.bijiao = bijiao; _msg = JSON.stringify(_msg); module_util.submitError(_msg,e.stack); } } //查找手牌中大于当前连牌牌型的所有连牌 module_algorithm.findLink = function(_handsCard,_iCount,_iType,_iLevel){ try{ var _handsCardInfo = _handsCard[0]; var linkCount = 0; var result = []; for(var i=_handsCardInfo.length-1;i>=0;i--){ linkCount = 0; linkIndex = -1; for(var j=i-1;j>=0;j--){ if(_handsCardInfo[j].level - _handsCardInfo[j+1].level == 1 && _handsCardInfo[i].count >= _iType &&_handsCardInfo[j].count >= _iType && _handsCardInfo[i].level > _iLevel){ linkCount == 0 ? linkCount = 1 : linkCount; linkCount++; if(linkCount == _iCount){ var resultTemp = []; var delList = []; var idInput = []; var levelInput = []; for(var k = 0;k < linkCount;k++){ for(var m=0;m < _iType;m++){ resultTemp.push(_handsCardInfo[i-k].idList[m]); idInput.push(_handsCardInfo[i-k].idList[m]); } levelInput.push(_handsCardInfo[i-k].level); } if(_iType == 3){ var findAddResult = module_algorithm.findAddition(_handsCard,_iCount*2,levelInput,idInput); //console.log("findAddResult------>>>>>>"); //console.log(findAddResult); for(var k=0;k=0;i--){ if(_handsCardInfo[i].level > _iLevel && _handsCardInfo[i].count >= _iCount){ var resultTemp = []; idInput = []; levelInput = []; for(var m=0;m < _iCount;m++){ resultTemp.push(_handsCardInfo[i].idList[m]); idInput.push(_handsCardInfo[i].idList[m]); levelInput.push(_handsCardInfo[i].level); } if(_iCount == 3){ var findAddResult = module_algorithm.findAddition(_handsCard,2,levelInput,idInput); //console.log("findAddResult------>>>>>>"); //console.log(findAddResult); for(var k=0;k=0 ;i--){ _handCount += _handsCardInfo[i].count; if(_handsCardInfo[i].count < 3 && _iLevelList.indexOf(_handsCardInfo[i].level) == -1 && _handsCardInfo[i].tag == module_const.TAG.sde){ for(var j=0;j<_handsCardInfo[i].idList.length;j++){ result.push(_handsCardInfo[i].idList[j]); //module_util.removeItemFromArray(_handsCardInfo[i].idList,_handsCardInfo[i].idList[j]); //if(_handsCard[i].idList.length==0){ //_handsCard.splice(i,1); //} addCount++; if(addCount == _iCount){ return result; } } } } for(var i=_restCards.length-1;i>=0;i--){ //for(var j=_handsCardInfo[i].idList.length-1;j>=0;j--){ if(_iIdList.indexOf(_restCards[i].id) == -1){ result.push(_restCards[i].id); addCount++; if(addCount == _iCount){ return result; } } //} } for(var i=_handsCardInfo.length-1;i>=0;i--){ for(var j=_handsCardInfo[i].idList.length-1;j>=0;j--){ if(_iIdList.indexOf(_handsCardInfo[i].idList[j]) == -1 && result.indexOf(_handsCardInfo[i].idList[j])==-1){ result.push(_handsCardInfo[i].idList[j]); addCount++; if(addCount == _iCount){ return result; } } } } if(_handCount - _iIdList.length + _restCards.length< _iCount){//已经无牌可带 return result; } return null; }catch(e){ var _msg = {}; _msg._handsCard = _handsCard; _msg._iCount = _iCount; _msg._iLevelList = _iLevelList; _msg._iIdList = _iIdList; _msg.func = "module_algorithm.findAddition"; _msg.spyzuobiao = spyzuobiao; _msg.chshoupai = chshoupai; _msg.zshu = zshu; _msg.bijiao = bijiao; _msg = JSON.stringify(_msg); module_util.submitError(_msg,e.stack); } } //查找符合条件的所有炸弹 module_algorithm.findAllBoom = function(_handsCardInfo,_iClass,_iLevel,_bTemp/*是否是庄家*/){ try{ var result = []; var resultTemp = []; var cardTypeList = []; switch(_iClass){ case CARDTYPE.cboom510K1: resultTemp = module_algorithm.findBoom(_handsCardInfo,CARDTYPE.cboom510K1,_iLevel); if(resultTemp.length>0){ for(var i=0;i0){ for(var i=0;i0){ for(var i=0;i0){ for(var i=0;i0){ for(var i=0;i0){ for(var i=0;i0){ for(var i=0;i0){ for(var i=0;i0){ for(var i=0;i0){ for(var i=0;i0){ for(var i=0;i0){ for(var j=0;j= 0;i--){ if(_handsCardInfo[i].count >= 4 && _handsCardInfo[i].level > _iLevel){ var resultTemp = []; for(var j=_handsCardInfo[i].idList.length-1;j>=0;j--){ resultTemp.push(_handsCardInfo[i].idList[j]); if(resultTemp.length == 4){break;} } result.push(resultTemp); } } break; case CARDTYPE.cboom5: for(var i=_handsCardInfo.length - 1;i >= 0;i--){ if(_handsCardInfo[i].count >= 5 && _handsCardInfo[i].level > _iLevel){ var resultTemp = []; for(var j=_handsCardInfo[i].idList.length-1;j>=0;j--){ resultTemp.push(_handsCardInfo[i].idList[j]); if(resultTemp.length == 5){break;} } result.push(resultTemp); } } break; case CARDTYPE.cboom6: for(var i=_handsCardInfo.length - 1;i >= 0;i--){ if(_handsCardInfo[i].count >= 6 && _handsCardInfo[i].level > _iLevel){ var resultTemp = []; for(var j=_handsCardInfo[i].idList.length-1;j>=0;j--){ resultTemp.push(_handsCardInfo[i].idList[j]); if(resultTemp.length == 6){break;} } result.push(resultTemp); } } break; case CARDTYPE.cboom7: for(var i=_handsCardInfo.length - 1;i >= 0;i--){ if(_handsCardInfo[i].count >= 7 && _handsCardInfo[i].level > _iLevel){ var resultTemp = []; for(var j=_handsCardInfo[i].idList.length-1;j>=0;j--){ resultTemp.push(_handsCardInfo[i].idList[j]); if(resultTemp.length == 7){break;} } result.push(resultTemp); } } break; case CARDTYPE.cboom8: for(var i=_handsCardInfo.length - 1;i >= 0;i--){ if(_handsCardInfo[i].count >= 8 && _handsCardInfo[i].level > _iLevel){ var resultTemp = []; for(var j=_handsCardInfo[i].idList.length-1;j>=0;j--){ resultTemp.push(_handsCardInfo[i].idList[j]); if(resultTemp.length == 8){break;} } result.push(resultTemp); } } break; case CARDTYPE.cboom510K1: if(_iLevel>-1){ var spK105_1 = [[-1,-1],[-1,-1],[-1,-1]]; for(var i = 0;i<_handsCardInfo.length;i++){ if(_handsCardInfo[i].number == 13){ spK105_1[0][0] = _handsCardInfo[i].count; spK105_1[0][1] = i; } if(_handsCardInfo[i].number == 10){ spK105_1[1][0] = _handsCardInfo[i].count; spK105_1[1][1] = i; } if(_handsCardInfo[i].number == 5){ spK105_1[2][0] = _handsCardInfo[i].count; spK105_1[2][1] = i; } } var min510K_1 = spK105_1[0][0]; for(var i=0;i<3;i++){ spK105_1[i][0] < min510K_1 ? min510K = spK105_1[i][0] : min510K_1; if(spK105_1[i][0] == -1){bTemp = true;} } if(bTemp){break;} if(min510K_1>0){ var resultTemp = []; for(var i=0;i-1){ var spK105_3 = [[-1,-1],[-1,-1],[-1,-1]]; for(var i = 0;i<_handsCardInfo.length;i++){ if(_handsCardInfo[i].number == 13){ spK105_3[0][0] = _handsCardInfo[i].count; spK105_3[0][1] = i; } if(_handsCardInfo[i].number == 10){ spK105_3[1][0] = _handsCardInfo[i].count; spK105_3[1][1] = i; } if(_handsCardInfo[i].number == 5){ spK105_3[2][0] = _handsCardInfo[i].count; spK105_3[2][1] = i; } } var min510K_3 = spK105_3[0][0]; for(var i=0;i<3;i++){ spK105_3[i][0] < min510K_3 ? min510K_3 = spK105_3[i][0] : min510K_3; if(spK105_3[i][0] == -1){bTemp = true;} } if(bTemp){break;} if(min510K_3>=3){ var resultTemp = []; for(var i=0;i-1){ var spK105_4 = [[-1,-1],[-1,-1],[-1,-1]]; for(var i = 0;i<_handsCardInfo.length;i++){ if(_handsCardInfo[i].number == 13){ spK105_4[0][0] = _handsCardInfo[i].count; spK105_4[0][1] = i; } if(_handsCardInfo[i].number == 10){ spK105_4[1][0] = _handsCardInfo[i].count; spK105_4[1][1] = i; } if(_handsCardInfo[i].number == 5){ spK105_4[2][0] = _handsCardInfo[i].count; spK105_4[2][1] = i; } } var min510K_4 = spK105_4[0][0]; for(var i=0;i<3;i++){ spK105_4[i][0] < min510K_4 ? min510K_4 = spK105_4[i][0] : min510K_4; if(spK105_4[i][0] == -1){bTemp = true;} } if(bTemp){break;} if(min510K_4>=4){ var resultTemp = []; for(var i=0;i-1){ var spK105_5 = [[-1,-1],[-1,-1],[-1,-1]]; for(var i = 0;i<_handsCardInfo.length;i++){ if(_handsCardInfo[i].number == 13){ spK105_5[0][0] = _handsCardInfo[i].count; spK105_5[0][1] = i; } if(_handsCardInfo[i].number == 10){ spK105_5[1][0] = _handsCardInfo[i].count; spK105_5[1][1] = i; } if(_handsCardInfo[i].number == 5){ spK105_5[2][0] = _handsCardInfo[i].count; spK105_5[2][1] = i; } } var min510K_5 = spK105_5[0][0]; for(var i=0;i<3;i++){ spK105_5[i][0] < min510K_5 ? min510K_5 = spK105_5[i][0] : min510K_5; if(spK105_5[i][0] == -1){bTemp = true;} } if(bTemp){break;} if(min510K_5>=5){ var resultTemp = []; for(var i=0;i-1){ var spJoker_3 = [[0,0],[0,0]]; for(var i=_handsCardInfo.length - 1;i >= 0;i--){ if(_handsCardInfo[i].number == 54){ spJoker_3[0][0] = _handsCardInfo[i].count; spJoker_3[0][1] = i; } if(_handsCardInfo[i].number == 53){ spJoker_3[1][0] = _handsCardInfo[i].count; spJoker_3[1][1] = i; } } var sumJoker_3 = spJoker_3[0][0] + spJoker_3[1][0]; if(sumJoker_3 >=3){ var resultTemp = []; var sumTemp = 0; for(var i=0;i<2;i++){ for(var j=0;j-1){ var spJoker_4 = [[0,0],[0,0]]; for(var i=_handsCardInfo.length - 1;i >= 0;i--){ if(_handsCardInfo[i].number == 54){ spJoker_4[0][0] = _handsCardInfo[i].count; spJoker_4[0][1] = i; } if(_handsCardInfo[i].number == 53){ spJoker_4[1][0] = _handsCardInfo[i].count; spJoker_4[1][1] = i; } } var sumJoker_4 = spJoker_4[0][0] + spJoker_4[1][0]; if(sumJoker_4 == 4){ var resultTemp = []; var sumTemp = 0; for(var i=0;i<2;i++){ for(var j=0;j _ObjectList[j][_key][_index]){ var temp = _ObjectList[i]; _ObjectList[i] = _ObjectList[j]; _ObjectList[j] = temp; } }else{ if(_ObjectList[i][_key][_index] < _ObjectList[j][_key][_index]){ var temp = _ObjectList[i]; _ObjectList[i] = _ObjectList[j]; _ObjectList[j] = temp; } } } } return _ObjectList; } //比较两牌型(前者能否大于后者)返回值 true->能 false->不能 module_algorithm.compareCards = function(_cardsList_1,_cardsList_2){ } //将id转为数值 //module_algorithm.convertIdToNumber = function(_id){ //var rt = _id % 54; //if (rt == 52){ //小王 //return 53; //} //if (rt == 53){ //大王 //return 54; //} //return rt % 13 + 1; //} //将id转为分 module_algorithm.convertIdToScore = function(_id){ var rt = 0; var num = this.convertIdToNumber(_id); switch(num){ case 5: rt = 5; break; case 10: rt = 10; break; case 13: rt = 10; break; default: rt = 0; break; } return rt; }