package com.lordcard.rule;

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

import android.util.Log;

import com.lordcard.entity.Number;
import com.lordcard.entity.Poker;

/**
 * 鏂楀湴涓昏鍒?
 * 
 */
public class DoudizhuRule {

	public static final int Danpai = 1;
	public static final int Yidui = 2;
	public static final int Santiao = 3;
	public static final int Sandaiyi = 4;
	public static final int Sandaier = 5;
	public static final int zhadan = 6;
	public static final int sidaiyi = 7;
	public static final int sidaier = 8;
	public static final int shunzi = 9;
	public static final int feiji = 10;
	public static final int feijidaisan = 11;
	public static final int feijidaidui = 12;
	public static final int wangzha = 13;
	public static final int liandui = 14;
	public static final int siZhang = 15;
	public static final int error = 0;

	/**
	 * 瀵绘壘涓€寮犵墝涓嚭鐜版鏁版渶澶氾紝鐗屾渶澶х殑鏁板瓧
	 * 
	 * @param cards
	 * @return
	 */
	public static int getMaxNumber(List<Poker> cards) {
		int max = 0;
		int count = getPokeCount(cards);
		// //System.out.println("c鍑虹幇鏈€澶氭槸"+count+"娆?);
		for (int i = 0; i < cards.size(); i++) {
			if (count == numberCount(cards.get(i).getValue(), cards)) {
				max = cards.get(i).getValue();
				// //System.out.println("鏈€澶х殑鐗屼綅"+max);
				return max;
			}
		}
		return max;
	}

	/**
	 * 妫€娴嬬墝鐨勫ぇ灏忥紝濡傛灉澶ц兘鍑哄氨true
	 * 
	 * @param typeOher
	 *            鍒汉鐗屽瀷
	 * @param typeMe
	 *            鑷繁鐗屽瀷
	 * @param maxOhther
	 *            鍒ヤ汉鏈€澶х殑鐗?
	 * @param maxMe
	 *            鑷繁鏈€澶х殑鐗?
	 * @param OtherCardsSize
	 *            鍒ヤ汉鍑虹墝鐨勯暦搴?
	 * @param meCardsSize
	 *            鑷繁鍑虹墝鐨勯暦搴?
	 * @return
	 */
	public static boolean compterpai(int typeOher, int typeMe, int maxOhther, int maxMe, int OtherCardsSize, int meCardsSize) {
		boolean compter = false;
		// 濡傛灉涓や釜浜哄嚭鐨勭墝绫诲瀷涓嶄竴鏍?
		if (typeMe != typeOher) {
			// System.out.println("鐗屽瀷涓嶄竴鏍?);
			if (typeOher == 13) {// 濡傛灉鍒汉鍑虹帇鐐稿垯涓€瀹氳嚜宸辨墦涓嶈繃
				compter = false;
			}
			if (typeOher == 6 && typeMe != 13) {// 濡傛灉鍒汉鍑虹偢鑰岃嚜宸变笉鏄帇鐐镐竴瀹氭墦涓嶈繃
				compter = false;
			}
			if (typeMe == 13) {// 鑷繁濡傛灉鏄帇鐐稿垯鑷繁涓€瀹氱墝姣旇緝澶?
				compter = true;
			}
			if (typeMe == 6 && typeOher != 13) {// 濡傛灉鑷繁鍑虹偢鑰屽埆浜轰笉鏄帇鐐镐竴瀹氭墦寰楄繃
				compter = true;
			}
		} else {// 涓や釜浜哄嚭鐗岀殑绫诲瀷涓€鏍?
				// System.out.println("鐗屽瀷涓€鏍?);
			if (maxOhther >= maxMe) {
				compter = false;
			} else {
				compter = true;
			}
			if (meCardsSize != OtherCardsSize) {// 濡傛灉鏄『瀛愰渶瑕佹娴嬬墝鐨勯暱搴︼紝濡傛灉涓や釜浜虹殑鐗岄暱搴︿笉涓€鏍凤紝閭h嚜宸辨墦涓嶈繃
				compter = false;
			}
		}
		return compter;

	}

	/**
	 * 妫€娴嬭嚜宸辩殑鐗屾槸鍚︽湁鐏 鐢变簬鐗岀殑椤哄簭宸茬粡鎺掑ソ锛屾墍浠ュ彧瑕佺涓€鍜岀浜屽紶鐗屾槸澶ч鍜屽皬楝煎氨鍙互浜?
	 * 
	 * @param list
	 * @return
	 */
	public static boolean IfWangzha(List<Poker> list) {
		if (list.size() < 2)
			return false;

		return list.get(0).getValue() + list.get(1).getValue() == 33 ? true : false;

	}

	/**
	 * 妾㈡脯鑷繁鐨勭墝鏄惁鏈夌偢褰?
	 * 
	 * @param list
	 * @return
	 */
	public static int ifZhadan(List<Poker> list) {
		int number = -1;
		for (int i = list.size() - 1; i > 1; i--) {
			if (numberCount(list.get(i).getValue(), list) == 4) {
				number = i;
				return number;
			}
		}
		return -1;

	}

	/**
	 * 鎻愮ず鍔熻兘
	 * 
	 * @param cards
	 * @return
	 */
	public static int[] GettiShi(List<Poker> Othercards, List<Poker> Mycards) {
		int[] tishi = null;

		// 濡傛灉鍒汉鍑虹帇鐐哥洿鎺ヨ繑鍥?
		if (Othercards.size() != 1) {
			if (IfWangzha(Othercards)) {
				return null;
			}
		}

		// 鑷繁鍓╀笅鐨勭墝灏戜簬瀵规柟鍑虹殑鐗?
		// if(Othercards.size()>Mycards.size()){
		// return null;
		// }

		List<Poker> now = new ArrayList<Poker>();
		for (Poker card : Mycards) {
			now.add(card);
		}
		/*
		 * for(Card card :Othercards){ //System.out.println(card.getValue()); }
		 */
		// 棣栧厛妫€娴嬪埆浜烘槸浠€涔堢被鍨嬬殑鐗?
		int cardType = checkpai(Othercards);

		if (Mycards.size() >= Othercards.size()) {
			switch (cardType) {
			case Danpai: // 濡傛灉鏄崟鐗岀殑璇?
				int value = Othercards.get(0).getValue();
				tishi = new int[1];
				for (int i = Mycards.size() - 1; i >= 0; i--) {
					// //System.out.println("鏈€鍚庝竴寮犵殑鍊间负"+Mycards.get(i).getValue());
					if (value < Mycards.get(i).getValue()) {
						tishi[0] = Mycards.get(i).getNumber();
						return tishi;
					}
				}

				break;
			case Yidui:// 濡傛灉鏄竴瀵圭殑璇?
				tishi = new int[2];
				int yiduivalue = Othercards.get(0).getValue();

				for (int i = Mycards.size() - 1; i > 0; i--) {
					// //System.out.println("鏈€鍚庝竴寮犵殑鍊间负"+Mycards.get(i).getValue());
					if (yiduivalue < Mycards.get(i).getValue()) {
						if (Mycards.get(i).getValue() == Mycards.get(i - 1).getValue()) {
							tishi[0] = Mycards.get(i).getNumber();
							tishi[1] = Mycards.get(i - 1).getNumber();
							return tishi;
						}
					}
				}
				break;
			case Santiao:
				tishi = new int[3];
				int santiaovalue = Othercards.get(0).getValue();

				for (int i = Mycards.size() - 1; i > 1; i--) {
					// //System.out.println("鏈€鍚庝竴寮犵殑鍊间负"+Mycards.get(i).getValue());
					if (santiaovalue < Mycards.get(i).getValue()) {
						if (Mycards.get(i).getValue() == Mycards.get(i - 1).getValue()
								&& Mycards.get(i - 2).getValue() == Mycards.get(i - 1).getValue()) {
							tishi[0] = Mycards.get(i).getNumber();
							tishi[1] = Mycards.get(i - 1).getNumber();
							tishi[2] = Mycards.get(i - 2).getNumber();
							return tishi;
						}
					}
				}
				break;
			case Sandaiyi:
				tishi = new int[4];
				int Sandaiyivalue = getMaxNumber(Othercards);
				// System.out.println("涓夊甫涓€鏈€澶х墝鏄?"+Sandaiyivalue);
				int taget = 0;
				int j = 1;
				for (int i = Mycards.size() - 1; i > 1; i--) {
					// //System.out.println("鏈€鍚庝竴寮犵殑鍊间负"+Mycards.get(i).getValue());
					if (Sandaiyivalue < Mycards.get(i).getValue()) {
						if (Mycards.get(i).getValue() == Mycards.get(i - 1).getValue()
								&& Mycards.get(i - 2).getValue() == Mycards.get(i - 1).getValue()) {
							tishi[0] = Mycards.get(i).getNumber();
							tishi[1] = Mycards.get(i - 1).getNumber();
							tishi[2] = Mycards.get(i - 2).getNumber();
							tishi[3] = 100;
							taget = Mycards.get(i).getValue();
							break;
						}
					}
				}
				while (tishi[3] == 100) {
					if (Mycards.get(Mycards.size() - j).getValue() != taget) {
						tishi[3] = Mycards.get(Mycards.size() - j).getNumber();
						return tishi;
					} else {
						j++;
					}
				}
				break;
			case Sandaier:
				tishi = new int[5];
				int Sandaier = getMaxNumber(Othercards);
				// System.out.println("涓夊甫2鏈€澶х墝鏄?"+Sandaier);
				// int taget1 = 0;
				// int j1 = 1;
				for (int i = Mycards.size() - 1; i > 1; i--) {
					// //System.out.println("鏈€鍚庝竴寮犵殑鍊间负"+Mycards.get(i).getValue());
					if (Sandaier < Mycards.get(i).getValue()) {
						if (Mycards.get(i).getValue() == Mycards.get(i - 1).getValue()
								&& Mycards.get(i - 2).getValue() == Mycards.get(i - 1).getValue()) {
							tishi[0] = Mycards.get(i).getNumber();
							tishi[1] = Mycards.get(i - 1).getNumber();
							tishi[2] = Mycards.get(i - 2).getNumber();
							now.remove(Mycards.get(i));
							now.remove(Mycards.get(i - 1));
							now.remove(Mycards.get(i - 2));
							for (int x = now.size() - 1; x > 0; x--) {
								if (now.get(x).getValue() == now.get(x - 1).getValue()) {
									tishi[3] = now.get(x).getNumber();
									tishi[4] = now.get(x - 1).getNumber();
									return tishi;
								}
							}

						}
					}
				}
				break;
			case zhadan:
				tishi = new int[4];
				int zhadan = Othercards.get(0).getValue();
				for (int i = Mycards.size() - 1; i > 2; i--) {
					// //System.out.println("鏈€鍚庝竴寮犵殑鍊间负"+Mycards.get(i).getValue());

					if (zhadan < Mycards.get(i).getValue()) {
						if (numberCount(Mycards.get(i).getValue(), Mycards) == 4) {
							tishi[0] = Mycards.get(i).getNumber();
							tishi[1] = Mycards.get(i - 1).getNumber();
							tishi[2] = Mycards.get(i - 2).getNumber();
							tishi[3] = Mycards.get(i - 3).getNumber();
							return tishi;
						}
					}

				}
				// if (Mycards.get)

				break;
			case sidaiyi:
				tishi = new int[6];
				int max = getMaxNumber(Othercards);
				for (int i = Mycards.size() - 1; i > 2; i--) {
					// //System.out.println("鏈€鍚庝竴寮犵殑鍊间负"+Mycards.get(i).getValue());

					if (max < Mycards.get(i).getValue()) {
						if (numberCount(Mycards.get(i).getValue(), Mycards) == 4) {
							tishi[0] = Mycards.get(i).getNumber();
							tishi[1] = Mycards.get(i - 1).getNumber();
							tishi[2] = Mycards.get(i - 2).getNumber();
							tishi[3] = Mycards.get(i - 3).getNumber();

							now.remove(Mycards.get(i));
							now.remove(Mycards.get(i - 1));
							now.remove(Mycards.get(i - 2));
							tishi[4] = now.get(now.size() - 1).getNumber();
							tishi[5] = now.get(now.size() - 2).getNumber();

							return tishi;
						}
					}

				}
				break;
			case sidaier:

				tishi = getSiDaiErTiShi(Othercards, now);
				if (tishi != null) {
					return tishi;
				}
				break;
			case feiji:
				tishi = getFeiJiTiShi(Othercards, now);
				if (tishi != null) {
					return tishi;
				}
				break;
			case feijidaisan:

				tishi = getFeiJiDaiSanTiShi(Othercards, now);
				if (tishi != null) {
					return tishi;
				}
				break;
			case feijidaidui:
				// tishi = new int[Othercards.size()];
				tishi = getFeiJiDaiDuiTiShi(Othercards, now);
				if (tishi != null) {
					return tishi;
				}
				break;
			case liandui:
				tishi = new int[Othercards.size()];
				int minPai = Othercards.get(Othercards.size() - 1).getValue();

				int tishiPos = 0;
				int lastPaiValue = -1;
				// hjr 閲嶅啓
				for (int i = Mycards.size() - 1; i > 0 && tishiPos < tishi.length; --i) {
					// 鐗岀殑鏁板皬浜庣瓑浜庢垜瀵规墜鏈€灏忕殑鐗?
					if (Mycards.get(i).getValue() <= minPai) {
						continue;
					}
					// 纰板埌2鐨勬椂鍊欙紝鐩存帴閫€鍑?
					if (Mycards.get(i).getValue() == 15) {
						break;
					}
					// 鍙湁鍜屼笅涓€寮犵墝鏋勬垚涓€瀵规椂锛屾墠鍚戜笅璧帮紝
					if (Mycards.get(i - 1).getValue() != Mycards.get(i).getValue()) {
						// lastPaiValue = -1;
						continue;
					}
					// 鎵惧埌绗竴涓鍚堟潯浠剁殑瀵?
					if (lastPaiValue == -1) {
						tishi[0] = Mycards.get(i).getNumber();
						--i;
						tishi[1] = Mycards.get(i).getNumber();
						tishiPos = 2;
						lastPaiValue = Mycards.get(i).getValue();
						continue;
					}
					// 瀛樺湪3寮犳垨鑰?寮狅紝璺宠繃绗笁寮犲拰绗洓寮?
					if (Mycards.get(i).getValue() == lastPaiValue) {
						continue;
					}
					// 褰撳墠鐗屽鏋滄垚瀵癸紝浣嗕笉鍜屼笂涓€瀵规槸杩炵潃鐨勶紝鍒欐竻闄ゅ凡鏈夌殑鏍囨敞锛岄噸鏂板皢鍏跺仛涓鸿繛瀵圭殑鏈€灏忎竴瀵?
					if (Mycards.get(i).getValue() != lastPaiValue + 1) {
						tishi[0] = Mycards.get(i).getNumber();
						--i;
						tishi[1] = Mycards.get(i).getNumber();
						tishiPos = 2;

					} else {
						// 鎵惧埌绗﹀悎鏉′欢鐨勪笅涓€瀵癸紝瀛樺叆tishi闃熷垪
						tishi[tishiPos++] = Mycards.get(i).getNumber();
						--i;
						// ++tishiPos;
						tishi[tishiPos++] = Mycards.get(i).getNumber();

					}
					lastPaiValue = Mycards.get(i).getValue();
				}
				// 濡傛灉tishi闃熷垪鏄弧鐨勶紝鍒欐壘鍒伴渶瑕佺殑鎻愮ず鐗?
				if (tishiPos == tishi.length) {
					return tishi;
				}
				break;
			case shunzi:
				tishi = new int[Othercards.size()];
				int shunzi = Othercards.get(Othercards.size() - 1).getValue();
				// //System.out.println("鍒汉椤哄瓙鏈€灏忕墝涓?+shunzi);
				for (int i = Mycards.size() - 1; i > Othercards.size() - 2; i--) {
					if (shunzi < Mycards.get(i).getValue()) {
						int shunCount = 1;
						tishi[0] = Mycards.get(i).getNumber();
						for (int z = 1; z < Othercards.size(); z++) {
							for (int s = i; s >= 1; s--) {
								if (Mycards.get(i).getValue() + z == Mycards.get(s - 1).getValue() && Mycards.get(s - 1).getValue() < 15) {
									tishi[shunCount] = Mycards.get(s - 1).getNumber();
									shunCount++;
									break;
								}
							}
						}
						if (shunCount == Othercards.size()) {
							return tishi;
							/*
							 * }else{ return null;
							 */
						}
					}
				}
				break;

			}
		}
		// 濡傛灉鎵撲笉杩囧悓绫诲瀷鐨勫垯妫€娴嬭嚜宸辨槸鍚︽湁鐐稿脊
		int number = ifZhadan(Mycards);
		if (number != -1 && cardType != zhadan) {
			tishi = new int[4];
			for (int i = 0; i < 4; i++) {
				tishi[i] = Mycards.get(number - i).getNumber();
			}
			return tishi;
		} else {
			if (Othercards.size() != 1) {
				if (IfWangzha(Mycards)) {
					// System.out.println("浣犳湁鐜嬬偢");
					tishi = new int[2];
					tishi[0] = Mycards.get(0).getNumber();
					tishi[1] = Mycards.get(1).getNumber();
					;
					return tishi;
				}
			}
		}

		return null;
	}

	/**
	 * 妫€鏌ヨ嚜宸辩殑鐗屼腑鏄惁鏈夐鏈?
	 * 
	 * @param othercards
	 *            瀵规墜鐗?
	 * @param myCards
	 *            鑷繁鐜板湪鐨勭墝
	 * @return 鎻愮ず鏁扮粍锛歩tem涓殑鐗岀殑number
	 */
	private static int[] getFeiJiTiShi(List<Poker> othercards, List<Poker> myCards) {
		if (myCards.size() < othercards.size()) {
			return null;
		}
		// 鏌ュ嚭瀵规墜鏈€澶х殑涓€寮犵墝
		int maxValue = othercards.get(0).getValue();
		if (maxValue == 0) {
			return null;
		}

		// 椋炴満鎬绘暟
		int feijiCount = othercards.size() / 3;

		List<Poker> del = new ArrayList<Poker>();
		// int count4 = -1;
		for (int i = myCards.size() - 1; i >= 0; --i) {
			// if (mycards.get(i).getValue() < )
			int sameCardCount = numberCount(myCards.get(i).getValue(), myCards);
			// 濡傛灉鍙嚭鐝句竴娆?
			if (sameCardCount < 3) {
				// cards.remove(i);
				del.add(myCards.get(i));
				// //System.out.println("shanchu");
			} else if (sameCardCount == 4) {
				del.add(myCards.get(i));
				i = i - 3;
			}
		}

		for (int i = 0; i < del.size(); i++) {
			myCards.remove(del.get(i));

		}

		if (myCards.size() < feijiCount * 3) {
			return null;
		}

		int tiShi[] = new int[feijiCount * 3];
		int tiShiIndex = 0;
		for (int i = myCards.size() - 1; i >= 2; i = i - 3) {
			if (myCards.get(i).getValue() < maxValue) {
				continue;
			}
			// 鏈€鍚庝竴涓惊鐜紝鑰屼笖tiShiIndex涓嶇瓑浜?锛岃鏄庢帴涓嬫潵鐨勪笁寮犵墝涔熸槸椋炴満鐨勪竴閮ㄥ垎
			// if (i - 3 < 0 && tiShiIndex != 0){
			// if (tiShiIndex <= tiShi.length - 3){
			// tiShi[tiShiIndex++] = myCards.get(i).getNumber();
			// tiShi[tiShiIndex++] = myCards.get(i-1).getNumber();
			// tiShi[tiShiIndex++] = myCards.get(i-2).getNumber();
			// }
			// break;
			// }
			// 鏈€鍚庝竴涓惊鐜紝
			if (i - 3 < 0) {
				if (tiShiIndex == 0) {
					// 鏈€鍚庝竴涓惊鐜紝浣嗘槸杩樻病鏈夊叾浠栦笁涓紝娌℃湁椋炴満锛岄€€鍑?
					break;
				}
				// 鑰屼笖tiShiIndex涓嶇瓑浜?锛岃鏄庢帴涓嬫潵鐨勪笁寮犵墝涔熸槸椋炴満鐨勪竴閮ㄥ垎
				if (tiShiIndex <= tiShi.length - 3) {
					tiShi[tiShiIndex++] = myCards.get(i).getNumber();
					tiShi[tiShiIndex++] = myCards.get(i - 1).getNumber();
					tiShi[tiShiIndex++] = myCards.get(i - 2).getNumber();
				}
				break;
			}
			if (myCards.get(i).getValue() + 1 == myCards.get(i - 3).getValue()) {
				if (tiShiIndex <= tiShi.length - 3) {
					tiShi[tiShiIndex++] = myCards.get(i).getNumber();
					tiShi[tiShiIndex++] = myCards.get(i - 1).getNumber();
					tiShi[tiShiIndex++] = myCards.get(i - 2).getNumber();
				}
				if (tiShiIndex == tiShi.length) {
					return tiShi;
				}
			} else {
				tiShiIndex = 0;
			}
		}

		if (tiShiIndex == tiShi.length) {
			return tiShi;
		}
		return null;

		// for(int i = 0;i<cards.size();i++){
		//
		// }
		// if(checkFeiji(cards)){
		// return true;
		// }else{
		// return false;
		// }
	}

	/**
	 * 妫€鏌ヨ嚜宸辩殑鐗屼腑鏄惁鏈夊洓甯︿簩鐨勭墝
	 * 
	 * @param othercards
	 *            瀵规墜鐗?
	 * @param myCards
	 *            鑷繁鐜板湪鐨勭墝
	 * @return 鎻愮ず鏁扮粍锛歩tem涓殑鐗岀殑number
	 */
	private static int[] getSiDaiErTiShi(List<Poker> othercards, List<Poker> myCards) {
		if (myCards.size() < othercards.size()) {
			return null;
		}
		int maxValue = getMaxNumber(othercards);
		int tishi[] = new int[othercards.size()];
		int tiShiIndex = 0;
		int i = 0;
		for (i = myCards.size() - 1; i >= 3; --i) {
			if (myCards.get(i).getValue() < maxValue) {
				continue;
			}
			int count = numberCount(myCards.get(i).getValue(), myCards);
			if (count == 4) {
				tishi[tiShiIndex++] = myCards.get(i).getNumber();
				tishi[tiShiIndex++] = myCards.get(i - 1).getNumber();
				tishi[tiShiIndex++] = myCards.get(i - 2).getNumber();
				tishi[tiShiIndex++] = myCards.get(i - 3).getNumber();
				break;
			}
		}

		if (i == 2) {
			return null;
		}

		// 瀵绘壘涓ゅ
		for (int j = myCards.size() - 1; j > 0; --j) {
			if (j > i - 4 && j <= i) {
				continue;
			}
			if (myCards.get(j).getValue() == myCards.get(j - 1).getValue()) {
				tishi[tiShiIndex++] = myCards.get(j).getNumber();
				tishi[tiShiIndex++] = myCards.get(j - 1).getNumber();
				--j;
			}
			if (tiShiIndex == tishi.length) {
				return tishi;
			}
		}

		return null;
	}

	/**
	 * 妫€鏌ラ鏈哄甫瀵?
	 * 
	 * @param othercards
	 *            瀵规墜鐗?
	 * @param mycards
	 *            鎴戠殑鐗?
	 * @return 鎻愮ず鐨勭墝鐨勬暟缁?
	 */
	private static int[] getFeiJiDaiDuiTiShi(List<Poker> othercards, List<Poker> myCards) {

		if (myCards.size() < othercards.size()) {
			return null;
		}

		int feiJiCount = othercards.size() / 5;

		// 鏌ュ嚭瀵规墜鏈€澶х殑涓€寮犵墝
		int maxValue = DoudizhuRule.checkFeijiDaidui(othercards);
		if (maxValue == 0) {
			return null;
		}

		List<Poker> del = new ArrayList<Poker>();
		// int duiCount = 0; //瀵瑰瓙鐨勬暟閲?

		for (int i = 0; i < myCards.size(); i++) {
			// 濡傛灉鍙嚭鐝句竴娆?
			int count = numberCount(myCards.get(i).getValue(), myCards);
			if (count == 1) {
				del.add(myCards.get(i));
			} else if (count == 2) {
				del.add(myCards.get(i));
				del.add(myCards.get(i + 1));
				++i;
			} else if (count == 4) {
				del.add(myCards.get(i));
				i = i + 3;
			}
		}

		// 鍙暀涓嬩笁寮?
		for (int i = 0; i < del.size(); i++) {

			myCards.remove(del.get(i));
		}

		if (myCards.size() < feiJiCount * 3) {
			return null;
		}

		// 鏌ュ嚭鎵€鏈夌殑鏁版嵁锛屽苟灏嗗叾
		Poker tiShiPoker[] = new Poker[feiJiCount * 3];// 鏆傛椂缂撳瓨鏌愪釜鐗屽湪闃熷垪涓殑浣嶇疆
		int tiShiIndex = 0;
		int i;
		for (i = myCards.size() - 1; i >= 2; i = i - 3) {
			if (myCards.get(i).getValue() < maxValue) {
				continue;
			}
			// 鏈€鍚庝竴涓惊鐜紝鑰屼笖tiShiIndex涓嶇瓑浜?锛岃鏄庢帴涓嬫潵鐨勪笁寮犵墝涔熸槸椋炴満鐨勪竴閮ㄥ垎
			// if (i - 3 < 0 && tiShiIndex != 0){
			// if (tiShiIndex <= tiShiPoker.length - 3){
			// tiShiPoker[tiShiIndex++] = myCards.get(i);
			// tiShiPoker[tiShiIndex++] = myCards.get(i - 1);
			// tiShiPoker[tiShiIndex++] = myCards.get(i - 2);
			// }
			// break;
			// }
			// 鏈€鍚庝竴涓惊鐜紝
			if (i - 3 < 0) {
				if (tiShiIndex == 0) {
					// 鏈€鍚庝竴涓惊鐜紝浣嗘槸杩樻病鏈夊叾浠栦笁涓紝娌℃湁椋炴満锛岄€€鍑?
					break;
				}
				// 鑰屼笖tiShiIndex涓嶇瓑浜?锛岃鏄庢帴涓嬫潵鐨勪笁寮犵墝涔熸槸椋炴満鐨勪竴閮ㄥ垎
				if (tiShiIndex <= tiShiPoker.length - 3) {
					tiShiPoker[tiShiIndex++] = myCards.get(i);
					tiShiPoker[tiShiIndex++] = myCards.get(i - 1);
					tiShiPoker[tiShiIndex++] = myCards.get(i - 2);
				}
				break;
			}
			if (myCards.get(i).getValue() + 1 == myCards.get(i - 3).getValue()) {
				if (tiShiIndex <= tiShiPoker.length - 3) {
					tiShiPoker[tiShiIndex++] = myCards.get(i);
					tiShiPoker[tiShiIndex++] = myCards.get(i - 1);
					tiShiPoker[tiShiIndex++] = myCards.get(i - 2);
				}
				if (tiShiIndex == tiShiPoker.length) {
					break;
				}
			} else {
				// 灏嗕笉闇€瑕佺殑鐗屾坊鍔犲埌del鏁扮粍涓?
				for (int j = 0; j < tiShiIndex; ++j) {
					del.add(tiShiPoker[j]);
				}
				tiShiIndex = 0;
			}
		}
		if (tiShiIndex != tiShiPoker.length) {
			return null;
		}
		// 灏嗗叾浠栫墝鍜屽湪涓€璧?
		for (i = i - 3; i >= 0; --i) {
			del.add(myCards.get(i));
		}
		for (int j = 0; j < del.size(); ++j) {
			myCards.remove(del.get(j));
		}
		// 鍒ゆ柇鏄惁鏈夎冻澶熺殑瀵瑰瓙
		int duiCount = 0;
		boolean hasCheck[] = new boolean[del.size()];
		// 璁$畻瀵圭殑鏁伴噺
		for (i = 0; i < del.size(); ++i) {
			if (hasCheck[i]) {
				continue;
			}
			for (int j = i + 1; j < del.size(); ++j) {
				if (hasCheck[j]) {
					continue;
				}
				if (del.get(i).getValue() == del.get(j).getValue()) {
					if (++duiCount >= feiJiCount) {
						// 杩斿洖鐩稿簲鐨勬彁绀烘暟缁?
						int tiShi[] = new int[myCards.size()];
						for (int k = 0; k < myCards.size(); ++k) {
							tiShi[k] = myCards.get(k).getNumber();
						}
						return tiShi;
					} else {
						hasCheck[j] = true;
					}
					break;
				}
			}

		}

		return null;

	}

	/**
	 * 妫€鏌ュ嚭椋炴満甯︽暎鐗岀殑鎻愮ず
	 * 
	 * @param othercards
	 *            瀵规墜鐗?
	 * @param mycards
	 *            鎴戠殑鐗?
	 * @return 鎻愮ず鏁扮粍
	 */
	private static int[] getFeiJiDaiSanTiShi(List<Poker> othercards, List<Poker> mycards) {
		if (mycards.size() < othercards.size()) {
			return null;
		}
		// 鏌ュ嚭瀵规墜鏈€澶х殑涓€寮犵墝
		int maxValue = DoudizhuRule.checkFeijiDaisan(othercards);
		if (maxValue == 0) {
			return null;
		}

		// 椋炴満鎬绘暟
		int feijiCount = othercards.size() / 4;

		List<Poker> del = new ArrayList<Poker>();
		// int count4 = -1;
		for (int i = mycards.size() - 1; i >= 0; --i) {
			// if (mycards.get(i).getValue() < )
			int sameCardCount = numberCount(mycards.get(i).getValue(), mycards);
			// 濡傛灉鍙嚭鐝句竴娆?
			if (sameCardCount < 3) {
				// cards.remove(i);
				del.add(mycards.get(i));
				// //System.out.println("shanchu");
			} else if (sameCardCount == 4) {
				del.add(mycards.get(i));
				i = i - 3;
			}
		}

		for (int i = 0; i < del.size(); i++) {
			mycards.remove(del.get(i));

		}

		if (mycards.size() < feijiCount * 3) {
			return null;
		}

		int tiShi[] = new int[feijiCount * 3];
		int tiShiIndex = 0;
		for (int i = mycards.size() - 1; i >= 2; i = i - 3) {
			if (mycards.get(i).getValue() < maxValue) {
				continue;
			}
			// 鏈€鍚庝竴涓惊鐜紝
			if (i - 3 < 0) {
				if (tiShiIndex == 0) {
					// 鏈€鍚庝竴涓惊鐜紝浣嗘槸杩樻病鏈夊叾浠栦笁涓紝娌℃湁椋炴満锛岄€€鍑?
					break;
				}
				// 鑰屼笖tiShiIndex涓嶇瓑浜?锛岃鏄庢帴涓嬫潵鐨勪笁寮犵墝涔熸槸椋炴満鐨勪竴閮ㄥ垎
				if (tiShiIndex <= tiShi.length - 3) {
					tiShi[tiShiIndex++] = mycards.get(i).getNumber();
					tiShi[tiShiIndex++] = mycards.get(i - 1).getNumber();
					tiShi[tiShiIndex++] = mycards.get(i - 2).getNumber();
				}
				break;
			}
			if (mycards.get(i).getValue() + 1 == mycards.get(i - 3).getValue()) {
				if (tiShiIndex <= tiShi.length - 3) {
					tiShi[tiShiIndex++] = mycards.get(i).getNumber();
					tiShi[tiShiIndex++] = mycards.get(i - 1).getNumber();
					tiShi[tiShiIndex++] = mycards.get(i - 2).getNumber();
				}
				if (tiShiIndex == tiShi.length) {
					return tiShi;
				}
			} else {
				tiShiIndex = 0;
			}
		}

		if (tiShiIndex == tiShi.length) {
			return tiShi;
		}
		return null;

		// for(int i = 0;i<cards.size();i++){
		//
		// }
		// if(checkFeiji(cards)){
		// return true;
		// }else{
		// return false;
		// }
	}
   /**
    * 妫€娴嬬墝鍨嬬浉鍏崇殑鐗岄潰鍊?
    * @param type
    * @param cards
    * @return
    */
   public static int getValueForpoker(List<Poker> cards,int count)
   {
	   int value = -1;
	   int[][]tmV = new int[cards.size()][2];
	   for(int i=0;i<cards.size();i++)
	   {
		   Poker p = cards.get(i);
		   boolean isExists = false;
		   for(int j =0;j<tmV.length;j++)
		   {
			   if(tmV[j][0] == p.getValue())
			   {
				   isExists = true;
				   tmV[j][1]++;
				   if(tmV[j][1] == count)
				   {
					   value = p.getValue();
					   break;
				   }
			   }
		   }
		   if(!isExists)
		   {
			   tmV[i][0] = p.getValue();
		   }
		   if(value != -1)
		   {
			   break;
		   }
	   }
	   return value;
   }
   public static int checkpaiValue(int cardStyle,List<Poker> cards)
   {
	   int value = -1;
	   switch (cardStyle) {
	    case Danpai:
	    case Yidui:
	    case Santiao:
	    	value = cards.get(0).getValue();
			break;
		}
	   return value;
   }
	/**
	 * 妫€娴嬫槸浠€涔堢墝
	 * 
	 * @param cards
	 * @return
	 */
	public static int checkpai(List<Poker> cards) {
		int cardStyle = 0;
		if (cards.size() == 0) {// 濡傛灉0寮犵墝
			cardStyle = error; // error
		}
		int pokerCount = getPokeCount(cards);
		switch (cards.size()) {
		case 1: // 濡傛灉鏄竴寮犵墝
			cardStyle = Danpai; // 鍗曠墝
			break;
		case 2:// 濡傛灉鏄袱寮犵墝
			if (cards.get(0).getValue() == cards.get(1).getValue()) {
				cardStyle = Yidui;// 涓€瀵?
			} else if (cards.get(0).getValue() + cards.get(1).getValue() == 33) {
				cardStyle = wangzha;// 鐜嬬偢
			}
			break;
		case 3:// 濡傛灉鏄笁寮犵墝
			if (pokerCount == 3) {
				cardStyle = Santiao;
				// System.out.println("涓夊紶");
			}
			break;
		case 4:// 濡傛灉鏄洓寮犵墝
			if (pokerCount == 4) {
				cardStyle = zhadan; // 鐐稿脊
			} else if (pokerCount == 3) {// 涓夊甫涓€
				cardStyle = Sandaiyi;
			}
			break;
		case 5:// 濡傛灉鏄簲寮犵墝
			if (pokerCount == 3) {// 涓夊緟浜?
				if (cards.get(3).getValue() == cards.get(4).getValue() && cards.get(0).getValue() == cards.get(1).getValue()) {
					cardStyle = Sandaier;
				}
			} else if (checkShunpai(cards)) {// 鏄『鐗?
				cardStyle = shunzi;
			}
			break;
		case 6:// 濡傛灉鏄?寮?
			if (pokerCount == 4) {
				cardStyle = sidaiyi;
				return sidaiyi;
			} else if (checkShunpai(cards)) {
				cardStyle = shunzi;
				return shunzi;
			} else if (checkLiandui(cards)) {
				cardStyle = liandui;
				return liandui;
			} else if (pokerCount == 3) {
				if (checkFeiji(cards)) {
					cardStyle = feiji;
				}
			}
			break;
		}

		if (cards.size() >= 7) {
			// 妫€娴?甯?灏?
			if (pokerCount == 4 && cards.size() == 8 && cards.get(0).getValue() == cards.get(1).getValue()
					&& cards.get(2).getValue() == cards.get(3).getValue() && cards.get(4).getValue() == cards.get(5).getValue()
					&& cards.get(6).getValue() == cards.get(7).getValue()) {
				return sidaier;
			}
			// 妫€娴嬮『鐗?
			if (checkShunpai(cards)) {
				return shunzi;
			}
			// 妫€娴嬭繛瀵?
			if (checkLiandui(cards)) {
				return liandui;
			}
			// 妫€娴嬭繛椋炴満
			if (checkFeiji(cards)) {
				return feiji;
			}
			if (cards.size() % 4 == 0) {
				if (0 != checkFeijiDaisan(cards)) {
					// System.out.println("椋炴満甯︽暎鐗?);
					return feijidaisan;
				}
			}
			if (cards.size() % 5 == 0) {
				if (0 != checkFeijiDaidui(cards)) {
					// System.out.println("椋炴満甯﹂槦");
					return feijidaidui;
				}
			}
		}
		return cardStyle;

	}

	/**
	 * 缁熻鏄笉鏄『鐗岋紝椤虹墝涓嶅寘鎷?
	 * 
	 * @param cards
	 * @return
	 */
	public static boolean checkShunpai(List<Poker> cards) {
		int first = cards.get(0).getValue();
		if (first == 15 || first == 16 || first == 17) {
			return false;
		}
		for (int i = 0; i < cards.size() - 1; i++) {
			if (cards.get(i + 1).getValue() + 1 == first) {
				first = cards.get(i + 1).getValue();
			} else {
				return false;
			}
		}
		return true;
	}

	/**
	 * 妫€鏌ュ幓闄ら噸澶嶇墝鍚庣殑鎵嬬墝锛屽苟鎵惧嚭鏈€澶х殑椤哄瓙
	 * 
	 * @Title: check
	 * @Description: TODO
	 * @param @param set
	 * @param @return
	 * @return String[]
	 * @throws
	 */

	public static String[] checkShunZi(TreeSet<Integer> set) {
		ArrayList<String[]> result = new ArrayList<String[]>();
		StringBuilder temp = new StringBuilder();
		int count = 0;
		Integer[] nums = new Integer[1];
		nums = set.toArray(nums);
		int begin = 0;
		// ================閫夊嚭鎵€鏈夌殑椤哄瓙===================
		for (Integer i : set) {
			if (count == 0) {
				begin = i;
				count++;
				temp.append("" + begin);
			} else if (i != 15 && i != 16 && i != 17 && (i == begin + count)) {
				temp.append("," + i);
				count++;
			} else {
				if (count > 4) {
					result.add(temp.toString().split(","));
				}
				begin = i;
				temp.replace(0, temp.length(), i + "");
				count = 1;
			}
		}

		if (count > 4)
			result.add(temp.toString().split(","));
		// ====================================================

		// ---------------閫夊嚭鏈€澶х殑椤哄瓙--------------------
		String[] max;
		if (result.size() == 0) {
			max = null;
		} else {
			max = result.get(0);
			System.out.println("鍏辨湁" + result.size() + "涓『瀛?");
			for (int i = 1; i < result.size(); i++) {
				if (max.length < result.get(i).length) {
					max = result.get(i);
				}
			}
		}
		return max;
	}

	/**
	 * 婊戝姩閫夌墝鏃讹紝5瀵瑰強5瀵逛互涓婄殑杩炲妫€娴?
	 * @param pokers
	 * @return
	 */
	public static List<Integer> checkLianDui2(List<Poker> pokers) {
		List<Integer> card = new ArrayList<Integer>();
		List<Integer> cardId1 = new ArrayList<Integer>();
		List<Integer> card2 = new ArrayList<Integer>();
		int[] cardss = new int[pokers.size()];
		for (int i = 0; i < pokers.size(); i++) {
			//			cards.add(pokers.get(i).getValue());
			cardss[i] = pokers.get(i).getValue();
			System.out.println("鎵戝厠锛? + pokers.get(i).getValue());
		}
		int[] cards = Sorts(cardss);
		Log.i("checkLianDui2","==========鍘熷鐗?=============");
		for (int i = 0; i < cards.length; i++) {
			Log.i("checkLianDui2","" + cards[i]);
		}
		Log.i("checkLianDui2","===============================");
		if (cards.length > 0) {
			int current = cards[0];
			cardId1.add(cards[0]);
			for (int i = 1; i < cards.length; i++) {//鎵捐繛缁殑鐗?
				int cardsValue = cards[i];
				if (cardsValue != 15 && cardsValue != 16 && cardsValue != 17 && cardsValue - current == 1) {
					current = cardsValue;
					cardId1.add(cardsValue);
				} else if (cardsValue - current > 1) {
					current = cardsValue;
					if (cardId1.size() > 4) {//濡傛灉鏈?涓互涓婄殑杩炵墝锛屽氨閫€鍑哄惊鐜?
						break;
					} else {
						cardId1.clear();
						cardId1.add(cardsValue);
					}
				}
			}
			Log.i("checkLianDui2","==========杩炵画鐨勭墝==============");
			for (int i = 0; i < cardId1.size(); i++) {
				Log.i("checkLianDui2",cardId1.get(i) + " ,");
			}
			Log.i("checkLianDui2","==============================");
			if (cardId1.size() >= 5) {
				for (int i = 0; i < cardId1.size(); i++) {
					int cardId = cardId1.get(i);
					int count = 0;
					for (int j = 0; j < cards.length; j++) {
						if (cardId == cards[j]) {//濡傛灉鐩稿悓
							++count;
							if (count < 3) {
								card.add(cards[j]);
							} else {
								continue;
							}
						}
					}
					if (count < 2) {
						if (card.size() >= 1) {
							card.remove(card.size() - 1);
						}
					}
				}
			} else {
				return card2;
			}
			Log.i("checkLianDui2","==========鏁e瀛?=============");
			for (int i = 0; i < card.size(); i++) {
				Log.i("checkLianDui2",card.get(i) + " ,");
			}
			Log.i("checkLianDui2","==============================");

			cardId1.clear();
			current = cards[0];
			cardId1.add(cards[0]);
			for (int i = 1; i < card.size(); i++) {//鎵捐繛缁殑鐗?
				if (card.get(i) - current == 1) {
					current = card.get(i);
					cardId1.add(card.get(i));
				} else if (card.get(i) - current > 1) {
					current = card.get(i);
					if (cardId1.size() > 4) {//濡傛灉鏈?涓互涓婄殑杩炵墝锛屽氨閫€鍑哄惊鐜?
						break;
					} else {
						cardId1.clear();
						cardId1.add(card.get(i));
					}
				}
			}
			Log.i("checkLianDui2","==========鏁e瀛?===杩炵画鐨勭墝==========");
			for (int i = 0; i < cardId1.size(); i++) {
				Log.i("checkLianDui2",cardId1.get(i) + " ,");
			}
			Log.i("checkLianDui2","==================================");
			if (cardId1.size() >= 5) {
				for (int i = 0; i < cardId1.size(); i++) {
					int cardId = cardId1.get(i);
					int count = 0;
					for (int j = 0; j < card.size(); j++) {
						if (cardId == card.get(j)) {//濡傛灉鐩稿悓
							++count;
							if (count < 3) {
								card2.add(card.get(j));
							} else {
								continue;
							}
						}
					}
					if (count < 2) {
						if (card2.size() >= 1) {
							card2.remove(card2.size() - 1);
						}
					}
				}
			}
			Log.i("checkLianDui2","==========杩炲==============");
			for (int i = 0; i < card2.size(); i++) {
				Log.i("checkLianDui2",card2.get(i) + " ,");
			}
			Log.i("checkLianDui2","============================");
		}
		return card2;
	}

	
	/**鍐掓场鎺掑簭
	 * @param score
	 * @return
	 */
	public static int[] Sorts(int[] score) {
		for (int i = 0; i < score.length - 1; i++) { //鏈€澶氬仛n-1瓒熸帓搴?
			for (int j = 0; j < score.length - i - 1; j++) { //瀵瑰綋鍓嶆棤搴忓尯闂磗core[0......length-i-1]杩涜鎺掑簭(j鐨勮寖鍥村緢鍏抽敭锛岃繖涓寖鍥存槸鍦ㄩ€愭缂╁皬鐨?
				if (score[j] > score[j + 1]) { //鎶婂皬鐨勫€间氦鎹㈠埌鍚庨潰
					int temp = score[j];
					score[j] = score[j + 1];
					score[j + 1] = temp;
				}
			}
		}
		return score;
	}
	/**
	 * 鍒ゆ柇杩炲
	 * 
	 * @param cards
	 * @return
	 */
	public static boolean checkLiandui(List<Poker> cards) {
		int count = 0;
		if (cards.size() >= 6 && cards.size() % 2 == 0) {
			for (int i = 0; i < cards.size() - 1; i += 2) {
				// 鎺掗櫎2鍜岀帇
				if (cards.get(i).getValue() == 16 || cards.get(i).getValue() == 17 || cards.get(i).getValue() == 15) {
					return false;
				}

				if (cards.get(i).getValue() == cards.get(i + 1).getValue()) {
					count++;
				} else {
					return false;
				}
				// //System.out.println("鎵ц鍒颁簡杩欓噷"+count);
				if (i + 2 < cards.size() - 1) {
					if (cards.get(i + 2).getValue() + 1 != cards.get(i).getValue()) {
						return false;
					}
				}
			}
		}
		// //System.out.println(count);
		if (count == cards.size() / 2) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * //妾㈡脯涓€寮电墝鍦ㄤ竴鎵嬬墝涓嚭鐝剧殑娆℃暩
	 * 
	 * @param number
	 * @param cards
	 * @return
	 */
	public static int numberCount(int number, List<Poker> cards) {
		int count = 0;
		for (int i = 0; i < cards.size(); i++) {
			if (cards.get(i).getValue() == number) {
				// //System.out.println("value"+cards.get(i).getValue()+"number"+number);
				count++;
			}
		}
		// //System.out.println("妫€娴媍ount闀垮害"+count);
		return count;
	}

	/**
	 * 妫€娴嬫槸涓嶆槸椋炴満甯︽暎鐗?
	 * 
	 * @param cards
	 * @return
	 */
	public static int checkFeijiDaisan(List<Poker> myCards) {

		if (myCards.size() % 4 != 0) {
			return 0;
		}

		// 澶嶅埗涓€鎵嬬墝杩涜妫€鏌?
		List<Poker> cards = new ArrayList<Poker>();
		for (int i = 0; i < myCards.size(); ++i) {
			cards.add(myCards.get(i));
		}

		// 椋炴満鎬绘暟
		int feijiCount = cards.size() / 4;

		List<Poker> del = new ArrayList<Poker>();
		// int count4 = -1;
		for (int i = 0; i < cards.size(); i++) {
			// 濡傛灉鍙嚭鐝句竴娆?
			if (numberCount(cards.get(i).getValue(), cards) < 3) {
				// cards.remove(i);
				del.add(cards.get(i));
				// //System.out.println("shanchu");
			} else if (numberCount(cards.get(i).getValue(), cards) == 4) {
				del.add(cards.get(i));
				i = i + 3;
			}
		}

		// 鍒ゆ柇闄ゅ幓椋炴満鐨勭墝鐨勬暟鐩槸鍚︿负椋炴満鏁?
		// if(del.size()!=cards.size()/4){
		// ////System.out.println("del.size()"+del.size()+"cards.size()/4"+cards.size()/4);
		// return false;
		// }

		for (int i = 0; i < del.size(); i++) {
			// System.out.println(del.get(i));

			cards.remove(del.get(i));

		}

		if (cards.size() % 3 != 0 || cards.size() == 0) {
			return 0;
		}

		int lianCount = 1;
		int maxLianCount = 1;
		for (int i = 0; i < cards.size() - 3; i = i + 3) {
			if (cards.get(i).getValue() - 1 == cards.get(i + 3).getValue() && cards.get(i).getValue() < 15) {
				++lianCount;
			} else {
				if (lianCount > maxLianCount) {
					maxLianCount = lianCount;
				}
				lianCount = 1;
			}
		}
		if (lianCount > maxLianCount) {
			maxLianCount = lianCount;
		}
		if (maxLianCount == feijiCount) {
			return cards.get(0).getValue();
		}
		return 0;

		// for(int i = 0;i<cards.size();i++){
		//
		// }
		// if(checkFeiji(cards)){
		// return true;
		// }else{
		// return false;
		// }

	}

	/**
	 * 妫€娴嬫槸涓嶆槸椋炴満甯﹀
	 * 
	 * @param cards
	 * @return
	 */
	public static int checkFeijiDaidui(List<Poker> myCards) {
		if (myCards.size() % 5 != 0 || myCards.size() / 5 < 2) {
			return 0;
		}
		// 澶嶅埗涓€鎵嬬墝杩涜妫€鏌?
		List<Poker> cards = new ArrayList<Poker>();
		for (int i = 0; i < myCards.size(); ++i) {
			cards.add(myCards.get(i));
		}

		List<Poker> del = new ArrayList<Poker>();

		for (int i = 0; i < cards.size(); i++) {
			// 濡傛灉鍙嚭鐝句竴娆?
			int count = numberCount(cards.get(i).getValue(), cards);
			if (count == 1) {
				return 0;
				// wangCount = wangCount +cards.get(i).getValue();
			} else if (count == 2) {
				del.add(myCards.get(i));
				del.add(myCards.get(i + 1));
				++i;
			} else if (count == 4) {
				del.add(myCards.get(i));
				del.add(myCards.get(i + 1));
				del.add(myCards.get(i + 2));
				del.add(myCards.get(i + 3));
				i = i + 3;
			}
		}

		for (int i = 0; i < del.size(); i++) {
			// System.out.println(del.get(i));

			cards.remove(del.get(i));
		}

		if (cards.size() % 3 != 0 || cards.size() / 3 < 2 || cards.size() / 3 != del.size() / 2) {
			return 0;
		}

		for (int i = 0; i < cards.size() - 3; i = i + 3) {
			if (cards.get(i).getValue() - 1 != cards.get(i + 3).getValue()) {
				return 0;
			}
			if (cards.get(i).getValue() > 14) {
				return 0;
			}
		}

		return cards.get(0).getValue();

	}

	/**
	 * 妫€娴嬫槸涓嶆槸椋炴満
	 * 
	 * @param cards
	 * @return
	 */
	public static boolean checkFeiji(List<Poker> cards) {

		int count = 1;
		int size = cards.size();
		// 濡傛灉鏄鏈轰笉甯?
		if (size % 3 == 0) {
			for (int i = 0; i < cards.size() - 3; i += 3) {
				// 鎺掗櫎2鍜岀帇
				if (cards.get(i).getValue() == 16 || cards.get(i).getValue() == 17 || cards.get(i).getValue() == 15) {
					return false;
				} else {
					if (cards.get(i).getValue() - 1 == cards.get(i + 3).getValue() && cards.get(i).getValue() == cards.get(i + 1).getValue()
							&& cards.get(i).getValue() == cards.get(i + 2).getValue()) {
						count++;
					} else {
						return false;
					}
				}
			}
			// 妫€鏌ユ渶鍚庣殑鍑犲紶鐗屾槸鍚︿竴鑷?
			if (cards.get(cards.size() - 1).getValue() == cards.get(cards.size() - 2).getValue()
					&& cards.get(cards.size() - 1).getValue() == cards.get(cards.size() - 3).getValue() && count == size / 3) {
				return true;
			}

		}
		return false;

	}

	/**
	 * 妫€娴嬫槸涓嶆槸鍥涘甫涓ゅ
	 * 
	 * @param cards
	 * @return
	 */
	public static boolean checkSidai2dui(List<Poker> cards) {

		if (getPokeCount(cards) == 4 && cards.get(4).getValue() == cards.get(5).getValue() && cards.get(6).getValue() == cards.get(7).getValue()) {
			return true;
		}
		return false;
	}

	//
	/**
	 * 缁熻涓€鎵嬬墝涓悓鍊肩殑鐗屽嚭鐜扮殑娆℃暟鏉ュ垽鏂槸瀵圭墝,涓夐『,涓夊甫涓€,鐐稿脊,鍥涗唬浜岀瓑
	 * 
	 * @param cards
	 * @return
	 */
	public static int getPokeCount(List<Poker> cards) {
		int count = 1;
		int maxcount = 1;
		int nowvalue = cards.get(0).getValue(); // 鍏堝彇寰楃涓€涓墝鐨勫€?
		for (int i = 0; i < cards.size() - 1; i++) {
			if (nowvalue == cards.get(i + 1).getValue()) {// 濡傛灉鐩稿悓count++锛屼笉鍚屾敼鍙榥owvalue鍊?
				count++;
			} else {
				nowvalue = cards.get(i + 1).getValue();
				if (maxcount < count)
					maxcount = count;
				count = 1;
			}
		}
		if (maxcount > count) {
			return maxcount;
		} else {
			return count;
		}
	}

	//
	/**
	 * 灏嗙墝鎺掑簭浠庡皬鍒板ぇ
	 * 
	 * @param cards
	 * @param poker
	 * @return
	 */
	public static int[] sort(int[] cards, Poker[] poker) {
		if (null == poker || null == cards) {
			return null;
		}
		int zhi[] = new int[cards.length];
		Number[] num = new Number[cards.length];
		// * 鍐掓场鎺掑簭
		for (int i = 0; i < cards.length; i++) {
			num[i] = new Number();
			num[i].setValue(poker[cards[i]].getValue() * 100 + poker[cards[i]].getStyle());
			num[i].setPokerNumber(cards[i]);
			zhi[i] = poker[cards[i]].getValue();
		}

		for (int i = 0; i < num.length; i++) {
			for (int j = i + 1; j < num.length; j++) {
				if (num[i].getValue() < num[j].getValue()) {
					Number a = num[i];
					num[i] = num[j];
					num[j] = a;
				}
			}
		}
		for (int i = 0; i < num.length; i++) {
			zhi[i] = num[i].getPokerNumber();
		}
		return zhi;
	}
}