目录结构调整
This commit is contained in:
@@ -0,0 +1,465 @@
|
||||
/*================= cls_aset2: 小局基础类 =================
|
||||
注意:
|
||||
1,此牌类是基础小局类;各子游戏需要继承此基础类后下编写自己的小局类。
|
||||
2,子游戏开发人员不能修改该文件。
|
||||
=========================================================*/
|
||||
var cls_aset2 = {
|
||||
|
||||
//================ 新建一小局 ================
|
||||
New: function(){
|
||||
//定义小局
|
||||
var o_aset = this.declare();
|
||||
//初始化牌列表
|
||||
this.initcardlist(o_aset);
|
||||
//除掉不要的牌
|
||||
this.deletecard(o_aset);
|
||||
//设置每张牌的分值
|
||||
this.setcardscore(o_aset);
|
||||
return o_aset;
|
||||
},
|
||||
//小局的数据定义
|
||||
declare: function(){
|
||||
var o_aset = {};
|
||||
//玩家列表
|
||||
o_aset.playerlist = []; //在此定义和存储玩家的状态,比如准备状态、叫分的分值、游戏的得分等等,格式如[[], [], ...], [{}, {}, ...], [player, player, ...]
|
||||
//牌列表
|
||||
o_aset.cardlist = []; //格式为[[], [], [], ...],里面的每个小数组就是一张牌
|
||||
//庄(位置)
|
||||
o_aset.zhuang = -1;
|
||||
//控制权(位置)
|
||||
o_aset.control = -1;
|
||||
//当前是第几轮出牌
|
||||
o_aset.play = 0;
|
||||
//当前是本轮的第几个出牌
|
||||
o_aset.index = 0;
|
||||
|
||||
return o_aset;
|
||||
},
|
||||
//初始化牌列表
|
||||
initcardlist: function(o_aset){
|
||||
//几副牌
|
||||
var card_count = this.get_cardcount();
|
||||
//牌类
|
||||
var card_class = this.get_cardclass();
|
||||
//初始化
|
||||
for (var i = 1; i <= card_count; i++){ //几副牌
|
||||
for (var j = 1; j <= 4; j++){ //方块、梅花、红心、黑桃四种花色
|
||||
for (var k = 1; k <= 13; k++){ //A到K
|
||||
var id = (i - 1) * 54 + (j - 1) * 13 + k - 1; //牌的绝对id
|
||||
//新建一张牌
|
||||
var card_object = card_class.New(id);
|
||||
o_aset.cardlist.push(card_object);
|
||||
}
|
||||
}
|
||||
//小王
|
||||
var card_object = card_class.New((i - 1) * 54 + 53 - 1);
|
||||
o_aset.cardlist.push(card_object);
|
||||
//大王
|
||||
var card_object = card_class.New((i - 1) * 54 + 54 - 1);
|
||||
o_aset.cardlist.push(card_object);
|
||||
}
|
||||
},
|
||||
//几副牌
|
||||
get_cardcount: function(){
|
||||
return 1;
|
||||
},
|
||||
//小局对应的牌类
|
||||
get_cardclass: function(){
|
||||
return cls_card2;
|
||||
},
|
||||
//除掉不要的牌
|
||||
deletecard: function(o_aset){
|
||||
for (var i = 0; i < o_aset.cardlist.length; i++){
|
||||
var o_card = o_aset.cardlist[i];
|
||||
this.get_cardclass().SetDeal(o_card, -1);
|
||||
}
|
||||
|
||||
//下面的代码是3人二七王除掉3、4的例子。类似功能需要在子游戏中重写该方法
|
||||
// for (var i = 0; i < o_aset.cardlist.length; i++){
|
||||
// var o_card = o_aset.cardlist[i];
|
||||
// var card_number = this.get_cardclass().GetNumber(o_card);
|
||||
// if (card_number == 3 || card_number == 4){
|
||||
// this.get_cardclass().SetDeal(o_card, -2);
|
||||
// }
|
||||
// }
|
||||
},
|
||||
//设置每张牌的分值
|
||||
setcardscore: function(o_aset){
|
||||
for (var i = 0; i < o_aset.cardlist.length; i++){
|
||||
var o_card = o_aset.cardlist[i];
|
||||
var card_deal = this.get_cardclass().GetDeal(o_card);
|
||||
if (card_deal != -2){
|
||||
this.get_cardclass().SetScore(o_card, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//下面的代码是设置5、10、K分值的例子。类似功能需要在子游戏中重写该方法
|
||||
// for (var i = 0; i < o_aset.cardlist.length; i++){
|
||||
// var o_card = o_aset.cardlist[i];
|
||||
// var card_deal = this.get_cardclass().GetDeal(o_card);
|
||||
// if (card_deal != -2){
|
||||
// var card_number = this.get_cardclass().GetNumber(o_card);
|
||||
// switch (card_number){
|
||||
// case 5:
|
||||
// this.get_cardclass().SetScore(o_card, 5);
|
||||
// break;
|
||||
// case 10:
|
||||
// this.get_cardclass().SetScore(o_card, 10);
|
||||
// break;
|
||||
// case 13:
|
||||
// this.get_cardclass().SetScore(o_card, 10);
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
},
|
||||
|
||||
//===================== 发牌 =====================
|
||||
DealCard: function(o_aset, o_desk){
|
||||
//需要发牌的位置列表
|
||||
var seatlist = this.get_dealseatlist(o_aset, o_desk);
|
||||
//每人需要发多少张牌
|
||||
var dealcount = this.get_dealcount(o_aset, o_desk);
|
||||
//需要留几张底牌
|
||||
var bottomcount = this.get_bottomcount(o_aset, o_desk);
|
||||
//注意:dealcount * seatlist + bottomcount必须等于除掉不要的牌之后的牌的总数
|
||||
|
||||
//发牌数组
|
||||
var tmplist = [];
|
||||
for (var i = 0; i < seatlist.length; i++){
|
||||
for (var j = 0; j < dealcount; j++){
|
||||
tmplist.push(seatlist[i]);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < bottomcount; i++){
|
||||
tmplist.push(-1);
|
||||
}
|
||||
|
||||
//随机发牌
|
||||
for (var i = 0; i < o_aset.cardlist.length; i++){
|
||||
var o_card = o_aset.cardlist[i];
|
||||
var card_deal = this.get_cardclass().GetDeal(o_card);
|
||||
if (card_deal != -2){
|
||||
var idx = min_random(0, tmplist.length - 1);
|
||||
this.get_cardclass().SetDeal(o_card, tmplist[idx]);
|
||||
this.get_cardclass().SetStart(o_card, tmplist[idx]);
|
||||
this.get_cardclass().SetPlay(o_card, -1);
|
||||
this.get_cardclass().SetOver(o_card, tmplist[idx]);
|
||||
//将发牌数组的最后一位移至该位置
|
||||
if (idx < tmplist.length - 1) {
|
||||
tmplist[idx] = tmplist[tmplist.length - 1];
|
||||
};
|
||||
//发牌数组长度减一
|
||||
tmplist.length = tmplist.length - 1;
|
||||
}
|
||||
}
|
||||
},
|
||||
//需要发牌的位置列表
|
||||
get_dealseatlist: function(o_aset, o_desk){
|
||||
var seatlist = [];
|
||||
for (var i = 0; i < o_desk.o_room.seatlist.length; i++){
|
||||
if (o_desk.o_room.seatlist[i]){
|
||||
if (o_desk.o_room.seatlist[i].gameinfo.isbet){
|
||||
seatlist.push(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
return seatlist;
|
||||
},
|
||||
//每人需要发多少张牌
|
||||
get_dealcount: function(o_aset, o_desk){
|
||||
return 0;
|
||||
},
|
||||
//需要留几张底牌
|
||||
get_bottomcount: function(o_aset, o_desk){
|
||||
return 0;
|
||||
},
|
||||
|
||||
//==================== 拿底牌 ====================
|
||||
PutBottomCard: function(o_aset, seat){
|
||||
var bottomcardlist = this.GetBottomCards(o_aset);
|
||||
for (var i = 0; i < bottomcardlist.length; i++) {
|
||||
var o_card = bottomcardlist[i];
|
||||
this.get_cardclass().SetStart(o_card, seat);
|
||||
}
|
||||
},
|
||||
|
||||
//===================== 埋牌 =====================
|
||||
BuryCard: function(o_aset, seat, cardidlist){
|
||||
/*参数:
|
||||
seat:哪个位置要埋牌
|
||||
cardidlist:要埋的牌的id
|
||||
返回值:true表示执行成功,false表示执行失败。*/
|
||||
if (this.canBuryCard(o_aset, seat, cardidlist)){
|
||||
this.doBuryCard(o_aset, seat, cardidlist);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
get_burycardcount: function(){
|
||||
return 8;
|
||||
},
|
||||
//检查是否可埋牌
|
||||
canBuryCard: function(o_aset, seat, cardidlist){
|
||||
//检查控制权
|
||||
if (seat != o_aset.control){
|
||||
return false;
|
||||
}
|
||||
//检查埋牌数量
|
||||
if (cardidlist.length != this.get_burycardcount()){
|
||||
return false;
|
||||
}
|
||||
//检查要埋的牌是否在玩家手上
|
||||
var inhandcardids = this.GetCardIdsInhand(o_aset, seat);
|
||||
return min_ary_include(inhandcardids, cardidlist);
|
||||
},
|
||||
//埋牌
|
||||
doBuryCard: function(o_aset, seat, cardidlist){
|
||||
var cardlist = this.CardIdsToCards(o_aset, cardidlist);
|
||||
for (var i = 0; i < cardlist.length; i++) {
|
||||
var o_card = cardlist[i];
|
||||
this.get_cardclass().SetPlay(o_card, -2);
|
||||
}
|
||||
},
|
||||
|
||||
//===================== 出牌 =====================
|
||||
PlayCard: function(o_aset, seat, cardidlist, mode){
|
||||
/*参数:
|
||||
seat:哪个位置要出牌
|
||||
cardidlist:要出的牌的id
|
||||
mode:出牌模式 0-需要跟随上一家出牌 1-需要跟随第一家出牌
|
||||
返回值:true表示执行成功,false表示执行失败。*/
|
||||
var can = this.canPlayCard(o_aset, seat, cardidlist, mode); //检查是否可出
|
||||
if (can.result){ //可出
|
||||
this.doPlayCard(o_aset, seat, cardidlist); //出下去
|
||||
return true;
|
||||
} else { //不可出
|
||||
return false;
|
||||
}
|
||||
},
|
||||
//检查是否可出牌
|
||||
canPlayCard: function(o_aset, seat, cardidlist, mode){
|
||||
var can = {}; //返回的结果
|
||||
can.result = false; //是否可以出出去
|
||||
can.cards = null; //牌(对象)
|
||||
can.cardtype = null; //牌型
|
||||
can.value = null; //大小
|
||||
can.flower = null; //花色
|
||||
|
||||
//检查控制权
|
||||
if (seat != o_aset.control){
|
||||
can.result = false;
|
||||
return can;
|
||||
}
|
||||
//检查要出的牌是否在玩家手上
|
||||
var inhandcardids = this.GetCardIdsInhand(o_aset, seat);
|
||||
if (!min_ary_include(inhandcardids, cardidlist)){
|
||||
can.result = false;
|
||||
return can;
|
||||
}
|
||||
|
||||
return can;
|
||||
},
|
||||
//第一个出牌时分析选中的牌是否可以出出去(主要是分析牌型)
|
||||
canPlayCard_first: function(o_aset, cardidlist){
|
||||
var can = {}; //返回的结果
|
||||
can.result = false; //是否可以出出去
|
||||
can.cards = null; //牌(对象)
|
||||
can.cardtype = null; //牌型
|
||||
can.value = null; //大小
|
||||
can.flower = null; //花色
|
||||
|
||||
|
||||
return can;
|
||||
},
|
||||
//不是第一个出牌时分析选中的牌是否可以出出去(主要是分析牌型是否符合前面出牌的牌型)
|
||||
canPlayCard_second: function(o_aset, cardidlist, mode){
|
||||
var can = {}; //返回的结果
|
||||
can.result = false; //是否可以出出去
|
||||
can.cards = null; //牌(对象)
|
||||
can.cardtype = null; //牌型
|
||||
can.value = null; //大小
|
||||
can.flower = null; //花色
|
||||
|
||||
return can;
|
||||
},
|
||||
//出牌
|
||||
doPlayCard: function(o_aset, seat, cardidlist){
|
||||
var cardlist = this.CardIdsToCards(o_aset, cardidlist);
|
||||
for (var i = 0; i < cardlist.length; i++) {
|
||||
var o_card = cardlist[i];
|
||||
this.get_cardclass().SetPlay(o_card, o_aset.play);
|
||||
this.get_cardclass().SetIndex(o_card, o_aset.index);
|
||||
}
|
||||
},
|
||||
|
||||
//=================== 可跟随的牌 ===================
|
||||
CanFollowCard: function(o_aset, seat, mode){
|
||||
//根据第一个人或上一个人出的牌,分析seat这个位置上的人必出的牌和可出的牌
|
||||
|
||||
},
|
||||
|
||||
//==================== 小局结算 =====================
|
||||
CloseAccount: function(o_aset, o_desk){
|
||||
|
||||
},
|
||||
|
||||
//================ 获取各种情况的牌 ================
|
||||
//获取开局时玩家发到手上的牌
|
||||
GetDealCardsBySeat: function(o_aset, seat){
|
||||
return this.GetCardsByDealstate(o_aset, seat);
|
||||
},
|
||||
GetDealCardIdsBySeat: function(o_aset, seat){
|
||||
var cardlist = this.GetDealCardsBySeat(o_aset, seat);
|
||||
return this.CardsToCardIds(cardlist);
|
||||
},
|
||||
//获取底牌
|
||||
GetBottomCards: function(o_aset){
|
||||
return this.GetCardsByDealstate(o_aset, -1);
|
||||
},
|
||||
GetBottomCardIds: function(o_aset){
|
||||
var cardlist = this.GetBottomCards(o_aset);
|
||||
return this.CardsToCardIds(cardlist);
|
||||
},
|
||||
//获取玩家当前手上有的牌
|
||||
GetCardsInhand: function(o_aset, seat){
|
||||
var cardlist = [];
|
||||
for (var i = 0; i < o_aset.cardlist.length; i++){
|
||||
var o_card = o_aset.cardlist[i];
|
||||
var card_start = this.get_cardclass().GetStart(o_card);
|
||||
if (card_start == seat){
|
||||
var card_play = this.get_cardclass().GetPlay(o_card);
|
||||
if (card_play == -1 || card_play == null){
|
||||
cardlist.push(o_card);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cardlist;
|
||||
},
|
||||
GetCardIdsInhand: function(o_aset, seat){
|
||||
var cardlist = this.GetCardsInhand(o_aset, seat);
|
||||
return this.CardsToCardIds(cardlist);
|
||||
},
|
||||
//获取埋牌 参数:seat谁埋的牌,可以不传,默认只有一个人会埋牌
|
||||
GetBuryCards: function(o_aset, seat){
|
||||
return this.GetCardsByPlaystate(o_aset, -2, seat);
|
||||
},
|
||||
GetBuryCardIds: function(o_aset, seat){
|
||||
var cardlist = this.GetBuryCards(o_aset, seat);
|
||||
return this.CardsToCardIds(cardlist);
|
||||
},
|
||||
//获取上一轮出牌
|
||||
GetPriorPlayCard: function(o_aset, round){
|
||||
|
||||
},
|
||||
//获取下一轮出牌
|
||||
GetNextPlayCard: function(o_aset, round){
|
||||
|
||||
},
|
||||
|
||||
//================== 各种底层函数 ==================
|
||||
//根据发牌状态获取牌列表
|
||||
GetCardsByDealstate: function(o_aset, dealstate){
|
||||
var cardlist = [];
|
||||
for (var i = 0; i < o_aset.cardlist.length; i++){
|
||||
var o_card = o_aset.cardlist[i];
|
||||
var card_deal = this.get_cardclass().GetDeal(o_card);
|
||||
if (card_deal == dealstate){
|
||||
cardlist.push(o_card);
|
||||
}
|
||||
}
|
||||
return cardlist;
|
||||
},
|
||||
//根据出牌状态获取牌列表
|
||||
GetCardsByPlaystate: function(o_aset, playstate, seat){
|
||||
var cardlist = [];
|
||||
for (var i = 0; i < o_aset.cardlist.length; i++){
|
||||
var o_card = o_aset.cardlist[i];
|
||||
var card_play = this.get_cardclass().GetPlay(o_card);
|
||||
if (card_play == playstate){
|
||||
if (seat != null){
|
||||
var card_start = this.get_cardclass().GetStart(o_card);
|
||||
if (card_start == seat){
|
||||
cardlist.push(o_card);
|
||||
}
|
||||
} else {
|
||||
cardlist.push(o_card);
|
||||
}
|
||||
}
|
||||
}
|
||||
return cardlist;
|
||||
},
|
||||
//将牌对象列表转换成牌id列表
|
||||
CardsToCardIds: function(cardlist){
|
||||
var cardidlist = [];
|
||||
for (var i = 0; i < cardlist.length; i++){
|
||||
var o_card = cardlist[i];
|
||||
var card_id = this.get_cardclass().GetId(o_card);
|
||||
cardidlist.push(card_id);
|
||||
}
|
||||
return cardidlist;
|
||||
},
|
||||
//将牌id列表转换成牌对象列表
|
||||
CardIdsToCards: function(o_aset, cardidlist){
|
||||
var cardlist = [];
|
||||
for (var i = 0; i < cardidlist.length; i++){
|
||||
var o_card = o_aset.cardlist[cardidlist[i]];
|
||||
cardlist.push(o_card);
|
||||
}
|
||||
return cardlist;
|
||||
},
|
||||
|
||||
//新建小局类
|
||||
NewClass: function(){
|
||||
var cls = {};
|
||||
cls.New = cls_aset2.New;
|
||||
cls.declare = cls_aset2.declare;
|
||||
cls.initcardlist = cls_aset2.initcardlist;
|
||||
cls.get_cardcount = cls_aset2.get_cardcount;
|
||||
cls.get_cardclass = cls_aset2.get_cardclass;
|
||||
cls.deletecard = cls_aset2.deletecard;
|
||||
cls.setcardscore = cls_aset2.setcardscore;
|
||||
|
||||
cls.DealCard = cls_aset2.DealCard;
|
||||
cls.get_dealseatlist = cls_aset2.get_dealseatlist;
|
||||
cls.get_dealcount = cls_aset2.get_dealcount;
|
||||
cls.get_bottomcount = cls_aset2.get_bottomcount;
|
||||
|
||||
cls.PutBottomCard = cls_aset2.PutBottomCard;
|
||||
|
||||
cls.BuryCard = cls_aset2.BuryCard;
|
||||
cls.get_burycardcount = cls_aset2.get_burycardcount;
|
||||
cls.canBuryCard = cls_aset2.canBuryCard;
|
||||
cls.doBuryCard = cls_aset2.doBuryCard;
|
||||
|
||||
cls.PlayCard = cls_aset2.PlayCard;
|
||||
cls.canPlayCard = cls_aset2.canPlayCard;
|
||||
cls.canPlayCard_first = cls_aset2.canPlayCard_first;
|
||||
cls.canPlayCard_second = cls_aset2.canPlayCard_second;
|
||||
cls.doPlayCard = cls_aset2.doPlayCard;
|
||||
|
||||
cls.CanFollowCard = cls_aset2.CanFollowCard;
|
||||
|
||||
cls.CloseAccount = cls_aset2.CloseAccount;
|
||||
|
||||
cls.GetDealCardsBySeat = cls_aset2.GetDealCardsBySeat;
|
||||
cls.GetDealCardIdsBySeat = cls_aset2.GetDealCardIdsBySeat;
|
||||
cls.GetBottomCards = cls_aset2.GetBottomCards;
|
||||
cls.GetBottomCardIds = cls_aset2.GetBottomCardIds;
|
||||
cls.GetCardsInhand = cls_aset2.GetCardsInhand;
|
||||
cls.GetCardIdsInhand = cls_aset2.GetCardIdsInhand;
|
||||
cls.GetBuryCards = cls_aset2.GetBuryCards;
|
||||
cls.GetBuryCardIds = cls_aset2.GetBuryCardIds;
|
||||
cls.GetPriorPlayCard = cls_aset2.GetPriorPlayCard;
|
||||
cls.GetNextPlayCard = cls_aset2.GetNextPlayCard;
|
||||
|
||||
cls.GetCardsByDealstate = cls_aset2.GetCardsByDealstate;
|
||||
cls.GetCardsByPlaystate = cls_aset2.GetCardsByPlaystate;
|
||||
cls.CardsToCardIds = cls_aset2.CardsToCardIds;
|
||||
cls.CardIdsToCards = cls_aset2.CardIdsToCards;
|
||||
return cls;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,747 @@
|
||||
/*===================== cls_card2: 牌的基础类 ======================
|
||||
扑克牌的统一定义:
|
||||
1,单张牌的定义是一个长度为14的数组 [Id, Flower, Number, ArithF, ArithN, Score, Deal, Start, Play, Index, Over, Tag1, Tag2, Tag3]
|
||||
第一位:Id,牌的绝对id,即数组下标,从0开始计数。
|
||||
第二位:Flower,牌的物理花色,5:王 4:黑桃 3:红心 2:梅花 1:方块。
|
||||
第三位:Number,牌的物理大小,1:A 2:2 ... 9:9 10:10 11:J 12:Q 13:K 53:小王 54:大王。
|
||||
第四位:ArithF,牌的算法花色,区别于物理花色,用于牌型计算和比较牌的大小。
|
||||
要求是大于0的整数,不能等于0或小于0,默认等于物理花色。
|
||||
第五位:ArithN,牌的算法大小,区别于物理大小,用于牌型计算和比较牌的大小。
|
||||
要求是大于0的整数,不能等于0或小于0,默认等于物理大小。
|
||||
第六位:Score,牌的分值,如5、10、K。
|
||||
第七位:Deal,发牌状态。
|
||||
-2:规则去除的牌;
|
||||
-1:未发的牌(底牌);
|
||||
>=0:发牌发到谁手上,即座位号。
|
||||
第八位:Start,开局状态,开局时牌在谁手上,与座位编号对应。
|
||||
第九位:Play,出牌状态。
|
||||
-2:埋的牌;
|
||||
-1:未出的牌(手上的牌);
|
||||
>=0:牌是第几轮出出去的,从0开始计数。
|
||||
第十位:Index,本轮中的出牌顺序号,从0开始计数。
|
||||
第十一位:Over,牌局结束时被谁得到,与座位编号对应。
|
||||
第十二位:Tag1,扩展属性1。
|
||||
第十三位:Tag2,扩展属性2。
|
||||
第十四位:Tag3,扩展属性3。
|
||||
2,基础牌型的统一定义:
|
||||
所有基础牌型都由两个值表示:tong,同,表示一样的牌;shun,顺,表示连续的牌。
|
||||
单张:tong=1,shun=1
|
||||
对子:tong=2,shun=1
|
||||
两连对:tong=2,shun=2
|
||||
三连对:tong=2,shun=3
|
||||
三个:tong=3,shun=1
|
||||
飞机:tong=3,shun=2
|
||||
四个:tong=4,shun=1
|
||||
五连顺:tong=1,shun=5
|
||||
六连顺:tong=1,shun=6
|
||||
其他基础牌型以此类推
|
||||
|
||||
注意:
|
||||
1,此牌类是基础扑克牌类、通用扑克牌类;各子游戏可以直接使用,也可以继承此基础类后下编写自己的牌类。
|
||||
2,子游戏开发人员不能修改该文件。
|
||||
3,访问牌的属性时要求使用Get和Set方法,不能直接通过数组下标的形式访问。
|
||||
===================================================================*/
|
||||
var cls_card2 = {
|
||||
|
||||
//新建一张牌
|
||||
New: function(id){
|
||||
return this.declare(id);
|
||||
},
|
||||
//牌的数据定义
|
||||
declare: function(id){
|
||||
//id转物理花色
|
||||
var IdToFlower = function(cardid){
|
||||
var yu = cardid % 54;
|
||||
if (yu == 52 || yu == 53){
|
||||
return 5;
|
||||
}
|
||||
return parseInt(yu / 13) + 1;
|
||||
}
|
||||
//id转物理数值
|
||||
var IdToNumber = function(cardid){
|
||||
var yu = cardid % 54;
|
||||
if (yu == 52){
|
||||
return 53;
|
||||
}
|
||||
if (yu == 53){
|
||||
return 54;
|
||||
}
|
||||
return yu % 13 + 1;
|
||||
}
|
||||
|
||||
var o_card = [];
|
||||
o_card[0] = id;
|
||||
o_card[1] = IdToFlower(id);
|
||||
o_card[2] = IdToNumber(id);
|
||||
o_card[3] = o_card[1];
|
||||
o_card[4] = o_card[2];
|
||||
o_card[5] = null;
|
||||
o_card[6] = null;
|
||||
o_card[7] = null;
|
||||
o_card[8] = null;
|
||||
o_card[9] = null;
|
||||
o_card[10] = null;
|
||||
o_card[11] = null;
|
||||
o_card[12] = null;
|
||||
o_card[13] = null;
|
||||
return o_card;
|
||||
},
|
||||
//牌的id,整型,只读
|
||||
GetId: function(o_card){
|
||||
return o_card[0];
|
||||
},
|
||||
//牌的物理花色,整型,只读
|
||||
GetFlower: function(o_card){
|
||||
return o_card[1];
|
||||
},
|
||||
//牌的物理大小,整型,只读
|
||||
GetNumber: function(o_card){
|
||||
return o_card[2];
|
||||
},
|
||||
//牌的算法花色,整型
|
||||
GetArithF: function(o_card){
|
||||
return o_card[3];
|
||||
},
|
||||
SetArithF: function(o_card, value){
|
||||
o_card[3] = value;
|
||||
},
|
||||
//牌的算法大小,整型
|
||||
GetArithN: function(o_card){
|
||||
return o_card[4];
|
||||
},
|
||||
SetArithN: function(o_card, value){
|
||||
o_card[4] = value;
|
||||
},
|
||||
//牌的分值,整型
|
||||
GetScore: function(o_card){
|
||||
return o_card[5];
|
||||
},
|
||||
SetScore: function(o_card, value){
|
||||
o_card[5] = value;
|
||||
},
|
||||
//发牌状态,整型
|
||||
GetDeal: function(o_card){
|
||||
return o_card[6];
|
||||
},
|
||||
SetDeal: function(o_card, value){
|
||||
o_card[6] = value;
|
||||
},
|
||||
//开局状态,整型
|
||||
GetStart: function(o_card){
|
||||
return o_card[7];
|
||||
},
|
||||
SetStart: function(o_card, value){
|
||||
o_card[7] = value;
|
||||
},
|
||||
//出牌状态,整型
|
||||
GetPlay: function(o_card){
|
||||
return o_card[8];
|
||||
},
|
||||
SetPlay: function(o_card, value){
|
||||
o_card[8] = value;
|
||||
},
|
||||
//出牌顺序,整型
|
||||
GetIndex: function(o_card){
|
||||
return o_card[9];
|
||||
},
|
||||
SetIndex: function(o_card, value){
|
||||
o_card[9] = value;
|
||||
},
|
||||
//结束时被谁得到,整型
|
||||
GetOver: function(o_card){
|
||||
return o_card[10];
|
||||
},
|
||||
SetOver: function(o_card, value){
|
||||
o_card[10] = value;
|
||||
},
|
||||
//扩展属性
|
||||
GetTag1: function(o_card){
|
||||
return o_card[11];
|
||||
},
|
||||
SetTag1: function(o_card, value){
|
||||
o_card[11] = value;
|
||||
},
|
||||
GetTag2: function(o_card){
|
||||
return o_card[12];
|
||||
},
|
||||
SetTag2: function(o_card, value){
|
||||
o_card[12] = value;
|
||||
},
|
||||
GetTag3: function(o_card){
|
||||
return o_card[13];
|
||||
},
|
||||
SetTag3: function(o_card, value){
|
||||
o_card[13] = value;
|
||||
},
|
||||
/*
|
||||
以下提供几个针对牌数组的基础算法,这两个方法是基于牌的算法花色和算法大小实现的,各子游戏在调用前需要将牌的算法花色和算法大小先设置好。
|
||||
|
||||
设置算法花色的原则是:
|
||||
1,如果对花色没要求则需要将所有牌的算法花色统一。比如斗地主中的五连顺是任何花色都可以一起连顺子的,则需要将所有牌的算法花色全部设置成0,表示都是同一花色,然后在同一花色下取顺子。
|
||||
2,如果对花色有要求则需要根据实际情况区分算法花色。比如升级中的两连对是指同一花色下的两连对,则需要将算法花色设置成不同的值,表示不同算法花色之间是不能组成两连对的。
|
||||
|
||||
设置算法大小的原则是:算法大小即可表示是否连牌,也可表示牌的大小关系。
|
||||
1,设置算法大小时要求做到数字连续则表示是连牌。比如A的物理大小是1,K的物理大小是13,1和13是不连续的,此时需要将A的算法大小设置成14,将K的算法大小设置成13,14和13是连续的,表示A和K可以连牌。再比如王牌和A是不能作为连牌出现的,则需要将王的算法大小设置成16,将A的算法大小设置成14,16和14不是连续的,表示王和A不能连牌。
|
||||
2,设置算法大小时要求做到数字大小则表示是牌的大小。比如A的物理大小是1,K的物理大小是13,1比13小,但A比K大,此时需要将A的算法大小设置成14,将K的算法大小设置成13,14比13大,表示A比K大。再比如王牌比A大,则需要将王的算法大小设置成16,将A的算法大小设置成14,16大于14,表示王比A大。
|
||||
*/
|
||||
|
||||
//根据算法花色筛选牌
|
||||
FilterCardListByArithF: function(o_cardlist, ArithF){
|
||||
/*参数说明
|
||||
o_cardlist:需要进行筛选的牌数组
|
||||
ArithF:要筛选的算法花色,默认不筛选
|
||||
|
||||
返回值:筛选后的牌数组*/
|
||||
var result = [];
|
||||
for (var i = 0; i < o_cardlist.length; i++) {
|
||||
var o_card = o_cardlist[i];
|
||||
var card_ArithF = this.GetArithF(o_card);
|
||||
if (!ArithF || card_ArithF == ArithF) {
|
||||
result.push(o_cardlist[i]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
//根据算法大小筛选牌
|
||||
FilterCardListByArithN: function(o_cardlist, min_ArithN, max_ArithN){
|
||||
/*参数说明
|
||||
o_cardlist:需要进行筛选的牌数组
|
||||
min_ArithN:要筛选的算法大小最小值,>=,默认不限制
|
||||
max_ArithN:要筛选的算法大小最大值,<=,默认不限制
|
||||
返回值:筛选后的牌数组*/
|
||||
var result = [];
|
||||
for (var i = 0; i < o_cardlist.length; i++) {
|
||||
var o_card = o_cardlist[i];
|
||||
var card_ArithN = this.GetArithN(o_card);
|
||||
if ((!min_ArithN || card_ArithN >= min_ArithN) &&
|
||||
(!max_ArithN || card_ArithN <= max_ArithN)) {
|
||||
result.push(o_cardlist[i]);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
//根据算法大小对牌数组进行排序(冒泡排序法)
|
||||
SortCardList: function(o_cardlist, options){
|
||||
/*参数说明
|
||||
o_cardlist: 需要进行排序的牌数组
|
||||
options : 排序选项,长度为2的数组,结构为[大小排序方向,花色排序方向]
|
||||
第一位: 算法大小排序方向,0-从小到大排序 1-从大到小排序,默认为0。
|
||||
第二位: 物理花色排序方向,算法大小相同时是否再按物理花色排序,默认为0。
|
||||
0-根据算法大小排序方向默认选择物理花色排序方向,
|
||||
options[0]=0时,物理花色默认按“方块->梅花->红心->黑桃”排序;
|
||||
options[0]=1时,物理花色默认按“黑桃->红心->梅花->方块”排序。
|
||||
1-不按物理花色排序,在o_cardlist中是什么顺序就什么顺序。
|
||||
2-按物理花色从小到大,方块->梅花->红心->黑桃
|
||||
3-按物理花色从大到小,黑桃->红心->梅花->方块
|
||||
返回值: 排序后的牌数组*/
|
||||
var ArithN_direct = 0; //算法大小排序方向
|
||||
var Flower_direct = 0; //物理花色排序方向
|
||||
if (options) {
|
||||
ArithN_direct = parseInt(options[0]);
|
||||
Flower_direct = parseInt(options[1]);
|
||||
}
|
||||
if (!Flower_direct){
|
||||
if (ArithN_direct) {
|
||||
//算法大小从大到小排序时,默认按“黑桃->红心->梅花->方块”排序
|
||||
Flower_direct = 3;
|
||||
} else {
|
||||
//算法大小从小到大排序时,默认按“方块->梅花->红心->黑桃”排序
|
||||
Flower_direct = 2;
|
||||
}
|
||||
}
|
||||
|
||||
//j与j+1互换位置
|
||||
var doChangej = function(){
|
||||
var tmp = o_cardlist[j];
|
||||
o_cardlist[j] = o_cardlist[j + 1];
|
||||
o_cardlist[j + 1] = tmp;
|
||||
}
|
||||
|
||||
for (var i = 0; i < o_cardlist.length; i++){
|
||||
for (var j = 0; j < o_cardlist.length - i - 1; j++){
|
||||
var ArithN_j = this.GetArithN(o_cardlist[j]);
|
||||
var ArithN_j1 = this.GetArithN(o_cardlist[j + 1]);
|
||||
if (ArithN_direct == 0 && ArithN_j > ArithN_j1){
|
||||
//从小到大排序
|
||||
doChangej();
|
||||
continue;
|
||||
}
|
||||
if (ArithN_direct == 1 && ArithN_j < ArithN_j1){
|
||||
//从大到小排序
|
||||
doChangej();
|
||||
continue;
|
||||
}
|
||||
if (ArithN_j == ArithN_j1){
|
||||
//算法大小相同时
|
||||
if (Flower_direct == 1){
|
||||
//不按物理花色排序
|
||||
continue;
|
||||
}
|
||||
var Flower_j = this.GetFlower(o_cardlist[j]);
|
||||
var Flower_j1 = this.GetFlower(o_cardlist[j + 1]);
|
||||
if (Flower_direct == 2 && Flower_j > Flower_j1){
|
||||
//按“方块->梅花->红心->黑桃”排序
|
||||
doChangej();
|
||||
continue;
|
||||
}
|
||||
if (Flower_direct == 3 && Flower_j < Flower_j1){
|
||||
//按“黑桃->红心->梅花->方块”排序
|
||||
doChangej();
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return o_cardlist;
|
||||
},
|
||||
|
||||
//获取指定牌型(基础牌型)的各种组合(只组合,无排列)
|
||||
GetCardListByCardType: function(o_cardlist, cardtype, options){
|
||||
/*参数说明
|
||||
o_cardlist:在这些牌中获取指定牌型,必须是经过了从小到大排序后的牌数组。
|
||||
cardtype :目标牌型,长度为2的数组,结构为[同,顺]。
|
||||
例如单张为[1,1],对子为[2,1],五连顺为[1,5]。
|
||||
options :取牌选项,长度为4的数组,结构为[结果数量,取牌方向,拆牌标志,一次标志]
|
||||
第一位:结果数量,0-获取所有可能的结果,>0要取的结果数量,默认为0。
|
||||
比如,牌数组为[2,3,5,7]时,
|
||||
当options[0]=0时,则取单张的结果为2,3,5,7;
|
||||
当options[0]=1时,则取单张的结果为2;
|
||||
当options[0]=3时,则取单张的结果为2,3,5。
|
||||
第二位:取牌方向,0-从小到大取结果,1-从大到小取结果,默认为0。
|
||||
第三位:拆牌标志,0-不拆牌,1-拆牌,默认为0。
|
||||
比如,牌数组为[2,2,3,5,5,5,7],
|
||||
当options[2]=0时,则取单张时会不取对子的牌和三张的牌,即结果为3,7;
|
||||
当options[2]=1时,则取单张时会拆掉对子的牌和三张的牌,即结果为2,3,5,7。
|
||||
第四位:一次标志,0-相同大小的牌只取一次,1-取所有情况,默认为0。
|
||||
比如,牌数组为[红心2, 黑桃2, 方块3, 方块5, 红心5, 黑桃5, 方块7],
|
||||
当options[3]=0时,则取单张的结果为:红心2, 方块3, 方块5, 方块7;
|
||||
当options[3]=1时,则取单张时结果为:红心2, 黑桃2, 方块3, 方块5, 红心5, 黑桃5, 方块7。
|
||||
返回值:满足牌型要求的牌组合数组。
|
||||
格式如
|
||||
[
|
||||
[o_card, o_card, o_card, ...],
|
||||
[o_card, o_card, o_card, ...],
|
||||
[o_card, o_card, o_card, ...],
|
||||
...
|
||||
]
|
||||
注意:统一用第一张牌的算法大小值表示牌型大小,比如34567是顺子,56789也是顺子,用3表示34567顺子的大小,用5表示56789顺子的大小,5大于3,表示56789的顺子比34567的顺子大*/
|
||||
|
||||
var cardtype_tong = parseInt(cardtype[0]); //牌型-同
|
||||
var cardtype_shun = parseInt(cardtype[1]); //牌型-顺
|
||||
var options_count = 0; //结果数量
|
||||
var options_direct= 0; //取牌方向
|
||||
var options_split = 0; //拆牌标志
|
||||
var options_once = 0; //一次标志
|
||||
if (options){
|
||||
options_count = parseInt(options[0]);
|
||||
options_direct= parseInt(options[1]);
|
||||
options_split = parseInt(options[2]);
|
||||
options_once = parseInt(options[3]);
|
||||
}
|
||||
|
||||
//将牌按大小分组,即相同大小的牌归为一组。如,将[2,2,3,5,5,5,7]这样的牌数组转成[[2,2],[3],[5,5,5],[7]]
|
||||
var SameGroupList = [];
|
||||
var SameGroup = [];
|
||||
for (var i = 0; i < o_cardlist.length; i++){
|
||||
var o_card = o_cardlist[i];
|
||||
if (SameGroup.length == 0){
|
||||
SameGroup.push(o_card);
|
||||
} else {
|
||||
var card_ArithN = this.GetArithN(o_card);
|
||||
var SameGroup_ArithN = this.GetArithN(SameGroup[0]);
|
||||
if (card_ArithN == SameGroup_ArithN){
|
||||
SameGroup.push(o_card);
|
||||
} else {
|
||||
SameGroupList.push(SameGroup);
|
||||
SameGroup = [];
|
||||
SameGroup.push(o_card);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (SameGroup.length > 0){
|
||||
SameGroupList.push(SameGroup);
|
||||
}
|
||||
|
||||
//将牌分组按牌型的“同”获取各自的组合。例如,将[[2,2],[3],[5,5,5],[7]]这样的牌分组按“同”等于2转成[[[2,2]], [[方5,梅5],[方5,红5],[梅5,红5]]]
|
||||
var TongGroupList = [];
|
||||
for (var i = 0; i < SameGroupList.length; i++){
|
||||
if (SameGroupList[i].length < cardtype_tong){
|
||||
// TongGroupList.push([]);
|
||||
continue;
|
||||
}
|
||||
if (SameGroupList[i].length == cardtype_tong){
|
||||
TongGroupList.push([SameGroupList[i]]);
|
||||
continue;
|
||||
}
|
||||
if (SameGroupList[i].length > cardtype_tong){
|
||||
if (!options_split){ //不允许拆牌
|
||||
// TongGroupList.push([]);
|
||||
continue;
|
||||
}
|
||||
if (!options_once){ //同样大小的牌只取一次
|
||||
TongGroupList.push([SameGroupList[i].slice(0, cardtype_tong)]);
|
||||
} else {
|
||||
TongGroupList.push(min_CombineInAry(SameGroupList[i], cardtype_tong));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//返回结果
|
||||
var resultlist = [];
|
||||
var ShunGroup = [];
|
||||
//检查ShunGroup是否是连顺,如果是连顺则在ShunGroup取结果保存到resultlist中
|
||||
var check_return_ShunGroup = function(){
|
||||
var isShun = true;
|
||||
for (var j = 0; j < ShunGroup.length; j++){
|
||||
if (ShunGroup[j].length == 0) {
|
||||
isShun = false;
|
||||
break;
|
||||
}
|
||||
if (j > 0) {
|
||||
var j1_ArithN = this.GetArithN(ShunGroup[j-1][0][0]);
|
||||
var j_ArithN = this.GetArithN(ShunGroup[j][0][0]);
|
||||
//相减等于1表示是顺
|
||||
if (j_ArithN - j1_ArithN != 1){
|
||||
isShun = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isShun){
|
||||
return false;
|
||||
}
|
||||
var result = min_CombineByArys(ShunGroup);
|
||||
for (var j = 0; j < result.length; j++) {
|
||||
var temp = [];
|
||||
for (var k = 0; k < result[j].length; k++) {
|
||||
temp = temp.concat(result[j][k]);
|
||||
}
|
||||
resultlist.push(temp);
|
||||
|
||||
if (options_count && resultlist.length >= options_count) {
|
||||
//达到了要取的结果数量
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}.bind(this);
|
||||
|
||||
//按牌型的“顺”获取符合要求的结果
|
||||
if (!options_direct){
|
||||
//从小到大取结果
|
||||
for (var i = 0; i <= TongGroupList.length - cardtype_shun; i++){
|
||||
ShunGroup = TongGroupList.slice(i, i + cardtype_shun);
|
||||
if (check_return_ShunGroup()){
|
||||
return resultlist;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
//从大到小取结果
|
||||
for (var i = TongGroupList.length - cardtype_shun; i >= 0; i--){
|
||||
ShunGroup = TongGroupList.slice(i, i + cardtype_shun);
|
||||
if (check_return_ShunGroup()){
|
||||
return resultlist;
|
||||
}
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
},
|
||||
GetCardListByCardTypeA: function(o_cardlist, cardtype, options, min_ArithN, max_ArithN){
|
||||
/*参数说明
|
||||
o_cardlist:同GetCardListByCardType中的参数说明。
|
||||
cardtype :同GetCardListByCardType中的参数说明。
|
||||
options :同GetCardListByCardType中的参数说明。
|
||||
min_ArithN:同FilterCardListByArithN中的参数说明。
|
||||
max_ArithN:同FilterCardListByArithN中的参数说明。
|
||||
返回值:同GetCardListByCardType中的参数说明。*/
|
||||
var cardlist = this.FilterCardListByArithN(o_cardlist, min_ArithN, max_ArithN);
|
||||
return this.GetCardListByCardType(cardlist, cardtype, options);
|
||||
},
|
||||
GetCardListByCardTypeB: function(o_cardlist, cardtype, options, ArithF, min_ArithN, max_ArithN){
|
||||
/*参数说明
|
||||
o_cardlist:可以是未排序的牌数组,该函数会实现排序。
|
||||
cardtype :同GetCardListByCardType中的参数说明。
|
||||
options :同GetCardListByCardType中的参数说明。
|
||||
ArithF :同FilterCardListByArithF中的参数说明。
|
||||
min_ArithN:同FilterCardListByArithN中的参数说明。
|
||||
max_ArithN:同FilterCardListByArithN中的参数说明。
|
||||
返回值:同GetCardListByCardType中的参数说明。*/
|
||||
var cardlist = this.FilterCardListByArithF(o_cardlist, ArithF);
|
||||
this.SortCardList(cardlist);
|
||||
cardlist = this.FilterCardListByArithN(cardlist, min_ArithN, max_ArithN);
|
||||
return this.GetCardListByCardType(cardlist, cardtype, options);
|
||||
},
|
||||
|
||||
//获取指定牌型(扩展牌型)的一种组合(只取一种组合)
|
||||
GetCardListByExtendCardTypeA: function(o_cardlist, cardtypelist){
|
||||
/*参数说明
|
||||
o_cardlist :同GetCardListByCardTypeA中的参数说明。
|
||||
cardtypelist:扩展牌型和取牌选项。
|
||||
结构为[
|
||||
[cardtype, options, min_ArithN, max_ArithN],
|
||||
[cardtype, options, min_ArithN, max_ArithN],
|
||||
[cardtype, options, min_ArithN, max_ArithN]
|
||||
]
|
||||
其中cardtype、options、min_ArithN、max_ArithN同GetCardListByCardTypeA中的参数说明。
|
||||
例如3带1,cardtypelist=[
|
||||
[[3,1], [1,x,x,x], min_ArithN, max_ArithN],
|
||||
[[1,1], [1,x,x,x], min_ArithN, max_ArithN]
|
||||
]
|
||||
3带2,cardtypelist=[
|
||||
[[3,1], [1,x,x,x], min_ArithN, max_ArithN],
|
||||
[[1,1], [1,x,x,x], min_ArithN, max_ArithN],
|
||||
[[1,1], [1,x,x,x], min_ArithN, max_ArithN]
|
||||
]
|
||||
3带1对,cardtypelist=[
|
||||
[[3,1], [1,x,x,x], min_ArithN, max_ArithN],
|
||||
[[2,1], [1,x,x,x], min_ArithN, max_ArithN]
|
||||
]
|
||||
注意:options中第一参数一定为1,表示只取一个结果,如果传的值不等于1,也会按等于1处理。
|
||||
|
||||
返回值:同GetCardListByCardTypeA中的参数说明。*/
|
||||
|
||||
var cardlist = o_cardlist;
|
||||
var result = [];
|
||||
for (var i = 0; i < cardtypelist.length; i++){
|
||||
var cardtype = cardtypelist[i][0];
|
||||
var options = cardtypelist[i][1];
|
||||
if (options[0] != 1){
|
||||
options[0] = 1;
|
||||
}
|
||||
var min_ArithN = cardtypelist[i][2];
|
||||
var max_ArithN = cardtypelist[i][3];
|
||||
var BaseCardGroup = this.GetCardListByCardTypeA(cardlist, cardtype, options, min_ArithN, max_ArithN);
|
||||
if (BaseCardGroup.length == 0){
|
||||
return [];
|
||||
}
|
||||
result = result.concat(BaseCardGroup[0]);
|
||||
cardlist = min_ary_deduct(cardlist, BaseCardGroup[0]);
|
||||
}
|
||||
return [result];
|
||||
},
|
||||
|
||||
//获取牌数组的最大牌型
|
||||
GetMaxCardTypeByCardList: function(o_cardlist, option){
|
||||
/*参数说明
|
||||
o_cardlist: 必须是经过了从小到大排序后的牌数组。
|
||||
option: 选项,默认为0
|
||||
0-返回"同"最多的最大牌型(如果"同"相同则取"顺"最多的,如果"顺"也相同则取"值"最大的)
|
||||
1-返回"顺"最多的最大牌型(如果"顺"相同则取"同"最多的,如果"同"也相同则取"值"最大的)
|
||||
返回值:结构为[cardtype, cardlist]。其中,
|
||||
cardtype为基础牌型,结构为[同,顺];
|
||||
cardlist为满足cardtype的牌数组,牌型相同时取最大值的牌。
|
||||
|
||||
例如,当option=0时,
|
||||
牌数组为[3,7,7,7,9,9,J,J,J,Q,Q], 返回值为[[3,1], [J,J,J]]
|
||||
牌数组为[3,7,7,7,8,8,8,9,9,J,J,J,Q,Q], 返回值为[[3,2], [7,7,7,8,8,8]]
|
||||
牌数组为[3,7,7,7,8,8,8,9,9,J,J,J,Q,Q,Q],返回值为[[3,2], [J,J,J,Q,Q,Q]]
|
||||
当option=1时,
|
||||
牌数组为[2,4,5,6,8,9,J,J,Q,Q,K], 返回值为[[1,3], [J,Q,K]]
|
||||
牌数组为[2,4,4,5,5,6,6,8,9,J,J,Q,Q,K], 返回值为[[2,3], [4,4,5,5,6,6]]
|
||||
牌数组为[2,4,4,5,5,6,6,8,9,J,J,Q,Q,K,K],返回值为[[2,3], [J,J,Q,Q,K,K]]*/
|
||||
var result = [];
|
||||
|
||||
//将o_cardlist按大小分组。
|
||||
//如,将[2,2,3,5,5,5,7]这样的牌数组转成[[2,2],[3],[5,5,5],[7]]
|
||||
var changeto_SameGroupList = function(){
|
||||
var SameGroupList = [];
|
||||
var SameGroup = [];
|
||||
for (var i = 0; i < o_cardlist.length; i++){
|
||||
var o_card = o_cardlist[i];
|
||||
if (SameGroup.length == 0){
|
||||
SameGroup.push(o_card);
|
||||
} else {
|
||||
var card_ArithN = this.GetArithN(o_card);
|
||||
var SameGroup_ArithN = this.GetArithN(SameGroup[0]);
|
||||
if (card_ArithN == SameGroup_ArithN){
|
||||
SameGroup.push(o_card);
|
||||
} else {
|
||||
SameGroupList.push(SameGroup);
|
||||
SameGroup = [];
|
||||
SameGroup.push(o_card);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (SameGroup.length > 0){
|
||||
SameGroupList.push(SameGroup);
|
||||
}
|
||||
return SameGroupList;
|
||||
}.bind(this);
|
||||
|
||||
var SameGroupList = changeto_SameGroupList();
|
||||
switch (option){
|
||||
case 0: //取"同"最多的牌型 [A,2,2,3,4,4,5,5,7,7,8,8,9,9,J,J,Q,Q,K,K]
|
||||
//检查ShunGroup是否是连顺
|
||||
var check_ShunGroup_isShun = function(){
|
||||
for (var j = 0; j < ShunGroup.length; j++){
|
||||
if (ShunGroup[j].length == 0) {
|
||||
return false;
|
||||
}
|
||||
if (j > 0) {
|
||||
var j1_ArithN = this.GetArithN(ShunGroup[j-1][0]);
|
||||
var j_ArithN = this.GetArithN(ShunGroup[j][0]);
|
||||
//相减等于1表示是顺
|
||||
if (j_ArithN - j1_ArithN != 1){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}.bind(this);
|
||||
|
||||
result[0] = [SameGroupList[0].length, 1];
|
||||
result[1] = SameGroupList[0];
|
||||
for (var i = 1; i < SameGroupList.length; i++) {
|
||||
if (SameGroupList[i].length > result[0][0]){
|
||||
result[0] = [SameGroupList[i].length, 1];
|
||||
result[1] = SameGroupList[i];
|
||||
} else if (SameGroupList[i].length == result[0][0]){
|
||||
var ArithN_i = this.GetArithN(SameGroupList[i][0]);
|
||||
var ArithN_r = this.GetArithN(result[1][result[1].length - 1]);
|
||||
if (ArithN_i - ArithN_r == 1){ //相减等于1表示是顺
|
||||
result[0][1] = result[0][1] + 1;
|
||||
result[1] = result[1].concat(SameGroupList[i]);
|
||||
} else {
|
||||
if (i + result[0][1] <= SameGroupList.length){
|
||||
var ShunGroup = SameGroupList.slice(i, i + result[0][1]);
|
||||
var isShun = check_ShunGroup_isShun();
|
||||
if (isShun){
|
||||
var check_Tong = true;
|
||||
for (var j = 1; j < ShunGroup.length; j++) {
|
||||
if (ShunGroup[j].length != result[0][0]){
|
||||
check_Tong = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (check_Tong) {
|
||||
result[1] = [];
|
||||
for (var j = 0; j < ShunGroup.length; j++) {
|
||||
result[1] = result[1].concat(ShunGroup[j]);
|
||||
}
|
||||
i = i + result[0][1] - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 1: //取"顺"最多的牌型 [A,3,4,6,8,8,9,9,J,J,J,Q,Q,Q]
|
||||
//将SameGroupList转成ShunGroupList
|
||||
//如,将[[2,2],[3],[5,5,5],[6,6],[7],[9,9]]转成[[[2,2],[3]], [[5,5,5],[6,6],[7]], [[9,9]]]
|
||||
var changeto_ShunGroupList = function(){
|
||||
var ShunGroupList = [];
|
||||
for (var i = 0; i < SameGroupList.length; i++) {
|
||||
var ArithN_i = this.GetArithN(SameGroupList[i][0]);
|
||||
var isFound = false;
|
||||
for (var j = 0; j < ShunGroupList.length; j++) {
|
||||
var ArithN_j = this.GetArithN(ShunGroupList[j][ShunGroupList[j].length - 1][0]);
|
||||
if (ArithN_i - ArithN_j == 1) {
|
||||
ShunGroupList[j].push(SameGroupList[i]);
|
||||
isFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!isFound){
|
||||
ShunGroupList.push([SameGroupList[i]]);
|
||||
}
|
||||
}
|
||||
return ShunGroupList;
|
||||
}.bind(this);
|
||||
|
||||
//获取ShunGroup中最小的"同"数
|
||||
var get_ShunGroup_minTong = function(){
|
||||
var min_Tong = ShunGroup[0].length;
|
||||
for (var j = 1; j < ShunGroup.length; j++) {
|
||||
if (ShunGroup[j].length < min_Tong) {
|
||||
min_Tong = ShunGroup[j].length;
|
||||
}
|
||||
}
|
||||
return min_Tong;
|
||||
}.bind(this);
|
||||
|
||||
//根据ShunGroup的min_Tong设置result
|
||||
var set_result_byShunGroup_byMinTong = function(){
|
||||
result[0] = [min_Tong, ShunGroup.length];
|
||||
result[1] = [];
|
||||
for (var j = 0; j < ShunGroup.length; j++) {
|
||||
result[1] = result[1].concat(ShunGroup[j].slice(0, min_Tong));
|
||||
}
|
||||
}.bind(this);
|
||||
|
||||
var ShunGroupList = changeto_ShunGroupList();
|
||||
//在ShunGroupList中取最长的"顺"
|
||||
for (var i = 0; i < ShunGroupList.length; i++) {
|
||||
var ShunGroup = ShunGroupList[i];
|
||||
var min_Tong = get_ShunGroup_minTong();
|
||||
if (i == 0){
|
||||
set_result_byShunGroup_byMinTong();
|
||||
} else {
|
||||
if (ShunGroup.length > result[0][1]) {
|
||||
set_result_byShunGroup_byMinTong();
|
||||
} else if (ShunGroup.length == result[0][1]) {
|
||||
if (min_Tong >= result[0][0]){
|
||||
set_result_byShunGroup_byMinTong();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
GetMaxCardTypeByCardListA: function(o_cardlist){
|
||||
/*参数说明 o_cardlist:可以是未排序的牌数组,该函数会实现排序。*/
|
||||
this.SortCardList(o_cardlist);
|
||||
return this.GetMaxCardTypeByCardList(o_cardlist);
|
||||
},
|
||||
|
||||
//新建单张牌类
|
||||
NewClass: function(){
|
||||
var cls = {};
|
||||
cls.New = cls_card2.New;
|
||||
cls.declare = cls_card2.declare;
|
||||
cls.GetId = cls_card2.GetId;
|
||||
cls.GetFlower = cls_card2.GetFlower;
|
||||
cls.GetNumber = cls_card2.GetNumber;
|
||||
cls.GetArithF = cls_card2.GetArithF;
|
||||
cls.SetArithF = cls_card2.SetArithF;
|
||||
cls.GetArithN = cls_card2.GetArithN;
|
||||
cls.SetArithN = cls_card2.SetArithN;
|
||||
cls.GetScore = cls_card2.GetScore;
|
||||
cls.SetScore = cls_card2.SetScore;
|
||||
cls.GetDeal = cls_card2.GetDeal;
|
||||
cls.SetDeal = cls_card2.SetDeal;
|
||||
cls.GetStart = cls_card2.GetStart;
|
||||
cls.SetStart = cls_card2.SetStart;
|
||||
cls.GetPlay = cls_card2.GetPlay;
|
||||
cls.SetPlay = cls_card2.SetPlay;
|
||||
cls.GetIndex = cls_card2.GetIndex;
|
||||
cls.SetIndex = cls_card2.SetIndex;
|
||||
cls.GetOver = cls_card2.GetOver;
|
||||
cls.SetOver = cls_card2.SetOver;
|
||||
cls.GetTag1 = cls_card2.GetTag1;
|
||||
cls.SetTag1 = cls_card2.SetTag1;
|
||||
cls.GetTag2 = cls_card2.GetTag2;
|
||||
cls.SetTag2 = cls_card2.SetTag2;
|
||||
cls.GetTag3 = cls_card2.GetTag3;
|
||||
cls.SetTag3 = cls_card2.SetTag3;
|
||||
cls.FilterCardListByArithF = cls_card2.FilterCardListByArithF;
|
||||
cls.FilterCardListByArithN = cls_card2.FilterCardListByArithN;
|
||||
cls.SortCardList = cls_card2.SortCardList;
|
||||
cls.GetCardListByCardType = cls_card2.GetCardListByCardType;
|
||||
cls.GetCardListByCardTypeA = cls_card2.GetCardListByCardTypeA;
|
||||
cls.GetCardListByCardTypeB = cls_card2.GetCardListByCardTypeB;
|
||||
cls.GetCardListByExtendCardTypeA = cls_card2.GetCardListByExtendCardTypeA;
|
||||
cls.GetMaxCardTypeByCardList = cls_card2.GetMaxCardTypeByCardList;
|
||||
cls.GetMaxCardTypeByCardListA = cls_card2.GetMaxCardTypeByCardListA;
|
||||
return cls;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,804 @@
|
||||
var panduan = function(shangjia,chupai){ //牌型,手牌,出的牌
|
||||
var yici = 0;
|
||||
var can_play = 1;//判断出的牌是否能出
|
||||
var paixing = [];//本次出牌牌型
|
||||
var chupaipx0 = [];//同算法
|
||||
var shangjiapai = [];//上家出的牌
|
||||
var sjpshuzu = [];//上家的牌数组
|
||||
var cpshuzu = [];//本次出牌数组
|
||||
var zuidazha = 0;
|
||||
var shangjiapx = [];
|
||||
if (shangjia) {
|
||||
if ( shangjia.length>0) {
|
||||
shangjiapx = shangjia[0];
|
||||
shangjiapai = game.xs_dapai[game.chu];
|
||||
}
|
||||
}
|
||||
if ( game.people == 2) {//根据人数判断最大的炸
|
||||
zuidazha = 14;
|
||||
} else {
|
||||
zuidazha = 15;
|
||||
}
|
||||
cpshuzu = cls_aset2_gp.CardIdsToCards(gp.pai, chupai);//获取打出牌的11位数组牌
|
||||
cls_card2_gp.SortCardList(cpshuzu);//从小到大排序牌(以下都经过排序)
|
||||
chupai = cls_aset2_gp.CardsToCardIds(cpshuzu);//从小到大排序出牌的ID(以下都经过排序)
|
||||
chupaipx0=cls_card2_gp.GetMaxCardTypeByCardList(cpshuzu, 0);////返回"同"最多的最大牌型(如果"同"相同则取"顺"最多的,如果"顺"也相同则取"值"最大的)
|
||||
|
||||
|
||||
sjpshuzu = cls_aset2_gp.CardIdsToCards(gp.pai, shangjiapai);
|
||||
paixing=chupaipx0[0];
|
||||
if(chupaipx0[0][0]==chupai.length && chupaipx0[0][0]<5)
|
||||
{
|
||||
paixing=chupaipx0[0];//同
|
||||
}else if(chupaipx0[0][1] == chupai.length && chupai.length>=5)
|
||||
{
|
||||
paixing=chupaipx0[0];//顺子
|
||||
}else if(chupaipx0[0][0]==2 && chupaipx0[1].length==chupai.length)
|
||||
{
|
||||
paixing=chupaipx0[0];//连对
|
||||
}else if(chupaipx0[0][0]==3&&chupaipx0[0][1]>1&&chupai.length==chupaipx0[0][1]*5 && chupaipx0[1][chupaipx0[1].length-1][4] != 15){
|
||||
paixing=chupaipx0[0];//飞机
|
||||
}else if(chupaipx0[0][0]==3&&chupaipx0[0][1]>1&&chupai.length==chupaipx0[0][1]*3 && chupaipx0[1][chupaipx0[1].length-1][4] != 15){
|
||||
paixing=chupaipx0[0];//飞机
|
||||
}else if(chupaipx0[0][0]==3&&chupaipx0[0][1]==1&&chupai.length==chupaipx0[0][1]*5){
|
||||
paixing=chupaipx0[0];//3带二
|
||||
}else if(chupaipx0[0][0]==4&&chupaipx0[0][1]==1&&chupai.length==5){
|
||||
paixing=chupaipx0[0];//3带二
|
||||
paixing[0]=chupaipx0[0][0]-1;
|
||||
}else if(chupaipx0[0][0]==3&&chupaipx0[0][1]>=1&&chupai.length <= chupaipx0[0][1]*5 && chupai.length >= chupaipx0[0][1]*3 && game.pai.length == chupai.length){
|
||||
paixing=chupaipx0[0];//3带1
|
||||
}else if (chupaipx0[0][0] == 4 && chupaipx0[0][1] >= 1 && chupai.length > 4) {//有个炸弹
|
||||
if (chupai.length !=game.pai.length) {
|
||||
if (chupai.length == 10) {//10张牌
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,2], [0,0,1,1], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,2];
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}else if (chupai.length == 15) {//15张牌
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,3], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,3];
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}else{
|
||||
if (chupai.length >6) {//多余6张牌
|
||||
if(chupai.length <=9){//飞机 2
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,2], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,2];
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
else if (chupai.length <=12 && chupai.length >9) {//飞机 3
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,3], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,3];
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
else if (chupai.length <= 15) {//飞机 3.4
|
||||
if (shangjiapx[0] == 3 && shangjiapx[1] == 4) {//飞机 4
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,4], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,4];
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}else if(shangjiapx[0] == 3 && shangjiapx[1] == 3) {//飞机 3
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,3], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,3];
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}else {
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,3], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,3];
|
||||
}else {
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,4], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,4];
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if (chupai.length > 15) {//飞机 3.4
|
||||
if (shangjiapx[0] == 3 && shangjiapx[1] == 4) {//飞机 4
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,4], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,4];
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}else if(shangjiapx[0] == 3 && shangjiapx[1] == 5) {//飞机 3
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,5], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,5];
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}else {
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,5], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,5];
|
||||
}else {
|
||||
var feiji = cls_card2_gp.GetCardListByCardTypeA(cls_card2_gp.SortCardList(cpshuzu,[0,0]),
|
||||
// 牌的类型 [所有可能,小到大,拆牌,取所有情况] 起始牌
|
||||
[3,4], [0,0,1,0], null ,null);
|
||||
if(feiji.length){//如果有就是飞机
|
||||
paixing = [3,4];
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}else {
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
|
||||
if( shangjiapx && shangjiapx.length!=0)//上家出了牌
|
||||
{
|
||||
if(chupai.length != shangjiapai.length)//判断出的牌的长度相同
|
||||
{
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
|
||||
if(paixing[0]!=shangjiapx[0]&&paixing[1]!=shangjiapx[1]&&yici == 0)//判断牌型是否与上家相同
|
||||
{
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
|
||||
if(paixing[0]==shangjiapx[0]&&paixing[1]==shangjiapx[1]&&yici == 0 && shangjiapai.length == paixing[0]*paixing[1])//未带牌的情况
|
||||
{
|
||||
//判断牌型相同的第一张的算法大小
|
||||
|
||||
if(cls_card2_gp.GetArithN(cpshuzu[0]) >= cls_card2_gp.GetArithN(sjpshuzu[0]) + 1)//
|
||||
{
|
||||
can_play = 1;//能出
|
||||
}
|
||||
else
|
||||
{
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
else if(paixing[0]==shangjiapx[0]&&paixing[1]==shangjiapx[1] &&paixing[0]==3 &&shangjiapai.length > shangjiapx[0]*shangjiapx[1])//3带2比大小
|
||||
{
|
||||
//判断牌型相同的第一张的算法大小
|
||||
if (game.pai.length == chupai.length ) {
|
||||
if(cls_card2_gp.GetArithN(chupaipx0[1][0]) >= cls_card2_gp.GetArithN(cls_card2_gp.GetMaxCardTypeByCardList(sjpshuzu, 0)[1][0]) + 1)
|
||||
{
|
||||
can_play = 1;//能出
|
||||
}
|
||||
else
|
||||
{
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}else {
|
||||
if(chupai.length != shangjiapai.length)//判断出的牌的长度相同
|
||||
{
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}else {
|
||||
if(cls_card2_gp.GetArithN(chupaipx0[1][0]) >= cls_card2_gp.GetArithN(cls_card2_gp.GetMaxCardTypeByCardList(sjpshuzu, 0)[1][0]) + 1)
|
||||
{
|
||||
can_play = 1;//能出
|
||||
}
|
||||
else
|
||||
{
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if(chupai.length == 2&&yici == 0)//长度为2只能为对子
|
||||
{
|
||||
if(cls_card2_gp.GetArithN(cpshuzu[0]) != cls_card2_gp.GetArithN(cpshuzu[1]))
|
||||
{
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
|
||||
if(yici == 0)
|
||||
{
|
||||
for(var er = 0;er<chupai.length;er++)
|
||||
{
|
||||
if(chupaipx0[0][0]==2&&chupaipx0[0][1]>=2)//大于等于3的牌组中 如果有2 则不能出(顺子和连对)
|
||||
{
|
||||
if(cls_card2_gp.GetArithN(cpshuzu[er]) == 15)
|
||||
{
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
else if(chupaipx0[0][0] == 1&& chupaipx0[1].length == chupai.length && chupai.length >= 5)
|
||||
{
|
||||
if(cls_card2_gp.GetArithN(cpshuzu[er]) == 15)
|
||||
{
|
||||
can_play = 0;//不能出
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(shangjiapx && shangjiapx.length!=0)//上家出牌
|
||||
{
|
||||
if(chupai.length == 4)//判断炸弹是否能出
|
||||
{
|
||||
var s=0;
|
||||
var zhadan = 0;
|
||||
for(var aaa = 0;aaa<=chupai.length - 1;aaa++)
|
||||
{
|
||||
if(cls_card2_gp.GetArithN(cpshuzu[0])==cls_card2_gp.GetArithN(cpshuzu[aaa]))
|
||||
{
|
||||
s++;
|
||||
{
|
||||
if(s==chupai.length)
|
||||
{ //下家炸弹要比上家大或者比上家长
|
||||
if (laizi_mun == 0) {//出真炸弹
|
||||
if((cls_card2_gp.GetArithN(cpshuzu[0]) <= cls_card2_gp.GetArithN(sjpshuzu[0]))&&shangjiapx[0]==4&&shangjiapx[1] == 1)
|
||||
{
|
||||
if (game.laizi_bian[game.chu].length == 0) {
|
||||
can_play = 0;//不能出,炸弹大小小于上家
|
||||
yici++;
|
||||
} else {
|
||||
can_play = 1;
|
||||
}
|
||||
|
||||
}else {
|
||||
can_play = 1;
|
||||
}
|
||||
} else {//出假炸弹
|
||||
if (shangjiapx[0]==4&&shangjiapx[1] == 1) {//上家也是炸
|
||||
if((cls_card2_gp.GetArithN(cpshuzu[0]) > cls_card2_gp.GetArithN(sjpshuzu[0])))
|
||||
{
|
||||
if (game.laizi_bian[game.chu].length == 0) {//上家真炸弹
|
||||
can_play = 0;//不能出,炸弹大小小于上家
|
||||
yici++;
|
||||
} else {
|
||||
can_play = 1;
|
||||
}
|
||||
|
||||
}else {
|
||||
can_play = 0;//不能出,炸弹大小小于上家
|
||||
yici++;
|
||||
}
|
||||
} else {
|
||||
can_play = 1;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if(chupai.length==3)//判断炸弹(无视牌型)
|
||||
{
|
||||
var s=0;
|
||||
for(var aaa = 0;aaa<=chupai.length - 1;aaa++)
|
||||
{
|
||||
if(cls_card2_gp.GetArithN(cpshuzu[0])==cls_card2_gp.GetArithN(cpshuzu[aaa]))
|
||||
{
|
||||
s++;
|
||||
{
|
||||
if(s==chupai.length && cls_card2_gp.GetArithN(cpshuzu[0]) == zuidazha)//判断为最大的炸
|
||||
{
|
||||
if (shangjiapx[0]==4&&shangjiapx[1] == 1 && cls_card2_gp.GetArithN(sjpshuzu[0]) == zuidazha) {//上家出了最大炸
|
||||
can_play = 0;//不能出,炸弹大小小于上家
|
||||
yici++;
|
||||
}else {
|
||||
if (shangjiapx[0]==4&&shangjiapx[1] == 1 && game.laizi_bian[game.chu].length == 0 && laizi_mun > 0){
|
||||
can_play = 0;//不能出,炸弹大小小于上家
|
||||
yici++;
|
||||
}else {
|
||||
can_play = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(chupai.length == 4)//判断炸弹是否能出
|
||||
{
|
||||
var s=0;
|
||||
var zhadan = 0;
|
||||
for(var aaa = 0;aaa<=chupai.length - 1;aaa++)
|
||||
{
|
||||
if(cls_card2_gp.GetArithN(cpshuzu[0])==cls_card2_gp.GetArithN(cpshuzu[aaa]))
|
||||
{
|
||||
s++;
|
||||
{
|
||||
if(s==chupai.length)
|
||||
{
|
||||
if(cls_card2_gp.GetArithN(cpshuzu[0]) == 15)
|
||||
{
|
||||
can_play = 0;//不能出,
|
||||
yici++;
|
||||
}else if(cls_card2_gp.GetArithN(cpshuzu[0]) == 14 && game.people == 2){
|
||||
can_play = 0;//不能出,
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
var cppx = [];
|
||||
cppx[0] = chupai;
|
||||
cppx[1] = paixing;
|
||||
cppx[2] = chupaipx0[1];
|
||||
if (can_play == 0 ) {
|
||||
cppx[0]=[];
|
||||
cppx[1] = [];
|
||||
cppx[2] = [];
|
||||
}else
|
||||
{
|
||||
var iqas = 0;
|
||||
}
|
||||
return cppx;
|
||||
}
|
||||
|
||||
|
||||
|
||||
var pd_laizi = function(chupai,laizi){//出的牌id,选的癞子牌
|
||||
for(var a = 0;a<gp.pai.cardlist.length;a++)//改变A和2的算法大小
|
||||
{
|
||||
if(cls_card2_gp.GetNumber(gp.pai.cardlist[a])==1&&laizi == 14)
|
||||
{
|
||||
cls_card2_gp.SetArithN(gp.pai.cardlist[a],14);
|
||||
}else if(cls_card2_gp.GetNumber(gp.pai.cardlist[a])==2&&laizi == 15){
|
||||
cls_card2_gp.SetArithN(gp.pai.cardlist[a],15);
|
||||
}
|
||||
}
|
||||
|
||||
if (laizi == 1) {
|
||||
laizi = 14;
|
||||
} else if (laizi == 2){
|
||||
laizi = 15;
|
||||
}
|
||||
laizi_paizu = []; //存癞子的数组
|
||||
laizi_mun = 0; //癞子数目
|
||||
var pais = cls_aset2_gp.CardIdsToCards(gp.pai,chupai); //出的牌转数组
|
||||
cls_card2.SortCardList(pais); //从小到大排序牌(以下都经过排序)
|
||||
if (laizi == 0) {
|
||||
return panduan(game.paixing,chupai)[0];
|
||||
}
|
||||
else {
|
||||
var pai_s = cls_aset2.CardsToCardIds(pais);
|
||||
var paiss = [];
|
||||
var zdz =15;
|
||||
laizi_weizhi = [];
|
||||
for (var i = 0; i < pais.length; i++) { //出的牌中癞子数量以及位置
|
||||
paiss[i] = cls_card2.GetArithN(pais[i]);
|
||||
if (paiss[i] == laizi) {
|
||||
laizi_mun ++;
|
||||
laizi_weizhi.push(i);
|
||||
}
|
||||
}
|
||||
if (laizi_mun == chupai.length) {
|
||||
return panduan(game.paixing,chupai)[0];
|
||||
} else {
|
||||
switch (laizi_mun){
|
||||
case 0:
|
||||
var rr = cls_aset2.CardsToCardIds(pais)
|
||||
return panduan(game.paixing,rr)[0];
|
||||
break;
|
||||
case 1:
|
||||
var sz = [];
|
||||
if ( game.people == 2) {
|
||||
zdz =14;
|
||||
}
|
||||
for (var i = zdz; i >= 3; i--) {
|
||||
cls_card2_gp.SetArithN(pais[laizi_weizhi[0]],i);
|
||||
var rr = cls_aset2.CardsToCardIds(pais);
|
||||
var keyichu = panduan(game.paixing,rr)[0];
|
||||
var zd = panduan(game.paixing,rr)[1];
|
||||
if(keyichu.length!=0)
|
||||
{
|
||||
sz.push([i]);
|
||||
laizi_paizu[laizi_paizu.length]=[];
|
||||
var ss = cls_aset2.CardIdsToCards(gp.pai,pai_s);
|
||||
ss = cls_card2_gp.SortCardList(ss);
|
||||
var uu = cls_aset2.CardsToCardIds(ss)
|
||||
laizi_paizu[laizi_paizu.length-1] = laizi_paizu[laizi_paizu.length-1].concat(uu.slice());
|
||||
if(zd[0] ==4 && chupai.length == 4){//如果为炸弹直接跳出
|
||||
sz = [[i]];
|
||||
laizi_paizu = [laizi_paizu[laizi_paizu.length-1]];
|
||||
a = 0;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
var sz = [];
|
||||
if ( game.people == 2) {
|
||||
zdz =14;
|
||||
}
|
||||
for (var a = zdz; a >= 3; a--) {
|
||||
for (var b = zdz; b >= 3; b--) {
|
||||
cls_card2_gp.SetArithN(pais[laizi_weizhi[0]],a);
|
||||
cls_card2_gp.SetArithN(pais[laizi_weizhi[1]],b);
|
||||
var rr = cls_aset2.CardsToCardIds(pais);
|
||||
var keyichu = panduan(game.paixing,rr)[0];
|
||||
var zd = panduan(game.paixing,rr)[1];
|
||||
if(keyichu.length!=0)
|
||||
{
|
||||
sz.push([a,b]);
|
||||
|
||||
laizi_paizu[laizi_paizu.length]=[];
|
||||
var ss = cls_aset2.CardIdsToCards(gp.pai,pai_s);
|
||||
ss = cls_card2_gp.SortCardList(ss);
|
||||
var uu = cls_aset2.CardsToCardIds(ss)
|
||||
laizi_paizu[laizi_paizu.length-1] = laizi_paizu[laizi_paizu.length-1].concat(uu.slice());
|
||||
if(zd[0] ==4 && chupai.length == 4){//如果为炸弹直接跳出
|
||||
sz = [[a,b]];
|
||||
laizi_paizu = [laizi_paizu[laizi_paizu.length-1]];
|
||||
a = 0;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
var sz = [];
|
||||
if ( game.people == 2) {
|
||||
zdz =14;
|
||||
}
|
||||
for (var c = zdz; c >= 3; c--) {
|
||||
for (var a = zdz; a >= 3; a--) {
|
||||
for (var b = zdz; b >= 3; b--) {
|
||||
cls_card2_gp.SetArithN(pais[laizi_weizhi[0]],c);
|
||||
cls_card2_gp.SetArithN(pais[laizi_weizhi[1]],a);
|
||||
cls_card2_gp.SetArithN(pais[laizi_weizhi[2]],b);
|
||||
var rr = cls_aset2.CardsToCardIds(pais);
|
||||
var keyichu = panduan(game.paixing,rr)[0];
|
||||
var zd = panduan(game.paixing,rr)[1];
|
||||
if(keyichu.length!=0)
|
||||
{
|
||||
sz.push([c,a,b]);
|
||||
laizi_paizu[laizi_paizu.length]=[];
|
||||
var ss = cls_aset2.CardIdsToCards(gp.pai,pai_s);
|
||||
ss = cls_card2_gp.SortCardList(ss);
|
||||
var uu = cls_aset2.CardsToCardIds(ss)
|
||||
laizi_paizu[laizi_paizu.length-1] = laizi_paizu[laizi_paizu.length-1].concat(uu.slice());
|
||||
if(zd[0] ==4 && chupai.length == 4){//如果为炸弹直接跳出
|
||||
sz = [[c,a,b]];
|
||||
laizi_paizu = [laizi_paizu[laizi_paizu.length-1]];
|
||||
a = 0;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
var sz = [];
|
||||
if ( game.people == 2) {
|
||||
zdz =14;
|
||||
}
|
||||
for (var d = zdz; d >= 3; d--) {
|
||||
for (var c = zdz; c >= 3; c--) {
|
||||
for (var a = zdz; a >= 3; a--) {
|
||||
for (var b = zdz; b >= 3; b--) {
|
||||
cls_card2_gp.SetArithN(pais[laizi_weizhi[2]],d);
|
||||
cls_card2_gp.SetArithN(pais[laizi_weizhi[1]],c);
|
||||
cls_card2_gp.SetArithN(pais[laizi_weizhi[3]],a);
|
||||
cls_card2_gp.SetArithN(pais[laizi_weizhi[0]],b);
|
||||
var rr = cls_aset2.CardsToCardIds(pais);
|
||||
var keyichu = panduan(game.paixing,rr)[0];
|
||||
var zd = panduan(game.paixing,rr)[1];
|
||||
if(keyichu.length!=0)
|
||||
{
|
||||
sz.push([d,c,a,b]);
|
||||
laizi_paizu[laizi_paizu.length]=[];
|
||||
var ss = cls_aset2.CardIdsToCards(gp.pai,pai_s);
|
||||
ss = cls_card2_gp.SortCardList(ss);
|
||||
var uu = cls_aset2.CardsToCardIds(ss)
|
||||
laizi_paizu[laizi_paizu.length-1] = laizi_paizu[laizi_paizu.length-1].concat(uu.slice());
|
||||
if(zd[0] ==4 && chupai.length == 4){//如果为炸弹直接跳出
|
||||
sz = [[d,c,a,b]];
|
||||
laizi_paizu = [laizi_paizu[laizi_paizu.length-1]];
|
||||
a = 0;
|
||||
break ;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
for(var a = 0;a<gp.pai.cardlist.length;a++)
|
||||
{
|
||||
if(cls_card2_gp.GetNumber(gp.pai.cardlist[a])==laizi){
|
||||
cls_card2_gp.SetArithN(gp.pai.cardlist[a],laizi); //癞子算法还原
|
||||
}
|
||||
if ( laizi > 13 && laizi < 16) { //癞子为A和2
|
||||
if(cls_card2_gp.GetNumber(gp.pai.cardlist[a])==laizi-13){
|
||||
cls_card2_gp.SetArithN(gp.pai.cardlist[a],laizi); //癞子算法还原
|
||||
}
|
||||
}
|
||||
}
|
||||
for(var p = 0;p<sz.length;p++)
|
||||
{
|
||||
if(sz[p].length>1)
|
||||
{
|
||||
systemSort(sz[p]);
|
||||
}
|
||||
}
|
||||
//console.log(sz);
|
||||
|
||||
shanchu = sz.distinct_t()[1];//癞子位置
|
||||
shanchu_pai = sz.distinct_t()[0];//癞子牌型算法
|
||||
jieguo_pai = [];
|
||||
paipai = [];
|
||||
|
||||
for(var b=0;b<shanchu.length;b++)
|
||||
{
|
||||
for(var a=0;a<laizi_paizu.length;a++)//去掉多个癞子位置不同但结果相同的情况
|
||||
{
|
||||
if(shanchu[b] == a)
|
||||
{
|
||||
jieguo_pai.push(laizi_paizu[a]);
|
||||
paipai.push(sz[a]);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (jieguo_pai.length>1 ) {
|
||||
|
||||
for(var i = 0; i < jieguo_pai.length; i++){//改变后的可出牌
|
||||
jieguo_pai_gai[i] = [];
|
||||
for (var j = 0; j < jieguo_pai[i].length; j++) {
|
||||
jieguo_pai_gai[i].push(jieguo_pai[i][j]);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < jieguo_pai.length; i++) {//把癞子id换成改变后的
|
||||
var yici = 0;
|
||||
for (var a = 0; a < jieguo_pai[i].length; a++) {
|
||||
if (jieguo_pai[i][a]%13+1 ==game.laizi ) {
|
||||
jieguo_pai_gai[i][a]= (paipai[i][yici]-1)%13;
|
||||
yici++;
|
||||
}
|
||||
}
|
||||
}
|
||||
var tongpaixing = [];
|
||||
for (var i = 0; i < jieguo_pai_gai.length; i++ ) {
|
||||
|
||||
tongpaixing[i] = panduan(game.paixing,jieguo_pai_gai[i]);
|
||||
tongpaixing[i].splice(0,1);
|
||||
}
|
||||
for (var i = 0; i < jieguo_pai_gai.length-1; i++) { //删除同类型的牌
|
||||
if (tongpaixing.length>1 ) { //当牌型大于一的情况
|
||||
for (var j = i+1;j<tongpaixing.length;j++) { //遍历所有的牌型 每一个都比较
|
||||
if (tongpaixing[i][0][0] == tongpaixing[j][0][0] && tongpaixing[i][0][1] == tongpaixing[j][0][1]) { //牌型相同
|
||||
if ( tongpaixing[i][1][0][4]>tongpaixing[j][1][0][4]) { //牌型大于后面的删除后面
|
||||
jieguo_pai.splice(j,1);
|
||||
paipai.splice(j,1);
|
||||
tongpaixing.splice(j,1);
|
||||
jieguo_pai_gai.splice(j,1);
|
||||
i = -1;
|
||||
break;
|
||||
}else {//否则删除前面的
|
||||
jieguo_pai.splice(i,1);
|
||||
paipai.splice(i,1);
|
||||
tongpaixing.splice(i,1);
|
||||
jieguo_pai_gai.splice(i,1);
|
||||
i = -1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return jieguo_pai;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Array.prototype.distinct_t = function() { //数组去重
|
||||
var arr = this,
|
||||
i,
|
||||
obj = {},
|
||||
result = [],
|
||||
dd = [],
|
||||
len = arr.length;
|
||||
for(i = 0; i < arr.length; i++) {
|
||||
if(!obj[arr[i]]) { //如果能查找到,证明数组元素重复了
|
||||
obj[arr[i]] = 1;
|
||||
result.push(arr[i]);
|
||||
dd.push(i);
|
||||
}
|
||||
}
|
||||
return [result,dd];
|
||||
}
|
||||
|
||||
function systemSort(array) { //快速排序
|
||||
return array.sort(function(a, b) {
|
||||
return a - b;
|
||||
});
|
||||
}
|
||||
|
||||
Array.prototype.duplicate = function() { //数组中相同数tmp 有几个tem.length
|
||||
var tmp = [];
|
||||
this.concat().sort().sort(function(a, b) {
|
||||
if(a == b && tmp.indexOf(a) === -1) tmp.push(a);
|
||||
});
|
||||
return tmp;
|
||||
}
|
||||
var gp_ui_duoxuan = function(kechu)
|
||||
{
|
||||
set_group(222,37,1,0,0);
|
||||
set_group(223,37,0,0,0);
|
||||
set_self(1145,21,160+100*kechu.length,0,0);
|
||||
set_self(1145,20,160+75*kechu[0].length,0,0);
|
||||
set_self(1145,18,640-get_self(1145,20)/2,0,0);
|
||||
if (get_self(1145,20)>1290) {
|
||||
set_self(1145,20,1290,0,0);
|
||||
}
|
||||
for (var i = 1152; i < 1186; i++) {
|
||||
set_self(i,33,55,0,0);
|
||||
}
|
||||
var gbh_laizi = [[]]; //癞子为改编后牌组
|
||||
var cishu = 0;
|
||||
for (var i = 0; i < kechu.length; i++) {//把癞子id换成改变后的
|
||||
var yici = 0;
|
||||
for (var a = 0; a < kechu[i].length; a++) {
|
||||
gbh_laizi[i][a]= kechu[i][a];
|
||||
if (kechu[i][a]%13+1 ==game.laizi ) {
|
||||
gbh_laizi[i][a]= paipai[i][yici]-1;
|
||||
yici++;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
for (var a=0;a<kechu.length;a++) {
|
||||
for (var i=0;i<kechu[0].length;i++) {
|
||||
var dxpaishu = kechu[0].length;
|
||||
set_self(1152+dxpaishu*a+i,37,1,0,0);
|
||||
set_self(1152+dxpaishu*a+i,43,kechu[a][i],0,0);
|
||||
set_self(1152+dxpaishu*a+i,19,170+a*100,0,0);
|
||||
set_self(1152+dxpaishu*a,18,610-kechu[0].length*73/2,0,0);
|
||||
set_self(1152+dxpaishu*a+i,18,get_self(1152+dxpaishu*a,18,0,0,0)+73*i,0,0);
|
||||
}
|
||||
gp_ui_laizidx(kechu[a],paipai[a],1152+a*kechu[0].length);
|
||||
set_self(1148+a,19,get_self(1152+dxpaishu*a,19)+40,0,0);
|
||||
set_self(1148+a,18,get_self(1152+dxpaishu*a,18)+25,0,0);
|
||||
set_self(1148+a,20,75*kechu[0].length,0,0);
|
||||
set_self(1148+a,37,1,0,0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var gp_ui_laizidx = function(pai,_paipai,diyz){ //癞子出牌变帧 pai为id paipai为该变后的算法大小 diyz为精灵id
|
||||
var bianzhen = [];
|
||||
var yici = 0;
|
||||
|
||||
for(var i=0;i<pai.length;i++)
|
||||
{
|
||||
bianzhen[i] = pai[i];
|
||||
|
||||
var da=pai[i]%13+1;
|
||||
if ( da == game.laizi ) {
|
||||
bianzhen[i] = _paipai[yici]-1;
|
||||
yici++;
|
||||
var xiao =bianzhen[i]%13+1
|
||||
set_self(diyz+i,1,567,0,0); //癞子牌变帧
|
||||
set_self(diyz+i,43,xiao,0,0);
|
||||
}else {
|
||||
set_self(diyz+i,1,53,0,0); //癞子牌变帧
|
||||
set_self(diyz+i,43, bianzhen[i]+1,0,0);
|
||||
set_self(diyz+i,37,1,0,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
////////////////////////////////////////////////////////
|
||||
///////////小局类/////////////////
|
||||
var cls_aset2_gp=cls_aset2.NewClass();
|
||||
//几副牌
|
||||
cls_aset2_gp.get_cardcount = function(){
|
||||
return 1;
|
||||
}
|
||||
//初始化牌列表
|
||||
cls_aset2_gp.initcardlist = function(o_aset){
|
||||
//几副牌
|
||||
var card_count = this.get_cardcount();
|
||||
//牌类
|
||||
var card_class = this.get_cardclass();
|
||||
//初始化
|
||||
for (var i = 1; i <= card_count; i++){ //几副牌
|
||||
for (var j = 1; j <= 4; j++){ //方块、梅花、红心、黑桃四种花色
|
||||
for (var k = 1; k <= 13; k++){ //A到K
|
||||
var id = (i - 1) * 54 + (j - 1) * 13 + k - 1; //牌的绝对id
|
||||
//新建一张牌
|
||||
var card_object = card_class.New(id);
|
||||
o_aset.cardlist.push(card_object);
|
||||
}
|
||||
}
|
||||
//小王
|
||||
var card_object = card_class.New((i - 1) * 54 + 53 - 1);
|
||||
o_aset.cardlist.push(card_object);
|
||||
//大王
|
||||
var card_object = card_class.New((i - 1) * 54 + 54 - 1);
|
||||
o_aset.cardlist.push(card_object);
|
||||
}
|
||||
}
|
||||
//每人需要发多少张牌
|
||||
cls_aset2_gp.get_dealcount = function(o_aset, o_desk){
|
||||
return 17;
|
||||
}
|
||||
//将牌id列表转换成牌对象列表
|
||||
cls_aset2_gp.CardIdsToCards = function(o_aset, cardidlist){
|
||||
var cardlist = [];
|
||||
for (var i = 0; i < cardidlist.length; i++){
|
||||
if(cardidlist[i]==214||cardidlist[i]==215){
|
||||
var o_card = o_aset.cardlist[cardidlist[i]-52];
|
||||
}else{
|
||||
var o_card = o_aset.cardlist[cardidlist[i]];
|
||||
}
|
||||
cardlist.push(o_card);
|
||||
}
|
||||
return cardlist;
|
||||
}
|
||||
//设置每张牌的分值
|
||||
cls_aset2_gp.setcardscore = function(o_aset){
|
||||
//下面的代码是设置5、10、K分值的例子。类似功能需要在子游戏中重写该方法
|
||||
for (var i = 0; i < o_aset.cardlist.length; i++){
|
||||
var o_card = o_aset.cardlist[i];
|
||||
var card_deal = this.get_cardclass().GetDeal(o_card);
|
||||
if (card_deal != -2){
|
||||
var card_number = this.get_cardclass().GetNumber(o_card);
|
||||
switch (card_number){
|
||||
case 5:
|
||||
this.get_cardclass().SetScore(o_card, 5);
|
||||
break;
|
||||
case 10:
|
||||
this.get_cardclass().SetScore(o_card, 10);
|
||||
break;
|
||||
case 13:
|
||||
this.get_cardclass().SetScore(o_card, 10);
|
||||
break;
|
||||
default :
|
||||
this.get_cardclass().SetScore(o_card, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
///////////牌类/////////////////
|
||||
var cls_card2_gp=cls_card2.NewClass();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
782
codes/games/client/Projects/guanpai-jx/js/gp_cards/minhttp.js
Normal file
782
codes/games/client/Projects/guanpai-jx/js/gp_cards/minhttp.js
Normal file
@@ -0,0 +1,782 @@
|
||||
(function(wnd, undef){
|
||||
|
||||
//复制json对象
|
||||
function min_copyjson(json)
|
||||
{
|
||||
return JSON.parse(JSON.stringify(json));
|
||||
}
|
||||
|
||||
function min_clone(myObj){
|
||||
if(!myObj)
|
||||
return myObj;
|
||||
if(typeof(myObj) != 'object')
|
||||
return myObj;
|
||||
|
||||
var myNewObj = new Object();
|
||||
|
||||
for(var i in myObj)
|
||||
myNewObj[i] = min_clone(myObj[i]);
|
||||
|
||||
return myNewObj;
|
||||
}
|
||||
|
||||
//json对象转字符串
|
||||
function min_jsontostr(json) {
|
||||
return JSON.stringify(json);
|
||||
}
|
||||
|
||||
//字符串转json对象
|
||||
function min_strtojson(str) {
|
||||
return JSON.parse(str);
|
||||
}
|
||||
|
||||
//字符串转整型 def:转换失败时返回的默认值
|
||||
function min_strtoint(str, def) {
|
||||
var i = parseInt(str);
|
||||
if (i == 0) {
|
||||
return 0;
|
||||
};
|
||||
if (!i) { //=0也会进来
|
||||
if (!def) {
|
||||
def = 0;
|
||||
};
|
||||
i = def;
|
||||
}
|
||||
return i;
|
||||
};
|
||||
|
||||
//整型转字符串
|
||||
function min_inttostr(i) {
|
||||
return i.toString();
|
||||
};
|
||||
|
||||
//去左空格
|
||||
function min_ltrim(s){
|
||||
return s.replace(/(^\s*)/g, "");
|
||||
};
|
||||
|
||||
//去右空格;
|
||||
function min_rtrim(s){
|
||||
return s.replace(/(\s*$)/g, "");
|
||||
};
|
||||
|
||||
//去左右空格;
|
||||
function min_trim(s){
|
||||
return s.replace(/(^\s*)|(\s*$)/g, "");
|
||||
};
|
||||
|
||||
//整除
|
||||
function min_div(i, b)
|
||||
{
|
||||
if (!b) {
|
||||
return parseInt(i);
|
||||
}
|
||||
return parseInt(i / b);
|
||||
};
|
||||
|
||||
//取余数
|
||||
function min_mod(a, b){
|
||||
return a % b;
|
||||
};
|
||||
|
||||
//取绝对值
|
||||
function min_abs(b) {
|
||||
return Math.abs(b);
|
||||
};
|
||||
|
||||
//取随机数(范围包含了min和max)
|
||||
function min_random(min, max) {
|
||||
var Range = max - min;
|
||||
var Rand = Math.random();
|
||||
return (min + Math.round(Rand * Range));
|
||||
};
|
||||
//取随机数1
|
||||
function min_random1(num) {
|
||||
return parseInt(Math.random()*num);
|
||||
};
|
||||
|
||||
//随机字符串
|
||||
function min_randomChar(length){
|
||||
var x = "0123456789";
|
||||
var y = "qwertyuioplkjhgfdsazxcvbnm";
|
||||
var z = "QWERTYUIOPLKJHGFDSAZXCVBNM";
|
||||
var tmp = "";
|
||||
for (var i = 0; i < length; i++) {
|
||||
switch(min_random(0, 2)) {
|
||||
case 0:
|
||||
tmp += x.charAt(Math.ceil(Math.random()*100000000)%x.length);
|
||||
break;
|
||||
case 1:
|
||||
tmp += y.charAt(Math.ceil(Math.random()*100000000)%y.length);
|
||||
break;
|
||||
case 2:
|
||||
tmp += z.charAt(Math.ceil(Math.random()*100000000)%z.length);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// var timestamp = new Date().getTime();
|
||||
// return timestamp + tmp;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
//取长度
|
||||
function min_length(key) {
|
||||
if (typeof(key) != "string") {
|
||||
var key = key + "";
|
||||
}
|
||||
return key.length;
|
||||
}
|
||||
|
||||
//字符全替换 ignoreCase:true忽略大小写 false不忽略大小写
|
||||
function min_replaceAll(str, str_old, str_new, ignoreCase)
|
||||
{
|
||||
if (!RegExp.prototype.isPrototypeOf(str_old)) {
|
||||
return str.replace(new RegExp(str_old, (ignoreCase ? "gi": "g")), str_new);
|
||||
} else {
|
||||
return str.replace(str_old, str_new);
|
||||
}
|
||||
}
|
||||
|
||||
//取本地当前时间,格式yyyy-MM-dd HH:MM:SS
|
||||
function min_now()
|
||||
{
|
||||
var date = new Date();
|
||||
var seperator1 = "-";
|
||||
var seperator2 = ":";
|
||||
var month = date.getMonth() + 1;
|
||||
var strDate = date.getDate();
|
||||
if (month >= 1 && month <= 9) {
|
||||
month = "0" + month;
|
||||
}
|
||||
if (strDate >= 0 && strDate <= 9) {
|
||||
strDate = "0" + strDate;
|
||||
}
|
||||
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate
|
||||
+ " " + date.getHours() + seperator2 + date.getMinutes()
|
||||
+ seperator2 + date.getSeconds();
|
||||
return currentdate;
|
||||
}
|
||||
|
||||
//取本地当前日期,格式yyyy-MM-dd
|
||||
function min_day()
|
||||
{
|
||||
var date = new Date();
|
||||
var seperator1 = "-";
|
||||
var month = date.getMonth() + 1;
|
||||
var strDate = date.getDate();
|
||||
if (month >= 1 && month <= 9) {
|
||||
month = "0" + month;
|
||||
}
|
||||
if (strDate >= 0 && strDate <= 9) {
|
||||
strDate = "0" + strDate;
|
||||
}
|
||||
var currentdate = date.getFullYear() + seperator1 + month + seperator1 + strDate;
|
||||
return currentdate;
|
||||
}
|
||||
|
||||
//获取时间差
|
||||
function min_datediff(startTime, endTime, diffType) {
|
||||
//将xxxx-xx-xx的时间格式,转换为 xxxx/xx/xx的格式
|
||||
startTime = startTime.replace(/\-/g, "/");
|
||||
endTime = endTime.replace(/\-/g, "/");
|
||||
|
||||
//将计算间隔类性字符转换为小写
|
||||
diffType = diffType.toLowerCase();
|
||||
var sTime = new Date(startTime); //开始时间
|
||||
var eTime = new Date(endTime); //结束时间
|
||||
//作为除数的数字
|
||||
var divNum = 1;
|
||||
switch (diffType) {
|
||||
case "second":
|
||||
divNum = 1000;
|
||||
break;
|
||||
case "minute":
|
||||
divNum = 1000 * 60;
|
||||
break;
|
||||
case "hour":
|
||||
divNum = 1000 * 3600;
|
||||
break;
|
||||
case "day":
|
||||
divNum = 1000 * 3600 * 24;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return parseInt((eTime.getTime() - sTime.getTime()) / parseInt(divNum));
|
||||
}
|
||||
|
||||
//本地存储数据
|
||||
function min_writefile_gameid(msg, gameid, fileid) {
|
||||
localStorage.setItem("file_" + gameid + "_" + fileid, msg);
|
||||
}
|
||||
|
||||
//读取本地数据
|
||||
function min_readfile_gameid(gameid, fileid) {
|
||||
return localStorage.getItem("file_" + gameid + "_" + fileid);
|
||||
}
|
||||
|
||||
//取当前页面url中的参数值 def:没取到时返回的默认值
|
||||
function min_getQueryString(name, def) {
|
||||
var self = window;
|
||||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
||||
var r = self.location.search.substr(1).match(reg);
|
||||
if (r != null) {
|
||||
return unescape(r[2])
|
||||
} else {
|
||||
if (def) {
|
||||
return def;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//获取当前页面的路径
|
||||
function min_getUrlRootPath() {
|
||||
var curWwwPath = window.location.host;
|
||||
var pathName = window.location.pathname;
|
||||
return curWwwPath + pathName.substr(0,pathName.lastIndexOf('/'));
|
||||
}
|
||||
|
||||
//设置cookie
|
||||
function min_setCookie(name, value, exp_minute) {
|
||||
if (!exp_minute) {
|
||||
exp_minute = 20; //默认时效20分钟
|
||||
}
|
||||
var exp = new Date();
|
||||
exp.setTime(exp.getTime() + exp_minute*60*1000);
|
||||
document.cookie = name + "=" + value + ";expires=" + exp.toGMTString()+';path=/';
|
||||
}
|
||||
|
||||
//读取cookie
|
||||
function min_getCookie(name) {
|
||||
var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
|
||||
if(arr != null)
|
||||
return arr[2];
|
||||
return null;
|
||||
}
|
||||
|
||||
//删除cookie
|
||||
function min_delCookie(name) {
|
||||
var value = min_getCookie(name);
|
||||
if (value) {
|
||||
min_setCookie(name, value, 0);
|
||||
}
|
||||
}
|
||||
|
||||
//获取一个dom
|
||||
function min_getdom(id)
|
||||
{
|
||||
return document.getElementById(id);
|
||||
};
|
||||
|
||||
//设置一个dom属性值 id:dom、或dom的id、或实列,key:属性,val:值
|
||||
function min_setdom(id, key, val) {
|
||||
var obj;
|
||||
if (typeof(id) == 'string') {
|
||||
obj = min_getdom(id);
|
||||
}
|
||||
else {
|
||||
obj = id;
|
||||
}
|
||||
obj.setAttribute(key, val);
|
||||
}
|
||||
|
||||
//添加一段innerHTML
|
||||
function min_uphtml(id, str, isadd) {
|
||||
/*
|
||||
setAttribute是设置网页元素的属性,就是在标签里内如<img />标签的src属性。
|
||||
innerHTML不是属性,只是JS里内代表一个双标记中间的文本,如:<span> </span>中间的字符。
|
||||
*/
|
||||
var obj = window.document.getElementById(id);
|
||||
if (isadd) {
|
||||
obj.innerHTML = obj.innerHTML + str;
|
||||
}
|
||||
else {
|
||||
obj.innerHTML = str;
|
||||
}
|
||||
}
|
||||
|
||||
//新建一个定时器每隔time毫秒执行一次func函数,函数返回定时器id
|
||||
function min_ontime(func, time)
|
||||
{
|
||||
return setInterval(func, time);
|
||||
}
|
||||
|
||||
//新建一个定时器time毫秒后执行一次func函数(只执行一次),函数返回定时器id
|
||||
function min_ontimeout(func, time)
|
||||
{
|
||||
return setTimeout(func, time);
|
||||
}
|
||||
|
||||
//关闭定时器id为timerid的定时器
|
||||
function min_closetime(timerid)
|
||||
{
|
||||
return clearTimeout(timerid);
|
||||
}
|
||||
|
||||
//encode转码
|
||||
function min_encode(s)
|
||||
{
|
||||
return encodeURIComponent(s);
|
||||
}
|
||||
|
||||
//decode解码
|
||||
function min_decode(s)
|
||||
{
|
||||
return decodeURIComponent(s);
|
||||
}
|
||||
|
||||
//新建一个tcp连接
|
||||
function min_tcp(config)
|
||||
{
|
||||
var ws = new WebSocket("ws://" + config.ipport); //不要带htpp,例如127.0.0.1:5414
|
||||
|
||||
//连接上服务器后触发的事件
|
||||
if (config.onopen) {
|
||||
ws.onopen = config.onopen;
|
||||
};
|
||||
|
||||
//收到服务器发来的数据包后触发的事件,onmessage函数会有一个底层的msg参数,其中msg.data才是服务器发过来的业务数据
|
||||
if (config.onmessage) {
|
||||
ws.onmessage = config.onmessage;
|
||||
};
|
||||
|
||||
//断开与服务器的连接后触发的事件
|
||||
if (config.onclose) {
|
||||
ws.onclose = config.onclose; //断开连接的事件
|
||||
};
|
||||
|
||||
//错误事件
|
||||
if (config.onerror) {
|
||||
ws.onerror = config.onerror; //错误事件
|
||||
};
|
||||
|
||||
return ws;
|
||||
}
|
||||
|
||||
//http请求
|
||||
function min_http(config) {
|
||||
/*
|
||||
config =
|
||||
{
|
||||
url: "http://127.0.0.1:5414/index.html",
|
||||
type: "POST", //GET or POST 方法
|
||||
data: "", //请求的数据
|
||||
success: func_callback_succ, //请求成功后的回调函数function(data,status,callbackdata)
|
||||
error: func_callback_err, //请求失败后的回调函数function(data,status)
|
||||
callbackdata: "", //作为回调函数第三个参数带入回调函数的数据
|
||||
//enurl: 0, //是否encodeURIComponent转码, 默认0不转码
|
||||
//deurl: 0, //是否decodeURIComponent解码,默认0不解码
|
||||
debugLog: false, //是否输出debug日志,默认false
|
||||
method: "(OPTIONAL) True for async and False for Non-async | By default its Async"
|
||||
}
|
||||
*/
|
||||
if (!config.debugLog) {
|
||||
config.debugLog = false;
|
||||
}
|
||||
if (!config.enurl) {
|
||||
config.enurl = 0;
|
||||
}
|
||||
if (!config.deurl) {
|
||||
config.deurl = 0;
|
||||
}
|
||||
if (!config.method) {
|
||||
config.method = true;
|
||||
}
|
||||
|
||||
if (!config.url) {
|
||||
if (config.debugLog == true) {
|
||||
console.log("No Url!");
|
||||
}
|
||||
return;
|
||||
};
|
||||
|
||||
if (!config.type) {
|
||||
if (config.debugLog == true) {
|
||||
console.log("No Default type (GET/POST) given!");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var xmlhttp = initXMLhttp();
|
||||
|
||||
xmlhttp.onreadystatechange = function() {
|
||||
if (xmlhttp.readyState == 4 && xmlhttp.status == 200 && config.success)
|
||||
{
|
||||
var responseText = mydecodeURIComponent(xmlhttp.responseText, config.deurl);
|
||||
if (!config.callbackdata) {
|
||||
config.success(responseText, xmlhttp.readyState);
|
||||
}
|
||||
else {
|
||||
config.success(responseText, xmlhttp.readyState, config.callbackdata);
|
||||
}
|
||||
if (config.debugLog == true) {
|
||||
console.log("SuccessResponse");
|
||||
}
|
||||
if (config.debugLog == true) {
|
||||
console.log("Response Data:" + xmlhttp.responseText);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (xmlhttp.readyState == 4 && config.error)
|
||||
{
|
||||
if (!config.callbackdata) {
|
||||
config.error(xmlhttp.readyState, xmlhttp.status);
|
||||
}
|
||||
else {
|
||||
config.error(xmlhttp.readyState, xmlhttp.status, config.callbackdata);
|
||||
}
|
||||
}
|
||||
if (config.debugLog == true) {
|
||||
console.log("FailureResponse --> readyState:" + xmlhttp.readyState + ", Status:" + xmlhttp.status);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var sendString = [],
|
||||
sendData = config.data;
|
||||
if (typeof sendData === "string") {
|
||||
var tmpArr = String.prototype.split.call(sendData, '&');
|
||||
for (var i = 0, j = tmpArr.length; i < j; i++) {
|
||||
var datum = tmpArr[i].split('=');
|
||||
if (datum[1]) {
|
||||
sendString.push(myencodeURIComponent(datum[0], config.enurl) + "=" + myencodeURIComponent(datum[1], config.enurl));
|
||||
}
|
||||
else {
|
||||
sendString.push(myencodeURIComponent(datum[0], config.enurl));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (typeof sendData === 'object' && !(sendData instanceof String || (FormData && sendData instanceof FormData))) {
|
||||
for (var k in sendData) {
|
||||
var datum = sendData[k];
|
||||
if (Object.prototype.toString.call(datum) == "[object Array]") {
|
||||
for (var i = 0, j = datum.length; i < j; i++) {
|
||||
sendString.push(myencodeURIComponent(k, config.enurl) + "[]=" + myencodeURIComponent(datum[i], config.enurl));
|
||||
}
|
||||
}
|
||||
else {
|
||||
sendString.push(myencodeURIComponent(k, config.enurl) + "=" + myencodeURIComponent(datum, config.enurl));
|
||||
}
|
||||
}
|
||||
}
|
||||
sendString = sendString.join('&');
|
||||
|
||||
if (config.type == "GET") {
|
||||
var g;
|
||||
var i = config.url.lastIndexOf("?");
|
||||
if (i > 8) {
|
||||
g = "&";
|
||||
} else {
|
||||
g = "?";
|
||||
}
|
||||
var ddata = new Date().getMilliseconds();
|
||||
if (sendString == "") {
|
||||
sendString = '#dfw1977=' + (ddata + min_random(1, 99999) * 1000);
|
||||
} else {
|
||||
sendString = sendString + '#dfw1977=' + (ddata + min_random(1, 99999) * 1000);
|
||||
}
|
||||
xmlhttp.open("GET", config.url + g + sendString, config.method);
|
||||
xmlhttp.send();
|
||||
|
||||
if (config.debugLog == true) {
|
||||
console.log("GET fired at:" + config.url + "?" + sendString);
|
||||
}
|
||||
}
|
||||
if (config.type == "POST") {
|
||||
xmlhttp.open("POST", config.url, config.method);
|
||||
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
|
||||
xmlhttp.send(sendString);
|
||||
|
||||
if (config.debugLog == true) {
|
||||
console.log("POST fired at:" + config.url + " || Data:" + sendString);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function initXMLhttp() {
|
||||
var xmlhttp;
|
||||
if (window.XMLHttpRequest) {
|
||||
//code for IE7,firefox chrome and above
|
||||
xmlhttp = new XMLHttpRequest();
|
||||
} else {
|
||||
//code for Internet Explorer
|
||||
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
|
||||
}
|
||||
return xmlhttp;
|
||||
}
|
||||
|
||||
//转码
|
||||
function myencodeURIComponent(s, ifif)
|
||||
{
|
||||
if (ifif == 1) {
|
||||
return min_encode(s);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
//解码
|
||||
function mydecodeURIComponent(s, ifif)
|
||||
{
|
||||
if (ifif == 1) {
|
||||
return min_decode(s);
|
||||
} else {
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//在数组中根据元素值查找下标
|
||||
function min_ary_indexof(array1, val, name)
|
||||
{
|
||||
for (var i = 0; i < array1.length; i++)
|
||||
{
|
||||
if (!name)
|
||||
{
|
||||
if (array1[i] == val)
|
||||
return i;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (array1[i][name] == val)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
};
|
||||
|
||||
//在数组中根据值删除元素
|
||||
function min_ary_delval(array1, val, name)
|
||||
{
|
||||
var index = min_ary_indexof(array1, val, name);
|
||||
if (index > -1)
|
||||
{
|
||||
array1.splice(index, 1);
|
||||
}
|
||||
};
|
||||
|
||||
//在数组中根据下标删除诺干个元素
|
||||
function min_ary_delfromto(array1, from, to)
|
||||
{
|
||||
var rest = array1.slice((to || from) + 1 || array1.length);
|
||||
array1.length = from < 0 ? array1.length + from : from;
|
||||
array1.push.apply(array1, rest);
|
||||
};
|
||||
|
||||
//在数组中删除某一对象元素
|
||||
function min_ary_delobj(array1, object)
|
||||
{
|
||||
for (var i = 0; i < array1.length; ++i)
|
||||
{
|
||||
if (array1[i] === object)
|
||||
{
|
||||
array1.splice(i, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
//数组包含
|
||||
function min_ary_include(aryparent, arychild){
|
||||
for (var i = 0; i < arychild.length; i++) {
|
||||
var found = false;
|
||||
for (var j = 0; j < aryparent.length; j++) {
|
||||
if (aryparent[j] == arychild[i]){
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
//数组相减
|
||||
function min_ary_deduct(aryparent, arychild){
|
||||
var re = [];
|
||||
for (var i = 0; i < aryparent.length; i++){
|
||||
var found = false;
|
||||
for (var j = 0; j < arychild.length; j++){
|
||||
if (aryparent[i] == arychild[j]){
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found){
|
||||
re.push(aryparent[i])
|
||||
}
|
||||
}
|
||||
return re;
|
||||
};
|
||||
|
||||
//从m个数中获取n个数的组合,只取组合,不取排列(递归算法)
|
||||
function min_CombineInAry(ary, n){
|
||||
if (ary.length < n){
|
||||
return [];
|
||||
}
|
||||
if (ary.length == n){
|
||||
return [ary];
|
||||
}
|
||||
if (ary.length > n){
|
||||
var result = [];
|
||||
for (var i = 0; i <= ary.length - n; i++) {
|
||||
var tmplist = [];
|
||||
tmplist.push(ary[i]);
|
||||
if (n - 1 > 0){
|
||||
var sub_cardlist = ary.slice(i + 1);
|
||||
var sub_tmplist = min_CombineInAry(sub_cardlist, n - 1);
|
||||
for (var j = 0; j < sub_tmplist.length; j++) {
|
||||
result.push(tmplist.concat(sub_tmplist[j]));
|
||||
}
|
||||
} else {
|
||||
result.push(tmplist);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//从n个数组中各取一个元素出来进行组合,只取组合,不取排列(递归算法)
|
||||
function min_CombineByArys(arylist){
|
||||
if (arylist.length == 0){
|
||||
return [];
|
||||
}
|
||||
var result = [];
|
||||
for (var i = 0; i < arylist[0].length; i++) {
|
||||
result.push([arylist[0][i]]);
|
||||
}
|
||||
if (arylist.length == 1){
|
||||
return result;
|
||||
}
|
||||
var resultlist = [];
|
||||
var sub_result = min_CombineByArys(arylist.slice(1));
|
||||
for (var i = 0; i < result.length; i++) {
|
||||
for (var j = 0; j < sub_result.length; j++) {
|
||||
resultlist.push(result[i].concat(sub_result[j]));
|
||||
}
|
||||
}
|
||||
return resultlist;
|
||||
}
|
||||
|
||||
//是否存在指定函数
|
||||
function min_ExitsFunction(funcName)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (typeof(eval(funcName)) == "function")
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch(e)
|
||||
{}
|
||||
return false;
|
||||
}
|
||||
|
||||
//(按顺序)加载js文件
|
||||
function min_loadJsFile(str_jsfile, func_succ, NoRandomFlag)
|
||||
{
|
||||
var domScript = document.createElement('script');
|
||||
if (!NoRandomFlag)
|
||||
{
|
||||
// str_jsfile = str_jsfile + '?' + Math.random() * 10000;
|
||||
// str_jsfile = str_jsfile + '?' + min_random(1, 10000000);
|
||||
str_jsfile = str_jsfile + '?' + min_timestamp();
|
||||
}
|
||||
domScript.src = str_jsfile;
|
||||
func_succ = func_succ || function(){};
|
||||
domScript.onload = domScript.onreadystatechange = function() {
|
||||
if (!this.readyState || 'loaded' === this.readyState || 'complete' === this.readyState) {
|
||||
func_succ();
|
||||
this.onload = this.onreadystatechange = null;
|
||||
this.parentNode.removeChild(this);
|
||||
}
|
||||
}
|
||||
document.getElementsByTagName('head')[0].appendChild(domScript);
|
||||
}
|
||||
|
||||
//生成一个GUID
|
||||
function min_guid()
|
||||
{
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
||||
return v.toString(16);});
|
||||
}
|
||||
|
||||
//获取时间戳
|
||||
function min_timestamp()
|
||||
{
|
||||
return new Date().getTime();
|
||||
}
|
||||
|
||||
wnd.min_copyjson = min_copyjson; //复制json对象
|
||||
wnd.min_clone = min_clone;
|
||||
wnd.min_jsontostr = min_jsontostr; //json转字符串
|
||||
wnd.min_strtojson = min_strtojson; //字符串转json
|
||||
wnd.min_inttostr = min_inttostr; //整型转字符型
|
||||
wnd.min_strtoint = min_strtoint; //字符型转整型
|
||||
|
||||
wnd.min_ltrim = min_ltrim; //去左空格
|
||||
wnd.min_rtrim = min_rtrim; //去右空格
|
||||
wnd.min_trim = min_trim; //去左右空格
|
||||
|
||||
wnd.min_div = min_div; //整除
|
||||
wnd.min_mod = min_mod; //取余数
|
||||
wnd.min_abs = min_abs; //取绝对值
|
||||
wnd.min_random = min_random; //取随机数
|
||||
wnd.min_random1 = min_random1; //取随机数1
|
||||
wnd.min_randomChar = min_randomChar; //随机字符串
|
||||
wnd.min_length = min_length; //取长度
|
||||
wnd.min_replaceAll = min_replaceAll; //字符全替换
|
||||
|
||||
wnd.min_now = min_now; //取本地当前时间
|
||||
wnd.min_day = min_day; //取本地当前日期
|
||||
wnd.min_datediff = min_datediff; //获取时间差
|
||||
wnd.min_guid = min_guid; //生成一个GUID
|
||||
|
||||
wnd.min_getQueryString = min_getQueryString; //取当前页面url中的参数值
|
||||
wnd.min_getUrlRootPath = min_getUrlRootPath; //获取当前页面的路径
|
||||
|
||||
wnd.min_setCookie = min_setCookie; //设置cookie
|
||||
wnd.min_getCookie = min_getCookie; //读取cookie
|
||||
wnd.min_delCookie = min_delCookie; //删除cookie
|
||||
|
||||
wnd.min_getdom = min_getdom; //获取一个dom
|
||||
wnd.min_setdom = min_setdom; //设置一个dom属性值
|
||||
wnd.min_uphtml = min_uphtml; //添加一段innerHTML
|
||||
|
||||
wnd.min_ontime = min_ontime; //新建一个周期性的定时器
|
||||
wnd.min_ontimeout = min_ontimeout; //新建一个一次性的定时器
|
||||
wnd.min_closetime = min_closetime; //关闭定时器
|
||||
|
||||
wnd.min_writefile_gameid = min_writefile_gameid; //本地存储数据
|
||||
wnd.min_readfile_gameid = min_readfile_gameid; //读取本地数据
|
||||
|
||||
wnd.min_encode = min_encode; //encodeURIComponent转码
|
||||
wnd.min_decode = min_decode; //decodeURIComponent解码
|
||||
|
||||
wnd.min_tcp = min_tcp; //新建一个tcp连接
|
||||
wnd.min_http = min_http; //http请求
|
||||
|
||||
wnd.min_ary_indexof = min_ary_indexof; //在数组中根据元素值查找下标
|
||||
wnd.min_ary_delval = min_ary_delval; //在数组中根据值删除元素
|
||||
wnd.min_ary_delfromto = min_ary_delfromto; //在数组中根据下标删除诺干个元素
|
||||
wnd.min_ary_delobj = min_ary_delobj; //在数组中删除某一对象元素
|
||||
wnd.min_ary_include = min_ary_include; //数组包含
|
||||
wnd.min_ary_deduct = min_ary_deduct; //数组相减
|
||||
wnd.min_CombineInAry = min_CombineInAry; //从m个数中取n个数的组合
|
||||
wnd.min_CombineByArys = min_CombineByArys; //从n个数组中各取一个元素出来进行组合
|
||||
|
||||
wnd.min_ExitsFunction = min_ExitsFunction; //是否存在函数
|
||||
wnd.min_loadJsFile = min_loadJsFile; //加载js文件
|
||||
|
||||
wnd.min_guid = min_guid; //生成一个GUID
|
||||
wnd.min_timestamp = min_timestamp; //获取时间戳
|
||||
})(window);
|
||||
Reference in New Issue
Block a user