//以下是java程序
package org.mbox.zajinhua;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 此暂时只能2人玩
*
* */
public class ZaJinHua {
/
/ 一副扑克中的13张牌的数字
static String shu[] = new String[] { "A", "K", "Q", "J", "10", "9", "8",
"7", "6", "5", "4", "3", "2" };
// 一副扑克牌中的4种花
static String se[] = new String[] { "红桃", "黑桃", "方块", "梅花" };
// 花和数字的组合,用来判断随机牌的时候,判断前边所发的牌是否存在,且为最后所发放的牌数
static List<String> seshulist = new ArrayList<String>();
// 分别为玩家1和玩家2的牌
static List<String> pone = new ArrayList<String>();
static List<String> ptwo = new ArrayList<String>();
// 扑克牌级别集合
static String bz = "豹子";
static String ths = "同花顺";
static String th = "同花";
static String sz = "顺子";
static String dz = "对子";
static String sp = "散牌";
static String[] secarray = new String[] { bz, ths, th, sz, dz, sp };
// 随机发扑克牌
public static List<String> getListRandomseshu() {
for (int i = 0; i < 6; i++) {
getRandomseshu();
}
return seshulist;
}
// 对随机发扑克牌的处理
public static String getRandomseshu() {
String randomse = se[(int) (Math.floor(Math.random() * 10 / 3))];
String randomshu = shu[(int) (Math.floor(Math.random() * 100 / 8))];
String randomseshu = randomse + randomshu;
if (ains(randomseshu)) {
getRandomseshu();
} else {
seshulist.add(randomseshu);
}
return randomseshu;
}
// 分别分配给两个玩家
public static void pukerPk() {
for (int i = 0; i < seshulist.size(); i++) {
if (i < (seshulist.size()) / 2) {
pone.(i));
} else {
ptwo.(i));
}
}
}
// 根据长度决定取最后的几位,数字
public static String getShu(String str) {
String newstr = null;
if (4 == str.length()) {
newstr = str.substring(2, 4);
} else if (3 == str.length()) {
newstr = str.substring(2, 3);
if ("J".equals(newstr)) {
newstr = "11";
} else if ("Q".equals(newstr)) {
newstr = "12";
} else if ("K".equals(newstr)) {
newstr = "13";
} else if ("A".equals(newstr)) {
newstr = "14";
}
}
return newstr;
}
/
/ 把字符转为数字
public static int getIntShu(String str) {
return Integer.parseInt(str);
}
// 三张牌的总数之和
public static int getAllShu(List<String> list) {
int j = 0;
for (int i = 0; i < list.size(); i++) {
j = j + getIntShu((i)));
}
return j;
}
// 判断两玩家的牌牌面数字对比是否相同
public static boolean oneShuvstwoShu(List<String> shuone,
List<String> shutwo) {
boolean b = false;
List<String> onelist = new ArrayList<String>();
List<Stri
ng> twolist = new ArrayList<String>();
for (int i = 0; i < shuone.size(); i++) {
onelist.add((i)));
}
for (int i = 0; i < shutwo.size(); i++) {
twolist.add((i)));
}
if (ainsAll(twolist)) {
b = true;
} else {
b = false;
}
return b;
}
// 取得扑克牌A的花
public static String getAse(List<String> list) {
String strAse = null;
for (int i = 0; i < list.size(); i++) {
if ("14".equals((i)))) {
strAse = (i));
break;
}
}
return strAse;
}
// 获取扑克牌花
public static String getSe(String str) {
String newstr = null;
newstr = str.substring(0, 2);
return newstr;
}
// 判断三张是否为相邻的扑克牌
public static boolean isUpon(int a, int b, int c) {
boolean boo = false;
// 第一种情况
int a1 = Math.abs(a - b);
int b1 = Math.abs(b - c);
int c1 = Math.abs(a - c);
// 第二中情况
int a2 = Math.abs(b - a);
int b2 = Math.abs(a - c);
int c2 = Math.abs(b - c);
// 第三种情况
int a3 = Math.abs(b - c);
int b3 = Math.abs(c - a);
int c3 = Math.abs(b - a);
if ((a1 == 1 && b1 == 1 && c1 == 2) || (a2 == 1 && b2 == 1 && c2 == 2)
|| (a3 == 1 && b3 == 1 && c3 == 2)) {
boo = true;
return boo;
}
return boo;
}
// 判断扑克牌级别
public static Map<String, List<String>> bijiaoPuker(List<String> plist) {
Map<String, List<String>> map = new HashMap<String, List<String>>();
String a = (0));
String b = (1));
String c = (2));
int ai = Integer.parseInt(a);
int bi = Integer.parseInt(b);
int ci = Integer.parseInt(c);
java怎么编写if (a.equals(b) && a.equals(c) && b.equals(c)) {
map.put(bz, plist);
} else if (isUpon(ai, bi, ci)
&& (0)).equals((1)))
&& (1)).equals((2)))) {
map.put(ths, plist);
} else if ((0)).equals((1)))
&& (1)).equals((2)))
&& !isUpon(ai, bi, ci)) {
map.put(th, plist);
} else if (isUpon(ai, bi, ci)
&& (!(1)).equals((0)))
|| !(0)).equals((2))) || !getSe(
<(1)).equals((2))))) {
map.put(sz, plist);
} else if (ai == bi || ai == ci || bi == ci
&& (ai != bi || ai != ci || bi != ci)) {
map.put(dz, plist);
} else if (ai != bi && bi != ci && ci != ai) {
map.put(sp, plist);
}
return map;
}
// 如果玩家1和玩家2的牌面数字比较相同,则进行最大值花的判断
public static int pkMaxSe(String str) {
int j = 0;
for (int i = 0; i < se.length; i++) {
if (se[i] == str) {
j = i;
break;
}
}
return j;
}
// 对扑克牌中的数字排序
public static int[] ascList(List<String> list) {
Str
ing[] str = new String[list.size()];
String[] strarr = Array(str);
int[] intarr = new int[strarr.length];
for (int i = 0; i < strarr.length; i++) {
intarr[i] = getIntShu(getShu(strarr[i]));
}
int temp;
for (int i = 0; i < intarr.length; i++) {
for (int j = i + 1; j <= intarr.length - 1; j++) {
if (intarr[i] < intarr[j]) {
temp = intarr[i];
intarr[i] = intarr[j];
intarr[j] = temp;
}
}
}
return intarr;
}
// 获取对子中相同的数
public static int getSameShu(List<String> list) {
int temp = 0;
for (int i = 0; i < list.size() - 1; i++) {
if ((i)).equals((i + 1)))) {
temp = getIntShu((i)));
break;
}
}
if (temp == 0) {
if ((0)).equals((2)))) {
temp = getIntShu((0)));
}
}
return temp;
}
// 获取对子中对子相同,第三张牌不同的牌
public static String getNotSameSeShu(List<String> list) {
String str = null;
for (int i = 0; i < list.size(); i++) {
if (getSameShu(list) != getIntShu((i)))) {
str = (i);
break;
}
}
return str;
}
// 获取牌中最大数的花
public static String getMaxShuSe(List<String> list) {
String temp = (0));
for (int i = 0; i < list.size() - 1; i++) {
if (getIntShu(temp) < getIntShu((i + 1)))) {
temp = (i + 1));
} else {
temp = temp;
}
}
return temp;
}
// 获取最大牌中的最大数
public static int getMaxShu(List<String> list) {
int j = (0));
for (int i = 0; i < list.size() - 1; i++) {
if (j < (i + 1))) {
j = (i + 1));
}
}
return j;
}
// 根据扑克级别返回不同的int值来进行判断扑克级别大小
public static int pkSec(Map<String, List<String>> map) {
int i = 0;
String[] str = new String[map.keySet().size()];
String[] strarr = map.keySet().toArray(str);
for (int j = 0; j < strarr.length; j++) {
for (int sec = 0; sec < secarray.length; sec++) {
if (strarr[j].equals(secarray[sec])) {
i = sec;
break;
}
}
}
return i;
}
// 根据玩家1和玩家2的扑克级别以及数字和花来判断大小
public static String panduanDaxiao(Map<String, List<String>> ponemap,
Map<String, List<String>> ptwomap) {
// 根据级别判断
if (pkSec(ponemap) > pkSec(ptwomap)) {
System.out.println("玩家2胜出");
} else if (pkSec(ponemap) < pkSec(ptwomap)) {
System.out.println("玩家1胜出");
// 级别为豹子的情况下判断
} else if (pkSec(ponemap) == pkSec(ptwomap) && pkSec(ponemap) == 0) {
if (Integer.parseInt((0))) > Integer
.parseInt((0)))) {
System.out.println("玩家1胜出");
} else {
System.out.println("
玩家2胜出");
}
// 级别为同花顺的情况下判断
} else if (pkSec(ponemap) == pkSec(ptwomap) && pkSec(ponemap) == 1) {
if (getAllShu(pone) == 19 && getAllShu(ptwo) != 19) {
System.out.println("玩家2胜出");
} else if (getAllShu(pone) != 19 && getAllShu(ptwo) == 19) {
System.out.println("玩家1胜出");
} else if (getAllShu(pone) == getAllShu(ptwo)
&& getAllShu(pone) == 19) {
if (pkMaxSe(getAse(pone)) > pkMaxSe(getAse(ptwo))) {
System.out.println("玩家2胜出");
} else if (pkMaxSe(getAse(pone)) < pkMaxSe(getAse(ptwo))) {
System.out.println("玩家1胜出");
}
} else if (getAllShu(pone) > getAllShu(ptwo)
&& getAllShu(pone) != 19 && getAllShu(ptwo) != 19) {
System.out.println("玩家1胜出");
} else if (getAllShu(pone) < getAllShu(ptwo)
&& getAllShu(pone) != 19 && getAllShu(ptwo) != 19) {
System.out.println("玩家2胜出");
} else if (getAllShu(pone) == getAllShu(ptwo)
&& getAllShu(pone) != 19) {
if (pkMaxSe(getMaxShuSe(pone)) > pkMaxSe(getMaxShuSe(ptwo))) {
System.out.println("玩家2获胜");
} else if (pkMaxSe(getMaxShuSe(pone)) < pkMaxSe(getMaxShuSe(ptwo))) {
System.out.println("玩家1获胜");
}
}
// 级别同花的情况进行判断
} else if (pkSec(ponemap) == pkSec(ptwomap) && pkSec(ponemap) == 2) {
if (oneShuvstwoShu(pone, ptwo)) {
if (pkMaxSe(getMaxShuSe(pone)) > pkMaxSe(getMaxShuSe(ptwo))) {
System.out.println("玩家2获胜");
} else if (pkMaxSe(getMaxShuSe(pone)) < pkMaxSe(getMaxShuSe(ptwo))) {
System.out.println("玩家1获胜");
}
} else {
if (ascList(pone)[0] > ascList(ptwo)[0]) {
System.out.println("玩家1胜出");
} else if (ascList(pone)[0] == ascList(ptwo)[0]) {
if (ascList(pone)[1] > ascList(ptwo)[1]) {
System.out.println("玩家1胜出");
} else if (ascList(pone)[1] == ascList(ptwo)[1]) {
if (ascList(pone)[2] > ascList(ptwo)[2]) {
System.out.println("玩家1胜出");
} else if (ascList(pone)[2] < ascList(ptwo)[2]) {
System.out.println("玩家2胜出");
}
} else if (ascList(pone)[1] < ascList(ptwo)[1]) {
System.out.println("玩家2胜出");
}
} else if (ascList(pone)[0] < ascList(ptwo)[0]) {
System.out.println("玩家2胜出");
}
}
// 级别是顺子的情况进行判断
} else if (pkSec(ponemap) == pkSec(ptwomap) && pkSec(ponemap) == 3) {
if (getAllShu(pone) == 19 && getAllShu(ptwo) != 19) {
System.out.println("玩家2胜出");
} else if (getAllShu(pone) != 19 && getAllShu(ptwo) == 19) {
System.out.println("玩家1胜出");
} else if (getAllShu(pone) == getAllShu(ptwo)
&& getAllShu(pone) == 19) {
if (pkMaxSe(getAse(pone)) > pkMaxSe(getAse(ptwo))) {
System.out.println("玩家2胜出");
} else if (pkMaxSe(getAse(pone)) < pkMaxSe(getAse(ptwo))) {
System.out.println("玩
家1胜出");
}
} else if (getAllShu(pone) > getAllShu(ptwo)
&& getAllShu(pone) != 19 && getAllShu(ptwo) != 19) {
System.out.println("玩家1胜出");
} else if (getAllShu(pone) < getAllShu(ptwo)
&& getAllShu(pone) != 19 && getAllShu(ptwo) != 19) {
System.out.println("玩家2胜出");
} else if (getAllShu(pone) == getAllShu(ptwo)
&& getAllShu(pone) != 19) {
if (pkMaxSe(getMaxShuSe(pone)) > pkMaxSe(getMaxShuSe(ptwo))) {
System.out.println("玩家2获胜");
} else if (pkMaxSe(getMaxShuSe(pone)) < pkMaxSe(getMaxShuSe(ptwo))) {
System.out.println("玩家1获胜");
}
}
// 级别为对子的情况下进行判断
} else if (pkSec(ponemap) == pkSec(ptwomap) && pkSec(ponemap) == 4) {
if (getSameShu(pone) > getSameShu(ptwo)) {
System.out.println("玩家1获胜");
} else if (getSameShu(pone) < getSameShu(ptwo)) {
System.out.println("玩家2获胜");
} else if (getSameShu(pone) == getSameShu(ptwo)) {
if (getIntShu(getShu(getNotSameSeShu(pone))) > getIntShu(getShu(getNotSameSeShu(ptwo)))) {
System.out.println("玩家1胜出");
} else if (getIntShu(getShu(getNotSameSeShu(pone))) < getIntShu(getShu(getNotSameSeShu(ptwo)))) {
System.out.println("玩家2胜出");
} else if (getIntShu(getShu(getNotSameSeShu(pone))) == getIntShu(getShu(getNotSameSeShu(ptwo)))) {
if (pkMaxSe(getSe(getNotSameSeShu(pone))) > pkMaxSe(getSe(getNotSameSeShu(ptwo)))) {
System.out.println("玩家2胜出");
} else {
System.out.println("玩家1胜出");
}
}
}
// 级别为散牌的进行判断
} else if (pkSec(ponemap) == pkSec(ptwomap) && pkSec(ponemap) == 5) {
if (oneShuvstwoShu(pone, ptwo)) {
if (pkMaxSe(getMaxShuSe(pone)) > pkMaxSe(getMaxShuSe(ptwo))) {
System.out.println("玩家2获胜");
} else if (pkMaxSe(getMaxShuSe(pone)) < pkMaxSe(getMaxShuSe(ptwo))) {
System.out.println("玩家1获胜");
}
} else {
if (ascList(pone)[0] > ascList(ptwo)[0]) {
System.out.println("玩家1胜出");
} else if (ascList(pone)[0] == ascList(ptwo)[0]) {
if (ascList(pone)[1] > ascList(ptwo)[1]) {
System.out.println("玩家1胜出");
} else if (ascList(pone)[1] == ascList(ptwo)[1]) {
if (ascList(pone)[2] > ascList(ptwo)[2]) {
System.out.println("玩家1胜出");
} else if (ascList(pone)[2] < ascList(ptwo)[2]) {
System.out.println("玩家2胜出");
}
} else if (ascList(pone)[1] < ascList(ptwo)[1]) {
System.out.println("玩家2胜出");
}
} else if (ascList(pone)[0] < ascList(ptwo)[0]) {
System.out.println("玩家2胜出");
}
}
}
return null;
}
public static void main(String[] args) {
for (int i = 0; i < 100; i++) {
System.out.println("第"+(i+1)+"次发牌");
getListRandomseshu();
pukerPk();
System.out.println("玩家1牌为:" + bijiaoPuker(pone));
System.

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。