package extend.zp.uitl;

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

import com.game.Util;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.ITObject;
import com.taurus.core.entity.TArray;
import com.taurus.core.entity.TObject;

public class ChowCard {
	private Map<Integer, Integer> cardMap;
	private int eventCard;
	@SuppressWarnings("unused")
	private int eventCardType;
	@SuppressWarnings("unused")
	private int modCard;
	
	public ChowCard(List<Integer> cardInhand,int eventCard) {
		this.eventCard = eventCard;
		this.eventCardType = eventCard / 100;
		this.modCard = eventCard % 100;
		this.cardMap = Util.getCardNumMap(cardInhand);
		/*List<Integer> removeList = new ArrayList<Integer>();
		for (Entry<Integer, Integer> entry1 : cardMap.entrySet()) {
			int card = entry1.getKey();
			int num = entry1.getValue();
			if(num>=3)removeList.add(card);
		}
		
		for(Integer card : removeList) {
			cardMap.remove(card);
		}*/
	}
	
	private boolean handle(ITArray p_list,int opcard1,int opcard2) {
		ITArray opcard = TArray.newInstance();
		opcard.addInt(opcard1);
		opcard.addInt(opcard2);
		boolean result = true;
		ITObject obj = TObject.newInstance();
		obj.putTArray("opcard", opcard);
		if(result)p_list.addTObject(obj);
		return result;
	}
	
	
	public boolean tryChow(ITArray list){
		boolean result = false;
		if (CardUtil.checkCard(eventCard - 1, cardMap)  && CardUtil.checkCard(eventCard - 2, cardMap)) {
			result = handle(list,eventCard-1,eventCard-2) || result;
		}
		
		if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard - 1, cardMap)) {
			result = handle(list,eventCard+1,eventCard-1) || result;
		}
		
		if (CardUtil.checkCard(eventCard + 1, cardMap) && CardUtil.checkCard(eventCard + 2, cardMap)) {
			result = handle(list,eventCard+1,eventCard+2) || result;
		}
		/*int type = this.eventCardType;
		int mod_card = this.modCard;
		
		if(mod_card == 2&&CardUtil.checkCard(type*100+7, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) {
			result = handle(list,type*100+7,type*100+10) || result;
		}else if(mod_card == 7&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+10, cardMap)) {
			result = handle(list,type*100+2,type*100+10) || result;
		}else if(mod_card == 10&&CardUtil.checkCard(type*100+2, cardMap)&&CardUtil.checkCard(type*100+7, cardMap)) {
			result = handle(list,type*100+2,type*100+7) || result;
		}*/
		return result;
	}
	
	public static void main(String[] args) {
		ArrayList<Integer> cardInhand = new ArrayList<Integer>();
		cardInhand.add(102);
		cardInhand.add(102);
		cardInhand.add(105);
		cardInhand.add(105);
		cardInhand.add(106);
		cardInhand.add(106);
		cardInhand.add(107);
		cardInhand.add(107);
		cardInhand.add(108);
		cardInhand.add(108);
		cardInhand.add(109);
		cardInhand.add(109);
		cardInhand.add(110);
		cardInhand.add(110);
		cardInhand.add(207);
		cardInhand.add(207);
		
		ChowCard chow = new ChowCard(cardInhand, 110);
		ITArray list = TArray.newInstance();
		chow.tryChow(list);
		System.out.println(list);
	}
}
