Three people tie golden flowers, showing the biggest one

Today, I suddenly thought that when comparing three single sheets, I can use three sorted integer arrays to synthesize strings and then convert them into integers to compare the size. For three single cards, the larger the integer number, the larger the card type.

//I just tested it again and found that most of the cases are right, but there is still a high chance of being wrong. For example, one person's card is 12 10 5 and the other person's card is 13 2 3. The number of integers must be the largest of the former, but the card type is the largest of the latter, so this method still does not work.

import java.lang.reflect.Array;
import java.util.Arrays;
public class zhajinhua {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Shuffle.xipai();
		Shuffle.fapai();
		Shuffle a=new Shuffle();
		Shuffle b=new Shuffle();
		Shuffle c=new Shuffle();
		ax(a.player1,"player one");
		a.zhuanhuan(a.playerpuke);
		a.paixing(a.playerhuase, a.playerpukeint1);
		bx(b.player2, "Player 2");
		b.zhuanhuan(b.playerpuke);
		b.paixing(b.playerhuase, b.playerpukeint1);
		cx(c.player3, "Player 3");
		c.zhuanhuan(c.playerpuke);
		c.paixing(c.playerhuase, c.playerpukeint1);
		Shuffle.bijiao(a.paixing, b.paixing, c.paixing, a.playerpukeint1, b.playerpukeint1, c.playerpukeint1,a.maxcard,b.maxcard,c.maxcard);
	}
}
class  Shuffle{
		 static int xipai;
		 static String temp;
		 static String [] allCard=new String[52];
		 static String [] huase={"Heart","Diamond","Spade","Club"};
		 static String [] puke={"A","2","3","4","5","6","7","8","9","10","J","Q","K"};
		 static int k=0;
		 static String [] player1=new String[3];//Player's hand
		 static String [] player2=new String[3];
		 static String [] player3=new String[3];
		 String [] playerhuase=new String[3];//The suit of each card in the player's hand
		 String [] playerpuke=new String[3];//The number of points for each card in the player's hand
		int[] playerpukeint1=new int[3];
		int one,two;
		int paixing;
		int maxcard;
 static void xipai(){
			
			for(int i=0;i<huase.length;i++){
				for(int j=0;j<puke.length;j++){
				allCard[k]=huase[i]+puke[j];
				k++;
				}
			}
		for(int i=0;i<52;i++){
			xipai=(int)(Math.random()*52);
			temp=allCard[i];
			allCard[i]=allCard[xipai];
			allCard[xipai]=temp;
		}
	}
static void fapai(){
		int i=0;
		for(int j=0;j<3;j++){
			player1[j]=allCard[i];
			player2[j]=allCard[i+1];
			player3[j]=allCard[i+2];
			i=i+3;
		}
		
	}
void x(String[] player,String play){
	System.out.print(play+"的牌:");
		for(int j=0;j<3;j++){
			System.out.print(player[j]+" ");
			if(player[j].length()==4){
				playerpuke[j]=player[j].substring(2, 4);
			}else{
				playerpuke[j]=player[j].substring(2, 3);
			}
			playerhuase[j]=player[j].substring(0, 2);
		}
		System.out.println();
}
void zhuanhuan(String[] puke){
		for(int i=0;i<3;i++){
			switch(puke[i]){
			case "2":
				playerpukeint1[i]=2;
				break;
			case "3":
				playerpukeint1[i]=3;
				break;
			case "4":
				playerpukeint1[i]=4;
				break;
			case "5":
				playerpukeint1[i]=5;
				break;
			case "6":
				playerpukeint1[i]=6;
				break;
			case "7":
				playerpukeint1[i]=7;
				break;
			case "8":
				playerpukeint1[i]=8;
				break;
			case "9":
				playerpukeint1[i]=9;
				break;
			case "10":
				playerpukeint1[i]=10;
				break;
			case "J":
				playerpukeint1[i]=11;
				break;
			case "Q":
				playerpukeint1[i]=12;
				break;
			case "K":
				playerpukeint1[i]=13;
				break;
			case "A":
				playerpukeint1[i]=14;
				break;
			}
			
		}
	}
void paixing(String[] playerhuase,int[] playerhuaseint1){
			Arrays.sort(playerhuaseint1);
				if(playerhuaseint1[0]==playerhuaseint1[1]&&playerhuaseint1[1]==playerhuaseint1[2]){
					paixing=6;
					maxcard=playerhuaseint1[0];
				}else if(playerhuaseint1[0]==playerhuaseint1[1]||playerhuaseint1[1]==playerhuaseint1[2]||playerhuaseint1[0]==playerhuaseint1[2]){
					paixing=2;
					for(int i=0;i<3;i++){//If it is a pair, the result of the subtraction of the two is 0.
						for(int j=i+1;j<3;j++){
							if(playerhuaseint1[i]-playerhuaseint1[j]==0){
								maxcard=playerhuaseint1[i];
							}
						}
					}
				}
				if(playerhuase[0].equals(playerhuase[1])&&playerhuase[0].equals(playerhuase[2])&&playerhuaseint1[2]-playerhuaseint1[1]==1&&playerhuaseint1[1]-playerhuaseint1[0]==1){
					paixing=5;
					maxcard=playerhuaseint1[2];
				}else if(playerhuase[0].equals(playerhuase[1])&&playerhuase[0].equals(playerhuase[2])){
					paixing=4;
					maxcard=playerhuaseint1[2];
				}else if(playerhuaseint1[2]-playerhuaseint1[1]==1&&playerhuaseint1[1]-playerhuaseint1[0]==1){
					paixing=3;
					maxcard=playerhuaseint1[2];
				}else if(playerhuaseint1[0]!=playerhuaseint1[1]&&playerhuaseint1[1]!=playerhuaseint1[2]){
					paixing=1;
					maxcard=playerhuaseint1[2];
				}
}
static void bijiao(int p1,int p2,int p3,int[] max1,int[] max2,int[] max3,int maxcard1,int maxcard2,int maxcard3){
		int[] paixing=new int[3];
		int a1,a2,a3;
		paixing[0]=p1;
		paixing[1]=p2;
		paixing[2]=p3;
		Arrays.sort(paixing);
		Arrays.sort(max1);
		a1=Integer.parseInt(String.valueOf(max1[2])+ String.valueOf(max1[1])+ String.valueOf(max1[0]));
		// Combine the array of three integers into a string and then turn it into an integer number. According to the size of this number, judge the size of the cards when all three are single.
		Arrays.sort(max2);
		a2=Integer.parseInt(String.valueOf(max2[2])+ String.valueOf(max2[1])+ String.valueOf(max2[0]));
		Arrays.sort(max3);
		a3=Integer.parseInt(String.valueOf(max3[2])+ String.valueOf(max3[1])+ String.valueOf(max3[0]));
		if(paixing[2]!=paixing[1]){
					if(p1==paixing[2]){
							System.out.println("Player wins!");
						}else if(p2==paixing[2]){
								System.out.println("Player 2 wins!");
							}else{
									System.out.println("Player wins three wins!");
								}
							}
			if(paixing[2]==paixing[1]&&paixing[1]!=paixing[0]){
				if(p1==paixing[0]){
					if(maxcard2>maxcard3){
						System.out.println("Player 2 wins!");
						}else if(maxcard3>maxcard2){
							System.out.println("Player wins three wins!");
							}else if(max2[1]>max3[1]){
								System.out.println("Player 2 wins!");
								}else if(max3[1]>max2[1]){
									System.out.println("Player wins three wins!");
									}else if(max2[0]>max3[0]){
										System.out.println("Player 2 wins!");
										}else if(max2[0]<max3[0]){
											System.out.println("Player wins three wins!");
											}else{
												System.out.println("Two people have the same card");
											}
				}else if(p2==paixing[0]){
					if(maxcard1>maxcard3){
						System.out.println("Player wins!");
						}else if(maxcard3>maxcard1){
							System.out.println("Player wins three wins!");
							}else if(max1[1]>max3[1]){
								System.out.println("Player wins!");
								}else if(max3[1]>max1[1]){
									System.out.println("Player wins three wins!");
									}else if(max1[0]>max3[0]){
										System.out.println("Player wins!");
										}else if(max1[0]<max3[0]){
											System.out.println("Player wins three wins!");
											}else{
												System.out.println("Two people have the same card");
											}
				}else{
					if(maxcard1>maxcard2){
						System.out.println("Player wins!");
						}else if(maxcard2>maxcard1){
							System.out.println("Player 2 wins!");
							}else if(max2[1]>max1[1]){
								System.out.println("Player 2 wins!");
								}else if(max1[1]>max2[1]){
									System.out.println("Player wins!");
									}else if(max2[0]>max1[0]){
										System.out.println("Player 2 wins!");
										}else if(max2[0]<max1[0]){
											System.out.println("Player wins!");
											}else{
												System.out.println("Two people have the same card");
											}
				}
			}
			if(paixing[0]==1&&paixing[1]==1&&paixing[2]==1){
				if(a1>a2&&a1>a3){
					System.out.println("Player wins!");
				}else if(a2>a1&&a2>a3){
					System.out.println("Player 2 wins!");
				}else if(a3>a2&&a3>a1){
					System.out.println("Player wins three wins!");
				}else if(a1==a2||a1==a3||a2==a3){
					System.out.println("The cards of these two people are the same size, so it doesn't count");
				}
			}
	}
}

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326761681&siteId=291194637