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

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

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

基础类

public class LongCard {@Getterprivate int number;@Getterprivate boolean red;@Getterprivate 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<LongCard> cards,List<LongCard> leftCard,List<List<LongCard>> pengOrOther, int needTuo,List<LongCard> cantPeng,List<List<LongTree>> groups) {List<LongCard> temp = new ArrayList<>(cards);List<List<LongCard>> complete = new ArrayList<>();List<LongCard> 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<LongCard> 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 6for(List<LongCard> 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<LongCard, Integer> leftMap = new HashMap<>();for(LongCard c : leftCard) {if(!leftMap.containsKey(c)) {leftMap.put(c, 0);}leftMap.put(c, leftMap.get(c) + 1);}//7需要特殊处理List<LongCard> seven = new ArrayList<>();Iterator<LongCard> iterator = temp.iterator();while(iterator.hasNext()) {LongCard c = iterator.next();if(c.getNumber() == 7) {seven.add(c);}}int otherMao = 0;int otherTuo = 0;Map<Integer, List<List<LongTree>>> findMaxGruop = new HashMap<>();if(!seven.isEmpty()) {          List<List<LongTree>> maxGroupSeven = getMaxGroup(seven, leftMap,cantPeng);if(!maxGroupSeven.isEmpty()) {           findMaxGruop.put(7, maxGroupSeven);List<LongTree> list = maxGroupSeven.get(0);otherMao += list.size();for(LongTree l : list) {otherTuo += l.getTuo();}}}//处理非7for(int i=2;i<7;i++) {List<LongCard> findCards = new ArrayList<>();Iterator<LongCard> 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<List<LongTree>> maxGroup = getMaxGroup(findCards, leftMap,cantPeng);if(!maxGroup.isEmpty()) {                 findMaxGruop.put(i, maxGroup);List<LongTree> list = maxGroup.get(0);otherMao += list.size();for(LongTree l : list) {otherTuo += l.getTuo();}}}}//组7卯规则可能有所不同,根据具体规则变化//拆碰组卯,一定少坨,暂时没找到拆一碰增两卯的反例//检测坨和卯if(hasTuo + otherTuo < needTuo) {for(List<List<LongTree>> l : findMaxGruop.values()) {List<LongTree> 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 28boolean findOne = false;int findNum = -1;int deleteCount = Integer.MAX_VALUE;int reduce = 0;List<List<LongTree>> findGruop = null;for(int num : findMaxGruop.keySet()) {List<LongTree> list = findMaxGruop.get(num).get(0);int oldTuo = 0;for(LongTree t : list) {oldTuo += t.getTuo();}for(LongTree l : list) {if(l.isPeng()) {List<LongCard> cantPengTemp = new ArrayList<>(cantPeng);cantPengTemp.add(l.getOne());if(num == 7) {List<List<LongTree>> maxGroup = getMaxGroup(seven, leftMap, cantPengTemp);if(!maxGroup.isEmpty()) {       List<LongTree> 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<LongCard> findCards = new ArrayList<>();Iterator<LongCard> iteratorCheck = temp.iterator();while(iteratorCheck.hasNext()) {LongCard next = iteratorCheck.next();if(next.getNumber() == num || next.getNumber() == 14 - num) {findCards.add(next);}}List<List<LongTree>> maxGroup = getMaxGroup(findCards, leftMap,cantPengTemp);if(!maxGroup.isEmpty()) {List<LongTree> 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<List<LongTree>> l : findMaxGruop.values()) {List<LongTree> list = l.get(0);groups.add(list);}}else {for(List<List<LongTree>> l : findMaxGruop.values()) {List<LongTree> list = l.get(0);groups.add(list);}return true;}}else {//找最大7卯if(complete.size() > 0) {return true;}int needMao = 7 - pengOrOther.size();List<LongTree> allOtherMao = new ArrayList<>();for(List<List<LongTree>> l : findMaxGruop.values()) {List<LongTree> list = l.get(0);allOtherMao.addAll(list);}Collections.sort(allOtherMao,new Comparator<LongTree>() {@Overridepublic int compare(LongTree o1, LongTree o2) {return o2.getTuo() - o1.getTuo();}});List<LongTree> list = new ArrayList<>();int extrTuo = 0;for(int i=0;i<needMao;i++) {extrTuo += allOtherMao.get(i).getTuo();list.add(allOtherMao.get(i));}groups.add(list);if(hasTuo + extrTuo < needTuo) {return false;}return true;}for(List<List<LongTree>> l : findMaxGruop.values()) {List<LongTree> list = l.get(0);groups.add(list);}return true;}/*** 采用树结构去获取最优解<br>* 红碰>黑碰>红吃>黑吃<br>* 逻辑不处理有碰没碰,过后不碰的逻辑,该逻辑在生成树的位置进行排除* * @param cards* @param leftCard* @return*/private List<List<LongTree>> getMaxGroup(List<LongCard> cards,Map<LongCard, Integer> leftMap,List<LongCard> cantPeng){List<List<LongTree>> list = new ArrayList<List<LongTree>>();List<LongCard> small = new ArrayList<>();List<LongCard> 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<LongCard>() {@Overridepublic 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<List<LongTree>> nodes = new ArrayList<>();List<LongTree> line = new ArrayList<>();getNodes(completeLongTree,nodes,line);//找出坨数最多的组合int max = -1;List<LongTree> find = null;out : for(List<LongTree> n : nodes) {int hasTuo = 0;Map<LongCard, Integer> 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<LongTree>> list,List<LongTree> line){List<LongTree> node = root.getNode();if(node == null || node.isEmpty()) {List<LongTree> 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进行特殊处理<br>* 极限 7,7,17,17,27,27* @param small* @param node*/private void getCompleteLongTreeAsSeven(List<LongCard> small,LongTree node,List<LongCard> cantPeng) {List<LongCard> smallTemp = new ArrayList<>(small);if(!smallTemp.isEmpty()) {LongCard[] cardByNumber = LongCardList.getCardByNumber(7);for(int i=0;i<smallTemp.size();i++) {if(i>0) {if(smallTemp.get(i-1) == smallTemp.get(i)) {continue;}}List<LongCard> smallTempLeft = new ArrayList<>(smallTemp);LongCard longCard = smallTempLeft.remove(0);if(smallTempLeft.contains(longCard)) {List<LongCard> 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;j<smallTempPeng.size();j++) {LongCard c = smallTempPeng.get(j);if(c == longCard) {continue;}if(j>0) {if(smallTempPeng.get(j - 1) == c) {continue;}}List<LongCard> 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;k<smallTempLeft.size();k++) {LongCard c = smallTempLeft.get(k);if(c == longCard) {continue;}if(k>0) {if(smallTempLeft.get(k - 1) == c) {continue;}}List<LongCard> 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<smallTempOther.size();j++) {if(j > 0) {if(smallTempOther.get(j-1) == smallTempOther.get(j)) {continue;}}List<LongCard> 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<LongCard> small,List<LongCard> big,LongTree node,List<LongCard> smallNoUse,List<LongCard> cantPeng) {List<LongCard> smallTemp = new ArrayList<>(small);List<LongCard> bigTemp = new ArrayList<>(big);List<LongCard> smallNoUseTemp = new ArrayList<>(smallNoUse);if(!smallTemp.isEmpty()) {LongCard longCard = smallTemp.remove(0);LongCard[] cardByNumber = LongCardList.getCardByNumber(14 - longCard.getNumber());if(smallTemp.contains(longCard)) {List<LongCard> 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<LongCard> 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<LongCard> 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);//#2LongTree 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碰吃手重复 #1if(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,只吃smallNoUseif(!bigTemp.isEmpty()) {LongCard longCardB = bigTemp.remove(0);LongCard[] cardByNumber = LongCardList.getCardByNumber(14 - longCardB.getNumber());if(bigTemp.contains(longCardB)) {List<LongCard> 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<LongCard> 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<LongCard> 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);
//                  }
//              }}}}@Datapublic static class LongTree{private LongCard one;private LongCard two;private LongCard need;private LongCard needHand;private List<LongTree> 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<LongCard> asList = Arrays.asList(allCards);List<LongCard> cards = new ArrayList<LongCard>();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<count;j++) {          List<LongCard> handCards = new ArrayList<>();List<LongCard> 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<LongCard>() {@Overridepublic int compare(LongCard o1, LongCard o2) {return o1.getNum() - o2.getNum();}});List<List<LongTree>> groups = new ArrayList<>();long t = System.currentTimeMillis();boolean checkBao = util.checkBao(handCards, cardsTemp, new ArrayList<List<LongCard>>(), 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<LongTree> 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<LongCard> handCards = new ArrayList<>();LongCard[] allCards = LongCardList.getAllCards();List<LongCard> asList = Arrays.asList(allCards);List<LongCard> cards = new ArrayList<LongCard>();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<List<LongTree>> groups = new ArrayList<>();List<LongCard> cardsTemp = new ArrayList<>(cards);for(LongCard c : handCards) {cardsTemp.remove(c);}boolean checkBao = util.checkBao(handCards, cardsTemp, new ArrayList<List<LongCard>>(), 34, new ArrayList<>(),groups);System.out.println(checkBao);}
}

长牌 算法 算包(不包含癞子)相关推荐

  1. 麻将普通胡牌算法JS版(含癞子,非轮训)

    记录一下麻将的通用胡牌算法实现,只要满足X*ABC + Y*DDD + EE 即可胡牌. 在这里先分析一下最简单的胡牌思路:先找出所有可能的将牌,若除去两张将牌之外的所有牌都能成刻或顺,则可胡牌. 将 ...

  2. 包含癞子的麻将胡牌算法

    记录一下麻将的通用胡牌算法实现,只要满足M x ABC + N x DDD + EE 即可胡牌. 在这里先分析一下最简单的胡牌思路:先找出所有可能的将牌,若除去两张将牌之外的所有牌都能成扑,则可胡牌. ...

  3. 癞子版本十三张自动摆牌算法

    癞子十三张自动摆牌算法横空出世,早两个月之前发布了非癞子版本十三张摆牌算法,那时候觉得癞子版本很复杂,没有深入研究.后面应粉丝要求出一个癞子版本的试试效果,经过一个月研究,成熟稳定的癞子算法终于完成. ...

  4. 麻将胡牌算法-癞子牌特别多(一)

    麻将内最核心的算法,每一次出牌,摸牌都需要使用到.(仅个人想法,想要更快速度,建用把算出来的结果存储下来,通过查表法来使用) 1.计算前准备 /*癞子数量*/protected byte laiNum ...

  5. 癞子麻将胡牌以及听牌算法实现

    最先实现的就是算法的实现. 需求:碰杠胡  ,不能吃 ,不能听 ,只能自摸胡,其中癞子可以做任意牌但是不能碰和杠. 写的时候还不会玩麻将,还是老板教的.^_^ 最麻烦的是胡牌算法.之前搜到的都是不包含 ...

  6. 麻将胡牌算法lua 不支持癞子

    --[[ file:game\lualib\mahjongHelper.lua desc:麻将辅助 + 胡牌 + 听牌 算法 auto:Carol Luo ]] local ipairs = ipai ...

  7. 癞子胡牌(听牌)算法

    import java.util.ArrayList; import java.util.Collections; import java.util.List;public class LaiZiTi ...

  8. 可带癞子的通用麻将胡牌算法

    本文原创文章,转载注明出处,博客地址 https://segmentfault.com/u/to... 第一时间看后续精彩文章.觉得好的话,顺手分享到朋友圈吧,感谢支持. 笔者前段时间做过一款地方麻将 ...

  9. 带癞子麻将查表判断胡牌高效率低内存算法

    同事曾问我麻将判定输赢有没有什么高效的方法,他说他随手写的三个癞子的情况下判定要6秒多.我当时只想他是需要循环 34 * 34 * 34(共有 34 种麻将) 次并依次判定输赢,这肯定不是个好方法,后 ...

最新文章

  1. adaptiveThreshold 阈值化的实现
  2. 黯然微信小程序杂记(二):小程序最新版登录并进行缓存模块的实现 附源码
  3. window 添加环境变量
  4. 获 3.8 亿用户青睐,中国电信翼支付如何数据化运营?
  5. (HDU)1058 --Humble Numbers( 丑数)
  6. C#算法设计排序篇之02-快速排序(附带动画演示程序)
  7. android 加载外部矢量图SVG
  8. mysql的to datetime_mysql-笔记-datetime
  9. 如何在应用内设计一份调查?
  10. CentOS7 安装Redis 单机版
  11. python 方差分解_从线性回归看偏差-方差分解(Bias-Variance Decomposition)
  12. Python实现统一社会信用代码校验(GB32100-2015)
  13. Android允许应用具有安装权限
  14. 使用win10自带虚拟光驱打开ISO镜像文件
  15. 细述QQ与TIM的不同之处
  16. oracle 执行计划耗时,oracle各种执行计划优缺点
  17. 巴蜀3540 -- 【Violet 6 最终话】蒲公英
  18. pl/sql---存储过程
  19. ptx760功能图解_摩托罗拉PTX760对讲机
  20. 校园的创客实验室是做什么的?

热门文章

  1. 数据库系统概论 第二章 关系数据库
  2. mate10如何android,华为Mate10怎么使用NFC功能?华为Mate10手机NFC功能使用详细教程...
  3. ios android app 混编,ios、android移动应用APP原生/混合定制开发
  4. Win10搜索框无法使用怎么办?Win10搜索栏用不了的解决办法
  5. Android游戏之——实现陆战棋
  6. 【报错】IE下使用js隐藏元素display='none'不生效
  7. 小分子量PEG/单分散修饰性聚乙二醇介绍
  8. github 私有化部署_用GitLab搭建自己的私有GitHub
  9. JSP和HTML有什么区别
  10. 贵州省最好的计算机专科学校,贵州计算机专业学校排名