package extend.mj.uitl;

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

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

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.JIHU);
            map.remove(WinCardType.PINGHU);
        }
        if (map.containsKey(type)) {
            WinCardType wct = map.get(type);
            wct.value += value;
            //Global.logger.info("putWinCardType: " + wct.toString());
            return wct;
        } else {
            WinCardType wct = new WinCardType(type, value,score, isDaHu, desc);
            map.put(type, wct);
            //Global.logger.info("putWinCardType: " + wct.toString());
            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 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);

        //变量定义
        List<Integer> wChiHuKind = new ArrayList<Integer>();

        List<Map<Integer, WinCardType>> tempLaiziMapList = new ArrayList<Map<Integer, WinCardType>>();

        //特殊胡牌
        if (config.getBoolean(Config.ROOM_CONFIG_QIDUI))
        {
            int DaDuiNum = IsQiXiaoDui(hand_cards, gui_num, opCards);
            if (DaDuiNum >= 0)
            {
                HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
                tempLaiziMapList.add(map);

                wChiHuKind.add(WinCardType.QIXIAODUI);
                if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI))
                {
                    if (DaDuiNum == 0)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_QIDUI))
                        {
                            if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN))
                            {
                                putWinCardType(map, WinCardType.QIXIAODUI, 1,  WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番");
                            }
                            else if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_4BEI))
                            {
                                putWinCardType(map, WinCardType.QIXIAODUI, 1,  WinCardType.QIXIAODUI_SOCRE * 4, true, "七对四倍");
                            }
                            else {
                                putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对");
                            }
                        }
                    }
                    else if (DaDuiNum == 1)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI))
                            putWinCardType(map, WinCardType.HAOHUA_QIXIAODUI, 1, WinCardType.HAOHUA_QIXIAODUI_SCORE, true, "豪华七小对");
                    }
                    else if (DaDuiNum == 2)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA2_QIDUI))
                            putWinCardType(map, WinCardType.HAOHUA2_QIXIAODUI, 1, WinCardType.HAOHUA2_QIXIAODUI_SCORE, true, "双豪华七小对");
                    }
                    else if (DaDuiNum == 3)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA3_QIDUI))
                            putWinCardType(map, WinCardType.HAOHUA3_QIXIAODUI, 1, WinCardType.HAOHUA3_QIXIAODUI_SCORE, true, "三豪华七小对");
                    }
                }
                else {
                    if (config.getBoolean(Config.ROOM_CONFIG_QIDUI))
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN))
                        {
                            putWinCardType(map, WinCardType.QIXIAODUI, 1,  WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番");
                        }
                        else if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_4BEI))
                        {
                            putWinCardType(map, WinCardType.QIXIAODUI, 1,  WinCardType.QIXIAODUI_SOCRE * 4, true, "七对四倍");
                        }
                        else {
                            putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对");
                        }
                    }
                }

                boolean qing_se = false;
                if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE))
                {
                    if (IsQingYiSe(hand_cards, gui_num, opCards))
                    {
                        wChiHuKind.add(WinCardType.QINGYISE);
                        putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色");

                        qing_se = true;
                    }
                }

                if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE))
                {
                    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 (config.getBoolean(Config.ROOM_CONFIG_HUNYISE))
                    {
                        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, "混一色");
                        }
                    }
                }

                Global.logger.info("get_hu_info-----begin------------");
                for (Map.Entry<Integer, WinCardType> entry :map.entrySet()) {
                    WinCardType cardType = entry.getValue();
                    Global.logger.info("get_hu_info  hu:" + cardType.toString());
                }
                Global.logger.info("get_hu_info-----end------------");
            }
        }

        if (config.getBoolean(Config.ROOM_CONFIG_SHISHANGYAO))
        {
            if (ThirteenOne(hand_cards, gui_num, opCards))
            {
                HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
                tempLaiziMapList.add(map);

                wChiHuKind.add(WinCardType.SHI_SHAN_YAO);
                putWinCardType(map, WinCardType.SHI_SHAN_YAO, 1, WinCardType.SHI_SHAN_YAO_SCORE, true, "十三幺");

                boolean qing_se = false;
                if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE))
                {
                    if (IsQingYiSe(hand_cards, gui_num, opCards))
                    {
                        wChiHuKind.add(WinCardType.QINGYISE);
                        putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色");

                        qing_se = true;
                    }
                }

                if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE))
                {
                    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 (config.getBoolean(Config.ROOM_CONFIG_HUNYISE))
                    {
                        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, "混一色");
                        }
                    }
                }

                Global.logger.info("get_hu_info-----begin------------");
                for (Map.Entry<Integer, WinCardType> entry :map.entrySet()) {
                    WinCardType cardType = entry.getValue();
                    Global.logger.info("get_hu_info  hu:" + cardType.toString());
                }
                Global.logger.info("get_hu_info-----end------------");
            }
        }

        //胡牌分析
        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++;
                }
            }

            //特殊--碰碰胡
            if (pengCardNum + lianOrPengNum == 4 || pAnalyseItem.isPengPengHu) {
                if (config.getBoolean(Config.ROOM_CONFIG_PENGPENGHU)) {
                    wChiHuKind.add(WinCardType.PENGPENGHU);
                    putWinCardType(map, WinCardType.PENGPENGHU, 1, WinCardType.PENGPENGHU_SCORE, true, "碰碰胡");
                } else {
                    if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) {
                        wChiHuKind.add(WinCardType.PINGHU);
                        putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡");
                    } else {
                        wChiHuKind.add(WinCardType.JIHU);
                        putWinCardType(map, WinCardType.JIHU, 1, WinCardType.JIHU_SCORE, false, "鸡胡");
                    }
                }
            }
            else if (lianCardNum + lianOrPengNum == 4) {
                wChiHuKind.add(WinCardType.PINGHU);
                putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡");
            } else {
                if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) {
                    wChiHuKind.add(WinCardType.PINGHU);
                    putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡");
                } else {
                    wChiHuKind.add(WinCardType.JIHU);
                    putWinCardType(map, WinCardType.JIHU, 1, WinCardType.JIHU_SCORE, false, "鸡胡");
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_YAO_JIU)) {
                if (config.getBoolean(Config.ROOM_CONFIG_han19)) {
                    if (IsHuYaoJiu(pAnalyseItem)) {
                        wChiHuKind.add(WinCardType.YAO_JIU);
                        putWinCardType(map, WinCardType.YAO_JIU, 1, WinCardType.YAO_JIU_SCORE, true, "混幺九");
                    }
                } else {
                    if (IsQingYaoJiu(pAnalyseItem)) {
                        wChiHuKind.add(WinCardType.YAO_JIU);
                        putWinCardType(map, WinCardType.YAO_JIU, 1, WinCardType.YAO_JIU_SCORE, true, "清幺九");
                    }
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_QING_YAO_JIU)) {
                if (IsQingYaoJiu(pAnalyseItem)) {
                    wChiHuKind.add(WinCardType.YAO_JIU);
                    putWinCardType(map, WinCardType.QING_YAO_JIU, 1, WinCardType.QING_YAO_JIU_SCORE, true, "清幺九");
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_QUAN_FENG)) {
                if (IsQuanFeng(pAnalyseItem)) {
                    wChiHuKind.add(WinCardType.QUAN_FENG);
                    putWinCardType(map, WinCardType.QUAN_FENG, 1, WinCardType.QUAN_FENG_SCORE, true, "全风");
                }
            }

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

            if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE))
            {
                if (IsZiYiSe(pAnalyseItem))
                {
                    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 (config.getBoolean(Config.ROOM_CONFIG_HUNYISE))
                {
                    if (IsHunYiSe(pAnalyseItem))
                    {
                        wChiHuKind.add(WinCardType.HUN_YI_SE);
                        putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色");
                    }
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_DASHANYUAN) || config.getBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN))
            {
                int sanyuan = IsDaXiaoSanYuan(pAnalyseItem);
                if (sanyuan > 0)
                {
                    //大三元
                    if (sanyuan == 1)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_DASHANYUAN))
                        {
                            wChiHuKind.add(WinCardType.DA_SHAN_YUAN);
                            putWinCardType(map, WinCardType.DA_SHAN_YUAN, 1, WinCardType.DA_SHAN_YUAN_SCORE, true, "大三元");
                        }
                    }
                    //小山元
                    else if (sanyuan == 2)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN))
                        {
                            wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN);
                            putWinCardType(map, WinCardType.XIAO_SHAN_YUAN, 1, WinCardType.XIAO_SHAN_YUAN_SCORE, true, "小三元");
                        }
                    }
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_DASIXI) || config.getBoolean(Config.ROOM_CONFIG_XIAOSIXI))
            {
                int sixi = IsDaXiaoSiXi(pAnalyseItem);
                if (sixi > 0)
                {
                    //大四喜
                    if (sixi == 1)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_DASIXI))
                        {
                            wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN);
                            putWinCardType(map, WinCardType.DA_SI_XI, 1, WinCardType.DA_SI_XI_SCORE, true, "大四喜");
                        }
                    }
                    //小四喜
                    else if (sixi == 2)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_XIAOSIXI))
                        {
                            wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN);
                            putWinCardType(map, WinCardType.XIAO_SI_XI, 1, WinCardType.XIAO_SI_XI_SCORE, true, "小四喜");
                        }
                    }
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_SHIBALUOHAN))
            {
                if (IsShiBaLuoHan(pAnalyseItem))
                {
                    wChiHuKind.add(WinCardType.SHI_BA_LUO_HAN);
                    putWinCardType(map, WinCardType.SHI_BA_LUO_HAN, 1, WinCardType.SHI_BA_LUO_HAN_SCORE, true, "十八罗汉");
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_QUAN_FENG_SCORE))
            {
                if (QuanQiuRen(opCards))
                {
                    wChiHuKind.add(WinCardType.QUAN_QIU_REN);
                    putWinCardType(map, WinCardType.QUAN_QIU_REN, 1, WinCardType.QUAN_QIU_REN_SCORE, true, "全求人");
                }
            }

            Global.logger.info("get_hu_info-----begin------------");
            if (pAnalyseItem.cbOpCard.size() != 4)
            {
                Global.logger.error("Exception cbOpCard.size() != 4");
            }

            Global.logger.info("get_hu_info-------ieye:" + pAnalyseItem.cbCardEye + " ieye2:" + pAnalyseItem.cbCardEye2);

            for(int j = 0; j < pAnalyseItem.cbOpCard.size(); j++)
            {
                OpCard op_card = pAnalyseItem.cbOpCard.get(j);
                if (op_card.type == RuleWeight.TYPE_CHOW)
                {
                    Global.logger.info("get_hu_info----------chi:" + op_card.card3 + " " + op_card.card2 + " " + op_card.card);
                }
                else {
                    Global.logger.info("get_hu_info----------pong:" + op_card.card3 + " " + op_card.card2 + " " + op_card.card);
                }
            }
            for (Map.Entry<Integer, WinCardType> entry :map.entrySet()) {
                WinCardType cardType = entry.getValue();
                Global.logger.info("get_hu_info  hu:" + cardType.toString());
            }
            Global.logger.info("get_hu_info-----end------------");
        }

        if (tempLaiziMapList.size() > 0)
        {
            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())
                    {
                        if (type == WinCardType.TIAN_HU || type == WinCardType.DI_HU || type == WinCardType.QUAN_FENG || type == WinCardType.YAO_JIU
                                || type == WinCardType.SHI_BA_LUO_HAN || type ==  WinCardType.XIAO_SHAN_YUAN || type ==  WinCardType.DA_SHAN_YUAN
                                || type == WinCardType.XIAO_SI_XI || type == WinCardType.DA_SI_XI || type == WinCardType.ZI_YI_SE)
                        {
                            if (cardType.score > maxScore)
                            {
                                maxScore = cardType.score;
                                maxType = type;
                            }
                        }
                        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 TempAnalyseChiHuCard(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);

        //变量定义
        List<Integer> wChiHuKind = new ArrayList<Integer>();

        List<Map<Integer, WinCardType>> tempLaiziMapList = new ArrayList<Map<Integer, WinCardType>>();

        //特殊胡牌
        if (config.getBoolean(Config.ROOM_CONFIG_QIDUI))
        {
            int DaDuiNum = IsQiXiaoDui(hand_cards, gui_num, opCards);
            if (DaDuiNum >= 0)
            {
                HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
                tempLaiziMapList.add(map);

                wChiHuKind.add(WinCardType.QIXIAODUI);
                if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI))
                {
                    if (DaDuiNum == 0)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_QIDUI))
                        {
                            if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN))
                            {
                                putWinCardType(map, WinCardType.QIXIAODUI, 1,  WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番");
                            }
                            else if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_4BEI))
                            {
                                putWinCardType(map, WinCardType.QIXIAODUI, 1,  WinCardType.QIXIAODUI_SOCRE * 4, true, "七对四倍");
                            }
                            else {
                                putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对");
                            }
                        }
                    }
                    else if (DaDuiNum == 1)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA_QIDUI))
                            putWinCardType(map, WinCardType.HAOHUA_QIXIAODUI, 1, WinCardType.HAOHUA_QIXIAODUI_SCORE, true, "豪华七小对");
                    }
                    else if (DaDuiNum == 2)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA2_QIDUI))
                            putWinCardType(map, WinCardType.HAOHUA2_QIXIAODUI, 1, WinCardType.HAOHUA2_QIXIAODUI_SCORE, true, "双豪华七小对");
                    }
                    else if (DaDuiNum == 3)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_HAOHUA3_QIDUI))
                            putWinCardType(map, WinCardType.HAOHUA3_QIXIAODUI, 1, WinCardType.HAOHUA3_QIXIAODUI_SCORE, true, "三豪华七小对");
                    }
                }
                else {
                    if (config.getBoolean(Config.ROOM_CONFIG_QIDUI))
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_JIA_FAN))
                        {
                            putWinCardType(map, WinCardType.QIXIAODUI, 1,  WinCardType.QIXIAODUI_SOCRE * 2, true, "七对加番");
                        }
                        else if (config.getBoolean(Config.ROOM_CONFIG_QIDUI_4BEI))
                        {
                            putWinCardType(map, WinCardType.QIXIAODUI, 1,  WinCardType.QIXIAODUI_SOCRE * 4, true, "七对四倍");
                        }
                        else {
                            putWinCardType(map, WinCardType.QIXIAODUI, 1, WinCardType.QIXIAODUI_SOCRE, true, "七小对");
                        }
                    }
                }

                boolean qing_se = false;
                if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE))
                {
                    if (IsQingYiSe(hand_cards, gui_num, opCards))
                    {
                        wChiHuKind.add(WinCardType.QINGYISE);
                        putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色");

                        qing_se = true;
                    }
                }

                if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE))
                {
                    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 (config.getBoolean(Config.ROOM_CONFIG_HUNYISE))
                    {
                        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, "混一色");
                        }
                    }
                }
            }
        }

        if (config.getBoolean(Config.ROOM_CONFIG_SHISHANGYAO))
        {
            if (ThirteenOne(hand_cards, gui_num, opCards))
            {
                HashMap<Integer, WinCardType> map = new HashMap<Integer, WinCardType>();
                tempLaiziMapList.add(map);

                wChiHuKind.add(WinCardType.SHI_SHAN_YAO);
                putWinCardType(map, WinCardType.SHI_SHAN_YAO, 1, WinCardType.SHI_SHAN_YAO_SCORE, true, "十三幺");

                boolean qing_se = false;
                if (config.getBoolean(Config.ROOM_CONFIG_QINGYISE))
                {
                    if (IsQingYiSe(hand_cards, gui_num, opCards))
                    {
                        wChiHuKind.add(WinCardType.QINGYISE);
                        putWinCardType(map, WinCardType.QINGYISE, 1,WinCardType.QINGYISE_SCORE, true, "清一色");

                        qing_se = true;
                    }
                }

                if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE))
                {
                    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 (config.getBoolean(Config.ROOM_CONFIG_HUNYISE))
                    {
                        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, "混一色");
                        }
                    }
                }
            }
        }

        //胡牌分析
        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++;
                }
            }

            //特殊--碰碰胡
            if (pengCardNum + lianOrPengNum == 4) {
                if (config.getBoolean(Config.ROOM_CONFIG_PENGPENGHU)) {
                    wChiHuKind.add(WinCardType.PENGPENGHU);
                    putWinCardType(map, WinCardType.PENGPENGHU, 1, WinCardType.PENGPENGHU_SCORE, true, "碰碰胡");
                } else {
                    if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) {
                        wChiHuKind.add(WinCardType.PINGHU);
                        putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡");
                    } else {
                        wChiHuKind.add(WinCardType.JIHU);
                        putWinCardType(map, WinCardType.JIHU, 1, WinCardType.JIHU_SCORE, false, "鸡胡");
                    }
                }
            }
            else if (lianCardNum + lianOrPengNum == 4) {
                    wChiHuKind.add(WinCardType.PINGHU);
                    putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡");
            } else {
                if (config.getBoolean(Config.ROOM_CONFIG_JIHU_SHI_PINGHU)) {
                    wChiHuKind.add(WinCardType.PINGHU);
                    putWinCardType(map, WinCardType.PINGHU, 1, WinCardType.PINGHU_SCORE, true, "平胡");
                } else {
                    wChiHuKind.add(WinCardType.JIHU);
                    putWinCardType(map, WinCardType.JIHU, 1, WinCardType.JIHU_SCORE, false, "鸡胡");
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_YAO_JIU)) {
                if (config.getBoolean(Config.ROOM_CONFIG_han19)) {
                    if (IsHuYaoJiu(pAnalyseItem)) {
                        wChiHuKind.add(WinCardType.YAO_JIU);
                        putWinCardType(map, WinCardType.YAO_JIU, 1, WinCardType.YAO_JIU_SCORE, true, "混幺九");
                    }
                } else {
                    if (IsQingYaoJiu(pAnalyseItem)) {
                        wChiHuKind.add(WinCardType.YAO_JIU);
                        putWinCardType(map, WinCardType.YAO_JIU, 1, WinCardType.YAO_JIU_SCORE, true, "清幺九");
                    }
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_QING_YAO_JIU)) {
                if (IsQingYaoJiu(pAnalyseItem)) {
                    wChiHuKind.add(WinCardType.YAO_JIU);
                    putWinCardType(map, WinCardType.QING_YAO_JIU, 1, WinCardType.QING_YAO_JIU_SCORE, true, "清幺九");
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_QUAN_FENG)) {
                if (IsQuanFeng(pAnalyseItem)) {
                    wChiHuKind.add(WinCardType.QUAN_FENG);
                    putWinCardType(map, WinCardType.QUAN_FENG, 1, WinCardType.QUAN_FENG_SCORE, true, "全风");
                }
            }

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

            if (config.getBoolean(Config.ROOM_CONFIG_ZIYISE))
            {
                if (IsZiYiSe(pAnalyseItem))
                {
                    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 (config.getBoolean(Config.ROOM_CONFIG_HUNYISE))
                {
                    if (IsHunYiSe(pAnalyseItem))
                    {
                        wChiHuKind.add(WinCardType.HUN_YI_SE);
                        putWinCardType(map, WinCardType.HUN_YI_SE, 1,WinCardType.HUN_YI_SE_SCORE, true, "混一色");
                    }
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_DASHANYUAN) || config.getBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN))
            {
                int sanyuan = IsDaXiaoSanYuan(pAnalyseItem);
                if (sanyuan > 0)
                {
                    //大三元
                    if (sanyuan == 1)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_DASHANYUAN))
                        {
                            wChiHuKind.add(WinCardType.DA_SHAN_YUAN);
                            putWinCardType(map, WinCardType.DA_SHAN_YUAN, 1, WinCardType.DA_SHAN_YUAN_SCORE, true, "大三元");
                        }
                    }
                    //小山元
                    else if (sanyuan == 2)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_XIAOSHANYUAN))
                        {
                            wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN);
                            putWinCardType(map, WinCardType.XIAO_SHAN_YUAN, 1, WinCardType.XIAO_SHAN_YUAN_SCORE, true, "小三元");
                        }
                    }
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_DASIXI) || config.getBoolean(Config.ROOM_CONFIG_XIAOSIXI))
            {
                int sixi = IsDaXiaoSiXi(pAnalyseItem);
                if (sixi > 0)
                {
                    //大四喜
                    if (sixi == 1)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_DASIXI))
                        {
                            wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN);
                            putWinCardType(map, WinCardType.DA_SI_XI, 1, WinCardType.DA_SI_XI_SCORE, true, "大四喜");
                        }
                    }
                    //小四喜
                    else if (sixi == 2)
                    {
                        if (config.getBoolean(Config.ROOM_CONFIG_XIAOSIXI))
                        {
                            wChiHuKind.add(WinCardType.XIAO_SHAN_YUAN);
                            putWinCardType(map, WinCardType.XIAO_SI_XI, 1, WinCardType.XIAO_SI_XI_SCORE, true, "小四喜");
                        }
                    }
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_SHIBALUOHAN))
            {
                if (IsShiBaLuoHan(pAnalyseItem))
                {
                    wChiHuKind.add(WinCardType.SHI_BA_LUO_HAN);
                    putWinCardType(map, WinCardType.SHI_BA_LUO_HAN, 1, WinCardType.SHI_BA_LUO_HAN_SCORE, true, "十八罗汉");
                }
            }

            if (config.getBoolean(Config.ROOM_CONFIG_QUAN_FENG_SCORE))
            {
                if (QuanQiuRen(opCards))
                {
                    wChiHuKind.add(WinCardType.QUAN_QIU_REN);
                    putWinCardType(map, WinCardType.QUAN_QIU_REN, 1, WinCardType.QUAN_QIU_REN_SCORE, true, "全求人");
                }
            }
        }

        if (tempLaiziMapList.size() > 0)
        {
            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 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 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;
    }
}
