当前位置: 首页 > >

Java 扑克洗牌

Java 扑克洗牌程序 :
public class fapai {

public static void main(String[] args){
System.out.println("Write by of NO.043 class of Software Engineering!");
System.out.println("Student Number:200426630305.");
///////////////////数组生成
String[] Real={"红A","红2","红3","红4","红5","红6","红7","红8","红9","红10","红J","红Q","红K",
"方A","方2","方3","方4","方5","方6","方7","方8","方9","方10","方J","方Q","方K",
"黑A","黑2","黑3","黑4","黑5","黑6","黑7","黑8","黑9","黑10","黑J","黑Q","黑K",
"草A","草2","草3","草4","草5","草6","草7","草8","草9","草10","草J","草Q","草K","小王","大王"};
////////////////////辅助数组
int[] All=new int[54];
for(int i=0;i<54;i++){
All[i]=i+1;
}
//////////////////洗牌
int n=0;
while(n!=100)
{
int ran1=(int)(Math.random()*54);
int ran2=(int)(Math.random()*54);
int a;
a=All[ran1];
All[ran1]=All[ran2];
All[ran2]=a;
n++;
}
//////////////////打印洗过的牌
System.out.print("洗过的整牌:");
for(int i=0;i<All.length;i++){
System.out.print(Real[All[i]-1]+" ");
if((i+1)%12==0){
System.out.println();
System.out.print(" ");
}
}
System.out.println();
System.out.println();
//////////////////四玩家的牌
int[] East=new int[12];
int[] South=new int[12];
int[] West=new int[12];
int[] North=new int[12];
for(int i=0;i<12;i++){
East[i]=All[4*i];
North[i]=All[4*i+1];
West[i]=All[4*i+2];
South[i]=All[4*i+3];
}
//////////////////庄家的牌
int[] Zhuang=new int[18];
int r=(int)(Math.random()*4);
switch(r){
case 0:
System.arraycopy(East,0,Zhuang,0,12);
System.arraycopy(All,48,Zhuang,12,6);
break;
case 1:
System.arraycopy(South,0,Zhuang,0,12);
System.arraycopy(All,48,Zhuang,12,6);
break;
case 2:
System.arraycopy(West,0,Zhuang,0,12);
System.arraycopy(All,48,Zhuang,12,6);
break;
case 3:
System.arraycopy(North,0,Zhuang,0,12);
System.arraycopy(All,48,Zhuang,12,6);
break;
}
//////////////////排序
fapai.taxis(East);
fapai.taxis(South);
fapai.taxis(West);
fapai.taxis(North);
//////////////////排庄家牌
fapai.taxis(Zhuang);
/////////////////输出
switch(r){
case 0:
System.out.print("东庄:");
fapai.print(Real,Zhuang);
System.out.print("南: ");
fapai.print(Real,South);
System.out.print("西: ");
fapai.print(Real,West);
System.out.print("北: ");
fapai.print(Real,North);
break;
case 1:
System.out.print("东: ");
fapai.print(Real,East);
System.out.print("南庄:");
fapai.print(Real,Zhuang);
System.out.print("西: ");
fapai.print(Real,West);
System.out.print("北: ");
fapai.print(Real,North);
break;
case 2:
System.out.print("东: ");
fapai.print(Real,East);
System.out.print("南: ");
fapai.print(Real,South);
System.out.print("西庄:");
fapai.print(Real,Zhuang);
System.out.print("北: ");
fapai.print(Real,North);
break;
case 3:
System.out.print("东: ");
fapai.print(Real,East);
System.out.print("南: ");
fapai.print(Real,South);
System.out.print("西: ");
fapai.print(Real,West);
System.out.print("北庄: ");
fapai.print(Real,Zhuang);
break;
}
}
public static void print(String arrfrom[],int arr[]){
for(int i=0;i<arr.length;i++){
System.out.print(arrfrom[arr[i]-1]+" ");
}
System.out.println();
}
public static void taxis(int arr[]){
for(int p=0;p<arr.length-1;p++){
for(int i=0;i<arr.length-1;i++){
if(arr[i+1]<arr[i]){
int t;
t=arr[i];
arr[i]=arr[i+1];
arr[i+1]=t;
}
}
}
}
}




友情链接: year2525网 工作范文网 QS-ISP 138资料网 528200 工作范文网 baothai 表格模版