package GameControl;

import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;

import java.io.*;
import java.time.Duration;
import java.time.LocalDateTime;
import java.util.*;

import Constants.Constants;
import ExternalControl.AIGame;

public class GameControl {
    //一局游戏的变量
    /**
     * 记牌器
     */
    private int[] cardRecorder;
    /**
     * 游戏局数
     */
    private int gameNumber;
    /**
     * 当前玩家动作集
     */
    private Set<CardInfo> actionSet;
    private Map<Integer, CardInfo> actionMap;
    /**
     * 上个玩家出牌
     */
    private CardInfo lastCard;
    /**
     * 当前有出牌权的玩家
     */
    private int playerWithRight;
    /**
     * 玩家的下家
     */
    private int[] nextPlayer;

    /**
     * 玩家的上家
     */
    private int[] lastPlayer;

    /**
     * 上局游戏结果
     */
    private int[] lastResult;
    /**
     * 当前游戏结果
     */
    private int[] currentResult;
    /**
     * 当前结果指针
     */
    private int pos;
    /**
     * 玩家
     */
    private Player[] players;

    /**
     * 当前比分:int[0]为0,2玩家级数，int[1]为1,3玩家级数
     */
    private int[] score;
    /**
     * 级牌
     */
    private int levelCard;
    /**
     * 打A数
     */
    private int[] playA;

    /**
     * 当前选择的动作,-1代表不出
     */
    private Integer selectedAction;

    /**
     * 记录一小局游戏是否结束
     */
    private boolean isSmallGameOver;

    private boolean isGameOver;

    //一局游戏的主进程
    public void gameControl() {
        this.initialize();
        //完整游戏循环：一局开始前判断游戏是否结束
        while (!isGameOver) {
            this.dealtCards();
            if (this.gameNumber != 0) {
                //贡牌
                this.tributeCard();
            }

            //小局游戏循环
            while (!isSmallGameOver) {
                showCards();
                this.getActionList();
                //让AI游戏选择动作
                if (actionMap == null || actionMap.isEmpty()) {
                    //牌权给下家
                    playerWithRight = nextPlayer[playerWithRight];
                } else {
                    //?????防止修改动作
                    final Map<Integer, CardInfo> finalActionMap = actionMap;
                    selectedAction = AIGame.selectAction(finalActionMap, players, levelCard);
                    this.doAction();
                    //游戏结束，清算
                    if (this.isSmallGameOver) {
                        //将剩下的玩家放入结果中
                        for (int i = 0; i < 4; ++i) {
                            if (this.nextPlayer[i] != -1) {
                                currentResult[pos++] = i;
                            }
                        }
                        this.lastResult = this.currentResult;
                        int winner = this.currentResult[0];
                        int teammate = (winner + 2) % 4;
                        int numOfUpgrade = 1;
                        if (currentResult[1] == teammate) {
                            numOfUpgrade = 3;
                        } else if (currentResult[2] == teammate) {
                            numOfUpgrade = 2;
                        }
                        if (score[winner & 1] == 13) {
                            if (numOfUpgrade > 1) {
                                this.isGameOver = true;
                            } else {
                                //三次不过A，打2
                                if (++this.playA[winner & 1] >= 3) {
                                    this.score[winner & 1] = 0;
                                    this.playA[winner & 1] = 0;
                                }
                            }
                        } else {
                            this.score[winner & 1] += numOfUpgrade;
                            this.score[winner & 1] = Math.min(this.score[winner & 1], 13);
                        }
                    }
                }
            }
            ++gameNumber;
        }
        //?????返回得分？
    }

    //其余函数

    private void showCards() {
        //System.out.println("--------0-------1-------2--------3-------");
        for (int i = 0; i < 14; ++i) {
            for (Player player : players) {
                int card = player.getCards()[i];
                for (int j = 7; j >= 0; --j) {
                    System.out.print(((card >> j) & 1) != 0 ? 1 : 0);
                }
                System.out.print("----");
            }
            System.out.println();
        }
        System.out.println();
    }

    private void showCards(int[] cards) {
        //System.out.println("--------0-------1-------2--------3-------");
        for (int card : cards) {
            for (int j = 7; j >= 0; --j) {
                System.out.print(((card >> j) & 1) != 0 ? 1 : 0);
            }
            System.out.print("----");
        }
        System.out.println();
        System.out.println();
    }

    //初始化
    private void initialize() {
        cardRecorder = new int[15];
        for (int i = 0; i < 13; ++i) {
            cardRecorder[i] = 0xff;
        }
        cardRecorder[13] = 0x11;
        cardRecorder[14] = 0x11;

        gameNumber = 0;

        actionSet = Collections.emptySet();

        actionMap = new HashMap<Integer, CardInfo>();

        lastCard = null;

        playerWithRight = 0;

        nextPlayer = new int[]{1, 2, 3, 0};
        lastPlayer = new int[]{3, 0, 1, 2};
        players = new Player[4];
        for (int i = 0; i < 4; ++i) {
            players[i] = new Player();
            players[i].setCards(new int[15]);
            players[i].setPlayerNum(i);
        }

        lastResult = new int[4];
        currentResult = new int[4];
        pos = 0;

        score = new int[2];
        playA = new int[2];
        score[0] = score[1] = 0;
        playA[0] = playA[1] = 0;

        levelCard = 0;

        selectedAction = -1;

        isSmallGameOver = false;
        isGameOver = false;

    }

    //随机发牌
    private void dealtCards() {
        for (int i = 0; i < 4; i++) {
            players[i].setCards(new int[15]);
        }
        Random random = new Random();
        int[] cards = new int[Constants.numberOfCards];
        for (int i = 0; i < Constants.numberOfCards; ++i) {
            cards[i] = i;
        }
        int temp;
        int randomNum;
        for (int i = Constants.numberOfCards - 1; i >= 0; --i) {
            randomNum = random.nextInt(i + 1);
            temp = cards[i];
            cards[i] = cards[randomNum];
            cards[randomNum] = temp;
        }
        int playerPos = 0;
        for (int card : cards) {
            players[playerPos].getCards()[card / 8] |= (1 << (card % 8));
            playerPos = (playerPos + 1) % 4;
        }
        for (Player player : players) {
            temp = player.getCards()[13];
            player.getCards()[13] = (((temp & 0x2) << 3) | (temp & 0x1));
            player.getCards()[14] = (((temp & 0x4) >> 2) | ((temp & 0x8) << 1));

            sortingCards(player);
        }
    }

    //
    private void sortingCards(Player player) {
        int card;
        for (int i = 0; i < 14; ++i) {
            card = player.getCards()[i];
            player.getCards()[i] = ((card & (card << 4)) | ((card | (card >> 4)) & 0xf));
        }
    }

    //贡牌
    private void tributeCard() {
        int winner = this.lastResult[0];
        //上游+二游，两方进贡
        if ((this.lastResult[0] & 1) == (this.lastResult[1] & 1)) {
            int winnerNext = (winner + 1) % 4;
            int secondNext = (winner + 3) % 4;
            //拿到双大王，抗供
            if (((this.players[winnerNext].getCards()[13] | this.players[secondNext].getCards()[13]) & 0x22) != 0) {
                this.playerWithRight = winner;
                return;
            } else {
                CardInfo winnerNextCard = this.getBiggestCard(players[winnerNext]);
                CardInfo secondNextCard = this.getBiggestCard(players[secondNext]);
                if (winnerNextCard.getCardLoc() >= secondNextCard.getCardLoc()) {
                    exchangeCards(winner, winnerNext, winnerNextCard);
                    exchangeCards(lastResult[1], secondNext, secondNextCard);
                    this.playerWithRight = winnerNext;
                } else {
                    exchangeCards(winner, secondNext, secondNextCard);
                    exchangeCards(lastResult[1], winnerNext, winnerNextCard);
                    this.playerWithRight = secondNext;
                }
            }
        } else {
            int loser = lastResult[3];
            //抗贡
            if ((this.players[loser].getCards()[13] & 0x22) != 0) {
                this.playerWithRight = winner;
            } else {
                CardInfo loserCard = this.getBiggestCard(players[loser]);
                exchangeCards(winner, loser, loserCard);
                this.playerWithRight = loser;
            }
        }
    }

    /**
     * 得到最大单牌，除逢人配外
     *
     * @param player
     * @return
     */
    private CardInfo getBiggestCard(Player player) {
        int[] card = new int[1];
        for (int i = 13; i >= 0; --i) {
            if (player.getCards()[i] != 0) {
                if (this.levelCard == i) {
                    if ((player.getCards()[i] & ~0x11) != 0) {
                        card[0] = getTopCard(player.getCards()[i] & ~0x11);
                        return CardInfo.buildCardInfo(Constants.single, card, i, player.getPlayerNum());
                    }
                } else {
                    card[0] = getTopCard(player.getCards()[i]);
                    return CardInfo.buildCardInfo(Constants.single, card, i, player.getPlayerNum());
                }
            }
        }
        return new CardInfo();
    }

    private int getTopCard(int card) {
        for (int i = 7; i >= 0; --i) {
            if ((card & (1 << i)) != 0) {
                return 1 << i;
            }
        }
        return 0;
    }

    private void exchangeCards(int winner, int loser, CardInfo tributeCard) {
        //提取出winner可贡牌，给AI选择(没有花色区别,逢人配最后考虑)
        Map<Integer, Integer> payTributeCards = new HashMap<Integer, Integer>();
        int i = 0;
        while (i < 10 || payTributeCards.isEmpty()) {
            if (players[winner].getCards()[i] != 0) {
                //取最上面一张牌
                //如果是级牌，去掉逢人配:不为0，取最上面一张;为0，不去掉取最上面一张
                if (levelCard == i) {
                    if ((players[winner].getCards()[i] & ~0x11) != 0) {
                        payTributeCards.put(i, getTopCard(players[winner].getCards()[i] & ~0x11));
                    } else {
                        payTributeCards.put(i, getTopCard(players[winner].getCards()[i]));
                    }
                } else {
                    payTributeCards.put(i, getTopCard(players[winner].getCards()[i]));
                }
            }
            ++i;
        }
        int payTribute = AIGame.tributeCard(payTributeCards);
        //两方互换牌
        players[winner].getCards()[payTribute] &= (~payTributeCards.get(payTribute));
        players[winner].getCards()[tributeCard.getCardLoc()] |= tributeCard.getPlayedCards()[0];

        players[loser].getCards()[payTribute] |= payTributeCards.get(payTribute);
        players[loser].getCards()[tributeCard.getCardLoc()] &= (~tributeCard.getPlayedCards()[0]);
    }

    //得到动作集
    private void getActionList() {
        actionMap.clear();
        int wildCardNum = getWildCardNum(players[playerWithRight]);
        //上家未出牌 or 出牌玩家为自己
        if (lastCard == null || lastCard.getPlayer() == playerWithRight) {
            getAllAction(actionMap);
            if (wildCardNum != 0) {
                actionMap.putAll(ActionJudgment.getPairWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getThreeWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getThreeWithTwoWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getTwoThreeWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getThreePairWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getStraightWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getBombWithWild(actionMap.size(), -1, -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getStraightFlushWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
            }
            return;
        }
        //普通牌型
        if (lastCard.getCardType() <= 7) {
            switch (lastCard.getCardType()) {
                case Constants.single:
                    actionMap.putAll(ActionJudgment.getSingle(actionMap.size(), lastCard.getCardPoint()[0], levelCard, players[playerWithRight]));
                    break;
                case Constants.pair:
                    actionMap.putAll(ActionJudgment.getPair(actionMap.size(), lastCard.getCardPoint()[0], levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getPairWithWild(actionMap.size(), lastCard.getCardPoint()[0], wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.three:
                    actionMap.putAll(ActionJudgment.getThree(actionMap.size(), lastCard.getCardPoint()[0], levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getThreeWithWild(actionMap.size(), lastCard.getCardPoint()[0], wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.threeWithTwo:
                    actionMap.putAll(ActionJudgment.getThreeWithTwo(actionMap.size(), lastCard.getCardPoint()[0], levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getThreeWithTwoWithWild(actionMap.size(), lastCard.getCardPoint()[0], wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.twoThree:
                    actionMap.putAll(ActionJudgment.getTwoThree(actionMap.size(), lastCard.getCardPoint()[0] + 1, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getTwoThreeWithWild(actionMap.size(), lastCard.getCardPoint()[0] + 1, wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.threePairs:
                    actionMap.putAll(ActionJudgment.getThreePair(actionMap.size(), lastCard.getCardPoint()[0] + 1, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getThreePairWithWild(actionMap.size(), lastCard.getCardPoint()[0] + 1, wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.straight:
                    actionMap.putAll(ActionJudgment.getStraight(actionMap.size(), lastCard.getCardPoint()[0] + 1, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getStraightWithWild(actionMap.size(), lastCard.getCardPoint()[0] + 1, wildCardNum, levelCard, players[playerWithRight]));
                    break;
            }
            actionMap.putAll(ActionJudgment.getBomb(actionMap.size(), -1, -1, levelCard, players[playerWithRight]));
            actionMap.putAll(ActionJudgment.getStraightFlush(actionMap.size(), -1, players[playerWithRight]));
            actionMap.putAll(ActionJudgment.getFourKings(actionMap.size(), players[playerWithRight]));
            actionMap.putAll(ActionJudgment.getBombWithWild(actionMap.size(), -1, -1, wildCardNum, levelCard, players[playerWithRight]));
            actionMap.putAll(ActionJudgment.getStraightFlushWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));

        } else {
            switch (lastCard.getCardType()) {
                case Constants.straightFlush:
                    actionMap.putAll(ActionJudgment.getStraightFlush(actionMap.size(), lastCard.getCardPoint()[0] + 1, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getStraightFlushWithWild(actionMap.size(), lastCard.getCardPoint()[0] + 1, wildCardNum, levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getBomb(actionMap.size(), 6, -1, levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getBombWithWild(actionMap.size(), 6, -1, wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.bomb:
                    int bombNum = Arrays.stream(lastCard.getPlayedCards()).map(ActionJudgment::numOfSameSuitCards).sum();
                    actionMap.putAll(ActionJudgment.getBomb(actionMap.size(), bombNum, lastCard.getCardPoint()[0], levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getBombWithWild(actionMap.size(), bombNum, lastCard.getCardPoint()[0], wildCardNum, levelCard, players[playerWithRight]));
                    if (bombNum < 6) {
                        actionMap.putAll(ActionJudgment.getStraightFlush(actionMap.size(), -1, players[playerWithRight]));
                        actionMap.putAll(ActionJudgment.getStraightFlushWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                    }
                    break;
            }
            actionMap.putAll(ActionJudgment.getFourKings(actionMap.size(), players[playerWithRight]));
        }
    }

    private void getAllAction(Map<Integer, CardInfo> actions) {
        actions.putAll(ActionJudgment.getSingle(actions.size(), -1, levelCard, players[playerWithRight]));
        actions.putAll(ActionJudgment.getPair(actions.size(), -1, levelCard, players[playerWithRight]));
        actions.putAll(ActionJudgment.getThree(actions.size(), -1, levelCard, players[playerWithRight]));
        actions.putAll(ActionJudgment.getThreeWithTwo(actions.size(), -1, levelCard, players[playerWithRight]));
        actions.putAll(ActionJudgment.getTwoThree(actions.size(), -1, players[playerWithRight]));
        actions.putAll(ActionJudgment.getThreePair(actions.size(), -1, players[playerWithRight]));
        actions.putAll(ActionJudgment.getStraightFlush(actions.size(), -1, players[playerWithRight]));
        actions.putAll(ActionJudgment.getStraight(actions.size(), -1, players[playerWithRight]));
        actions.putAll(ActionJudgment.getBomb(actions.size(), -1, -1, levelCard, players[playerWithRight]));
        actions.putAll(ActionJudgment.getFourKings(actions.size(), players[playerWithRight]));
    }

    private int getWildCardNum(Player player) {
        int flag = (player.getCards()[levelCard] & 0x11);
        if (flag == 0x11) {
            return 2;
        }
        return flag;
    }

    //执行动作
    private void doAction() {
        boolean isFinished;
        int finishedPlayer = -1;
        int lastPla = lastPlayer[playerWithRight];
        int teammate = (playerWithRight + 2) % 4;
        CardInfo cardInfo = actionMap.get(selectedAction);
        if (selectedAction == -1 || cardInfo == null) {
            playerWithRight = nextPlayer[playerWithRight];
            return;
        }
        //出牌
        for (int i = 0; i < cardInfo.getPlayedCards().length; ++i) {
            players[playerWithRight].getCards()[i + cardInfo.getCardLoc()] &= ~cardInfo.getPlayedCards()[i];
            cardRecorder[i + cardInfo.getCardLoc()] &= ~cardInfo.getPlayedCards()[i];
        }
        //如果手牌出完了
        isFinished = isFinished(players[playerWithRight]);
        if (isFinished) {
            finishedPlayer = playerWithRight;
            this.currentResult[pos++] = this.playerWithRight;
            //判断游戏是否结束
            if (nextPlayer[teammate] == -1) {
                this.isSmallGameOver = true;
                return;
            }
            //更改上、下家
            this.nextPlayer[this.lastPlayer[playerWithRight]] = nextPlayer[playerWithRight];
            this.lastPlayer[this.nextPlayer[playerWithRight]] = lastPlayer[playerWithRight];
        }
        sortingCards(players[playerWithRight]);
        //牌权给下家，清空动作
        this.playerWithRight = this.nextPlayer[playerWithRight];

        this.lastCard = cardInfo;

        if (isFinished) {
            this.nextPlayer[finishedPlayer] = -1;
            this.lastPlayer[finishedPlayer] = -1;
            playARound(lastPla, teammate);
        }
    }

    //走一轮牌，主要解决一玩家出完后，若全不要牌权给队友
    private void playARound(int lastPla, int teammate) {
        while (true) {
            this.getActionList();
            //让AI游戏选择动作
            if (actionMap == null || actionMap.isEmpty()) {
                //牌权给下家
                if (playerWithRight == lastPla) {
                    playerWithRight = teammate;
                    break;
                }
                playerWithRight = nextPlayer[playerWithRight];
            } else {
                final Map<Integer, CardInfo> finalActionMap = actionMap;
                selectedAction = AIGame.selectAction(finalActionMap, players, levelCard);
                if (selectedAction == -1) {
                    if (playerWithRight == lastPla) {
                        playerWithRight = teammate;
                        break;
                    }
                    playerWithRight = nextPlayer[playerWithRight];
                } else {
                    this.doAction();
                    break;
                }
            }
        }

    }

    //判断是否出完牌
    private boolean isFinished(Player player) {
        for (int i : player.getCards()) {
            if (i != 0) {
                return false;
            }
        }
        return true;
    }


    //************************test*****************************//
    public void testSpeed() throws IOException {
        File file = new File("D:\\ideaproject\\data\\主动发牌.csv");
        FileInputStream fis = new FileInputStream(file);
        Workbook workbook = new XSSFWorkbook(fis);
        System.out.println("主动发牌:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\主动发牌\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\单张.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("单张:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\单张\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\对子.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("对子:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\对子\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\三张.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("三张:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\三张\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\三带二.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("三带二:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\三带二\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\顺子.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("顺子:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\顺子\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\三连对.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("三连对:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\三连对\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\钢板.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("钢板:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\钢板\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\四炸.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("四炸:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\四炸\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\五炸.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("五炸:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\五炸\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\同花.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("同花:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\同花\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\六炸.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("六炸:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\六炸\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\七炸.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("七炸:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\七炸\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\八炸.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("八炸:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\八炸\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\九炸.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("九炸:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\九炸\\%s%.csv") + "ms");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\十炸.csv"));
        workbook = new XSSFWorkbook(fis);
        System.out.println("十炸:" + readFileAndGetAction(workbook, "D:\\ideaproject\\data2\\csvData\\十炸\\%s%.csv") + "ms");
        fis.close();
    }

    private void getAction(int cardType, int cardPoint, int bombNum) {
        int wildCardNum = getWildCardNum(players[0]);
        //上家未出牌 or 出牌玩家为自己
        if (cardType == 0) {
            getAllAction(actionMap);
            if (wildCardNum != 0) {
                actionMap.putAll(ActionJudgment.getPairWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getThreeWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getThreeWithTwoWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getTwoThreeWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getThreePairWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getStraightWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getBombWithWild(actionMap.size(), -1, -1, wildCardNum, levelCard, players[playerWithRight]));
                actionMap.putAll(ActionJudgment.getStraightFlushWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
            }
            return;
        }
        //普通牌型
        if (cardType <= 7) {
            switch (cardType) {
                case Constants.single:
                    actionMap.putAll(ActionJudgment.getSingle(actionMap.size(), cardPoint, levelCard, players[playerWithRight]));
                    break;
                case Constants.pair:
                    actionMap.putAll(ActionJudgment.getPair(actionMap.size(), cardPoint, levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getPairWithWild(actionMap.size(), cardPoint, wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.three:
                    actionMap.putAll(ActionJudgment.getThree(actionMap.size(), cardPoint, levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getThreeWithWild(actionMap.size(), cardPoint, wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.threeWithTwo:
                    actionMap.putAll(ActionJudgment.getThreeWithTwo(actionMap.size(), cardPoint, levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getThreeWithTwoWithWild(actionMap.size(), cardPoint, wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.twoThree:
                    actionMap.putAll(ActionJudgment.getTwoThree(actionMap.size(), cardPoint+1, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getTwoThreeWithWild(actionMap.size(), cardPoint + 1, wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.threePairs:
                    actionMap.putAll(ActionJudgment.getThreePair(actionMap.size(), cardPoint+1, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getThreePairWithWild(actionMap.size(), cardPoint + 1, wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.straight:
                    actionMap.putAll(ActionJudgment.getStraight(actionMap.size(), cardPoint+1, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getStraightWithWild(actionMap.size(), cardPoint + 1, wildCardNum, levelCard, players[playerWithRight]));
                    break;
            }
            actionMap.putAll(ActionJudgment.getBomb(actionMap.size(), -1, -1, levelCard, players[playerWithRight]));
            actionMap.putAll(ActionJudgment.getStraightFlush(actionMap.size(), -1, players[playerWithRight]));
            actionMap.putAll(ActionJudgment.getFourKings(actionMap.size(), players[playerWithRight]));
            actionMap.putAll(ActionJudgment.getBombWithWild(actionMap.size(), -1, -1, wildCardNum, levelCard, players[playerWithRight]));
            actionMap.putAll(ActionJudgment.getStraightFlushWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));

        } else {
            switch (cardType) {
                case Constants.straightFlush:
                    actionMap.putAll(ActionJudgment.getStraightFlush(actionMap.size(), cardPoint + 1, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getStraightFlushWithWild(actionMap.size(), cardPoint + 1, wildCardNum, levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getBomb(actionMap.size(), 6, -1, levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getBombWithWild(actionMap.size(), 6, -1, wildCardNum, levelCard, players[playerWithRight]));
                    break;
                case Constants.bomb:
                    actionMap.putAll(ActionJudgment.getBomb(actionMap.size(), bombNum, cardPoint, levelCard, players[playerWithRight]));
                    actionMap.putAll(ActionJudgment.getBombWithWild(actionMap.size(), bombNum, cardPoint, wildCardNum, levelCard, players[playerWithRight]));
                    if (bombNum < 6) {
                        actionMap.putAll(ActionJudgment.getStraightFlush(actionMap.size(), -1, players[playerWithRight]));
                        actionMap.putAll(ActionJudgment.getStraightFlushWithWild(actionMap.size(), -1, wildCardNum, levelCard, players[playerWithRight]));
                    }
                    break;
            }
            actionMap.putAll(ActionJudgment.getFourKings(actionMap.size(), players[playerWithRight]));
        }
    }

    private long readFileAndGetAction(Workbook workbook, String fileName) throws IOException {
        Workbook writebook = new XSSFWorkbook();
        Sheet sheet1 = writebook.createSheet("sheet");


        DataFormatter dataFormatter = new DataFormatter();
        players = new Player[4];
        players[0] = new Player();
        actionMap = new HashMap<Integer, CardInfo>();
        long card1;
        long card2;
        int cardType;
        int cardPoint;
        int bombNum;
        long timeCount = 0;
        Sheet sheet = workbook.getSheetAt(0);
        int numberOfRows = sheet.getPhysicalNumberOfRows();
        //第一行不读
        for (int j = 1; j < numberOfRows; j++) {
//            PrintWriter printWriter = new PrintWriter(fileName.replace("%s%", String.valueOf(j)));

            bombNum = -1;
            Row row = sheet.getRow(j);
            levelCard = Integer.parseInt(dataFormatter.formatCellValue(row.getCell(0)));
            card1 = Long.parseLong(dataFormatter.formatCellValue(row.getCell(1)));
            card2 = Long.parseLong(dataFormatter.formatCellValue(row.getCell(2)));


            cardType = Integer.parseInt(dataFormatter.formatCellValue(row.getCell(3)));
            cardPoint = Integer.parseInt(dataFormatter.formatCellValue(row.getCell(4)));

            if ((card1 | card2) != card1) {
                System.out.println("xxxx");
            }
            transCard(card1, card2);
//            showCards(players[0].getCards());
//            System.out.println(Long.toBinaryString(card1));
//            System.out.println(Long.toHexString(card1));
//            System.out.println(Long.toBinaryString(card2));
//            System.out.println(Long.toHexString(card2));

//            String[] str = new String[6];
//            str[0] = String.valueOf(levelCard);
//            str[1] = String.valueOf(card1);
//            str[2] = String.valueOf(card2);
//            str[3] = String.valueOf(cardType);
//            str[4] = String.valueOf(cardPoint);

            switch (cardType) {
                case 1:
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    break;
                case 2:
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    break;
                case 3:
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    break;
                case 4:
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    break;
                case 5:
                    cardType = Constants.straight;
                    cardPoint--;
                    break;
                case 6:
                    cardType = Constants.threePairs;
                    cardPoint--;
                    break;
                case 7:
                    cardType = Constants.twoThree;
                    cardPoint--;
                    break;
                case 8:
                    cardType = Constants.bomb;
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    bombNum = 4;
                    break;
                case 9:
                    cardType = Constants.bomb;
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    bombNum = 5;
                    break;
                case 10:
                    cardType = Constants.straightFlush;
                    cardPoint--;
                    break;
                case 11:
                    cardType = Constants.bomb;
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    bombNum = 6;
                    break;
                case 12:
                    cardType = Constants.bomb;
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    bombNum = 7;
                    break;
                case 13:
                    cardType = Constants.bomb;
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    bombNum = 8;
                    break;
                case 14:
                    cardType = Constants.bomb;
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    bombNum = 9;
                    break;
                case 15:
                    cardType = Constants.bomb;
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    bombNum = 10;
                    break;
                case 16:
                    cardType = Constants.fourKings;
                    cardPoint = transCardPoint(cardPoint, levelCard);
                    break;
            }
             LocalDateTime timeStart = LocalDateTime.now();
            getAction(cardType, cardPoint, bombNum);
            LocalDateTime timeEnd = LocalDateTime.now();
            timeCount+=Duration.between(timeStart,timeEnd).toNanos();
//            str[5] = String.valueOf(actionMap.size());
//            printWriter.println(String.join(",", str));
            //去重  有问题
//            for(int i=0;i<actionMap.size();++i){
//                CardInfo value = actionMap.get(i);
//                if(actionMap.values().stream().allMatch(cardInfo-> {
//                    return value.getPlayedCards().length == cardInfo.getPlayedCards().length
//                            && isEquals(value.getPlayedCards(), cardInfo.getPlayedCards());
//                })){
//                    actionMap.remove(i);
//                }
//            }

//            for (CardInfo cardInfo : actionMap.values()) {
//                //   showCards(cardInfo.getPlayedCards());
//                str = new String[5];
//                str[0] = String.valueOf(levelCard);
//                long[] cards = new long[2];
//                reverseCard(cards, cardInfo.getPlayedCards(), cardInfo.getCardLoc());
//                long temp = cards[0];
//                cards[0] |= cards[1];
//                cards[1] &= temp;
//                str[1] = String.valueOf(cards[0]);
//                str[2] = String.valueOf(cards[1]);
//                int bombNum2 = 0;
//                if (Constants.bomb == cardInfo.getCardType()) {
//                    bombNum2 = Arrays.stream(cardInfo.getPlayedCards()).map(ActionJudgment::numOfSameSuitCards).sum();
//                }
//                str[3] = String.valueOf(getCardType(cardInfo.getCardType(), bombNum2));
//                str[4] = String.valueOf(getCardPointBack(cardInfo.getCardPoint()[0], levelCard, cardInfo.getCardType()));
//
//                printWriter.println(String.join(",", str));

                //***********输出转化后的数据*******//
//                System.out.println(cardInfo.getCardType()+"   "+cardInfo.getCardPoint()[0]);
//                showCards(cardInfo.getPlayedCards());
//                System.out.println(cardInfo.getCardPoint()[0]);
//                System.out.println(Long.toBinaryString(cards[0]));
//                System.out.println(Long.toHexString(cards[0]));
//                System.out.println(Long.toBinaryString(cards[1]));
//                System.out.println(Long.toHexString(cards[1]));
                //*********************************//
//            }
            actionMap.clear();
//            printWriter.close();
        }
        return timeCount / 1000000;
    }

    boolean isEquals(int[] v1, int[] v2){
        for(int i = 0;i<Math.min(v1.length,v2.length);++i){
            if(v1[i] != v2[i]){
                return false;
            }
        }
        return true;
    }
    private int getCardPointBack(int cardPoint, int levelCard, int cardType) {
        if (cardType == Constants.straightFlush || cardType == Constants.straight || cardType == Constants.threePairs || cardType == Constants.twoThree) {
            if (cardPoint == 12) {
                cardPoint = 0;
            } else {
                ++cardPoint;
            }
        } else {

            if (cardPoint == levelCard) {
                return 12;
            } else if (cardPoint >= levelCard && cardPoint < 13) {
                return cardPoint - 1;
            }
        }
        return cardPoint;
    }

    private int transCardPoint(int cardPoint, int levelCard) {
        if (cardPoint == 12) {
            return levelCard;
        } else if (cardPoint >= levelCard && cardPoint < 13) {
            return cardPoint + 1;
        }
        return cardPoint;
    }

    private int getCardType(int cardType, int bombNum) {
        int result = cardType;
        switch (cardType) {
            case 7:
                result = 5;
                break;
            case 5:
                result = 7;
                break;
            case 9:
                if (bombNum == 4) {
                    result = 8;
                } else if (bombNum == 5) {
                    result = 9;
                } else if (bombNum == 6) {
                    result = 11;
                } else if (bombNum == 7) {
                    result = 12;
                } else if (bombNum == 8) {
                    result = 13;
                } else if (bombNum == 9) {
                    result = 14;
                } else if (bombNum == 10) {
                    result = 15;
                }
                break;
            case 10:
                result = 16;
                break;
            case 8:
                result = 10;
                break;
        }
        return result;
    }


    public void transCard(long card1, long card2) {
        players[0].setCards(new int[15]);

        players[0].getCards()[12] |= ((int) (card1 & (long) 0x2) >> 1);
        players[0].getCards()[12] |= ((int) (card1 & (long) 0x1) << 1);
        players[0].getCards()[12] |= ((int) (card1 & (long) 0x4));
        players[0].getCards()[12] |= ((int) (card1 & (long) 0x8));
        players[0].getCards()[12] |= ((int) (card2 & (long) 0x2) << 3);
        players[0].getCards()[12] |= ((int) (card2 & (long) 0x1) << 5);
        players[0].getCards()[12] |= ((int) (card2 & (long) 0x4) << 4);
        players[0].getCards()[12] |= ((int) (card2 & (long) 0x8) << 4);

        for (int i = 0; i < 12; ++i) {
            players[0].getCards()[i] |= ((int) ((card1 >> (4 * (i + 1))) & (long) 0x2) >> 1);
            players[0].getCards()[i] |= ((int) ((card1 >> (4 * (i + 1))) & (long) 0x1) << 1);
            players[0].getCards()[i] |= ((int) ((card1 >> (4 * (i + 1))) & (long) 0x4));
            players[0].getCards()[i] |= ((int) ((card1 >> (4 * (i + 1))) & (long) 0x8));
            players[0].getCards()[i] |= ((int) ((card2 >> (4 * (i + 1))) & (long) 0x2) << 3);
            players[0].getCards()[i] |= ((int) ((card2 >> (4 * (i + 1))) & (long) 0x1) << 5);
            players[0].getCards()[i] |= ((int) ((card2 >> (4 * (i + 1))) & (long) 0x4) << 4);
            players[0].getCards()[i] |= ((int) ((card2 >> (4 * (i + 1))) & (long) 0x8) << 4);
        }
        players[0].getCards()[13] |= ((int) (card1 >> 52) & 0x1);
        players[0].getCards()[13] |= ((int) (((card2 >> 52) & 0x1) << 4));

        players[0].getCards()[14] |= ((int) (card1 >> 53) & 0x1);
        players[0].getCards()[14] |= ((int) (((card2 >> 53) & 0x1) << 4));
    }

    public void reverseCard(long[] cards, int[] playedCards, int cardLoc) {
        if (playedCards.length + cardLoc >= 13 && cardLoc <= 12) {
            cards[0] |= ((playedCards[12 - cardLoc] & 0x2) >> 1);
            cards[0] |= ((playedCards[12 - cardLoc] & 0x1) << 1);
            cards[0] |= ((playedCards[12 - cardLoc] & 0x4));
            cards[0] |= ((playedCards[12 - cardLoc] & 0x8));

            cards[1] |= (((playedCards[12 - cardLoc] >> 4) & 0x2) >> 1);
            cards[1] |= (((playedCards[12 - cardLoc] >> 4) & 0x1) << 1);
            cards[1] |= (((playedCards[12 - cardLoc] >> 4) & 0x4));
            cards[1] |= (((playedCards[12 - cardLoc] >> 4) & 0x8));

//            cards[1] |= ((playedCards[12 - cardLoc] & 0x20) >> 5);
//            cards[1] |= ((playedCards[12 - cardLoc] & 0x10) >> 3);
//            cards[1] |= ((playedCards[12 - cardLoc] & 0x40) >> 4);
//            cards[1] |= ((playedCards[12 - cardLoc] & 0x80) >> 4);
        }
        for (int i = 0; i < playedCards.length; ++i) {
            if (cardLoc + i <= 11) {
                cards[0] |= ((long) (playedCards[i] & 0x2) << (4 * (cardLoc + i + 1) - 1));
                cards[0] |= ((long) (playedCards[i] & 0x1) << (4 * (cardLoc + i + 1) + 1));
                cards[0] |= ((long) (playedCards[i] & 0x4) << (4 * (cardLoc + i + 1)));
                cards[0] |= ((long) (playedCards[i] & 0x8) << (4 * (cardLoc + i + 1)));


                cards[1] |= ((long) ((playedCards[i] >> 4) & 0x2) << (4 * (cardLoc + i + 1) - 1));
                cards[1] |= ((long) ((playedCards[i] >> 4) & 0x1) << (4 * (cardLoc + i + 1) + 1));
                cards[1] |= ((long) ((playedCards[i] >> 4) & 0x4) << (4 * (cardLoc + i + 1)));
                cards[1] |= ((long) ((playedCards[i] >> 4) & 0x8) << (4 * (cardLoc + i + 1)));

//                if (i == 0) {
//                    cards[1] |= ((playedCards[i] & 0x20) >> 1);
//                } else {
//                    cards[1] |= ((long) (playedCards[i] & 0x20) << (4 * (cardLoc + i) - 5));
//                }
//                cards[1] |= ((long) (playedCards[i] & 0x10) << (4 * (cardLoc + i) - 3));
//                cards[1] |= ((long) (playedCards[i] & 0x40) << (4 * (cardLoc + i)));
//                cards[1] |= ((long) (playedCards[i] & 0x80) << (4 * (cardLoc + i)));
            }
        }
        if (playedCards.length + cardLoc >= 14 && cardLoc <= 13) {
            cards[0] |= ((long) (playedCards[13 - cardLoc] & 0x1) << 52);
            cards[1] |= ((long) (playedCards[13 - cardLoc] & 0x10) << 48);
        }
        if (playedCards.length + cardLoc >= 15 && cardLoc <= 14) {
            cards[0] |= ((long) (playedCards[14 - cardLoc] & 0x1) << 53);
            cards[1] |= ((long) (playedCards[14 - cardLoc] & 0x10) << 49);
        }
    }

    public void readFile() throws FileNotFoundException {
        String fileName = "D:\\ideaproject\\data2\\csvData\\三张\\%s%.csv";
        for (int i = 1; i < 100; ++i) {
            Scanner scanner = new Scanner(new File(fileName.replace("%s%", String.valueOf(i))));
            while (scanner.hasNextLine()) {
                String line = scanner.nextLine();
                String[] columns = line.split(",");
                // 处理每一列...
                System.out.println(Long.toBinaryString(Long.parseLong(columns[1])) + "   " + Long.toBinaryString(Long.parseLong(columns[2])));
            }
            scanner.close();
        }
    }


    public void handleCards() throws IOException {
        File file = new File("D:\\ideaproject\\data\\主动发牌.xlsx");
        FileInputStream fis = new FileInputStream(file);
        Workbook workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\主动发牌.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\单张.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\单张.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\对子.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\对子.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\三张.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\三张.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\三带二.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\三带二.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\顺子.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\顺子.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\三连对.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\三连对.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\钢板.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\钢板.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\四炸.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\四炸.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\五炸.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\五炸.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\同花.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\同花.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\六炸.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\六炸.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\七炸.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\七炸.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\八炸.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\八炸.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\九炸.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\九炸.csv");
        fis.close();

        fis = new FileInputStream(new File("D:\\ideaproject\\data\\十炸.xlsx"));
        workbook = new XSSFWorkbook(fis);
        handleCards(workbook, "D:\\ideaproject\\data\\csvData\\十炸.csv");
        fis.close();
    }

    private void handleCards(Workbook inFile, String outFile) throws IOException {
        Sheet sheet = inFile.getSheetAt(0);
        Workbook workbook = new XSSFWorkbook();
        Sheet outSheet = workbook.createSheet("sheet");
        DataFormatter dataFormatter = new DataFormatter();
        int numOfRow = sheet.getPhysicalNumberOfRows();
        for (int i = 1; i < numOfRow; ++i) {
            Row inRow = sheet.getRow(i);
            Row outRow = outSheet.createRow(i);
            outRow.createCell(0).setCellValue(dataFormatter.formatCellValue(inRow.getCell(0)));
            outRow.createCell(1).setCellValue(formatCard1(dataFormatter.formatCellValue(inRow.getCell(1)), dataFormatter.formatCellValue(inRow.getCell(2))));
            outRow.createCell(2).setCellValue(formatCard2(dataFormatter.formatCellValue(inRow.getCell(1)), dataFormatter.formatCellValue(inRow.getCell(2))));
            outRow.createCell(3).setCellValue(dataFormatter.formatCellValue(inRow.getCell(3)));
            outRow.createCell(4).setCellValue(dataFormatter.formatCellValue(inRow.getCell(4)));
        }
        workbook.write(new FileOutputStream(outFile));
    }

    private String formatCard1(String card1, String card2) {
        Long c1 = Long.parseLong(card1);
        Long c2 = Long.parseLong(card2);
        return String.valueOf(c1 | c2);
    }

    private String formatCard2(String card1, String card2) {
        Long c1 = Long.parseLong(card1);
        Long c2 = Long.parseLong(card2);
        return String.valueOf(c1 & c2);
    }

    //********************************************//

    //比较两者结果，挑出互相不包含的牌并保存
    public void compareResult() throws IOException {
        String fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\单张\\单张\\%s%.csv";
        String fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\单张\\%s%.csv";
        String outFileName = "D:\\ideaproject\\data2\\对比结果\\单张\\%s%.csv";

//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }

        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\主动发牌\\主动发牌\\%s%.csv";
        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\主动发牌\\%s%.csv";
        outFileName = "D:\\ideaproject\\data2\\对比结果\\主动发牌\\%s%.csv";

        for (int i = 1; i < 60001; i++) {
            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
            System.out.println(i);
        }
////
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\对子\\对子\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\对子\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\对子\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\三张\\三张\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\三张\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\三张\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\钢板\\钢板\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\钢板\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\钢板\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\三带二\\三带二\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\三带二\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\三带二\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//            System.out.println(i);
//        }
//
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\三连对\\三连对\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\三连对\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\三连对\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\顺子\\顺子\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\顺子\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\顺子\\%s%.csv";
//
//        for (int i = 1; i < 5000; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\四炸\\四炸\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\四炸\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\四炸\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\五炸\\五炸\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\五炸\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\五炸\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\同花\\同花\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\同花\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\同花\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\六炸\\六炸\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\六炸\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\六炸\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\七炸\\七炸\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\七炸\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\七炸\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\八炸\\八炸\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\八炸\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\八炸\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\九炸\\九炸\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\九炸\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\九炸\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
//        fileName1 = "D:\\ideaproject\\data2\\setOfActionOfNewData\\setOfActionOfNewData\\十炸\\十炸\\%s%.csv";
//        fileName2 = "D:\\ideaproject\\data2\\掼蛋结果\\十炸\\%s%.csv";
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\十炸\\%s%.csv";
//
//        for (int i = 1; i < 60001; i++) {
//            compareTwoFile(fileName1.replaceAll("%s%", String.valueOf(i)), fileName2.replaceAll("%s%", String.valueOf(i)), outFileName.replaceAll("%s%", String.valueOf(i)));
//        }
    }

    public void compareTwoFile(String fileName1, String fileName2, String outFileName) throws IOException {
        BufferedReader fileReader1 = new BufferedReader(new FileReader(fileName1));
        BufferedReader fileReader2 = new BufferedReader(new FileReader(fileName2));

        PrintWriter printWriter = new PrintWriter(outFileName);

        String line;
        String firstLine;
        String split = ",";
        String[] values;
        List<String> result1 = new ArrayList<>();
        List<String> result2 = new ArrayList<>();
        List<String> diff1 = new ArrayList<>();
        List<String> diff2 = new ArrayList<>();
        //写第一行
        firstLine = fileReader1.readLine();
        firstLine = fileReader2.readLine();
        printWriter.println(firstLine);
        while ((line = fileReader1.readLine()) != null) {
            values = line.split(split);
            result1.add(values[1] + "," + values[2] + "," + values[3] + "," + values[4]);
        }
        while ((line = fileReader2.readLine()) != null) {
            values = line.split(split);
            result2.add(values[1] + "," + values[2] + "," + values[3] + "," + values[4]);
        }
        for (String r1 : result1) {
            boolean hasSame = false;
            for (String r2 : result2) {
                if (r1.equals(r2)) {
                    hasSame = true;
                    break;
                }
            }
            if (!hasSame) {
                diff1.add(r1);
            }
        }

        for (String r1 : result2) {
            boolean hasSame = false;
            for (String r2 : result1) {
                if (r1.equals(r2)) {
                    hasSame = true;
                    break;
                }
            }
            if (!hasSame) {
                diff2.add(r1);
            }
        }

        for (String diff : diff1) {
            printWriter.println("1," + diff);
        }
        for (String diff : diff2) {
            printWriter.println("2," + diff);
        }

        printWriter.close();
        fileReader1.close();
        fileReader2.close();
    }

    //将比较结果分类输出到控制台，将不同行保存
    public void analyzeResult() throws IOException {

        String outFileName;
        String writeFileName;

        outFileName = "D:\\ideaproject\\data2\\对比结果\\主动发牌\\%s%.csv";
        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\主动发牌\\diff.csv";
        analyzeFile(writeFileName, outFileName);
//
        outFileName = "D:\\ideaproject\\data2\\对比结果\\单张\\%s%.csv";
        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\单张\\diff.csv";
        analyzeFile(writeFileName, outFileName);
//
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\对子\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\对子\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
//
//
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\三张\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\三张\\diff.csv";
//        analyzeFile(writeFileName, outFileName);

//        outFileName = "D:\\ideaproject\\data2\\对比结果\\三带二\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\三带二\\diff.csv";
//        analyzeFile(writeFileName, outFileName);

//        outFileName = "D:\\ideaproject\\data2\\对比结果\\钢板\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\钢板\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
//////
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\顺子\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\顺子\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
//
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\三连对\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\三连对\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
////
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\四炸\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\四炸\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
////
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\五炸\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\五炸\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
////
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\六炸\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\六炸\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
//
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\七炸\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\七炸\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
//
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\八炸\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\八炸\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
//
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\九炸\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\九炸\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
//
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\十炸\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\十炸\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
//
//        outFileName = "D:\\ideaproject\\data2\\对比结果\\同花\\%s%.csv";
//        writeFileName = "D:\\ideaproject\\data2\\不包含牌\\同花\\diff.csv";
//        analyzeFile(writeFileName, outFileName);
    }

    public void analyzeFile(String writeFileName, String outFileName) throws IOException {
        PrintWriter printWriter = new PrintWriter(new FileWriter(writeFileName));

        for (int i = 0; i < 18800; ++i) {
            BufferedReader reader = new BufferedReader(new FileReader(outFileName.replaceAll("%s%", String.valueOf(i + 1))));
            Long card1;
            Long card2;
            Integer levelCard;
            Long playedCard1;
            Long playedCard2;

            Map<String, List<String>> excludeCard = new HashMap<>();
            Map<String, List<String>> includeCard1 = new HashMap<>();
            Map<String, List<String>> includeCard2 = new HashMap<>();

            String line;
            String[] splitLine;
            String firstLine = reader.readLine();
            if(firstLine == null){
                continue;
            }else {
                splitLine = firstLine.split(",");
            }
            card1 = Long.parseLong(splitLine[1]);
            card2 = Long.parseLong(splitLine[2]);
            levelCard = Integer.parseInt(splitLine[0]);

            while ((line = reader.readLine()) != null) {
                splitLine = line.split(",");
                if (splitLine[1].equals("0") && splitLine[2].equals("0") && splitLine[3].equals("0") && splitLine[4].equals("0")) {
                    continue;
                }
                playedCard1 = Long.parseLong(splitLine[1]);
                playedCard2 = Long.parseLong(splitLine[2]);

                //手牌不包含该出牌
                if (((card1 | playedCard1) != card1) || (card2 | playedCard2) != card2) {
                    excludeCard.computeIfAbsent(splitLine[3] + "," + splitLine[4], k -> new ArrayList<>()).add(line);
                } else {
                    // if(Integer.parseInt(splitLine[3]) < 8 || Integer.parseInt(splitLine[3]) >15) {
                    if (splitLine[0].equals("1")) {
                        includeCard1.computeIfAbsent(splitLine[3] + "," + splitLine[4], k -> new ArrayList<>()).add(line);
                    }
                    if (splitLine[0].equals("2")) {
                        includeCard2.computeIfAbsent(splitLine[3] + "," + splitLine[4], k -> new ArrayList<>()).add(line);
                    }
                    //   }
                }
            }

//            excludeCard.values().stream().flatMap(List::stream).forEach(t -> {
//                String[] split = t.split(",");
//                System.out.println("不包含牌：  ");
//                System.out.println(split[0] + "  " + split[3] + "  " + split[4]);
//                System.out.println(":  " + Long.toBinaryString(Long.parseLong(split[1])) + "   " + Long.toBinaryString(Long.parseLong(split[2])));
//                System.out.println(":  " + Long.toHexString(Long.parseLong(split[1])) + "   " + Long.toHexString(Long.parseLong(split[2])));
//
//            });
            if (!(excludeCard.isEmpty() && includeCard1.isEmpty() && includeCard2.isEmpty())) {
                printWriter.println(i + 1);
            }

            int temp = i;

            //移除出牌相同但两card选择不同的牌
//            includeCard1.forEach((k, v1) -> {
//                List<String> v2 = includeCard2.getOrDefault(k,new ArrayList<>());
//                List<String> remove1 = new ArrayList<>();
//                List<String> remove2 = new ArrayList<>();
//                for (String line1 : v1) {
//                    Long c1 = Long.parseLong(line1.split(",")[1]) + Long.parseLong(line1.split(",")[2]);
//                    for (String line2 : v2) {
//                        Long c2 = Long.parseLong(line2.split(",")[1]) + Long.parseLong(line2.split(",")[2]);
//                        if (c1.equals(c2)) {
//                            remove1.add(line1);
//                            remove2.add(line2);
//                        }
//                    }
//                }
//                for (String r1 : remove1) {
//                    v1.remove(r1);
//                }
//                for (String r2 : remove2) {
//                    v2.remove(r2);
//                }
//            });


            includeCard1.forEach((k, v) -> {
                if (!v.isEmpty()) {
                    System.out.println(temp + 1);
                    System.out.println(levelCard + "   " + Long.toBinaryString(card1) + "   " + Long.toBinaryString(card2));
                    System.out.println(Long.toHexString(card1) + "   " + Long.toHexString(card2));
                    System.out.println(k);
                    int j = 0;
                    String[] split;
                    System.out.println("player1:");
                    for (String l : v) {
                        split = l.split(",");
                        System.out.println(j++ + ":  " + Long.toBinaryString(Long.parseLong(split[1])) + "   " + Long.toBinaryString(Long.parseLong(split[2])));
                        System.out.println(" :  " + Long.toHexString(Long.parseLong(split[1])) + "   " + Long.toHexString(Long.parseLong(split[2])));
                    }
                    System.out.println();
                    j = 0;
                    System.out.println("player2:");
                    for (String l : includeCard2.getOrDefault(k, new ArrayList<>())) {
                        split = l.split(",");
                        System.out.println(j++ + ":  " + Long.toBinaryString(Long.parseLong(split[1])) + "   " + Long.toBinaryString(Long.parseLong(split[2])));
                        System.out.println(" :  " + Long.toHexString(Long.parseLong(split[1])) + "   " + Long.toHexString(Long.parseLong(split[2])));
                    }

                    System.out.println("*******************************************");
                    includeCard2.remove(k);
                }
            });

            includeCard2.forEach((k, v) -> {
                if(!v.isEmpty()) {
                    System.out.println(temp + 1);
                    System.out.println(levelCard + "   " + Long.toBinaryString(card1) + "   " + Long.toBinaryString(card2));
                    System.out.println(Long.toHexString(card1) + "   " + Long.toHexString(card2));
                    System.out.println(k);
                    int j = 0;
                    String[] split;
                    System.out.println("player2:");
                    for (String l : v) {
                        split = l.split(",");
                        System.out.println(j++ + ":  " + Long.toBinaryString(Long.parseLong(split[1])) + "   " + Long.toBinaryString(Long.parseLong(split[2])));
                        System.out.println(" :  " + Long.toHexString(Long.parseLong(split[1])) + "   " + Long.toHexString(Long.parseLong(split[2])));
                    }
                    System.out.println("*******************************************");
                }
            });
        }

        printWriter.close();
    }

}
