import java.util.Arrays;
import java.util.Scanner;
public class ZJH
  {
static int duzi = 10000;
 static String[] style = {"三条","同花顺","同花","顺子","对子","单张"};
 static String[] huase = {"红心","黑桃","方块","梅花"};
 static String[] dianshu = {"A","K","Q","J","10","9","8","7","6","5","4","3","2"};
public static void main(String[] args)
 {
Scanner sca = new Scanner(System.in);
int duzhu = 0;
System.out.println("砸金花游戏开始!");
String[][] pai = new String[3][2];//三张牌,每个牌不同花色
while(duzi>0) //
 {
System.out.println("当前您的赌资为:"+duzi);
System.out.print("(A为您的牌,B为电脑)输入赌注:输入0时退出: ");
duzhu = sca.nextInt();
if(duzhu==0)
 {
System.exit(0);
}
if(duzhu<0 || duzhu > duzi)
 {
System.out.println("您输入赌注有问题!");
continue;
}
if(iswin())
 {
duzi += duzhu;
System.out.println("win");
}
else
 {
duzi -= duzhu;
System.out.println("lose");
}
}
System.out.println("赌博有害健康!");
}
static public boolean iswin()//状态依次为:8,7,6,4,3,2,1
 {
int[][] a = new int[3][2];//存放A B两副牌
int[][] b = new int[3][2];
int sab[] = new int[6];//存放随机数
int i=0,j=0,x;//循环变量i.j x为随机数
outer:for(i=0 ; i<6 ;i++)//产生6个互异的随机数
 {
x = (int)(Math.random()*100)%52;
for(j=i-1 ; j>=0 ; j--)
 {
if(sab[j]==x)
 {
i--;
continue outer;
}
}
sab[i] = x;
}
a[0][0] = sab[0]%13;//对应点数
a[0][1] = sab[0]/13;//对应花色
a[1][0] = sab[1]%13;
a[1][1] = sab[1]/13;
a[2][0] = sab[2]%13;
a[2][1] = sab[2]/13;
b[0][0] = sab[3]%13;
b[0][1] = sab[3]/13;
b[1][0] = sab[4]%13;
b[1][1] = sab[4]/13;
b[2][0] = sab[5]%13;
b[2][1] = sab[5]/13;
int astyle,bstyle;
astyle = bstyle = 0;
String stra = "A:";
String strb = "B:";
for(i=0 ; i<3 ; i++)
 {
stra += huase[a[i][1]]+"\'"+dianshu[a[i][0]]+"\'"+" ";
strb += huase[b[i][1]]+"\'"+dianshu[b[i][0]]+"\'"+" ";
}
//计算样式10为三条 7为同花顺 6为同花对 3为顺子 2为对子 0为单条
astyle = santiao(a)+tonghua(a)+shunzi(a)+duizi(a);
bstyle = santiao(b)+tonghua(b)+shunzi(b)+duizi(b);
System.out.println(stra+"\t"+style(astyle));//打印A B 牌和样式
System.out.println(strb+"\t"+style(bstyle));
if(astyle>bstyle)//样式大的一定大
 {
return true;
}
else if(astyle<bstyle)//小的一定小
 {
return false;
}
else//相等的需要判断
 {
if(astyle==2 || astyle==6)//带对子的情况比较复杂
 {
a = caiduizi(a);//第一个是对子 第二个是单张
b = caiduizi(b);
for(i=0 ; i<2 ; i++)
 {
if(a[i][0]<b[i][0])
return true;
else if(a[i][0]==b[i][0])
continue;
else
return false;
}
if(a[1][1]<b[1][1])//如果对子和单张都相等比较单张花色
return true;
}
else //其他情况都为单张相同即看最大的那个
 {
a = sort(a);
b = sort(b);
for(i=0 ; i<3 ;i++)
 {
if(a[i][0]<b[i][0])
return true;
else if(a[i][0]==b[i][0])
continue;
else
return false;
}
if(a[0][1]<b[0][1])
return true;
}
}
return false;
}
static int[][] caiduizi(int[][] a)
 {
if(a[0][0]==a[1][0])
 {
a[1][0] = a[1][0]^a[2][0];
a[2][0] = a[1][0]^a[2][0];
a[1][0] = a[1][0]^a[2][0];
a[1][1] = a[1][1]^a[2][1];
a[2][1] = a[1][1]^a[2][1];
a[1][1] = a[1][1]^a[2][1];
}
else if(a[0][0]==a[2][0])
 {
return a;
}
else
 {
a[0][0] = a[0][0]^a[2][0];
a[2][0] = a[0][0]^a[2][0];
a[0][0] = a[0][0]^a[2][0];
a[0][1] = a[0][1]^a[2][1];
a[2][1] = a[0][1]^a[2][1];
a[0][1] = a[0][1]^a[2][1];
}
return a;
}
static int[][] sort(int[][] a)
 {
for(int i=0 ; i<3 ; i++)
 {
for(int j=i+1 ; j<3 ; j++)
 {
if(a[i][0]>a[j][0])
 {
a[i][0] = a[i][0]^a[j][0];
a[j][0] = a[i][0]^a[j][0];
a[i][0] = a[i][0]^a[j][0];
a[i][1] = a[i][1]^a[j][1];
a[j][1] = a[i][1]^a[j][1];
a[i][1] = a[i][1]^a[j][1];
}
}
}
return a;
}
static int santiao(int[][] a)
 {
if(a[0][0]==a[1][0] && a[0][0]==a[2][0] && a[1][0]==a[2][0])
return 8;
return 0;
}
static int tonghua(int[][] a)
 {
if(a[0][1]==a[1][1] && a[0][1]==a[2][1] && a[1][1]==a[2][1])
return 4;
return 0;
}
static int shunzi(int[][] a)
 {
int[] b = new int[3];
b[0] = a[0][0];
b[1] = a[1][0];
b[2] = a[2][0];
Arrays.sort(b);
if((b[1]+1)==b[2] && (b[1]-1)==b[0])
return 3;
return 0;
}
static int duizi(int[][] a)
 {
if(a[0][0]==a[1][0] || a[0][0]==a[2][0] || a[1][0]==a[2][0])
return 2;
return 0;
}
static String style(int n)
 {
String str = "";
switch(n)
 {
case 2: str = "对子";break;
case 3: str = "顺子";break;
case 6: str = "同花对";break;
case 7: str = "同花顺";break;
case 8: str = "三条";break;
default:
str = "单张";
}
return str;
}
}
|
|
|
| 日 | 一 | 二 | 三 | 四 | 五 | 六 |
---|
31 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 |
|
导航
统计
常用链接
留言簿
随笔档案
搜索
最新评论

阅读排行榜
评论排行榜
|
|