package extend.mj.uitl;

import com.taurus.core.entity.ITObject;
import extend.mj.*;

import java.util.*;

public class WinSplitCard {
    //获取数值
    public static int GetCardValue(int cbCardData) { return cbCardData % 100; }
    //获取花色
    public static int GetCardColor(int cbCardData) { return cbCardData / 100; }

    //扑克转换
    public static int SwitchToCardData(int cbCardIndex)
    {
        int cbCardColor= cbCardIndex/10;
        int cbCardValue= cbCardIndex%10;
        if (cbCardIndex < 27)
        { //9 -> 200 + 1  //10 -> 202 //11 -> 203 // 17 -> 209 // 18 -> 301 19->302 20 -> 303 26->309
            if (cbCardValue + (cbCardColor+1) >= 10)
            {
                return (cbCardColor+2) * 100 + (cbCardValue + (cbCardColor+1)) % 10 + 1;
            }
            else {
                return (cbCardColor+1) * 100 + cbCardValue + (cbCardColor+1);
            }
        }
        else { //27 -> 400  //28 -> 403 // 29 -> 406 // 30 -> 409 //31 -> 412 // 32 -> 415 // 33 -> 418
            if (cbCardValue + (cbCardColor+1) >= 10)
            {
                return (cbCardColor+2) * 100 + (cbCardValue + (cbCardColor+1)) % 10 * 3;
            }
            else {
                return (cbCardColor+1) * 100 + (cbCardValue + cbCardColor) * 3;
            }
        }
    }

    //扑克转换
    public static int SwitchToCardIndex(int cbCardData)
    {
        //扑克属性
        int cbCardColor=GetCardColor(cbCardData);
        int cbCardValue=GetCardValue(cbCardData);
        if (cbCardColor <= 3)
        {
            return (cbCardColor-1)*10+cbCardValue-cbCardColor;
        }
        else {
            return (cbCardColor-1)*10+cbCardValue/3-cbCardColor+1;
        }
    }

    //扑克转换
    public static int[] SwitchToCardData(List<Integer> cardInhand)
    {
        int[] cardIndex = new int[34];
        for(int i = 0; i < cardIndex.length; i++)
        {
            cardIndex[i] = 0;
        }

        for(int i = 0; i < cardInhand.size(); i++)
        {
            int pos = SwitchToCardIndex(cardInhand.get(i));
            cardIndex[pos]++;
        }

        return cardIndex;
    }

    //扑克转换
    public static List<Integer> SwitchToCardIndex(int[] cardIndex)
    {
        List<Integer> cardIndexList = new ArrayList<Integer>();
        for(int i = 0; i < cardIndex.length; i++)
        {
            for(int j = 0; j < cardIndex[i]; j++)
            {
                int card = SwitchToCardData(i);
                cardIndexList.add(card);
            }
        }
        return cardIndexList;
    }

    public final static WinCardType putWinCardType(Map<Integer, WinCardType> map, int type, int value,int score, boolean isDaHu, String desc) {
        if (map == null)
            return null;
        if (isDaHu)
        {
            map.remove(WinCardType.DIANPAO);
            map.remove(WinCardType.PINGHU);
        }
        if (map.containsKey(type)) {
            WinCardType wct = map.get(type);
            wct.value += value;
            return wct;
        } else {
            WinCardType wct = new WinCardType(type, value,score, isDaHu, desc);
            map.put(type, wct);
            return wct;
        }
    }

    public static  boolean IsZiYiSe(int[] hand_cards, int max_gui,  List<OpCard> opCards)
    {
        for(int i = 0; i < opCards.size(); i++)
        {
            OpCard op_card = opCards.get(i);
            if (op_card.card != 0)
            {
                if (op_card.card < 400)
                {
                    return false;
                }
            }
        }

        for(int i = 0; i < hand_cards.length; i++)
        {
            int card = SwitchToCardData(i);
            int num = hand_cards[i];
            if (num > 0)
            {
                if (card < 400)
                {
                    return false;
                }
            }
        }

        return true;
    }

    public static boolean IsLuoDiLong(int[] hand_cards, int max_gui,  List<OpCard> opCards){
        List<Integer> addcards =new ArrayList<>();
        for (int j=0;j<opCards.size();j++){
            if (opCards.get(j).type==1){
                addcards.add(opCards.get(j).card);
                addcards.add(opCards.get(j).opCard.getInt(0));
                addcards.add(opCards.get(j).opCard.getInt(1));
            }else{
                addcards.add(opCards.get(j).card);
            }
        }
        System.out.println(addcards);
        int wz=0,tz=0,lz= 0;
        for (int i=0;i<hand_cards.length;i++){
            int card = SwitchToCardData(i);
            int num = hand_cards[i];
            if (card<400){
                if (addcards.contains(card)){
                    if(card<200&&card>100){
                        wz++;
                    }
                    if (card<300&&card>200){
                        tz++;
                    }
                    if (card<400&&card>300){
                        lz++;
                    }
                }else if (num>0){
                    if(card<200&&card>100){
                        wz++;
                    }
                    if (card<300&&card>200){
                        tz++;
                    }
                    if (card<400&&card>300){
                        lz++;
                    }
                }
            }
        }
        if (wz==9||tz==9||lz==9){
            return true;
        }
        return false;
    }

    public static  boolean IsYiTiaoLong(int[] hand_cards, int max_gui,  List<OpCard> opCards)
    {
        int wz=0,tz=0,lz= 0;
        for (int i=0;i<hand_cards.length;i++){
            int card = SwitchToCardData(i);
            int num = hand_cards[i];
            if (num>0){
                if(card<200&&card>100){
                    wz++;
                }
                if (card<300&&card>200){
                    tz++;
                }
                if (card<400&&card>300){
                    lz++;
                }
            }
        }
        if (wz==9||tz==9||lz==9){
            return true;
        }
        return false;
    }

    public static boolean IsYiTiaoLong(TagAnalyseItem item){
        //判断是否有
        System.out.println("item:");
         for(int i = 0; i < item.cbOpCard.size(); i++)
        {
            OpCard op_card = item.cbOpCard.get(i);
            System.out.println(op_card.card);
        }
        return false;
    }

    public static  boolean IsZiYiSe(TagAnalyseItem item)
    {
        if (item.cbCardEye != 0)
        {
            int card = item.cbCardEye;
            if (card < 400)
            {
                return false;
            }
        }

        for(int i = 0; i < item.cbOpCard.size(); i++)
        {
            OpCard op_card = item.cbOpCard.get(i);
            if (op_card.card != 0)
            {
                if (op_card.card < 400)
                {
                    return false;
                }
            }
        }

        return true;
    }

    public static  boolean IsQingYiSe(int[] hand_cards, int max_gui,  List<OpCard> opCards)
    {
        int perColor = -1;

        for(int i = 0; i < opCards.size(); i++)
        {
            OpCard op_card = opCards.get(i);
            if (op_card.card != 0)
            {
                int color = op_card.card / 100;
                if (color >= 4)
                {
                    return false;
                }
                if (perColor == -1)
                {
                    perColor = color;
                }
                else if (perColor != color)
                {
                    return false;
                }
                else {
                    perColor = color;
                }
            }
        }

        for(int i = 0; i < hand_cards.length; i++)
        {
            int card = SwitchToCardData(i);
            int num = hand_cards[i];
            if (num > 0)
            {
                int color = card / 100;
                if (color >= 4)
                {
                    return false;
                }
                if (perColor == -1)
                {
                    perColor = color;
                }
                else if (perColor != color)
                {
                    return false;
                }
                else {
                    perColor = color;
                }
            }
        }
        return true;
    }

    public static  boolean IsQingYiSe(TagAnalyseItem item)
    {
        int perColor = -1;
        if (item.cbCardEye != 0)
        {
            int card = item.cbCardEye;
            int color = card / 100;
            if (color >= 4)
            {
                return false;
            }
            if (perColor == -1)
            {
                perColor = color;
            }
            else if (perColor != color)
            {
                return false;
            }
            else {
                perColor = color;
            }
        }

        for(int i = 0; i < item.cbOpCard.size(); i++)
        {
            OpCard op_card = item.cbOpCard.get(i);
            if (op_card.card != 0)
            {
                int color = op_card.card / 100;
                if (color >= 4)
                {
                    return false;
                }
                if (perColor == -1)
                {
                    perColor = color;
                }
                else if (perColor != color)
                {
                    return false;
                }
                else {
                    perColor = color;
                }
            }
        }
        return true;
    }

    public static  boolean IsHunYiSe(int[] hand_cards, int max_gui,  List<OpCard> opCards)
    {
        int perColor = -1;
        boolean hunyise = false;

        for(int i = 0; i < opCards.size(); i++)
        {
            OpCard op_card = opCards.get(i);
            if (op_card.card != 0)
            {
                int color = op_card.card / 100;
                if (op_card.card < 400)
                {
                    if (perColor == -1)
                    {
                        perColor = color;
                    }
                    else if (perColor != color)
                    {
                        return false;
                    }
                    else {
                        perColor = color;
                    }
                }
                else
                {
                    hunyise = true;
                }
            }
            else {
                hunyise = true;
            }
        }

        for(int i = 0; i < hand_cards.length; i++)
        {
            int card = SwitchToCardData(i);
            int num = hand_cards[i];
            if (num > 0)
            {
                int color = card / 100;
                if (card < 400)
                {
                    if (perColor == -1)
                    {
                        perColor = color;
                    }
                    else if (perColor != color)
                    {
                        return false;
                    }
                    else {
                        perColor = color;
                    }
                }
                else
                {
                    hunyise = true;
                }
            }
        }

        int need_gui = 0;
        if (hunyise == false)
        {
            need_gui++;
            hunyise = true;
        }

        if (perColor == -1)
        {
            need_gui++;
            perColor = 1;
        }

        if (need_gui > max_gui)
        {
            return false;
        }

        if (perColor != -1 && hunyise)
            return true;

        return false;
    }

    public static boolean IsHunYiSe(TagAnalyseItem item)
    {
        int perColor = -1;
        boolean hunyise = false;
        if (item.cbCardEye != 0)
        {
            int card = item.cbCardEye;
            int color = card / 100;
            if (card < 400)
            {
                if (perColor == -1)
                {
                    perColor = color;
                }
                else if (perColor != color)
                {
                    return false;
                }
                else {
                    perColor = color;
                }
            }
            else
            {
                hunyise = true;
            }
        }
        else {
            hunyise = true;
        }


        for(int i = 0; i < item.cbOpCard.size(); i++)
        {
            OpCard op_card = item.cbOpCard.get(i);
            if (op_card.card != 0)
            {
                int color = op_card.card / 100;
                if (op_card.card < 400)
                {
                    if (perColor == -1)
                    {
                        perColor = color;
                    }
                    else if (perColor != color)
                    {
                        return false;
                    }
                    else {
                        perColor = color;
                    }
                }
                else
                {
                    hunyise = true;
                }
            }
            else {
                hunyise = true;
            }
        }

        if (perColor != -1 && hunyise)
            return true;

        return false;
    }

    public static boolean IsShiBaLuoHan(TagAnalyseItem item)
    {
        int count = 0;
        for(int i = 0; i < item.cbOpCard.size(); i++)
        {
            OpCard op_card = item.cbOpCard.get(i);
            if (op_card.type == RuleWeight.TYPE_KONG || op_card.type == RuleWeight.TYPE_SELF_KONG)
            {
                count++;
            }
        }

        if (count >= 4)
        {
            return true;
        }

        return false;
    }

    //混幺九
    public static boolean IsHuYaoJiu(TagAnalyseItem item) {
        boolean yaoKeZe = false;
        if (item.cbCardEye != 0)
        {
            if (item.cbCardEye < 400) {
                int value = item.cbCardEye % 100;
                if (value != 1 && value != 9) {
                    return false;
                }
            }
        }

        for (int i = 0; i < item.cbOpCard.size(); i++) {
            OpCard op_card = item.cbOpCard.get(i);
            if (op_card.type == RuleWeight.TYPE_CHOW) {
                return false;
            } else {
                int card = op_card.card;
                if (card != 0)
                {
                    if (card < 400) {
                        int value = card % 100;
                        if (value != 1 && value != 9) {
                            return false;
                        } else {
                            yaoKeZe = true;
                        }
                    }
                }
                else {
                    yaoKeZe = true;
                }
            }
        }

        if (yaoKeZe)
        {
            return true;
        }

        return false;
    }

    //清幺九
    public static boolean IsQingYaoJiu(TagAnalyseItem item) {
        if (item.cbCardEye != 0)
        {
            if (item.cbCardEye < 400) {
                int value = item.cbCardEye % 100;
                if (value != 1 && value != 9) {
                    return false;
                }
            }
            else
            {
                return false;
            }
        }


        for (int i = 0; i < item.cbOpCard.size(); i++) {
            OpCard op_card = item.cbOpCard.get(i);
            if (op_card.type == RuleWeight.TYPE_CHOW) {
                return false;
            } else {
                int card = op_card.card;
                if (card != 0)
                {
                    if (card < 400) {
                        int value = card % 100;
                        if (value != 1 && value != 9) {
                            return false;
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
            }
        }

        return true;
    }

    public static boolean IsQuanFeng(TagAnalyseItem item) {
        for (int i = 0; i < item.cbOpCard.size(); i++) {
            OpCard op_card = item.cbOpCard.get(i);
            if (op_card.type == RuleWeight.TYPE_CHOW) {
                return false;
            } else {
                int card = op_card.card;
                if (card != 0 && card < 400) {
                    return false;
                }
            }
        }

        return true;
    }


    public static int IsDaXiaoSanYuan(TagAnalyseItem item)
    {
        byte mKeCount = 0;
        byte mDuiCount = 0;

        if (item.cbCardEye != 0)
        {
            if (item.cbCardEye == Config.HONGZHONG
                    || item.cbCardEye == Config.FACAI
                    || item.cbCardEye == Config.BAIBAN)
            {
                mDuiCount++;
            }
        }
        else {
            mDuiCount++;
        }

        //组合判断
        for(int i = 0; i < item.cbOpCard.size(); i++)
        {
            OpCard op_card = item.cbOpCard.get(i);
            if (op_card.card != 0)
            {
                if (op_card.card == Config.HONGZHONG
                        || op_card.card == Config.FACAI
                        || op_card.card == Config.BAIBAN)
                {
                    mKeCount++;
                }
            }
            else {
                mKeCount++;
            }
        }

        //大三元
        if (mKeCount ==3)
        {
            return 1;
        }

        //小三元
        if ((mKeCount ==2) && (mDuiCount ==1))
        {
            return 2;
        }

        return 0;
    }

    public static int IsDaXiaoSiXi(TagAnalyseItem item)
    {
        int keCount = 0;
        int duiCount = 0;
        if (item.cbCardEye != 0)
        {
            if (item.cbCardEye == Config.DONGFENG
                    || item.cbCardEye == Config.NANFENG
                    || item.cbCardEye == Config.XIFENG
                    || item.cbCardEye == Config.BEIFENG)
            {
                duiCount++;
            }
        }
        else {
            duiCount++;
        }

        for(int i = 0; i < item.cbOpCard.size(); i++)
        {
            OpCard op_card = item.cbOpCard.get(i);
            if (op_card.card != 0)
            {
                if (op_card.card == Config.DONGFENG
                        || op_card.card == Config.NANFENG
                        || op_card.card == Config.XIFENG
                        || op_card.card == Config.BEIFENG)
                {
                    keCount++;
                }
            }
        }


        //大四喜
        if (keCount >= 4)
        {
            return 1;
        }
        //小四喜
        else if (keCount >= 3 && duiCount >= 1)
        {
            return 2;
        }

        return 0;
    }

    public static boolean QuanQiuRen(List<OpCard> opCards)
    {
        if (opCards.size() != 4)
        {
            return false;
        }

        return false;
    }

    //七小对
    public static int IsQiXiaoDui(int[] hand_cards, int max_gui, List<OpCard> opCards)
    {
        //组合判断
        if (opCards.size() != 0) return -1;

        //麻将判断
        int mCountTmp = 0;
        int mDaDuiNum = 0;

        int need_gui = 0;
        int curDuiNum = 0;
        for(int i = 0; i < hand_cards.length; i++)
        {
            int card = SwitchToCardData(i);
            int num = hand_cards[i];
            if (num == 1)
            {
                need_gui++;
                mCountTmp++;
                curDuiNum++;
                if (need_gui > max_gui)
                {
                    return -1;
                }
            }
            else if (num == 3)
            {
                need_gui++;
                mCountTmp += 2;
                mDaDuiNum++;
                if (need_gui > max_gui)
                {
                    return -1;
                }
            }
            else if (num == 2) {
                curDuiNum++;
                mCountTmp++;
            }
            else if (num == 4) {
                mCountTmp += 2;
                mDaDuiNum++;
            }
        }

        if (need_gui > max_gui)
        {
            return -1;
        }

        if ((max_gui - need_gui) % 2 != 0)
        {
            return -1;
        }

        int guiDuiNum = (max_gui - need_gui) / 2;
        if (curDuiNum <= guiDuiNum)
        {
            mCountTmp += curDuiNum;
            mDaDuiNum += curDuiNum;
            mDaDuiNum += (guiDuiNum-curDuiNum) / 2;
            mCountTmp += (guiDuiNum-curDuiNum);
        }
        else {
            mCountTmp += guiDuiNum;
            mDaDuiNum += guiDuiNum;
        }


        if (mCountTmp == 7)
        {
            return mDaDuiNum;
        }

        return -1;
    }

    public static boolean ThirteenOne(int[] hand_cards, int max_gui,  List<OpCard> opCards)
    {
        if (opCards.size() > 0)
        {
            return false;
        }

        List<Integer> tempList = new ArrayList<Integer>();
        tempList.add(0); //101
        tempList.add(8); //109
        tempList.add(9); //201
        tempList.add(17); //209
        tempList.add(18); //301
        tempList.add(26); //309
        tempList.add(27); //东风
        tempList.add(28);
        tempList.add(29);
        tempList.add(30);
        tempList.add(31);
        tempList.add(32);
        tempList.add(33);

        int jiangnum = 0;
        int need_gui = 0;
        for(int i = 0; i < tempList.size(); i++)
        {
            int card_num = hand_cards[tempList.get(i)];
            if (card_num != 1)
            {
                if (card_num == 0)
                {
                    need_gui++;
                    if (need_gui > max_gui)
                    {
                        return false;
                    }
                }
                else if (card_num == 2)
                {
                    jiangnum++;
                    if (jiangnum >= 2)
                    {
                        return false;
                    }
                }
                else {
                    return false;
                }
            }
        }

        if (jiangnum == 0)
        {
            need_gui++;
            jiangnum++;
            if (need_gui > max_gui)
            {
                return false;
            }
        }

        if (jiangnum == 1)
        {
            return true;
        }

        return false;
    }


    public static boolean AnalyseChiHuCard(Map<Integer, WinCardType> curMap, ITObject config, int[] hand_cards, int gui_num, List<OpCard> opCards, List<TagAnalyseItem> tagAnalyseItemList) {
        get_hu_info(hand_cards, gui_num, opCards, tagAnalyseItemList);
        System.out.println("AnalyseChiHuCard_bak");
        //变量定义
        List<Integer> wChiHuKind = new ArrayList<Integer>();
        List<Map<Integer, WinCardType>> tempLaiziMapList = new ArrayList<Map<Integer, WinCardType>>();

        //特殊胡牌
        int DaDuiNum = IsQiXiaoDui(hand_cards, gui_num, opCards);
        if (DaDuiNum >= 0)
        {
            HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
            tempLaiziMapList.add(map);
            if (DaDuiNum==3){
                wChiHuKind.add(WinCardType.SANLONGJIABEI);
                putWinCardType(map, WinCardType.SANLONGJIABEI, 1, WinCardType.SANLONGJIABEI_SCORE, false, "三龙夹背");
            }else if(DaDuiNum==2){
                wChiHuKind.add(WinCardType.SHUANGLONGJIABEI);
                putWinCardType(map, WinCardType.SHUANGLONGJIABEI, 1, WinCardType.SHUANGLONGJIABEI_SCORE, false, "双龙夹背");
            }else if(DaDuiNum==1){
                wChiHuKind.add(WinCardType.LONGJIABEI);
                putWinCardType(map, WinCardType.LONGJIABEI, 1, WinCardType.LONGJIABEI_SCORE, false, "龙夹背");
            }else {
                wChiHuKind.add(WinCardType.QIXIAODUI);
                putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, false, "七小对");
            }
            boolean qing_se = false;

            if (IsQingYiSe(hand_cards, gui_num, opCards))
            {
                wChiHuKind.add(WinCardType.QINGYISE);
                putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色");

                qing_se = true;
            }



            if (IsZiYiSe(hand_cards, gui_num, opCards))
            {
                wChiHuKind.add(WinCardType.ZI_YI_SE);
                putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, true, "字一色");
                qing_se = true;
            }


            if (!qing_se)
            {

                if (IsHunYiSe(hand_cards, gui_num, opCards))
                {
                    wChiHuKind.add(WinCardType.HUN_YI_SE);
                    putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色");
                }

            }
        }

        boolean qxybg = IsQiXingYiBanGao(hand_cards);
        //七星一般高
        if (qxybg){
            HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
            tempLaiziMapList.add(map);
            wChiHuKind.add(WinCardType.QIXINGYIBANGAO);
            putWinCardType(map, WinCardType.QIXINGYIBANGAO, 1, WinCardType.QIXINGYIBANGAO_SCORE, false, "七星一般高");
        }
        //七星
        boolean qx = IsQiXing(hand_cards);
        if (qx&&!qxybg){
            HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
            tempLaiziMapList.add(map);
            wChiHuKind.add(WinCardType.QIXING);
            putWinCardType(map, WinCardType.QIXING, 1, WinCardType.QIXING_SCORE, false, "七星");
        }

        //一般高
        boolean ybg = IsYiBanGao(hand_cards);
        if (ybg&&!qxybg){
            HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
            tempLaiziMapList.add(map);
            wChiHuKind.add(WinCardType.YIBANGAO);
            putWinCardType(map, WinCardType.YIBANGAO, 1, WinCardType.YIBANGAO_SCORE, false, "一般高");
        }

        //烂牌
        boolean lanpai = IsLanPai(hand_cards);
        if (lanpai&&!qxybg&&!qx&&!ybg){
            HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
            tempLaiziMapList.add(map);
            wChiHuKind.add(WinCardType.LANPAI);
            putWinCardType(map, WinCardType.LANPAI, 1, WinCardType.LANPAI_SCORE, false, "烂牌");
        }



        //胡牌分析
        System.out.println("tag:");
        System.out.println(tagAnalyseItemList);
        for (int i = 0; i < tagAnalyseItemList.size(); i++) {
            HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();

            tempLaiziMapList.add(map);

            //变量定义
            int lianCardNum = 0;
            int pengCardNum = 0;
            int lianOrPengNum = 0;
            TagAnalyseItem pAnalyseItem = tagAnalyseItemList.get(i);

            //牌型分析
            for (int j = 0; j < pAnalyseItem.cbOpCard.size(); j++) {
                OpCard cbWeaveKind = pAnalyseItem.cbOpCard.get(j);
                if (cbWeaveKind.type == RuleWeight.TYPE_PONG
                        || cbWeaveKind.type == RuleWeight.TYPE_KONG
                        || cbWeaveKind.type == RuleWeight.TYPE_SELF_KONG
                        || cbWeaveKind.type == RuleWeight.TYPE_PONG_KONG) {
                    if (cbWeaveKind.card == 0)
                    {
                        lianOrPengNum++;
                    }
                    else if (cbWeaveKind.card != 0 && cbWeaveKind.card2 == 0 && cbWeaveKind.card3 == 0)
                    {
                        lianOrPengNum++;
                    }
                    else {
                        pengCardNum++;
                    }
                }

                if (cbWeaveKind.type == RuleWeight.TYPE_CHOW) {
                    lianCardNum++;
                }
            }
            System.out.println(pengCardNum);
            //特殊--碰碰胡
            if (pengCardNum + lianOrPengNum == 4 || pAnalyseItem.isPengPengHu) {
                wChiHuKind.add(WinCardType.DADUIZI);
                putWinCardType(map, WinCardType.DADUIZI, 1, WinCardType.DADUIZI_SCORE, false, "碰碰胡");
            }


            boolean qing_se = false;
            if (IsQingYiSe(pAnalyseItem))
            {
                wChiHuKind.add(WinCardType.QINGYISE);
                putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, false, "清一色");
                qing_se = true;
            }


            if (IsZiYiSe(pAnalyseItem))
            {
                wChiHuKind.add(WinCardType.ZI_YI_SE);
                putWinCardType(map, WinCardType.ZI_YI_SE, 1,WinCardType.ZI_YI_SE_SCORE, false, "字一色");
                qing_se = true;
            }

            if(!qing_se)
            {
                if (IsHunYiSe(pAnalyseItem))
                {
                    wChiHuKind.add(WinCardType.HUN_YI_SE);
                    putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色");
                }
            }
        }

        System.out.println("laizi:"+tempLaiziMapList);
        if (tempLaiziMapList.size() > 0)
        {

            //判断是否是一条龙
            //是否是一条龙
            boolean yitiaolong = false;
            if (IsYiTiaoLong(hand_cards,0,opCards)){
                HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
                tempLaiziMapList.add(map);
                WinCard.putWinCardType(map, WinCardType.YI_TIAO_LONG, 1,WinCardType.YI_TIAO_LONG_SCORE, false, "一条龙");
            }

            boolean luodilong = IsLuoDiLong(hand_cards,0,opCards);
            if (luodilong){
                HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
                tempLaiziMapList.add(map);
                WinCard.putWinCardType(map, WinCardType.LOU_DI_LONG, 1,WinCardType.LUO_DI_LONG_SCORE, false, "落地龙");
            }

            int maxValue = 0;
            int maxIndex = 0;
            for(int i_i = 0; i_i < tempLaiziMapList.size(); i_i++)
            {
                Map<Integer, WinCardType> tempLaiziMap = tempLaiziMapList.get(i_i);


                int maxType = 0;
                int maxScore = 0;
                List<Integer> typeList = new ArrayList<Integer>();
                for (Map.Entry<Integer, WinCardType> entry : tempLaiziMap.entrySet()) {
                    WinCardType cardType = entry.getValue();
                    int type = cardType.type;
                    if (cardType.IsDaHu())
                    {
                        typeList.add(type);
                    }
                }

                if (maxType > 0)
                {
                    for(int i = 0; i < typeList.size(); i++)
                    {
                        int type = typeList.get(i);
                        if (type != maxType)
                        {
                            tempLaiziMap.remove(type);
                        }
                    }
                }

                int value = 0;
                for (Map.Entry<Integer, WinCardType> entry : tempLaiziMap.entrySet()) {
                    WinCardType cardType = entry.getValue();
                    value += cardType.score;
                }
                if (value > maxValue)
                {
                    maxValue = value;
                    maxIndex = i_i;
                }
            }

            Map<Integer, WinCardType> tempLaiziMap = tempLaiziMapList.get(maxIndex);
            curMap.putAll(tempLaiziMap);
            return true;
        }
        return false;
    }

    public static boolean get_hu_info(int[] hand_cards, int gui_num, List<OpCard> opCards, List<TagAnalyseItem> tagAnalyseItemList) {
        int[] cards = new int[34];
        System.arraycopy(hand_cards, 0, cards, 0, 34);

        int[] eye_tbl = new int[34];
        int eye_num = 0;
        int empty = -1;
        for (int i = 0; i < 34; ++i) {
            // 优化手段，三不靠的牌，必做将
            int min = (i / 9) * 9;
            int max = min + 8;
            if (max == 35) max = 33;
            if (cards[i] == 1 &&
                    (i - 2 < min || cards[i - 2] == 0) &&
                    (i - 1 < min || cards[i - 1] == 0) &&
                    (i + 1 > max || cards[i + 1] == 0) &&
                    (i + 2 > max || cards[i + 2] == 0)) {
                if (gui_num < 0) {
                    return false;
                }
                eye_num = 1;
                eye_tbl[0] = i;
                empty = -1;
                break;
            }
            if (empty == -1 && cards[i] == 0) empty = i;
            if (cards[i] > 0 && cards[i] + gui_num >= 2) {
                eye_tbl[eye_num++] = i;
            }
        }
        if (empty > 0) {
            eye_tbl[eye_num++] = empty;
        }

        boolean hu = false;
        int[] cache = {0, 0, 0, 0};
        TagAnalyseItem[] cache_item = {null, null, null, null};
        for (int i = 0; i < eye_num; i++) {
            int eye = eye_tbl[i];
            if (eye == empty) {
                TagAnalyseItem tagItem = new TagAnalyseItem();
                tagItem.cbCardEye = 0;
                tagItem.cbCardEye2 = 0;
                hu = foreach_eye(cards, gui_num - 2, gui_num, 1000, cache, tagItem, cache_item);
                if (hu)
                {
                    //设置结果
                    boolean isPengPengHu = true;
                    for (int j = 0; j < opCards.size(); j++)
                    {
                        OpCard src_card = opCards.get(j);
                        if (src_card.type == RuleWeight.TYPE_CHOW)
                        {
                            isPengPengHu = false;
                        }
                        OpCard op_card = new OpCard(src_card.type, src_card.card, src_card.card, src_card.card);
                        tagItem.cbOpCard.add(op_card);
                    }
                    if (isPengPengHu)
                    {
                        tagItem.isPengPengHu = isPengPengHu(cards, gui_num - 2);
                    }
                    tagAnalyseItemList.add(tagItem);
                }
            } else {
                int n = cards[eye];
                if (n == 1) {
                    cards[eye] = 0;
                    TagAnalyseItem tagItem = new TagAnalyseItem();
                    tagItem.cbCardEye = SwitchToCardData(eye);
                    tagItem.cbCardEye2 = 0;
                    hu = foreach_eye(cards, gui_num - 1, gui_num, eye / 9, cache, tagItem, cache_item);
                    if (hu)
                    {
                        //设置结果
                        boolean isPengPengHu = true;
                        for (int j = 0; j < opCards.size(); j++)
                        {
                            OpCard src_card = opCards.get(j);
                            if (src_card.type == RuleWeight.TYPE_CHOW)
                            {
                                isPengPengHu = false;
                            }
                            OpCard op_card = new OpCard(src_card.type, src_card.card, src_card.card, src_card.card);
                            tagItem.cbOpCard.add(op_card);
                        }
                        if (isPengPengHu)
                        {
                            tagItem.isPengPengHu = isPengPengHu(cards, gui_num - 1);
                        }
                        tagAnalyseItemList.add(tagItem);
                    }
                } else {
                    cards[eye] -= 2;
                    TagAnalyseItem tagItem = new TagAnalyseItem();
                    tagItem.cbCardEye = SwitchToCardData(eye);
                    tagItem.cbCardEye2 = SwitchToCardData(eye);
                    hu = foreach_eye(cards, gui_num, gui_num, eye / 9, cache, tagItem, cache_item);
                    if (hu)
                    {
                        //设置结果
                        boolean isPengPengHu = true;
                        for (int j = 0; j < opCards.size(); j++)
                        {
                            OpCard src_card = opCards.get(j);
                            if (src_card.type == RuleWeight.TYPE_CHOW)
                            {
                                isPengPengHu = false;
                            }
                            OpCard op_card = new OpCard(src_card.type, src_card.card, src_card.card, src_card.card);
                            tagItem.cbOpCard.add(op_card);
                        }
                        if (isPengPengHu)
                        {
                            tagItem.isPengPengHu = isPengPengHu(cards, gui_num);
                        }
                        tagAnalyseItemList.add(tagItem);
                    }
                }
                cards[eye] = n;
            }
        }

        return tagAnalyseItemList.size() > 0;
    }
    public static boolean IsLanPai(int[] cards){
        List<Integer> list = WinSplitCard.SwitchToCardIndex(cards);
        Map<Integer,Integer> tempCardList = new HashMap<>();
        for(Integer cd:list){
            if (tempCardList.containsKey(cd)){
                tempCardList.put(cd,tempCardList.get(cd)+1);
            }else{
                tempCardList.put(cd,1);
            }
        }
        int tongzi = 0;
        int wangzi = 0;
        int tiaozi = 0;
        ArrayList<Integer> wangzicard = new ArrayList<>();
        ArrayList<Integer> tongzicard = new ArrayList<>();
        ArrayList<Integer> tiaozicard = new ArrayList<>();
        ArrayList<Integer> checkmen = new ArrayList<>();

        for (Map.Entry<Integer, Integer> entry : tempCardList.entrySet()) {
            int card = entry.getKey();
            int num = entry.getValue();
            if (num>1){
                return  false;
            }
            if (card<200&&card>100){
                wangzi++;
                wangzicard.add(card);
            }
            if (card<300&&card>200){
                tongzi++;
                tongzicard.add(card);
            }
            if(card<400&&card>300){
                tiaozi++;
                tiaozicard.add(card);
            }
        }
        if(wangzi>3||tongzi>3||tiaozi>3){
            return false;
        }

        if (wangzicard.size()>0){
            checkmen.add(wangzicard.get(0)%100>6?wangzicard.get(0)%100-6:wangzicard.get(0)%100>3?wangzicard.get(0)%100-3:wangzicard.get(0)%100);
            if (wangzicard.size()==3){
                if(wangzicard.get(0)%100>3){
                    return false;
                }
                if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){
                    return false;
                }
            }else if(wangzicard.size()==2){
                if (wangzicard.get(0)+3==wangzicard.get(1)||wangzicard.get(0)+6==wangzicard.get(1)){

                }else{
                    return false;
                }
            }
        }
        if (tongzicard.size()>0){
            checkmen.add(tongzicard.get(0)%100>6?tongzicard.get(0)%100-6:tongzicard.get(0)%100>3?tongzicard.get(0)%100-3:tongzicard.get(0)%100);
            if (tongzicard.size()==3){
                if(tongzicard.get(0)%100>3){
                    return false;
                }
                if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){
                    return false;
                }
            }else if(tongzicard.size()==2){
                if (tongzicard.get(0)+3==tongzicard.get(1)||tongzicard.get(0)+6==tongzicard.get(1)){
                    // return false;
                }else{
                    return false;
                }

            }
        }
        if(tiaozicard.size()>0){
            checkmen.add(tiaozicard.get(0)%100>6?tiaozicard.get(0)%100-6:tiaozicard.get(0)%100>3?tiaozicard.get(0)%100-3:tiaozicard.get(0)%100);
            if (tiaozicard.size()==3){
                if(tiaozicard.get(0)%100>3){
                    return false;
                }
                if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){
                    return false;
                }
            }else if(tiaozicard.size()==2){
                if (tiaozicard.get(0)+3==tiaozicard.get(1)||tiaozicard.get(0)+6==tiaozicard.get(1)){

                }else{
                    return false;
                }
            }
        }


        List<Integer> uniqueList = new ArrayList<>(new HashSet<>(checkmen));
        System.out.println("cm:"+ uniqueList.size());

        List<Integer> tempList = new ArrayList<Integer>();
        Collections.sort(list);
        tempList.add(Config.DONGFENG);
        tempList.add(Config.NANFENG);
        tempList.add(Config.XIFENG);
        tempList.add(Config.BEIFENG);
        tempList.add(Config.HONGZHONG);
        tempList.add(Config.FACAI);
        tempList.add(Config.BAIBAN);
        List<Integer> ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size());
        int jiangnum = 0;
        if (ziList.size()<5){
            return false;
        }
        for(int i = 0; i < ziList.size(); i++)
        {
            int card = ziList.get(i);
            jiangnum = Collections.frequency(tempList,card);
            if (jiangnum!=1){
                return false;
            }
        }

        return true;
    }

    public static boolean IsYiBanGao(int[] cards){
        List<Integer> list = WinSplitCard.SwitchToCardIndex(cards);
        Map<Integer,Integer> tempCardList = new HashMap<>();
        for(Integer cd:list){
            if (tempCardList.containsKey(cd)){
                tempCardList.put(cd,tempCardList.get(cd)+1);
            }else{
                tempCardList.put(cd,1);
            }
        }
        int tongzi = 0;
        int wangzi = 0;
        int tiaozi = 0;
        ArrayList<Integer> wangzicard = new ArrayList<>();
        ArrayList<Integer> tongzicard = new ArrayList<>();
        ArrayList<Integer> tiaozicard = new ArrayList<>();
        ArrayList<Integer> checkmen = new ArrayList<>();

        for (Map.Entry<Integer, Integer> entry : tempCardList.entrySet()) {
            int card = entry.getKey();
            int num = entry.getValue();
            if (num>1){
                return  false;
            }
            if (card<200&&card>100){
                wangzi++;
                wangzicard.add(card);
            }
            if (card<300&&card>200){
                tongzi++;
                tongzicard.add(card);
            }
            if(card<400&&card>300){
                tiaozi++;
                tiaozicard.add(card);
            }
        }
        if(wangzi>3||tongzi>3||tiaozi>3){
            return false;
        }
        if (wangzicard.size()>0){
            checkmen.add(wangzicard.get(0)%100>6?wangzicard.get(0)%100-6:wangzicard.get(0)%100>3?wangzicard.get(0)%100-3:wangzicard.get(0)%100);
            if (wangzicard.size()==3){
                if(wangzicard.get(0)%100>3){
                    return false;
                }
                if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){
                    return false;
                }
            }else if(wangzicard.size()==2){
                if (wangzicard.get(0)+3==wangzicard.get(1)||wangzicard.get(0)+6==wangzicard.get(1)){

                }else{
                    return false;
                }
            }
        }
        if (tongzicard.size()>0){
            checkmen.add(tongzicard.get(0)%100>6?tongzicard.get(0)%100-6:tongzicard.get(0)%100>3?tongzicard.get(0)%100-3:tongzicard.get(0)%100);
            if (tongzicard.size()==3){
                if(tongzicard.get(0)%100>3){
                    return false;
                }
                if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){
                    return false;
                }
            }else if(tongzicard.size()==2){
                if (tongzicard.get(0)+3==tongzicard.get(1)||tongzicard.get(0)+6==tongzicard.get(1)){
                    // return false;
                }else{
                    return false;
                }

            }
        }
        if(tiaozicard.size()>0){
            checkmen.add(tiaozicard.get(0)%100>6?tiaozicard.get(0)%100-6:tiaozicard.get(0)%100>3?tiaozicard.get(0)%100-3:tiaozicard.get(0)%100);
            if (tiaozicard.size()==3){
                if(tiaozicard.get(0)%100>3){
                    return false;
                }
                if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){
                    return false;
                }
            }else if(tiaozicard.size()==2){
                if (tiaozicard.get(0)+3==tiaozicard.get(1)||tiaozicard.get(0)+6==tiaozicard.get(1)){

                }else{
                    return false;
                }
            }
        }


        List<Integer> uniqueList = new ArrayList<>(new HashSet<>(checkmen));
        if(uniqueList.size()>1){
            return false;
        }

        List<Integer> tempList = new ArrayList<Integer>();
        Collections.sort(list);
        tempList.add(Config.DONGFENG);
        tempList.add(Config.NANFENG);
        tempList.add(Config.XIFENG);
        tempList.add(Config.BEIFENG);
        tempList.add(Config.HONGZHONG);
        tempList.add(Config.FACAI);
        tempList.add(Config.BAIBAN);
        List<Integer> ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size());
        int jiangnum = 0;

        if (ziList.size()<5){
            return false;
        }
        for(int i = 0; i < ziList.size(); i++)
        {
            int card = ziList.get(i);
            jiangnum = Collections.frequency(tempList,card);
            if (jiangnum!=1){
                return false;
            }
        }

        return true;
    }

    public static boolean IsQiXing(int[] cards){
        List<Integer> list = WinSplitCard.SwitchToCardIndex(cards);
        Map<Integer,Integer> tempCardList = new HashMap<>();
        for(Integer cd:list){
            if (tempCardList.containsKey(cd)){
                tempCardList.put(cd,tempCardList.get(cd)+1);
            }else{
                tempCardList.put(cd,1);
            }
        }
        int tongzi = 0;
        int wangzi = 0;
        int tiaozi = 0;
        ArrayList<Integer> wangzicard = new ArrayList<>();
        ArrayList<Integer> tongzicard = new ArrayList<>();
        ArrayList<Integer> tiaozicard = new ArrayList<>();
        ArrayList<Integer> checkmen = new ArrayList<>();

        for (Map.Entry<Integer, Integer> entry : tempCardList.entrySet()) {
            int card = entry.getKey();
            int num = entry.getValue();
            if (num>1){
                return  false;
            }
            if (card<200&&card>100){
                wangzi++;
                wangzicard.add(card);
            }
            if (card<300&&card>200){
                tongzi++;
                tongzicard.add(card);
            }
            if(card<400&&card>300){
                tiaozi++;
                tiaozicard.add(card);
            }
        }
        if(wangzi>3||tongzi>3||tiaozi>3){
            return false;
        }
        System.out.println(wangzicard);
        if (wangzicard.size()>0){
            checkmen.add(wangzicard.get(0)%100>6?wangzicard.get(0)%100-6:wangzicard.get(0)%100>3?wangzicard.get(0)%100-3:wangzicard.get(0)%100);
            if (wangzicard.size()==3){
                if(wangzicard.get(0)%100>3){
                    return false;
                }
                if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){
                    return false;
                }
            }else if(wangzicard.size()==2){
                if (wangzicard.get(0)+3==wangzicard.get(1)||wangzicard.get(0)+6==wangzicard.get(1)){

                }else{
                    return false;
                }
            }
        }
        if (tongzicard.size()>0){
            checkmen.add(tongzicard.get(0)%100>6?tongzicard.get(0)%100-6:tongzicard.get(0)%100>3?tongzicard.get(0)%100-3:tongzicard.get(0)%100);
            if (tongzicard.size()==3){
                if(tongzicard.get(0)%100>3){
                    return false;
                }
                if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){
                    return false;
                }
            }else if(tongzicard.size()==2){
                if (tongzicard.get(0)+3==tongzicard.get(1)||tongzicard.get(0)+6==tongzicard.get(1)){
                    // return false;
                }else{
                    return false;
                }

            }
        }
        if(tiaozicard.size()>0){
            checkmen.add(tiaozicard.get(0)%100>6?tiaozicard.get(0)%100-6:tiaozicard.get(0)%100>3?tiaozicard.get(0)%100-3:tiaozicard.get(0)%100);
            if (tiaozicard.size()==3){
                if(tiaozicard.get(0)%100>3){
                    return false;
                }
                if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){
                    return false;
                }
            }else if(tiaozicard.size()==2){
                if (tiaozicard.get(0)+3==tiaozicard.get(1)||tiaozicard.get(0)+6==tiaozicard.get(1)){

                }else{
                    return false;
                }
            }
        }


        List<Integer> uniqueList = new ArrayList<>(new HashSet<>(checkmen));

        List<Integer> tempList = new ArrayList<Integer>();
        Collections.sort(list);
        tempList.add(Config.DONGFENG);
        tempList.add(Config.NANFENG);
        tempList.add(Config.XIFENG);
        tempList.add(Config.BEIFENG);
        tempList.add(Config.HONGZHONG);
        tempList.add(Config.FACAI);
        tempList.add(Config.BAIBAN);
        List<Integer> ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size());
        int jiangnum = 0;
        if (ziList.size()<7){
            return false;
        }
        System.out.println(ziList.size());
        for(int i = 0; i < ziList.size(); i++)
        {
            int card = ziList.get(i);
            jiangnum = Collections.frequency(tempList,card);
            if (jiangnum!=1){
                return false;
            }
        }

        return true;
    }

    public static boolean IsQiXingYiBanGao(int[] cards){
        List<Integer> list = WinSplitCard.SwitchToCardIndex(cards);
        Map<Integer,Integer> tempCardList = new HashMap<>();
        for(Integer cd:list){
            if (tempCardList.containsKey(cd)){
                tempCardList.put(cd,tempCardList.get(cd)+1);
            }else{
                tempCardList.put(cd,1);
            }
        }
        int tongzi = 0;
        int wangzi = 0;
        int tiaozi = 0;
        ArrayList<Integer> wangzicard = new ArrayList<>();
        ArrayList<Integer> tongzicard = new ArrayList<>();
        ArrayList<Integer> tiaozicard = new ArrayList<>();
        ArrayList<Integer> checkmen = new ArrayList<>();

        for (Map.Entry<Integer, Integer> entry : tempCardList.entrySet()) {
            int card = entry.getKey();
            int num = entry.getValue();
            if (num>1){
                return  false;
            }
            if (card<200&&card>100){
                wangzi++;
                wangzicard.add(card);
            }
            if (card<300&&card>200){
                tongzi++;
                tongzicard.add(card);
            }
            if(card<400&&card>300){
                tiaozi++;
                tiaozicard.add(card);
            }
        }
        if(wangzi>3||tongzi>3||tiaozi>3){
            return false;
        }
        System.out.println(wangzicard);
        if (wangzicard.size()>0){
            checkmen.add(wangzicard.get(0)%100>6?wangzicard.get(0)%100-6:wangzicard.get(0)%100>3?wangzicard.get(0)%100-3:wangzicard.get(0)%100);
            if (wangzicard.size()==3){
                if(wangzicard.get(0)%100>3){
                    return false;
                }
                if (wangzicard.get(0)+3!=wangzicard.get(1)||wangzicard.get(1)+3!=wangzicard.get(2)){
                    return false;
                }
            }else if(wangzicard.size()==2){
                if (wangzicard.get(0)+3==wangzicard.get(1)||wangzicard.get(0)+6==wangzicard.get(1)){

                }else{
                    return false;
                }
            }
        }
        if (tongzicard.size()>0){
            checkmen.add(tongzicard.get(0)%100>6?tongzicard.get(0)%100-6:tongzicard.get(0)%100>3?tongzicard.get(0)%100-3:tongzicard.get(0)%100);
            if (tongzicard.size()==3){
                if(tongzicard.get(0)%100>3){
                    return false;
                }
                if (tongzicard.get(0)+3!=tongzicard.get(1)||tongzicard.get(1)+3!=tongzicard.get(2)){
                    return false;
                }
            }else if(tongzicard.size()==2){
                if (tongzicard.get(0)+3==tongzicard.get(1)||tongzicard.get(0)+6==tongzicard.get(1)){
                   // return false;
                }else{
                    return false;
                }

            }
        }
        if(tiaozicard.size()>0){
            checkmen.add(tiaozicard.get(0)%100>6?tiaozicard.get(0)%100-6:tiaozicard.get(0)%100>3?tiaozicard.get(0)%100-3:tiaozicard.get(0)%100);
            if (tiaozicard.size()==3){
                if(tiaozicard.get(0)%100>3){
                    return false;
                }
                if (tiaozicard.get(0)+3!=tiaozicard.get(1)||tiaozicard.get(1)+3!=tiaozicard.get(2)){
                    return false;
                }
            }else if(tiaozicard.size()==2){
                if (tiaozicard.get(0)+3==tiaozicard.get(1)||tiaozicard.get(0)+6==tiaozicard.get(1)){

                }else{
                    return false;
                }
            }
        }


        List<Integer> uniqueList = new ArrayList<>(new HashSet<>(checkmen));
        if (uniqueList.size()!=1){
            return false;
        }

        List<Integer> tempList = new ArrayList<Integer>();
        Collections.sort(list);
        tempList.add(Config.DONGFENG);
        tempList.add(Config.NANFENG);
        tempList.add(Config.XIFENG);
        tempList.add(Config.BEIFENG);
        tempList.add(Config.HONGZHONG);
        tempList.add(Config.FACAI);
        tempList.add(Config.BAIBAN);
        List<Integer> ziList = list.subList(wangzicard.size()+tongzicard.size()+tiaozicard.size(),list.size());
        int jiangnum = 0;
        if (ziList.size()<7){
            return false;
        }
        System.out.println(ziList.size());
        for(int i = 0; i < ziList.size(); i++)
        {
            int card = ziList.get(i);
            jiangnum = Collections.frequency(tempList,card);
            if (jiangnum!=1){
                return false;
            }
        }

        return true;
    }

    public static boolean isPengPengHu(int[] cards, int gui_num)
    {
        int need_gui = 0;
        for(int i = 0; i < cards.length; i++)
        {
            int num = cards[i];
            if (num > 0)
            {
                if (num == 1)
                {
                    need_gui += 2;
                }
                else if (num == 2)
                {
                    need_gui++;
                }
                else if (num == 3)
                {

                }
                else if (num == 4)
                {
                    return false;
                }
            }
        }

        if (need_gui > gui_num)
        {
            return false;
        }

        if ((gui_num - need_gui) % 3 == 0)
        {
            return true;
        }

        return false;
    }

    public static boolean foreach_eye(int[] cards, int gui_num, int max_gui, int eye_color, int[] cache, TagAnalyseItem item, TagAnalyseItem[] cacheItemList) {
        int left_gui = gui_num;
        for (int i = 0; i < 3; i++) {
            int cache_index = -1;
            if (eye_color != i) cache_index = i;
            TagAnalyseItem cache_item = new TagAnalyseItem();
            int need_gui = check_normal(cards, i * 9, i * 9 + 8, max_gui, cache_index, cache, i, item, cacheItemList, cache_item);
            if (cache_index > 0) {
                cache[i] = need_gui + 1;
                cacheItemList[i] = cache_item;
            }
            left_gui -= need_gui;
            if (left_gui < 0) {
                return false;
            }
        }

        int cache_index = -1;
        if (eye_color != 3) cache_index = 3;
        TagAnalyseItem cache_item = new TagAnalyseItem();
        int need_gui = check_zi(cards, max_gui, cache_index, cache, 3, item, cacheItemList, cache_item);
        if (cache_index > 0) {
            cache[3] = need_gui + 1;
            cacheItemList[3] = cache_item;
        }
        for(int i = 1; i <= 4; i++)
        {
            if (left_gui - 3*i == need_gui)
            {
                for(int j = 0; j < i; j++) {
                    OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, 0, 0, 0);
                    item.cbOpCard.add(op_card);
                }
            }
        }

        return left_gui >= need_gui;
    }

    public static int check_normal(int[] cards, int from, int to, int max_gui, int cache_index, int[] cache, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item) {
        if (cache_index >= 0) {
            int n = cache[cache_index];
            if (n > 0) {
                TagAnalyseItem old_item = cacheItemList[cache_index];
                if (old_item != null)
                {
                    for(int i = 0; i < old_item.cbOpCard.size(); i++)
                    {
                        OpCard op_card = old_item.cbOpCard.get(i);
                        item.cbOpCard.add(new OpCard(op_card.type, op_card.card, op_card.card2, op_card.card3));


                        OpCard cache_card = old_item.cbOpCard.get(i);
                        cache_item.cbOpCard.add(new OpCard(cache_card.type, cache_card.card, cache_card.card2, cache_card.card3));
                    }
                }
                return n - 1;
            }
        }

        int n = 0;
        for (int i = from; i <= to; i++) {
            n = n * 10 + cards[i];
        }

        if (n == 0) return 0;

        boolean n3 = false;
        for (int i = 0; i <= max_gui; i++) {
            if ((n + i) % 3 == 0) {
                n3 = true;
                break;
            }
        }

        if (!n3) {
            return max_gui + 1;
        }

        return next_split(n, 0, max_gui, eye_color, item, cacheItemList, cache_item, 0);
    }

    public static int next_split(int n, int need_gui, int max_gui, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item, int cur_index) {
        int c = 0;
        while (true) {
            if (n == 0) return need_gui;

            while (n > 0) {
                c = n % 10;
                n = n / 10;
                cur_index++;
                if (c != 0) break;
            }
            if (c == 1 || c == 4) {
                if (c == 4)
                {
                    OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1));
                    item.cbOpCard.add(op_card);

                    OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1));
                    cache_item.cbOpCard.add(cache_card);
                }
                return one(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index);
            } else if (c == 2) {
                return two(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index);
            }
            else {
                OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1));
                item.cbOpCard.add(op_card);

                OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1));
                cache_item.cbOpCard.add(cache_card);
            }
        }
    }

    public static int one(int n, int need_gui, int max_gui, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item, int cur_index) {
        int c1 = n % 10;
        int c2 = (n % 100) / 10;

        OpCard op_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1));
        OpCard cache_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1));
        if (c1 == 0)
        {
            op_card.card2 = 0;
            cache_card.card2 = 0;
            ++need_gui;
        }
        else {
            op_card.card2 = (eye_color+1)*100+(9-cur_index+1-1);
            cache_card.card2 = (eye_color+1)*100+(9-cur_index+1-1);
            n -= 1;
        }

        if (c2 == 0) {
            op_card.card3 = 0;
            cache_card.card3 = 0;
            ++need_gui;
        }
        else {
            op_card.card3 = (eye_color+1)*100+(9-cur_index+1-2);
            cache_card.card3 = (eye_color+1)*100+(9-cur_index+1-2);
            n -= 10;
        }

        if (op_card.card2 == 0 && op_card.card3 == 0)
        {
            op_card.type = RuleWeight.TYPE_PONG;
            cache_card.type = RuleWeight.TYPE_PONG;
        }

        item.cbOpCard.add(op_card);
        cache_item.cbOpCard.add(cache_card);

        if (n == 0) return need_gui;

        if (need_gui > max_gui) return need_gui;

        return next_split(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index);
    }

    public static int two(int n, int need_gui, int max_gui, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item, int cur_index) {
        int c1 = n % 10;
        int c2 = (n % 100) / 10;
        int c3 = (n % 1000) / 100;
        int c4 = (n % 10000) / 1000;

        boolean choose_ke = true;
        if (c1 != 0) {
            if (c1 == 1) {
                // 刻子
                if (c2 != 0 && c2 != 1) {
                    if (c2 == 2) {
                        if (c3 == 2) {
                            if (c4 == 2) choose_ke = false;
                        } else if (c3 == 3) {
                            if (c4 != 2) choose_ke = false;
                        } else {
                            choose_ke = false;
                        }
                    } else if (c2 == 3) {
                        if (c3 != 3) {
                            choose_ke = false;
                        }
                    } else if (c2 == 4) {
                        if (c3 == 2) {
                            if (c4 == 2 || c4 == 3 || c4 == 4) choose_ke = false;
                        }
                        if (c3 == 3) {
                            choose_ke = false;
                        }
                    }
                }
            } else if (c1 == 2) {
                choose_ke = false;
            } else if (c1 == 3) {
                if (c2 == 2) {
                    if (c3 == 1 || c3 == 4) {
                        choose_ke = false;
                    } else if (c3 == 2) {
                        if (c4 != 2) choose_ke = false;
                    }
                }
                if (c2 == 3) {
                    choose_ke = false;
                } else if (c2 == 4) {
                    if (c3 == 2) {
                        choose_ke = false;
                    }
                }
            } else if (c1 == 4) {
                if (c2 == 2 && c3 != 2) {
                    choose_ke = false;
                } else if (c2 == 3) {
                    if (c3 == 0 || c3 == 1 || c3 == 2) {
                        choose_ke = false;
                    }
                } else if (c2 == 4) {
                    if (c3 == 2) choose_ke = false;
                }
            }
        }  // c1 == 0 全拆刻子


        if (choose_ke) {
            need_gui += 1;
            OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), 0);
            item.cbOpCard.add(op_card);

            OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, (eye_color+1)*100+(9-cur_index+1), (eye_color+1)*100+(9-cur_index+1), 0);
            cache_item.cbOpCard.add(cache_card);
        } else {
            OpCard op_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1));
            OpCard op_card2 = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1));

            OpCard cache_card = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1));
            OpCard cache_card2 = new OpCard(RuleWeight.TYPE_CHOW, (eye_color+1)*100+(9-cur_index+1));

            if (c1 < 2) {
                need_gui += (2 - c1);
                n -= c1;
                if (c1 == 0)
                {
                    op_card.card2 = 0;
                    op_card2.card2 = 0;

                    cache_card.card2 = 0;
                    cache_card2.card2 = 0;
                }
                else if (c1 == 1)
                {
                    op_card.card2 = (eye_color+1)*100+(9-cur_index+1-1);
                    op_card2.card2 = 0;

                    cache_card.card2 = (eye_color+1)*100+(9-cur_index+1-1);
                    cache_card2.card2 = 0;
                }
            } else {
                n -= 2;
                op_card.card2 = (eye_color+1)*100+(9-cur_index+1-1);
                op_card2.card2 =  (eye_color+1)*100+(9-cur_index+1-1);

                cache_card.card2 = (eye_color+1)*100+(9-cur_index+1-1);
                cache_card2.card2 = (eye_color+1)*100+(9-cur_index+1-1);
            }

            if (c2 < 2) {
                need_gui += (2 - c2);
                n -= c2 * 10;
                if (c2 == 0)
                {
                    op_card.card3 = 0;
                    op_card2.card3 = 0;

                    cache_card.card3 = 0;
                    cache_card2.card3 = 0;
                }
                else if (c2 == 1)
                {
                    op_card.card3 = (eye_color+1)*100+(9-cur_index+1-2);
                    op_card2.card3 = 0;

                    cache_card.card3 = (eye_color+1)*100+(9-cur_index+1-2);
                    cache_card2.card3 = 0;
                }
            } else {
                n -= 20;
                op_card.card3 = (eye_color+1)*100+(9-cur_index+1-2);
                op_card2.card3 = (eye_color+1)*100+(9-cur_index+1-2);

                cache_card.card3 = (eye_color+1)*100+(9-cur_index+1-2);
                cache_card2.card3 = (eye_color+1)*100+(9-cur_index+1-2);
            }

            item.cbOpCard.add(op_card);
            item.cbOpCard.add(op_card2);

            cache_item.cbOpCard.add(cache_card);
            cache_item.cbOpCard.add(cache_card2);
        }

        if (n == 0) return need_gui;

        if (need_gui > max_gui) return need_gui;

        return next_split(n, need_gui, max_gui, eye_color, item, cacheItemList, cache_item, cur_index);
    }

    public static int check_zi(int[] cards, int max_gui, int cache_index, int[] cache, int eye_color, TagAnalyseItem item, TagAnalyseItem[] cacheItemList, TagAnalyseItem cache_item) {
        if (cache_index >= 0) {
            int n = cache[cache_index];
            if (n > 0) {
                TagAnalyseItem old_item = cacheItemList[cache_index];
                if (old_item != null)
                {
                    for(int i = 0; i < old_item.cbOpCard.size(); i++)
                    {
                        OpCard op_card = old_item.cbOpCard.get(i);
                        item.cbOpCard.add(new OpCard(op_card.type, op_card.card, op_card.card2, op_card.card3));

                        OpCard cache_card = old_item.cbOpCard.get(i);
                        cache_item.cbOpCard.add(new OpCard(cache_card.type, cache_card.card, cache_card.card2, cache_card.card3));
                    }
                }
                return n - 1;
            }
        }

        int need_gui = 0;
        for (int i = 27; i < 34; i++) {
            int c = cards[i];
            if (c == 0) continue;
            if (c == 1 || c == 4) {
                if (c == 1)
                {
                    OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0);
                    item.cbOpCard.add(op_card);

                    OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0);
                    cache_item.cbOpCard.add(cache_card);
                }
                else if  (c == 4)
                {
                    OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0);
                    item.cbOpCard.add(op_card);
                    OpCard op_card2 = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), 0, 0);
                    item.cbOpCard.add(op_card2);

                    OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i));
                    cache_item.cbOpCard.add(cache_card);
                    OpCard cache_card2 = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i));
                    cache_item.cbOpCard.add(cache_card2);
                }
                need_gui = need_gui + 2;
            } else if (c == 2) {
                need_gui = need_gui + 1;
                OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), 0);
                item.cbOpCard.add(op_card);

                OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), 0);
                cache_item.cbOpCard.add(cache_card);
            }
            else {
                OpCard op_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i));
                item.cbOpCard.add(op_card);

                OpCard cache_card = new OpCard(RuleWeight.TYPE_PONG, SwitchToCardData(i), SwitchToCardData(i), SwitchToCardData(i));
                cache_item.cbOpCard.add(cache_card);
            }
            if (need_gui > max_gui) return need_gui;
        }

        return need_gui;
    }
}
