Landlords and landlords

Source: Internet
Author: User

Landlords and landlords

Some card-type definitions in the game, without too much explanation code is very detailed, can leave a message to ask?

Public enum DDZPaiType {
HuoJian ("Rocket", 30, "HuoJian "),
ZhaDan ("bomb", 20, "ZhaDan "),
DanPai ("Single Card", 10, "DanPai "),
DuiPai ("cards", 10, "DuiPai "),
SanZhangPai ("three cards", 10, "SanZhangPai "),
SanDaiYi ("Three Belts and one", 10, "SanDaiYi "),
SanDaiEr ("Three-belt two", 10, "SanDaiEr "),
DanShun ("DanShun", 10, "DanShun "),
ShuangShun ("ShuangShun", 10, "ShuangShun "),
SanShun ("SanShun", 10, "SanShun "),
FeiJiDaiDanPai ("aircraft with two tickets", 10, "FeiJiDaiDanPai "),
FeiJiDaiDuiZi ("aircraft with two pairs", 10, "FeiJiDaiDuiZi "),
SiDaiLiangDan ("Four with two tickets", 10, "SiDaiLiangDan "),
SiDaiLiangDui ("Four with two pairs", 10, "SiDaiLiangDui ");
Private String name;
Private String nickName;
Private int weight;
Private int size;

DDZPaiType (String name, int weight, String nickName ){
This. name = name;
This. weight = weight;
This. nickName = nickName;
}

@ Override
Public String toString (){
Return name;
}

Public String getName (){
Return name;
}

Public int getWeight (){
Return weight;
}
Public int getSize (){
Return size;
}
Public void setSize (int size ){
This. size = size;
}

Public String getNickName (){
Return nickName;
}

Public void setNickName (String nickName ){
This. nickName = nickName;
}

/**
* Obtain the card type
* @ Param pokers
* @ Return
* @ Return
* March January 27, 2018
* @ Throws ZJHPokerException
*/
Public static DDZPaiType getPaiType (DDZPai ddzPai) throws DDZPokerException {
List <DDZPoker> pokers = ddzPai. getDdzPokers ();
Collections. sort (pokers );
// Collections. sort (pokers );
If (isHuoJian (pokers )){
DdzPai. setDdzPoker (pokers. get (0 ));
Return HuoJian;
}
If (isZhaDan (pokers )){
DdzPai. setDdzPoker (pokers. get (0 ));
Return ZhaDan;
}
If (isDanPai (pokers )){
DdzPai. setDdzPoker (pokers. get (0 ));
Return DanPai;
}
If (isDuiZi (pokers )){
DdzPai. setDdzPoker (pokers. get (0 ));
Return DuiPai;
}
If (isSanZhangPai (pokers )){
DdzPai. setDdzPoker (pokers. get (0 ));
Return SanZhangPai;
}
If (isSanDaiYi (pokers, ddzPai )){
Return SanDaiYi;
}
If (isSanDaiEr (pokers, ddzPai )){
Return SanDaiEr;
}
If (isDanShun (pokers )){
DdzPai. setDdzPoker (pokers. get (0 ));
Return DanShun;
}
If (isShuangShun (pokers )){
DdzPai. setDdzPoker (pokers. get (0 ));
Return ShuangShun;
}
If (isSanShun (pokers )){
DdzPai. setDdzPoker (pokers. get (0 ));
Return SanShun;
}
If (isFeiJiDaiLiangDan (pokers, ddzPai )){
Return FeiJiDaiDanPai;
}
If (isFeiJiDaiLiangDui (pokers, ddzPai )){
Return FeiJiDaiDuiZi;
}
If (isSiDaiLiangDan (pokers, ddzPai )){
Return SiDaiLiangDan;
}
If (isSiDaiLiangDui (pokers, ddzPai )){
Return SiDaiLiangDui;
}
Return null;
}
// Ticket
Private static boolean isDanShun (List <DDZPoker> pokers ){
If (pokers. size ()> = 5 ){
If (pokers. get (0). getSize ()> = 15 ){
Return false;
}
For (int I = 0; I <pokers. size (); I ++ ){
If (I <pokers. size ()-1 & pokers. get (I). getSize ()-pokers. get (I + 1). getSize ()! = 1 ){
Return false;
}
}

Return true;
}
Return false;
}
// Four with two pairs
Private static boolean isSiDaiLiangDui (List <DDZPoker> pokers, DDZPai ddzPai ){
If (pokers. size () = 8 ){
Int count1 = 0;
Int count2 = 0;
DDZPoker ddzPoker = new DDZPoker ();
For (int I = 0; I <pokers. size (); I ++ ){
Int num = 0;
For (int j = 0; j <pokers. size (); j ++ ){
If (pokers. get (j). getPokerNum () = pokers. get (I). getPokerNum ()){
Num ++;
}
}
If (num = 4 ){
DdzPoker = pokers. get (I );
Count1 ++;
}
If (num = 2 ){
Count2 ++;
}
}
If (count1 = 4 & count2 = 4 ){
DdzPai. setDdzPoker (ddzPoker );
Return true;
}
}
Return false;
}

// Four with two tickets
Private static boolean isSiDaiLiangDan (List <DDZPoker> pokers, DDZPai ddzPai ){
If (pokers. size () = 6 ){
Int count1 = 0;
DDZPoker ddzPoker = new DDZPoker ();
For (int I = 0; I <pokers. size (); I ++ ){
Int num = 0;
For (int j = 0; j <pokers. size (); j ++ ){
If (pokers. get (j). getPokerNum () = pokers. get (I). getPokerNum ()){
Num ++;
}
}
If (num = 4 ){
DdzPoker = pokers. get (I );
Count1 ++;
}
}
If (count1 = 4 ){
DdzPai. setDdzPoker (ddzPoker );
Return true;
}
}
Return false;
}

// Aircraft band pair
Private static boolean isFeiJiDaiLiangDui (List <DDZPoker> pokers, DDZPai ddzPai ){
If (pokers. size () >=10 & pokers. size () % 5 = 0 ){
Int count1 = 0;
Int count2 = 0;
List <DDZPoker> ddzPokers = new ArrayList <DDZPoker> ();
For (int I = 0; I <pokers. size (); I ++ ){
Int num = 0;
For (int j = 0; j <pokers. size (); j ++ ){
If (pokers. get (j). getPokerNum () = pokers. get (I). getPokerNum ()){
Num ++;
}
}
If (num = 3 ){
Count1 ++;
DdzPokers. add (pokers. get (I ));
}
If (num = 2 ){
Count2 ++;
}
}
Collections. sort (ddzPokers );
If (count1 = (pokers. size ()/5) * 3 & count2 = (pokers. size ()/5) * 2
& DdzPokers. get (0). getSize () <15 &&
DdzPokers. get (0). getSize ()-ddzPokers. get (ddzPokers. size ()-1). getSize ()
= (Pokers. size ()/5)-1 ){
DdzPai. setDdzPoker (ddzPokers. get (0 ));
Return true;
}
}
Return false;
}

// Plane Waybill
Private static boolean isFeiJiDaiLiangDan (List <DDZPoker> pokers, DDZPai ddzPai ){
If (pokers. size ()> = 8 & pokers. size () % 4 = 0 ){
Int count = 0;
List <DDZPoker> ddzPokers = new ArrayList <DDZPoker> ();
For (int I = 0; I <pokers. size (); I ++ ){
Int num = 0;
For (int j = 0; j <pokers. size (); j ++ ){
If (pokers. get (j). getPokerNum () = pokers. get (I). getPokerNum ()){
Num ++;
}
}
If (num = 3 ){
Count ++;
DdzPokers. add (pokers. get (I ));
}
}
// Determine the four-to-two pair
If (ddzPokers. size ()> 0 & ddzPokers. get (0). getSize () <15 ){
If (count = (pokers. size ()/4) * 3 ){
Collections. sort (ddzPokers );
If (ddzPokers. get (0 ). getSize ()-ddzPokers. get (ddzPokers. size ()-1 ). getSize () = (pokers. size ()/4-1 )){
DdzPai. setDdzPoker (ddzPokers. get (0 ));
Return true;
} Else {
Return false;
}
}
}
}
Return false;
}

// Sanshun
Private static boolean isSanShun (List <DDZPoker> pokers ){
If (pokers. size () % 3 = 0 & pokers. size ()> = 6 ){
For (int I = 0; I <pokers. size (); I = I + 3 ){
If (pokers. get (I). getPokerNum ()! = Pokers. get (I + 2). getPokerNum ()){
Return false;
}
}
If (pokers. get (0). getSize ()> = 15 ){
Return false;
} Else {
If (pokers. get (0 ). getSize ()-pokers. get (pokers. size ()-1 ). getSize () = (pokers. size ()/3)-1 ){
Return true;
}
}
}
Return false;
}

// Shuangshun
Private static boolean isShuangShun (List <DDZPoker> pokers ){
If (pokers. size () % 2 = 0 & pokers. size ()> = 6 ){
For (int I = 0; I <pokers. size (); I = I + 2 ){
If (pokers. get (I). getPokerNum ()! = Pokers. get (I + 1). getPokerNum ()){
Return false;
}
}
If (pokers. get (0). getSize ()> = 15 ){
Return false;
} Else {
If (pokers. get (0 ). getSize ()-pokers. get (pokers. size ()-1 ). getSize () = (pokers. size ()/2)-1 ){
Return true;
}
}
}
Return false;
}

// Three-to-two
Private static boolean isSanDaiEr (List <DDZPoker> pokers, DDZPai ddzPai ){
If (pokers. size () = 5 & pokers. get (0 ). getPokerNum () = pokers. get (pokers. size ()-3 )). getPokerNum ()&&
Pokers. get (3). getPokerNum () = pokers. get (4). getPokerNum ()){
DdzPai. setDdzPoker (pokers. get (0 ));
Return true;
}
If (pokers. size () = 5 & pokers. get (2 ). getPokerNum () = pokers. get (pokers. size ()-1 )). getPokerNum ()&&
Pokers. get (0). getPokerNum () = pokers. get (1). getPokerNum ()){
DdzPai. setDdzPoker (pokers. get (2 ));
Return true;
}
Return false;
}

// Three-belt-one
Private static boolean isSanDaiYi (List <DDZPoker> pokers, DDZPai ddzPai ){
If (pokers. size () = 4 & pokers. get (0 ). getPokerNum () = pokers. get (pokers. size ()-2 )). getPokerNum ()){
DdzPai. setDdzPoker (pokers. get (0 ));
Return true;
}
If (pokers. size () = 4 & pokers. get (1 ). getPokerNum () = pokers. get (pokers. size ()-1 )). getPokerNum ()){
DdzPai. setDdzPoker (pokers. get (1 ));
Return true;
}
Return false;
}

// Three cards
Private static boolean isSanZhangPai (List <DDZPoker> pokers ){
If (pokers. size () = 3 & pokers. get (0 ). getPokerNum () = pokers. get (pokers. size ()-1 )). getPokerNum ()){
Return true;
}
Return false;
}

// Child
Private static boolean isDuiZi (List <DDZPoker> pokers ){
If (pokers. size () = 2 & pokers. get (0 ). getPokerNum () = pokers. get (pokers. size ()-1 )). getPokerNum ()){
Return true;
}
Return false;
}
// Single card
Private static boolean isDanPai (List <DDZPoker> pokers ){
If (pokers. size () = 1 ){
Return true;
}
Return false;
}
// Bomb
Private static boolean isZhaDan (List <DDZPoker> pokers ){
If (pokers. size () = 4 & pokers. get (0 ). getPokerNum () = pokers. get (pokers. size ()-1 )). getPokerNum ()){
Return true;
}
Return false;
}
// Wang fried
Private static boolean isHuoJian (List <DDZPoker> pokers ){
If (pokers. size () = 2 & pokers. get (0 ). getPokerNum () = PokerNum. p_DAWANG & pokers. get (pokers. size ()-1 ). getPokerNum () = PokerNum. p_XIAOWANG ){
Return true;
}
Return false;
}
// Test Method
Public static void main (String [] args ){
List <DDZPoker> pokers = new ArrayList <DDZPoker> ();
// Pokers. add (new DDZPoker (new Poker (PokerColorType. FANG_KUAI, PokerNum. P_J )));
// Pokers. add (new DDZPoker (new Poker (PokerColorType. FANG_KUAI, PokerNum. P_Q )));
// Pokers. add (new DDZPoker (new Poker (PokerColorType. FANG_KUAI, PokerNum. P_10 )));
// Pokers. add (new DDZPoker (new Poker (PokerColorType. FANG_KUAI, PokerNum. P_A )));
// Pokers. add (new DDZPoker (new Poker (PokerColorType. FANG_KUAI, PokerNum. P_K )));

// Pokers. add (new DDZPoker (new Poker (PokerColorType. WANG, PokerNum. P_DAWANG )));
// Pokers. add (new DDZPoker (new Poker (PokerColorType. WANG, PokerNum. P_XIAOWANG )));

Pokers. add (new DDZPoker (new Poker (PokerColorType. MEI_HUA, PokerNum. P_4 )));
Pokers. add (new DDZPoker (new Poker (PokerColorType. MEI_HUA, PokerNum. P_5 )));
Pokers. add (new DDZPoker (new Poker (PokerColorType. FANG_KUAI, PokerNum. P_6 )));
Pokers. add (new DDZPoker (new Poker (PokerColorType. MEI_HUA, PokerNum. P_7 )));
Pokers. add (new DDZPoker (new Poker (PokerColorType. FANG_KUAI, PokerNum. P_8 )));

Collections. sort (pokers );
DDZPai ddzPai = new DDZPai ();
Boolean flage = isDanShun (pokers );
System. out. println (ddzPai. toString ());
For (int I = 0; I <pokers. size (); I ++ ){
DDZPoker poker = pokers. get (I );
System. out. println (poker. getSize ());

}
System. out. println (flage );
}

}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.