import DataOfWildCard.DataOfWildCard;

import java.util.ArrayList;
import java.util.Iterator;

/**
 * author:gongyu
 * description:only one
 */
public class ArrayDataofGuanDan {
    public CardStorage cs;  // 存储手牌
    public FourDimIndex fdi;
    public DataOfWildCard DoWc;  //该变量包含了所有的动作集合
    public ArrayList<int[]> setOfActionIndex;//包含了被筛选过后的动作集合的索引   本身动作也是两个long整型
    public ArrayList<int[]> setOfPreviousCards;//基于上一个玩家出的牌，setOfActionIndex进行筛选得到的可选动作索引
    public ArrayDataofGuanDan(){
        cs = new CardStorage();
        fdi = new FourDimIndex();
        DoWc = new DataOfWildCard();
        setOfActionIndex = new ArrayList<>();
    }

    public void clearSetOfActionIndex(){
        setOfActionIndex.clear();
    }

    public void firstOptionalAction(int X, int numberOfHandCards, int [] numberOfEveryHandCards, int numberOfLaiZi){
        firsttakeAction(X, numberOfHandCards, numberOfEveryHandCards, numberOfLaiZi);
        System.out.println("第一个出牌的人可选动作集合个数："+setOfActionIndex.size());
    }

    public void firsttakeAction(int XIndex, int numberOfHandCards, int [] numberOfEveryHandCards, int numberOfLaiZi){
        int index =0;
        for (int j = 1; j < fdi.rankName.length; j++) {
            String rankName = fdi.rankName[j];
            for (int m = 0; m < fdi.typeName[j].length; m++) {
                String typeName = fdi.typeName[j][m];
                for (int n = 0; n < fdi.rankTypeName[j][m].length; n++) {
//                    String rankTypeName = fdi.rankTypeName[j][m][n];
                    switch (rankName) {
                        case "1" -> {
                            switch (typeName) {
                                case "1" -> {  //单张
                                    if ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 0)||numberOfHandCards == 0 ) {
                                        continue;
                                    }
                                }
                                case "2" -> {  //对子
                                    if ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 0 ||
                                            (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 1 && numberOfLaiZi == 0))||numberOfHandCards <= 1) {
                                        continue;
                                    }
                                }
                                case "3" -> {  //三张
                                    if ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 0 ||
                                            (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 1 && numberOfLaiZi < 2) ||
                                            (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 2 && numberOfLaiZi == 0))||numberOfHandCards <= 2) {
                                        continue;
                                    }
                                }
                                case "4" -> { //三带二  没对子或者没三张  直接continue
                                    if (((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 0 ||
                                            (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 1 && numberOfLaiZi == 0)) ||
                                            (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 0 ||
                                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 1 && numberOfLaiZi < 2) ||
                                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 2 && numberOfLaiZi == 0)))||numberOfHandCards <= 4) {
                                        continue;
                                    }
                                }
                                case "5" -> { // 顺子
                                    if (
                                            (numberOfLaiZi == 0 &&
                                                    (
                                                            (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1)
                                                    )
                                            )
                                                    ||(numberOfLaiZi == 1 &&
                                                    (
                                                            ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))

                                                    )
                                            )
                                                    ||(numberOfLaiZi == 2 &&
                                                    (
                                                            ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1))
                                                    )

                                            )||(numberOfHandCards <= 4)
                                    ) {
                                        continue;
                                    }
                                }
                                case "6" -> {  //钢板
                                    if (
                                                    (numberOfLaiZi == 0 &&
                                                    (
                                                            (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 3)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n])%13] < 3)
                                                    )
                                            )
                                                    ||(numberOfLaiZi == 1 &&
                                                    (
                                                            ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 2)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n])%13] < 3))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 3)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n])%13] < 2))

                                                    )
                                            )
                                                    ||(numberOfLaiZi == 2 &&
                                                    (
                                                            ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n])%13] < 3))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 2)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n])%13] < 2))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 3)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n])%13] < 1))
                                                    )

                                            )||(numberOfHandCards <= 5)
                                    ) {
                                        continue;
                                    }
                                }
                                case "7" -> {//三连对
                                    if (
                                                    (numberOfLaiZi == 0 &&
                                                    (
                                                            (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 2)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 2)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+1)%13] < 2)
                                                    )
                                            )
                                                    ||(numberOfLaiZi == 1 &&
                                                    (
                                                            ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 2)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+1)%13] < 2))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 2)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+1)%13] < 2))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 2)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 2)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+1)%13] < 1))

                                                    )
                                            )
                                                    ||(numberOfLaiZi == 2 &&
                                                    (
                                                            ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 2)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+1)%13] < 2))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 2)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+1)%13] < 2))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 2)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 2))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+1)%13] < 2))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 2)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+1)%13] < 1))
                                                                    &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 2)
                                                                    || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                                    || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+1)%13] < 1))
                                                    )

                                            )||(numberOfHandCards <= 5)
                                    ) {
                                        continue;
                                    }
                                }
                                //三连对
                            }
                        }
                        case "2" -> { //四炸
                            if((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] <= 1) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 2 && numberOfLaiZi <= 1) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 3 && numberOfLaiZi == 0)||
                                    (numberOfHandCards <= 3)){
                                continue;
                            }
                        }
                        case "3" -> {  //五炸
                            if((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] <= 2) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 3 && numberOfLaiZi <= 1) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 4 && numberOfLaiZi == 0)||
                                    (numberOfHandCards <= 4)){
                                continue;
                            }
                        }
                        case "4" -> { // 同花顺
                            if (
                                    (numberOfLaiZi == 0 &&
                                            (
                                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1)
                                            )
                                    )
                                            ||(numberOfLaiZi == 1 &&
                                            (
                                                    ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))

                                            )
                                    )
                                            ||(numberOfLaiZi == 2 &&
                                            (
                                                    ((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[(fdi.fourDimIndex[XIndex][j][m][n]+3)%13] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+2] < 1))
                                                            &&((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]] < 1)
                                                            || (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]+1] < 1))
                                            )

                                    )||(numberOfHandCards <= 4)
                            ) {
                                continue;
                            }
                        }
                        case "5" -> { // 六炸
                            if((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] <= 3) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 4 && numberOfLaiZi <= 1) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 5 && numberOfLaiZi == 0)||
                                    (numberOfHandCards <= 5) ){
                                continue;
                            }
                        }
                        case "6" -> {  //七炸
                            if((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] <= 4) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 5 && numberOfLaiZi <= 1) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 6 && numberOfLaiZi == 0)||
                                    (numberOfHandCards <= 6) ){
                                continue;
                            }
                        }
                        case "7" -> {  //八炸
                            if((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] <= 5) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 6 && numberOfLaiZi <= 1) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 7 && numberOfLaiZi == 0)||
                                    (numberOfHandCards <= 7)){
                                continue;
                            }
                        }
                        case "8" -> {  //九炸
//                            System.out.println(X+" "+rankName+" "+typeName+" "+rankTypeName);
                            if((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] <= 6) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 7 && numberOfLaiZi <= 1) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 8 && numberOfLaiZi == 0)||
                                    (numberOfHandCards <= 8)){
                                continue;
                            }
                        }
                        case "9" -> {  //十炸
                            if((numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] <= 7) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 8 && numberOfLaiZi <= 1) ||
                                    (numberOfEveryHandCards[fdi.fourDimIndex[XIndex][j][m][n]-1] == 9 && numberOfLaiZi == 0)||
                                    (numberOfHandCards <= 9)){
                                continue;
                            }
                        }
                        default -> {  //王炸
//                            System.out.println("gg "+numberOfEveryHandCards[14]);
//                            System.out.println("gg "+numberOfEveryHandCards[13]);
                            if(numberOfEveryHandCards[13] < 2 || numberOfEveryHandCards[14] < 2 || numberOfHandCards <= 3){
                                continue;
                            }
                        }
                    }
                    for (int k = 0; k < fdi.setName[j][m][n].length; k++) {
                        if (numberOfLaiZi == 0) {
                            // 只遍历dataSetName为"0"的情况
                            if (!fdi.setName[j][m][n][k].equals("0")) {
                                continue;
                            }
                        } else if (numberOfLaiZi == 1) {
                            // 只遍历dataSetName为"0"和"1"的情况
                            if (!fdi.setName[j][m][n][k].equals("0") && !fdi.setName[j][m][n][k].equals("1")) {
                                continue;
                            }
                        }
                        for (int p = 0; p<DoWc.DoWC[XIndex][j][m][n][k].length; p++) {
                            long cards1_played = DoWc.DoWC[XIndex][j][m][n][k][p][0];
                            long cards2_played = DoWc.DoWC[XIndex][j][m][n][k][p][1];

                            // 判断是否满足条件
                            if ((cards1_played | cs.getCards1()) == cs.getCards1() && (cards2_played | cs.getCards2()) == cs.getCards2()) {
//                                        System.out.println("wildcard:"+X+" "+"rankname:"+fdi.rankName[j]+" "+"typename:"+fdi.typeName[j][m]+" "+"ranktypename:"+fdi.rankTypeName[j][m][n]);
//                                        System.out.println(str);
//                                        System.out.println(fdi.rankName[j]+" "+fdi.typeName[j][m]+" "+fdi.rankTypeName[j][m][n]+" "+cards1_played+" "+cards2_played);
//                                        index++;
                                int[] row = {XIndex, j, m, n, k, p};
//                                System.out.println("gagag "+XIndex+' '+j+' '+m+' '+n+' '+k+' '+p);
                                // X:当前打的级数
                                //j：rankName对应的索引  当前牌的等级，
                                //m：typeName对应的索引  rankName中的等级1有7个  等级2中只有1个
                                //n:rankTypeName对应的索引
                                //k:setName对应的索引
                                //p:set中的元素对应的索引
                                setOfActionIndex.add(row);
//                                index ++;
                            }
                        }
                    }
                }
            }
        }
//        return index;
    }

    public void nofirsttakeAction(int XIndex, int rankNameIndex, int typeNameIndex, int rankTypeNameIndex){
        setOfPreviousCards = new ArrayList<>();
        for(int[] row:setOfActionIndex){
//            String str = DoWc.DoWC[row[0]][row[1]][row[2]][row[3]][row[4]][row[5]];
            if(rankNameIndex == row[1] && typeNameIndex == row[2] && row[3] > rankTypeNameIndex){
//                setOfPreviousCards.add(row);


            }else if(row[1]>rankNameIndex){
//                setOfPreviousCards.add(row);
            }
        }
        int [] row = {XIndex, 0, 0, 0, 0, 0};
//        setOfPreviousCards.add(row);
//        System.out.println(setOfPreviousCards.size());
    }


//    public int nofirsttakeAction(int XIndex, int rankNameIndex, int typeNameIndex, int rankTypeNameIndex){
//        ArrayList<int[]> setOfPreviousCards = new ArrayList<>();
//        int index =0;
//        for(int[] row:setOfActionIndex){
////            String str = DoWc.DoWC[row[0]][row[1]][row[2]][row[3]][row[4]][row[5]];
//            if(rankNameIndex == row[1] && typeNameIndex == row[2] && rankTypeNameIndex > row[3]){
////                setOfPreviousCards.add(row);
//                index++;
//            }else if(rankNameIndex > row[1]){
////                setOfPreviousCards.add(row);
//                index++;
//            }
//        }
//        int [] row = {XIndex, 0, 0, 0, 0, 0};
////        setOfPreviousCards.add(row);
//        index++;
//        return index;
//    }


    public void filterSetOfActionIndex(){
        Iterator<int[]> iterator = setOfActionIndex.iterator();
        while (iterator.hasNext()) {
            int[] row = iterator.next();
            long cards1_played = DoWc.DoWC[row[0]][row[1]][row[2]][row[3]][row[4]][row[5]][0];
            long cards2_played = DoWc.DoWC[row[0]][row[1]][row[2]][row[3]][row[4]][row[5]][1];

            // 判断是否满足条件
            if (!((cards1_played | cs.getCards1()) == cs.getCards1() && (cards2_played | cs.getCards2()) == cs.getCards2()) || (cards1_played==0 && cards2_played==0)) {
                iterator.remove();
            }
        }
    }

    public static void main(String[] args) {
        ArrayDataofGuanDan adogd = new ArrayDataofGuanDan();
//        adogd.cs.setCard(1);
//        adogd.cs.setCard(2);
////        adogd.cs.setCard(5);
//        adogd.cs.setCard(7);
//        adogd.cs.setCard(10);
//        adogd.cs.setCard(13);
//        adogd.cs.setCard(15);
//        adogd.cs.setCard(16);
//        adogd.cs.setCard(17);
//        adogd.cs.setCard(21);
//        adogd.cs.setCard(23);
//        adogd.cs.setCard(25);
//        adogd.cs.setCard(77);
//        adogd.cs.setCard(27);
//        adogd.cs.setCard(30);
//        adogd.cs.setCard(33);
//        adogd.cs.setCard(34);
////        adogd.cs.setCard(35);
//        adogd.cs.setCard(37);
//        adogd.cs.setCard(40);
//        adogd.cs.setCard(41);
//        adogd.cs.setCard(42);
////        adogd.cs.setCard(45);
//        adogd.cs.setCard(46);
//        adogd.cs.setCard(50);
//        adogd.cs.setCard(52);
//        adogd.cs.setCard(53);

//        adogd.cs.setCardDirectly(5205246233363100L, 1065472L);
//        adogd.cs.setCardDirectly(10453714454955500L, 281479271710720L);
        adogd.cs.setCardDirectly(13510798882111504L, 13510798882111504L);

        String binaryString1;
        String binaryString2;
        binaryString1 = Long.toBinaryString(adogd.cs.getCards1());
        binaryString2 = Long.toBinaryString(adogd.cs.getCards2());
        System.out.println("整数 " + adogd.cs.getCards1() + " 的二进制表示为：" + binaryString1);
        System.out.println("整数 " + adogd.cs.getCards2() + " 的二进制表示为：" + binaryString2);

        System.out.println("======================================================");

        long all_duration = 0L;
        int XIndex = 4;  //实际上当前打2
        int [] numberOfEveryHandCards = adogd.cs.getNumberOfEveryHandCards();
        for(int i : numberOfEveryHandCards){
            System.out.print(i+" ");
        }
        System.out.println();
        int numberOfHandCards = adogd.cs.getNumberOfHandCards();
        int numberOfLaiZi = adogd.cs.getNumberOfLaiZi(XIndex);
        System.out.println(numberOfHandCards + " " + numberOfLaiZi);
        System.out.println(numberOfLaiZi);
        for(int i=0;i<1;i++){
            long startTime;
            long endTime;
            long duration;
            //例子：第一个出牌的人可以出的牌的集合，假设当前打2
//            System.out.println("假设当前打"+X+"，并且是第一个人出牌");
            startTime = System.currentTimeMillis();
            adogd.firstOptionalAction(XIndex, numberOfHandCards, numberOfEveryHandCards, numberOfLaiZi);

            endTime = System.currentTimeMillis();
            duration = endTime - startTime;
            all_duration += duration;
        }

        for(int[] row:adogd.setOfActionIndex){
            long cards1_played = adogd.DoWc.DoWC[row[0]][row[1]][row[2]][row[3]][row[4]][row[5]][0];
            long cards2_played = adogd.DoWc.DoWC[row[0]][row[1]][row[2]][row[3]][row[4]][row[5]][1];
            System.out.println(cards1_played +" "+cards2_played);
            String binaryString3;
            String binaryString4;
            binaryString3 = Long.toBinaryString(cards1_played);
            binaryString4 = Long.toBinaryString(cards2_played);
            System.out.println(binaryString3 + " "+binaryString4);

        }

        System.out.println("第一个出牌的人可选动作集合收集——执行100次的平均时间：" + all_duration/100.0 + " 毫秒");

        System.out.println("======================================================");

//        ArrayList<int[]> setOfPreviousCards = adogd.nofirsttakeAction(1, 8,0,2);




    }
}
