package extend.zp.uitl;

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

import com.game.Util;
import com.taurus.core.util.Logger;

import extend.zp.EXPlayer;
import extend.zp.OpCard;

public class PaiXing {

	private static Logger logger = Logger.getLogger(PaiXing.class);
	public static boolean checkWin(EXPlayer player, int drawCard, List<OpCard> opCardList) {
		player.resetHuXi();
		boolean isWin = false;
		WinCard win = new WinCard(player.cardInhand, drawCard, player.AEhuXi, true, opCardList, player);
		try {
			if (win.checkHu()) {
				if (win.maxHuXi >= 10 || win.maxHuXi == 2) {
					isWin = true;
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		if (!isWin) {
			player.resetHuXi();
		}
		if (isWin) {
			player.huXi = win.maxHuXi;
			logger.info(player+"��maxHuXi:" + win.maxHuXi);
			logger.info("maxOpCard:" + win.maxOpCardToString());

			player.handCard.clear();
			for (OpCard opcard : win.maxOpCard) {
				player.handCard.push(opcard);
			}
		}
		return isWin;
	}
	public static boolean checkSpecialWin(EXPlayer player, int wanFa) {
		boolean quanHei = true, wuXi = false, SiBianDui = false,daYi = false,
				daShi = false, xiaoYi = false, xiaoShi = false;
		List<Integer> cardList = new ArrayList<Integer>(player.cardInhand);
		Map<Integer, Integer> cardNumMap = Util.getCardNumMap(cardList);
		int duiZiNum = 0, hongDuiNum = 0, fourNum = 0;
		for (Entry<Integer, Integer> entry : cardNumMap.entrySet()) {
			int card = entry.getKey();
			int num = entry.getValue();
			if (num >= 2) {
				if (CardUtil.checkHongCard(card)) {
					hongDuiNum += 1 ;
				}
				duiZiNum += 1;
				if (card % 100 == 1 && num == 2) {
					if (card / 100 == 1) {
						xiaoYi = true;
					}else {
						daYi = true;
					}
				}else if (card % 100 == 10 && num == 2) {
					if (card / 100 == 1) {
						xiaoShi = true;
					}else {
						daShi = true;
					}
				}
			}
		}
		for (Integer card : cardList) {
			if (CardUtil.checkHongCard(card)) {
				quanHei = false;
				break;
			}
		}
		if (xiaoYi && daYi && xiaoShi && daShi) SiBianDui = true;
		wuXi = CardUtil.checkWuXi(cardList);
		int bomb = CardUtil.checkHieHongZhaDan(cardList);
		player.specialList.add(quanHei ? 1 : 0);
		player.specialList.add(wuXi ? 1 : 0);
		player.specialList.add(hongDuiNum >= 6 ? 1 : 0);
		player.specialList.add(duiZiNum >= 9 ? 1 : 0);
		player.specialList.add(SiBianDui ? 1 : 0);
		player.specialList.add(fourNum >= 2 ? 1 : 0);// ��ը��
		player.specialList.add(bomb == 2 ? 1 : 0);// ��ը��
		player.specialList.add(bomb == 1 ? 1 : 0);// ��ը��
		boolean result = (quanHei || wuXi || hongDuiNum >= 6 
				|| duiZiNum >= 9 || SiBianDui || bomb > 0);
		return result;
	}
}








