package taurus.util;

import java.util.ArrayList;
import java.util.List;

public  class PlayerState {
        public List<Integer> handCards;          // 当前手牌
        public List<List<Integer>> pongGroups;   // 碰的牌组（每组3张）
        public List<List<Integer>> gangGroups;   // 杠的牌组（每组4张）
        public List<List<Integer>> chiGroups;    // 吃的牌组（每组3张）
        public boolean isZhuang;


        public PlayerState() {
            this.handCards = new ArrayList<>();
            this.pongGroups = new ArrayList<>();
            this.gangGroups = new ArrayList<>();
            this.chiGroups = new ArrayList<>();
            this.isZhuang = false;
        }

        public PlayerState(List<Integer> handCards) {
            this();
            this.handCards = new ArrayList<>(handCards);
        }

        // 添加碰牌组
        public void addPongGroup(List<Integer> pongGroup) {
            if (pongGroup.size() == 3) {
                this.pongGroups.add(new ArrayList<>(pongGroup));
            }
        }

        // 添加杠牌组
        public void addGangGroup(List<Integer> gangGroup) {
            if (gangGroup.size() == 4) {
                this.gangGroups.add(new ArrayList<>(gangGroup));
            }
        }

        // 添加吃牌组
        public void addChiGroup(List<Integer> chiGroup) {
            if (chiGroup.size() == 3) {
                this.chiGroups.add(new ArrayList<>(chiGroup));
            }
        }

        // 获取所有碰牌（扁平化）
        public List<Integer> getAllPongCards() {
            List<Integer> all = new ArrayList<>();
            for (List<Integer> group : pongGroups) {
                all.addAll(group);
            }
            return all;
        }

        // 获取所有杠牌（扁平化）
        public List<Integer> getAllGangCards() {
            List<Integer> all = new ArrayList<>();
            for (List<Integer> group : gangGroups) {
                all.addAll(group);
            }
            return all;
        }

        // 获取所有吃牌（扁平化）
        public List<Integer> getAllChiCards() {
            List<Integer> all = new ArrayList<>();
            for (List<Integer> group : chiGroups) {
                all.addAll(group);
            }
            return all;
        }

        // 获取碰牌组数
        public int getPongGroupCount() {
            return pongGroups.size();
        }

        // 获取杠牌组数
        public int getGangGroupCount() {
            return gangGroups.size();
        }

        // 获取吃牌组数
        public int getChiGroupCount() {
            return chiGroups.size();
        }

        // 获取总组数
        public int getTotalGroupCount() {
            return pongGroups.size() + gangGroups.size() + chiGroups.size();
        }
    }