长牌 算法 算包(不包含癞子)

        长牌又称斗14,是华南比较流行的一种牌类。原创分享一个长牌算包(判定牌是否满足最低胡牌要求)算法。该算法采用结构,通过对指定的牌进行组合所有可能,找出最优解,核心算法700行左右。测试平局0.2ms一次,最耗时的组合是6与8的组合和7组合,如果该牌很多的情况,算法极限耗时会达到50ms一次。该算法至少支持几百人同时在线同时游戏,更高为测试过。

        该算法也许能给你提供一种思路,算法中可能存在漏洞,如果有什么逻辑错误,欢迎指出。也许你有更好的,仅供学习参考。

       源码:https://download.csdn.net/download/jimheaven/12154451

基础类

public class LongCard {

	@Getter
	private int number;
	@Getter
	private boolean red;
	@Getter
	private int Num;
	
	public LongCard(int number,boolean red,int num) {
		this.number = number;
		this.red = red;
		this.Num = num;
	}
	
	public String toString() {
		return number+"-"+red+"-"+Num;
	}
}


public class LongCardList {

	public static final LongCard DiPai = new LongCard(2, true, 210);
	public static final LongCard DingDing = new LongCard(3, true, 310);
	public static final LongCard HePai = new LongCard(4, true, 410);
	public static final LongCard BanDeng = new LongCard(4, false, 400);
	public static final LongCard YaoSi = new LongCard(5, true, 510);
	public static final LongCard GuaiZi = new LongCard(5, false, 500);
	public static final LongCard MaoMao = new LongCard(6, true, 610);
	public static final LongCard ChangSan = new LongCard(6, false, 600);
	public static final LongCard ErHong = new LongCard(6, true, 611);
	public static final LongCard SanSi = new LongCard(7, true, 710);
	public static final LongCard GaoJiao = new LongCard(7, true, 711);
	public static final LongCard ErWu = new LongCard(7, false, 700);
	public static final LongCard RenPai = new LongCard(8, true, 810);
	public static final LongCard SanWu = new LongCard(8, false, 800);
	public static final LongCard PingBa = new LongCard(8, false, 801);
	public static final LongCard HongJiu = new LongCard(9, true, 910);
	public static final LongCard HeiJiu = new LongCard(9, false, 900);
	public static final LongCard MeiZi = new LongCard(10, false, 1000);
	public static final LongCard SiLiu = new LongCard(10, true, 1010);
	public static final LongCard FuTou = new LongCard(11, false, 1100);
	public static final LongCard TianPai = new LongCard(12, true, 1210);
	public static final LongCard CaiShenHei = new LongCard(13, false, 1300);
	public static final LongCard CaiShenHong = new LongCard(13, true,1310);

	public static LongCard[] getAllCards() {
		return new LongCard[] { TianPai, DiPai, RenPai, HePai, MeiZi, BanDeng, ChangSan, FuTou, SiLiu, MaoMao, GaoJiao,
				HongJiu, YaoSi, ErWu, GuaiZi, SanWu, PingBa, HeiJiu, ErHong, DingDing, SanSi };
	}
	
	public static LongCard[] getCardByNumber(int number) {
		if(number == 2) {
			return new LongCard[] {TianPai};
		}else if(number == 3) {
			return new LongCard[] {DingDing};
		}else if(number == 4) {
			return new LongCard[] {HePai,BanDeng};
		}else if(number == 5) {
			return new LongCard[] {YaoSi,GuaiZi};
		}else if(number == 6) {
			return new LongCard[] {MaoMao,ChangSan,ErHong};
		}else if(number == 7) {
			return new LongCard[] {SanSi,GaoJiao,ErWu};
		}else if(number == 8) {
			return new LongCard[] {RenPai,SanWu,PingBa};
		}else if(number == 9) {
			return new LongCard[] {HongJiu,HeiJiu};
		}else if(number == 10) {
			return new LongCard[] {MeiZi,SiLiu};
		}else if(number == 11) {
			return new LongCard[] {FuTou};
		}else if(number == 12) {
			return new LongCard[] {TianPai};
		}
		return null;
	}
	
	public static LongCard getOneCard(int num) {
		LongCard[] allCards = getAllCards();
		for(LongCard c : allCards) {
			if(c.getNum() == num) {
				return c;
			}
		}
		return null;
	}
}

核心逻辑

public class LongUtil {

	public static long useTime1 = 0;
	public static long useTime2 = 0;
	
	/**
	 * 检测包
	 * @param cards
	 * @param leftCard
	 */
	public boolean checkBao(List cards,List leftCard,List> pengOrOther, int needTuo,List cantPeng,List> groups) {
		List temp = new ArrayList<>(cards);
		List> complete = new ArrayList<>();
		List checkComplete = new ArrayList<>();
		for(LongCard c : temp) {
			if(checkComplete.isEmpty()) {
				checkComplete.add(c);
			}else {
				if(checkComplete.get(0) == c) {
					checkComplete.add(c);
				}else {
					if(checkComplete.size() > 2) {
						complete.add(checkComplete);
						checkComplete = new ArrayList<>();
						checkComplete.add(c);
					}else {
						checkComplete.clear();
						checkComplete.add(c);
					}
				}
			}
		}
		int hasTuo = 0;
		for(List l : complete) {
			for(LongCard c : l) {
				temp.remove(c);
			}
			if(l.size() == 3) {
				if(l.get(0).isRed()) {
					hasTuo += 12;
				}else {
					hasTuo += 6;
				}
			}else {
				if(l.get(0).isRed()) {
					hasTuo += 16;
				}else {
					hasTuo += 8;
				}
			}
		}
		//吃的格式一定是单张在中间,例6 8 6
		for(List l : pengOrOther) {
			LongCard longCard = l.get(0);
			if(l.size() < 3) {
				return false;
			}else if(l.size() == 3){
				LongCard longCard2 = l.get(1);
				if(longCard == longCard2) {
					if(longCard.isRed()) {
						hasTuo += 8;
					}else {
						hasTuo += 4;
					}
				}else {
					LongCard longCard3 = l.get(2);
					if(longCard.isRed()) {
						hasTuo += 1;
					}
					if(longCard2.isRed()) {
						hasTuo += 1;
					}
					if(longCard3.isRed()) {
						hasTuo += 1;
					}
				}
			}else if(l.size() == 4){
				if(longCard.isRed()) {
					hasTuo += 12;
				}else {
					hasTuo += 6;
				}
			}else {
				if(longCard.isRed()) {
					hasTuo += 16;
				}else {
					hasTuo += 8;
				}
			}
		}
		//剩余牌
		Map leftMap = new HashMap<>();
		for(LongCard c : leftCard) {
			if(!leftMap.containsKey(c)) {
				leftMap.put(c, 0);
			}
			leftMap.put(c, leftMap.get(c) + 1);
		}
		//7需要特殊处理
		List seven = new ArrayList<>();
		Iterator iterator = temp.iterator();
		while(iterator.hasNext()) {
			LongCard c = iterator.next();
			if(c.getNumber() == 7) {
				seven.add(c);
			}
		}
		int otherMao = 0;
		int otherTuo = 0;
		Map>> findMaxGruop = new HashMap<>();
		if(!seven.isEmpty()) {			
			List> maxGroupSeven = getMaxGroup(seven, leftMap,cantPeng);
			if(!maxGroupSeven.isEmpty()) {			
				findMaxGruop.put(7, maxGroupSeven);
				List list = maxGroupSeven.get(0);
				otherMao += list.size();
				for(LongTree l : list) {
					otherTuo += l.getTuo();
				}
			}
		}
		//处理非7
		for(int i=2;i<7;i++) {
			List findCards = new ArrayList<>();
			Iterator iteratorCheck = temp.iterator();
			while(iteratorCheck.hasNext()) {
				LongCard next = iteratorCheck.next();
				if(next.getNumber() == i || next.getNumber() == 14 - i) {
					findCards.add(next);
				}
			}
			if(!findCards.isEmpty()) {
				List> maxGroup = getMaxGroup(findCards, leftMap,cantPeng);
				if(!maxGroup.isEmpty()) {					
					findMaxGruop.put(i, maxGroup);
					List list = maxGroup.get(0);
					otherMao += list.size();
					for(LongTree l : list) {
						otherTuo += l.getTuo();
					}
				}
			}
		}
		//组7卯规则可能有所不同,根据具体规则变化
		//拆碰组卯,一定少坨,暂时没找到拆一碰增两卯的反例
		//检测坨和卯
		if(hasTuo + otherTuo < needTuo) {
			for(List> l : findMaxGruop.values()) {
				List list = l.get(0);
				groups.add(list);
			}
			return false;
		}
		if(otherMao + complete.size() + pengOrOther.size() < 7) {
			if(otherMao + complete.size() * 2 + pengOrOther.size() < 7) {
				//拆碰组卯
				int needMao = 7 - otherMao + complete.size() * 2 + pengOrOther.size();
				do {
					//理论上只能拆一碰,可增加1卯可能  6 6 16 16 8 8 18 28
					boolean findOne = false;
					int findNum = -1;
					int deleteCount = Integer.MAX_VALUE;
					int reduce = 0;
					List> findGruop = null;
					for(int num : findMaxGruop.keySet()) {
						List list = findMaxGruop.get(num).get(0);
						int oldTuo = 0;
						for(LongTree t : list) {
							oldTuo += t.getTuo();
						}
						for(LongTree l : list) {
							if(l.isPeng()) {
								List cantPengTemp = new ArrayList<>(cantPeng);
								cantPengTemp.add(l.getOne());
								if(num == 7) {
									List> maxGroup = getMaxGroup(seven, leftMap, cantPengTemp);
									if(!maxGroup.isEmpty()) {		
										List list2 = maxGroup.get(0);
										if(list.size() < list2.size()) {
											if(reduce < deleteCount) {
												findOne = true;
												int newTuo = 0;
												for(LongTree t : list2) {
													newTuo += t.getTuo();
												}
												reduce = oldTuo - newTuo;
												findNum = 7;
												findGruop = maxGroup;
											}
										}
									}
								}else {
									List findCards = new ArrayList<>();
									Iterator iteratorCheck = temp.iterator();
									while(iteratorCheck.hasNext()) {
										LongCard next = iteratorCheck.next();
										if(next.getNumber() == num || next.getNumber() == 14 - num) {
											findCards.add(next);
										}
									}
									List> maxGroup = getMaxGroup(findCards, leftMap,cantPengTemp);
									if(!maxGroup.isEmpty()) {
										List list2 = maxGroup.get(0);
										if(list.size() < list2.size()) {
											if(reduce < deleteCount) {
												findOne = true;
												int newTuo = 0;
												for(LongTree t : list2) {
													newTuo += t.getTuo();
												}
												reduce = oldTuo - newTuo;
												if(num < 7) {													
													findNum = num;
												}else {
													findNum = 14 - num;
												}
												findGruop = maxGroup;
											}
										}
									}
								}
							}
						}
					}
					if(findOne) {
						needMao -= 1;
						findMaxGruop.put(findNum, findGruop);
						otherTuo -= reduce;
						if(complete.size() == 0) {
							if(hasTuo + otherTuo < needTuo) {
								return false;
							}
						}
					}else {
						break;
					}
				}while(needMao > 0);
				if(needMao > 0) {
					return false;
				}
				for(List> l : findMaxGruop.values()) {
					List list = l.get(0);
					groups.add(list);
				}
			}else {
				for(List> l : findMaxGruop.values()) {
					List list = l.get(0);
					groups.add(list);
				}
				return true;
			}
		}else {
			//找最大7卯
			if(complete.size() > 0) {
				return true;
			}
			int needMao = 7 - pengOrOther.size();
			List allOtherMao = new ArrayList<>();
			for(List> l : findMaxGruop.values()) {
				List list = l.get(0);
				allOtherMao.addAll(list);
			}
			Collections.sort(allOtherMao,new Comparator() {
				@Override
				public int compare(LongTree o1, LongTree o2) {
					return o2.getTuo() - o1.getTuo();
				}
			});
			List list = new ArrayList<>();
			int extrTuo = 0;
			for(int i=0;i> l : findMaxGruop.values()) {
			List list = l.get(0);
			groups.add(list);
		}
		return true;
	}
	
	/**
	 * 采用树结构去获取最优解
* 红碰>黑碰>红吃>黑吃
* 逻辑不处理有碰没碰,过后不碰的逻辑,该逻辑在生成树的位置进行排除 * * @param cards * @param leftCard * @return */ private List> getMaxGroup(List cards,Map leftMap,List cantPeng){ List> list = new ArrayList>(); List small = new ArrayList<>(); List big = new ArrayList<>(); if(cards.get(0).getNumber() == 7) { small.addAll(cards); }else { for(LongCard c : cards) { if(c.getNumber() < 7) { small.add(c); }else { big.add(c); } } } LongTree completeLongTree = new LongTree(); if(cards.get(0).getNumber() == 7) { Collections.sort(small,new Comparator() { @Override public int compare(LongCard o1, LongCard o2) { return o1.getNum() - o2.getNum(); } }); long temp1 = System.currentTimeMillis(); getCompleteLongTreeAsSeven(small, completeLongTree,cantPeng); useTime1 += System.currentTimeMillis() - temp1; }else { long temp2 = System.currentTimeMillis(); getCompleteLongTree(small, big,completeLongTree,new ArrayList<>(),cantPeng); useTime2 += System.currentTimeMillis() - temp2; } //遍历一次,找出全部解 List> nodes = new ArrayList<>(); List line = new ArrayList<>(); getNodes(completeLongTree,nodes,line); //找出坨数最多的组合 int max = -1; List find = null; out : for(List n : nodes) { int hasTuo = 0; Map leftMapTemp = new HashMap<>(leftMap); for(LongTree l : n) { if(l.getNeedHand() == null && l.getNeed() == null){ continue; } if(l.getNeedHand() == null) { LongCard need = l.getNeed(); if(leftMapTemp.containsKey(need)) { int left = leftMapTemp.get(need); if(left > 0) { leftMapTemp.put(need, left - 1); hasTuo += l.getTuo(); continue; } } continue out; }else { hasTuo += l.getTuo(); } } if(hasTuo == 0) { continue; } if(max == -1) { find = n; max = hasTuo; }else if(max < hasTuo) { find = n; max = hasTuo; }else if(max == hasTuo) { if(find.size() < n.size()) { find = n; max = hasTuo; } } } if(find != null) { for(LongTree l : find) { if(l.getNeedHand() == null && l.getNeed() == null){ find.remove(l); break; } } list.add(find); } return list; } /** * 设置坨 * @param node */ private void setTuo(LongTree node) { int tuo = 0; LongCard one = node.getOne(); LongCard two = node.getTwo(); LongCard three = null; if(node.getNeed() != null) { three = node.getNeed(); }else { three = node.getNeedHand(); } if(one == two && one == three) { node.setPeng(true); if(one.isRed()) { tuo += 8; }else { tuo += 4; } }else { if(one.isRed()) { tuo += 1; } if(two.isRed()) { tuo += 1; } if(three.isRed()) { tuo += 1; } } node.setTuo(tuo); } /** * 遍历每条线 * * @param root * @param list * @param line */ private void getNodes(LongTree root,List> list,List line){ List node = root.getNode(); if(node == null || node.isEmpty()) { List findOne = new ArrayList<>(line); findOne.add(root); list.add(findOne); }else { line.add(root); for(LongTree n : node) { getNodes(n, list, line); } line.remove(root); } } /** * 对7进行特殊处理
* 极限 7,7,17,17,27,27 * @param small * @param node */ private void getCompleteLongTreeAsSeven(List small,LongTree node,List cantPeng) { List smallTemp = new ArrayList<>(small); if(!smallTemp.isEmpty()) { LongCard[] cardByNumber = LongCardList.getCardByNumber(7); for(int i=0;i0) { if(smallTemp.get(i-1) == smallTemp.get(i)) { continue; } } List smallTempLeft = new ArrayList<>(smallTemp); LongCard longCard = smallTempLeft.remove(0); if(smallTempLeft.contains(longCard)) { List smallTempPeng = new ArrayList<>(smallTempLeft); smallTempPeng.remove(longCard); if(!cantPeng.contains(longCard)) { LongTree newOne = new LongTree(); newOne.setOne(longCard); newOne.setTwo(longCard); newOne.setNeed(longCard); setTuo(newOne); node.getNode().add(newOne); getCompleteLongTreeAsSeven(smallTempPeng, newOne,cantPeng); } //吃外 for(LongCard c : cardByNumber) { if(c == longCard) { continue; } LongTree two = new LongTree(); two.setOne(longCard); two.setTwo(longCard); two.setNeed(c); setTuo(two); node.getNode().add(two); getCompleteLongTreeAsSeven(smallTempPeng, two,cantPeng); } //吃手 for(int j=0;j0) { if(smallTempPeng.get(j - 1) == c) { continue; } } List smallTempOther = new ArrayList<>(smallTempPeng); LongTree two = new LongTree(); two.setOne(longCard); two.setTwo(longCard); two.setNeedHand(c); setTuo(two); node.getNode().add(two); smallTempOther.remove(c); getCompleteLongTreeAsSeven(smallTempOther, two,cantPeng); } } for(int k=0;k0) { if(smallTempLeft.get(k - 1) == c) { continue; } } List smallTempOther = new ArrayList<>(smallTempLeft); smallTempOther.remove(c); LongTree newOne = new LongTree(); newOne.setOne(longCard); newOne.setTwo(c); newOne.setNeed(c); setTuo(newOne); node.getNode().add(newOne); getCompleteLongTreeAsSeven(smallTempOther, newOne,cantPeng); LongTree newOneOther = new LongTree(); newOneOther.setOne(longCard); newOneOther.setTwo(c); newOneOther.setNeed(longCard); setTuo(newOneOther); node.getNode().add(newOneOther); getCompleteLongTreeAsSeven(smallTempOther, newOneOther,cantPeng); for(int j=0;j 0) { if(smallTempOther.get(j-1) == smallTempOther.get(j)) { continue; } } List smallTempOtherLeft = new ArrayList<>(smallTempOther); LongCard other = smallTempOtherLeft.remove(j); LongTree two = new LongTree(); two.setOne(longCard); two.setTwo(c); two.setNeedHand(other); setTuo(newOneOther); node.getNode().add(two); getCompleteLongTreeAsSeven(smallTempOtherLeft, two,cantPeng); } } } } } private void getCompleteLongTree(List small,List big,LongTree node,List smallNoUse,List cantPeng) { List smallTemp = new ArrayList<>(small); List bigTemp = new ArrayList<>(big); List smallNoUseTemp = new ArrayList<>(smallNoUse); if(!smallTemp.isEmpty()) { LongCard longCard = smallTemp.remove(0); LongCard[] cardByNumber = LongCardList.getCardByNumber(14 - longCard.getNumber()); if(smallTemp.contains(longCard)) { List smallTempPeng = new ArrayList<>(smallTemp); smallTempPeng.remove(longCard); if(!cantPeng.contains(longCard)) { //碰 LongTree newOne = new LongTree(); newOne.setOne(longCard); newOne.setTwo(longCard); newOne.setNeed(longCard); setTuo(newOne); node.getNode().add(newOne); getCompleteLongTree(smallTempPeng, bigTemp, newOne,smallNoUseTemp,cantPeng); } for(LongCard o : cardByNumber) { //吃外 LongTree two = new LongTree(); two.setOne(longCard); two.setTwo(longCard); two.setNeed(o); setTuo(two); node.getNode().add(two); getCompleteLongTree(smallTempPeng, bigTemp, two,smallNoUseTemp,cantPeng); if(bigTemp.contains(o)) { //吃手 LongTree three = new LongTree(); three.setOne(longCard); three.setTwo(longCard); three.setNeedHand(o); setTuo(three); List bigThree = new ArrayList<>(bigTemp); bigThree.remove(o); node.getNode().add(two); getCompleteLongTree(smallTempPeng, bigThree, three,smallNoUseTemp,cantPeng); } } } for(LongCard o : cardByNumber) { if(bigTemp.contains(o)) { //吃外 List bigHand = new ArrayList<>(bigTemp); bigHand.remove(o); LongTree newOne = new LongTree(); newOne.setOne(longCard); newOne.setTwo(o); newOne.setNeed(o); setTuo(newOne); node.getNode().add(newOne); getCompleteLongTree(smallTemp, bigHand, newOne,smallNoUseTemp,cantPeng); //#2 LongTree newOneOther = new LongTree(); newOneOther.setOne(longCard); newOneOther.setTwo(o); newOneOther.setNeed(longCard); setTuo(newOneOther); node.getNode().add(newOneOther); getCompleteLongTree(smallTemp, bigHand, newOneOther,smallNoUseTemp,cantPeng); //吃手,与后续的big碰吃手重复 #1 if(bigHand.contains(o)) { bigHand.remove(o); LongTree two = new LongTree(); two.setOne(longCard); two.setTwo(o); two.setNeedHand(o); setTuo(two); node.getNode().add(two); getCompleteLongTree(smallTemp, bigHand, two,smallNoUseTemp,cantPeng); } } } //预留 smallNoUseTemp.add(longCard); getCompleteLongTree(smallTemp, bigTemp, node,smallNoUseTemp,cantPeng); }else { //组big,只吃smallNoUse if(!bigTemp.isEmpty()) { LongCard longCardB = bigTemp.remove(0); LongCard[] cardByNumber = LongCardList.getCardByNumber(14 - longCardB.getNumber()); if(bigTemp.contains(longCardB)) { List bigTempPeng = new ArrayList<>(bigTemp); bigTempPeng.remove(longCardB); LongTree newOne = new LongTree(); newOne.setOne(longCardB); newOne.setTwo(longCardB); newOne.setNeed(longCardB); setTuo(newOne); node.getNode().add(newOne); getCompleteLongTree(smallTemp, bigTempPeng, newOne,smallNoUseTemp,cantPeng); for(LongCard c : cardByNumber) { LongTree two = new LongTree(); two.setOne(longCardB); two.setTwo(longCardB); two.setNeedHand(c); setTuo(two); node.getNode().add(two); getCompleteLongTree(smallTemp, bigTempPeng, two,smallNoUseTemp,cantPeng); //与#1重合 // if(smallNoUseTemp.contains(c)) { // List smallThree = new ArrayList<>(smallNoUseTemp); // smallThree.remove(c); // LongTree three = new LongTree(); // three.setOne(longCardB); // three.setTwo(longCardB); // three.setNeedHand(c); // node.getNode().add(three); // getCompleteLongTree(smallTemp, bigTempPeng, three,smallThree); // } } } //与#2重合 // for(LongCard c : cardByNumber) { // if(smallNoUseTemp.contains(c)) { // List smallNoUseLeft = new ArrayList<>(smallNoUseTemp); // smallNoUseLeft.remove(c); // LongTree newOne = new LongTree(); // newOne.setOne(longCardB); // newOne.setTwo(c); // newOne.setNeed(c); // node.getNode().add(newOne); // getCompleteLongTree(smallTemp, bigTemp, newOne,smallNoUseLeft); // // LongTree newOneOther = new LongTree(); // newOneOther.setOne(longCardB); // newOneOther.setTwo(c); // newOneOther.setNeed(longCardB); // node.getNode().add(newOneOther); // getCompleteLongTree(smallTemp, bigTemp, newOneOther,smallNoUseLeft); // } // } } } } @Data public static class LongTree{ private LongCard one; private LongCard two; private LongCard need; private LongCard needHand; private List node = new ArrayList<>(); private int tuo = 0; private boolean peng = false; public String toString() { return one.toString()+" "+two.toString()+" "+ (need != null ? need.toString() : "无") + " "+(needHand != null ? needHand.toString() : "无")+" "+tuo+" "+peng; } } }

测试代码

public class Test {

	public static void main(String[] args) {
		long starTime = System.currentTimeMillis();
		test(100000,34);
		System.out.println(System.currentTimeMillis() - starTime);
//		checkOnce();
	}
	
	private static void test(int count,int needTuo) {
		LongUtil util = new LongUtil();
		LongCard[] allCards = LongCardList.getAllCards();
		List asList = Arrays.asList(allCards);
		List cards = new ArrayList();
		for(int i=0;i<5;i++) {
			cards.addAll(asList);
		}
		Collections.shuffle(cards);
		Random r = new Random();
		int times = 0;
		for(int j=0;j handCards = new ArrayList<>();
			List cardsTemp = new ArrayList<>(cards);
			for(int i=0;i<21;i++) {
				int nextInt = r.nextInt(cardsTemp.size());
				LongCard remove = cardsTemp.remove(nextInt);
				handCards.add(remove);
			}
			Collections.sort(handCards,new Comparator() {
				@Override
				public int compare(LongCard o1, LongCard o2) {
					return o1.getNum() - o2.getNum();
				}
			});
			List> groups = new ArrayList<>();
			long t = System.currentTimeMillis();
			boolean checkBao = util.checkBao(handCards, cardsTemp, new ArrayList>(), needTuo, new ArrayList<>(),groups);
//			System.out.println(j+" "+System.currentTimeMillis());
			if(System.currentTimeMillis() - t > 50) {
				System.out.println(System.currentTimeMillis() - t);
				times += 1;
				System.out.println("---------------------");
				System.out.println(checkBao);
				System.out.println(handCards);
				System.out.println();
				int tuo = 0;
				for(List gs : groups) {
					for(LongTree g : gs) {
						tuo += g.getTuo();
						System.out.println(g);
					}
				}
				System.out.println("坨"+tuo);
				System.out.println("---------------------");
				System.out.println();
			}
		}
		System.out.println(LongUtil.useTime1+" "+LongUtil.useTime2 + " " + times);
		
	}
	
	public static void checkOnce() {
		//[3-true-310, 4-false-400, 6-false-600, 6-false-600, 6-true-610, 6-true-610, 6-true-610, 6-true-611,
		//7-true-711, 8-false-800, 8-false-800, 8-false-801, 8-true-810, 8-true-810, 9-false-900, 9-false-900, 9-true-910, 10-false-1000, 11-false-1100, 12-true-1210, 12-true-1210]

		LongUtil util = new LongUtil();
		
		List handCards = new ArrayList<>();
		LongCard[] allCards = LongCardList.getAllCards();
		List asList = Arrays.asList(allCards);
		List cards = new ArrayList();
		for(int i=0;i<5;i++) {
			cards.addAll(asList);
		}
		
		handCards.add(LongCardList.getOneCard(310));
		handCards.add(LongCardList.getOneCard(400));
		handCards.add(LongCardList.getOneCard(600));
		handCards.add(LongCardList.getOneCard(600));
		handCards.add(LongCardList.getOneCard(610));
		handCards.add(LongCardList.getOneCard(610));
		handCards.add(LongCardList.getOneCard(610));
		handCards.add(LongCardList.getOneCard(611));
		handCards.add(LongCardList.getOneCard(711));
		handCards.add(LongCardList.getOneCard(800));
		handCards.add(LongCardList.getOneCard(800));
		handCards.add(LongCardList.getOneCard(801));
		handCards.add(LongCardList.getOneCard(801));
		handCards.add(LongCardList.getOneCard(801));
		handCards.add(LongCardList.getOneCard(900));
		handCards.add(LongCardList.getOneCard(900));
		handCards.add(LongCardList.getOneCard(910));
		handCards.add(LongCardList.getOneCard(1000));
		handCards.add(LongCardList.getOneCard(1100));
		handCards.add(LongCardList.getOneCard(1210));
		handCards.add(LongCardList.getOneCard(1210));
		List> groups = new ArrayList<>();
		List cardsTemp = new ArrayList<>(cards);
		for(LongCard c : handCards) {
			cardsTemp.remove(c);
		}
		boolean checkBao = util.checkBao(handCards, cardsTemp, new ArrayList>(), 34, new ArrayList<>(),groups);
		System.out.println(checkBao);
	}
}

 

你可能感兴趣的:(算法)