package ExternalControl;

import Constants.Constants;
import GameControl.ActionJudgment;
import GameControl.CardInfo;
import GameControl.Player;

import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.stream.IntStream;

public class AIGame {
    public static Integer selectAction(Map<Integer,CardInfo> actionMap, Player[] players,int levelCard){
       System.out.println("player **2**3**4**5**6**7**8**9**十**J**Q**K**A**-**-**");
       for(Player player:players){
           System.out.print("   "+player.getPlayerNum()+"     ");
           for(int i = 0;i< 13;++i){
               System.out.print(ActionJudgment.numOfSameSuitCards(player.getCards()[i])+"  ");
           }
           System.out.print(ActionJudgment.numOfSameSuitCards(player.getCards()[13]&0x11)+"  ");
           System.out.println(ActionJudgment.numOfSameSuitCards(player.getCards()[13]&0x22));
       }

       for(Map.Entry<Integer,CardInfo> entry:actionMap.entrySet()){
           System.out.print(entry.getKey()+"------");
                switch (entry.getValue().getCardType()){
                    case Constants.single:
                        System.out.print("单张----");
                        System.out.println(cardPosToCard(entry.getValue().getCardPoint()[0]));
                        break;
                    case Constants.pair:
                        System.out.print("对子----");
                        System.out.println(cardPosToCard(entry.getValue().getCardPoint()[0]));
                        break;
                    case Constants.three:
                        System.out.print("三张----");
                        System.out.println(cardPosToCard(entry.getValue().getCardPoint()[0]));
                        break;
                    case Constants.threeWithTwo:
                        System.out.print("三带二----");
                        System.out.println(cardPosToCard(entry.getValue().getCardPoint()[0])+"  "+cardPosToCard(entry.getValue().getCardPoint()[1]));
                        break;
                    case Constants.twoThree:
                        System.out.print("钢板----");
                        System.out.println(cardPosToCard(entry.getValue().getCardPoint()[0]));
                        break;
                    case Constants.threePairs:
                        System.out.print("连对----");
                        System.out.println(cardPosToCard(entry.getValue().getCardPoint()[0]));
                        break;
                    case Constants.straight:
                        System.out.print("顺子----");
                        System.out.println(cardPosToCard(entry.getValue().getCardPoint()[0]));
                        break;
                    case Constants.straightFlush:
                        System.out.print("同花顺----");
                        System.out.println(cardPosToCard(entry.getValue().getCardPoint()[0]));
                        break;
                    case Constants.bomb:
                        System.out.print("炸弹----");
                        System.out.println(cardPosToCard(entry.getValue().getCardPoint()[0])+"  " + Arrays.stream(entry.getValue().getPlayedCards()).map(ActionJudgment::numOfSameSuitCards).sum());
                        break;
                    case Constants.fourKings:
                        System.out.print("天王炸");
                        break;
           }
       }
       return new Scanner(System.in).nextInt();

    }

    private static char cardPosToCard(int cardPos){
        switch (cardPos){
            case 0:
                return '2';
            case 1:
                return '3';
            case 2:
                return '4';
            case 3:
                return '5';
            case 4:
                return '6';
            case 5:
                return '7';
            case 6:
                return '8';
            case 7:
                return '9';
            case 8:
                return '十';
            case 9:
                return 'J';
            case 10:
                return 'Q';
            case 11:
                return 'K';
            case 12:
                return 'A';
            case 13:
                return '王';
        }
        return '?';
    }

    public static Integer tributeCard(Map<Integer,Integer> cardsMap){
        for(Map.Entry<Integer,Integer> card:cardsMap.entrySet()){
            System.out.println(card.getKey()+"---"+card.getValue());
        }
        return new Scanner(System.in).nextInt();
    }
}
