package game.scene.sss.util;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import game.scene.sss.room.DDZRoomInfo;
import game.scene.sss.util.SssTypeUtil;
import mj.data.DDZUserPlace;
import mj.net.message.sss.SSSPokerInfo;
/**
* 比较两个人之间的分数,玩家的分数以三个数组的形式存放到一个list集合当中 ,把多个玩家的list集合存放到一个大的list集合当中
*
* @author pc
*
*/
public class PlayersCompareScoreUtil {
private static SssTypeUtil stu = new SssTypeUtil();
/**
* 提供给外界的接口,用于获取每个玩家的得分,DDZUserPlace主要获取三墩牌信息,这个地方需要自己的传值, mapaiIndex存放的是拥有马牌的坐标,这个大部分十三水都有。key=0,value为玩家的分。key=1,value是玩家打枪的对象
* @param list
* @return
*/
public static Map<Integer, Map<Integer, int[]>> getPlayersScoreUtil(List<DDZUserPlace> list,
List<Integer> mapaiIndex) {
/*** 记录玩家每墩牌的得分 */
Map<Integer, int[]> map = new HashMap<>();
/*** 记录玩家打枪的次数 */
Map<Integer, Integer> count = new HashMap<>();
/*** 记录单个对象打枪的对象集合 */
Map<Integer, List<Integer>> shoots = new HashMap<>();
/*** 记录单个对象打枪的对象集合转换 */
Map<Integer, int[]> shootMap = new HashMap<>();
/*** 作为返回值 */
Map<Integer, Map<Integer, int[]>> summary = new HashMap<>();
for(DDZUserPlace userplace:list){
shoots.put(userplace.getLocataionIndex(), new ArrayList<>());
}
for (int i = 0; i < list.size(); i++) {
for (int j = i + 1; j < list.size(); j++) {
List<int[]> msg = new ArrayList<>();
List<int[]> msf = new ArrayList<>();
msg.add(list.get(i).getPokerInfo().getFirst());
msg.add(list.get(i).getPokerInfo().getSecond());
msg.add(list.get(i).getPokerInfo().getThird());
msf.add(list.get(j).getPokerInfo().getFirst());
msf.add(list.get(j).getPokerInfo().getSecond());
msf.add(list.get(j).getPokerInfo().getThird());
int onelocation = list.get(i).getLocataionIndex();
int twolocation = list.get(j).getLocataionIndex();
// 通过比较两个的牌型得到他们的牌型比较总分
List<int[]> twoPlayers = compareSpecial(msg, msf);
int playerCount[] = new int[3];
int playerCount1[] = new int[3];
/** 玩家打枪的得分 */
if (twoPlayers.get(0)[0] > twoPlayers.get(1)[0] && twoPlayers.get(0)[1] > twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] > twoPlayers.get(1)[2]) {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 2,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
count.put(onelocation, count.get(onelocation) + 1);
/** 玩家打枪对象的下标 */
shoots.get(onelocation).add(twolocation);
} else if (twoPlayers.get(0)[0] < twoPlayers.get(1)[0] && twoPlayers.get(0)[1] < twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] < twoPlayers.get(1)[2]) {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 2,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
count.put(twolocation, count.get(twolocation) + 1);
shoots.get(twolocation).add(onelocation);
} else {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 1,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}
map.put(onelocation, playerCount);
map.put(twolocation, playerCount1);
}
}
/** 全垒打的走向 */
for(DDZUserPlace userPlace:list){
if(count.get(userPlace.getLocataionIndex())==(list.size()-1)){
map.clear();
map=swatCheck(userPlace.getLocataionIndex(), list, map, mapaiIndex);
}
}
summary.put(0, map);
Iterator<Map.Entry<Integer, List<Integer>>> iter = shoots.entrySet().iterator();
while (iter.hasNext()) {
Entry<Integer, List<Integer>> map1 = iter.next();
if (map1.getValue().size() > 0) {
int array[] = new int[map1.getValue().size()];
for (int i = 0; i < map1.getValue().size(); i++) {
array[i] = map1.getValue().get(i);
}
shootMap.put(map1.getKey(), array);
} else {
shootMap.put(map1.getKey(), new int[0]);
}
}
summary.put(1, shootMap);
// 将得到的结果封装到map集合当中,key是他们的地址location,value是他们之间进行比分之后得到的最终得分
return summary;
}
/**
* 庄家模式
* @param list
* @param mapaiIndex
* @param info
* @return
*/
public static Map<Integer, Map<Integer, int[]>> getZhuangScore(List<DDZUserPlace> list,
List<Integer> mapaiIndex,DDZRoomInfo info){
/*** 记录玩家每墩牌的得分 */
Map<Integer, int[]> map = new HashMap<>();
/*** 记录玩家打枪的次数 */
Map<Integer, Integer> count = new HashMap<>();
/*** 记录单个对象打枪的对象集合 */
Map<Integer, List<Integer>> shoots = new HashMap<>();
/*** 记录单个对象打枪的对象集合转换 */
Map<Integer, int[]> shootMap = new HashMap<>();
/*** 作为返回值 */
Map<Integer, Map<Integer, int[]>> summary = new HashMap<>();
for(DDZUserPlace userplace:list){
shoots.put(userplace.getLocataionIndex(), new ArrayList<>());
}
int zhuangIndex=info.getZhuangLocation();
int zhuangBei=info.getZhuangbei();
int xianBei[]=info.getXianbei();
for(int i=0;i<list.size();i++){
if(list.get(i).getLocataionIndex()!=zhuangIndex){
List<int[]> msg = new ArrayList<>();
List<int[]> msf = new ArrayList<>();
msg.add(list.get(zhuangIndex).getPokerInfo().getFirst());
msg.add(list.get(zhuangIndex).getPokerInfo().getSecond());
msg.add(list.get(zhuangIndex).getPokerInfo().getThird());
msf.add(list.get(i).getPokerInfo().getFirst());
msf.add(list.get(i).getPokerInfo().getSecond());
msf.add(list.get(i).getPokerInfo().getThird());
List<int[]>twoPlayers=compareSpecial(msg, msf);
int playerCount[] = new int[3];
int playerCount1[] = new int[3];
int twolocation=list.get(i).getLocataionIndex();
int beisize=zhuangBei*xianBei[i];
/** 玩家打枪的得分 */
if (twoPlayers.get(0)[0] > twoPlayers.get(1)[0] && twoPlayers.get(0)[1] > twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] > twoPlayers.get(1)[2]) {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 2*beisize,mapaiIndex,zhuangIndex,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
count.put(zhuangIndex, count.get(zhuangIndex) + 1);
/** 玩家打枪对象的下标 */
shoots.get(zhuangIndex).add(twolocation);
} else if (twoPlayers.get(0)[0] < twoPlayers.get(1)[0] && twoPlayers.get(0)[1] < twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] < twoPlayers.get(1)[2]) {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 2*beisize,mapaiIndex,zhuangIndex,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
count.put(twolocation, count.get(twolocation) + 1);
shoots.get(twolocation).add(zhuangIndex);
} else {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 1*beisize,mapaiIndex,zhuangIndex,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}
map.put(zhuangIndex, playerCount);
map.put(twolocation, playerCount1);
}
}
/** 全垒打的走向 */
for(DDZUserPlace userPlace:list){
if(count.get(userPlace.getLocataionIndex())==(list.size()-1)){
map.clear();
map=swatZhuangCheck(userPlace.getLocataionIndex(), list, map, mapaiIndex, info);
}
}
summary.put(0, map);
Iterator<Map.Entry<Integer, List<Integer>>> iter = shoots.entrySet().iterator();
while (iter.hasNext()) {
Entry<Integer, List<Integer>> map1 = iter.next();
if (map1.getValue().size() > 0) {
int array[] = new int[map1.getValue().size()];
for (int i = 0; i < map1.getValue().size(); i++) {
array[i] = map1.getValue().get(i);
}
shootMap.put(map1.getKey(), array);
} else {
shootMap.put(map1.getKey(), new int[0]);
}
}
summary.put(1, shootMap);
// 将得到的结果封装到map集合当中,key是他们的地址location,value是他们之间进行比分之后得到的最终得分
return summary;
}
/***
* 看牌下注
*/
public static Map<Integer, Map<Integer, int[]>> getSeePokerScore(List<DDZUserPlace> list,
List<Integer> mapaiIndex,DDZRoomInfo info){
/*** 记录玩家每墩牌的得分 */
Map<Integer, int[]> map = new HashMap<>();
/*** 记录玩家打枪的次数 */
Map<Integer, Integer> count = new HashMap<>();
/*** 记录单个对象打枪的对象集合 */
Map<Integer, List<Integer>> shoots = new HashMap<>();
/*** 记录单个对象打枪的对象集合转换 */
Map<Integer, int[]> shootMap = new HashMap<>();
/*** 作为返回值 */
Map<Integer, Map<Integer, int[]>> summary = new HashMap<>();
for(DDZUserPlace userplace:list){
shoots.put(userplace.getLocataionIndex(), new ArrayList<>());
}
//闲家的倍数
int xianBei[]=info.getXianbei();
for (int i = 0; i < list.size(); i++) {
for (int j = i + 1; j < list.size(); j++) {
List<int[]> msg = new ArrayList<>();
List<int[]> msf = new ArrayList<>();
msg.add(list.get(i).getPokerInfo().getFirst());
msg.add(list.get(i).getPokerInfo().getSecond());
msg.add(list.get(i).getPokerInfo().getThird());
msf.add(list.get(j).getPokerInfo().getFirst());
msf.add(list.get(j).getPokerInfo().getSecond());
msf.add(list.get(j).getPokerInfo().getThird());
int onelocation = list.get(i).getLocataionIndex();
int twolocation = list.get(j).getLocataionIndex();
// 通过比较两个的牌型得到他们的牌型比较总分
List<int[]> twoPlayers = compareSpecial(msg, msf);
int playerCount[] = new int[3];
int playerCount1[] = new int[3];
int maxbei=info.getXianbei()[onelocation]*info.getXianbei()[twolocation];
/** 玩家打枪的得分 */
if (twoPlayers.get(0)[0] > twoPlayers.get(1)[0] && twoPlayers.get(0)[1] > twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] > twoPlayers.get(1)[2]) {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 2*maxbei,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
count.put(onelocation, count.get(onelocation) + 1);
/** 玩家打枪对象的下标 */
shoots.get(onelocation).add(twolocation);
} else if (twoPlayers.get(0)[0] < twoPlayers.get(1)[0] && twoPlayers.get(0)[1] < twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] < twoPlayers.get(1)[2]) {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 2*maxbei,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
count.put(twolocation, count.get(twolocation) + 1);
shoots.get(twolocation).add(onelocation);
} else {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 1*maxbei,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}
map.put(onelocation, playerCount);
map.put(twolocation, playerCount1);
}
}
/** 全垒打的走向 */
for(DDZUserPlace userPlace:list){
if(count.get(userPlace.getLocataionIndex())==(list.size()-1)){
map.clear();
map=swatCheck(userPlace.getLocataionIndex(), list, map, mapaiIndex);
}
}
summary.put(0, map);
Iterator<Map.Entry<Integer, List<Integer>>> iter = shoots.entrySet().iterator();
while (iter.hasNext()) {
Entry<Integer, List<Integer>> map1 = iter.next();
if (map1.getValue().size() > 0) {
int array[] = new int[map1.getValue().size()];
for (int i = 0; i < map1.getValue().size(); i++) {
array[i] = map1.getValue().get(i);
}
shootMap.put(map1.getKey(), array);
} else {
shootMap.put(map1.getKey(), new int[0]);
}
}
summary.put(1, shootMap);
// 将得到的结果封装到map集合当中,key是他们的地址location,value是他们之间进行比分之后得到的最终得分
return summary;
}
/***
* 出现全垒打时候,玩家的得分
*
* @param index
* @param list
* @return
*/
public static Map<Integer, int[]> swatCheck(int index, List<DDZUserPlace> list, Map<Integer, int[]> map,List<Integer> mapaiIndex) {
for (int i = 0; i < list.size(); i++) {
for (int j = i + 1; j < list.size(); j++) {
List<int[]> msg = new ArrayList<>();
List<int[]> msf = new ArrayList<>();
// 分别取出两个对象中的数组对象,放入到创建好的集合当中
msg.add(list.get(i).getPokerInfo().getFirst());
msg.add(list.get(i).getPokerInfo().getSecond());
msg.add(list.get(i).getPokerInfo().getThird());
msf.add(list.get(j).getPokerInfo().getFirst());
msf.add(list.get(j).getPokerInfo().getSecond());
msf.add(list.get(j).getPokerInfo().getThird());
int onelocation = list.get(i).getLocataionIndex();
int twolocation = list.get(j).getLocataionIndex();
// 通过比较两个的牌型得到他们的牌型比较总分
List<int[]> twoPlayers = compareTwoPlayers(msg, msf);
int playerCount[] = new int[3];
int playerCount1[] = new int[3];
/** 玩家打枪的得分 */
if (twoPlayers.get(0)[0] > twoPlayers.get(1)[0] && twoPlayers.get(0)[1] > twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] > twoPlayers.get(1)[2]) {
if(index==onelocation){
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers,4,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}else{
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 2,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}
/** 玩家打枪的得分 */
} else if (twoPlayers.get(0)[0] < twoPlayers.get(1)[0] && twoPlayers.get(0)[1] < twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] < twoPlayers.get(1)[2]) {
if(index==twolocation){
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers,4,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}else{
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 2,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}
} else {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 1,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}
map.put(i, playerCount);
map.put(j, playerCount1);
}
}
return map;
}
/****
* 庄家全垒打
* @param index
* @param list
* @param map
* @param mapaiIndex
* @return
*/
public static Map<Integer, int[]> swatZhuangCheck(int index, List<DDZUserPlace> list, Map<Integer, int[]> map,List<Integer> mapaiIndex,DDZRoomInfo info) {
int zhuangbei=info.getZhuangbei();
int xianbei[]=info.getXianbei();
for(int i=0;i<list.size();i++){
if(list.get(i).getLocataionIndex()!=index){
List<int[]> msg = new ArrayList<>();
List<int[]> msf = new ArrayList<>();
msg.add(list.get(index).getPokerInfo().getFirst());
msg.add(list.get(index).getPokerInfo().getSecond());
msg.add(list.get(index).getPokerInfo().getThird());
msf.add(list.get(i).getPokerInfo().getFirst());
msf.add(list.get(i).getPokerInfo().getSecond());
msf.add(list.get(i).getPokerInfo().getThird());
List<int[]>twoPlayers=compareSpecial(msg, msf);
int playerCount[] = new int[3];
int playerCount1[] = new int[3];
int twolocation=list.get(i).getLocataionIndex();
int allbei=zhuangbei*xianbei[i];
/** 玩家打枪的得分 */
if (twoPlayers.get(0)[0] > twoPlayers.get(1)[0] && twoPlayers.get(0)[1] > twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] > twoPlayers.get(1)[2]) {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers,4*allbei,mapaiIndex,index,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}
map.put(index, playerCount);
map.put(i, playerCount1);
}
}
return map;
}
/***
* 看牌下注的全垒打
* @param map
* @param twoPlayers
* @param bei
* @param mapaiIndex
* @param onelocation
* @param twolocation
* @return
*/
public static Map<Integer, int[]> seePaiXiaZhu(int index, List<DDZUserPlace> list, Map<Integer, int[]> map,List<Integer> mapaiIndex,DDZRoomInfo info) {
for (int i = 0; i < list.size(); i++) {
for (int j = i + 1; j < list.size(); j++) {
List<int[]> msg = new ArrayList<>();
List<int[]> msf = new ArrayList<>();
// 分别取出两个对象中的数组对象,放入到创建好的集合当中
msg.add(list.get(i).getPokerInfo().getFirst());
msg.add(list.get(i).getPokerInfo().getSecond());
msg.add(list.get(i).getPokerInfo().getThird());
msf.add(list.get(j).getPokerInfo().getFirst());
msf.add(list.get(j).getPokerInfo().getSecond());
msf.add(list.get(j).getPokerInfo().getThird());
int onelocation = list.get(i).getLocataionIndex();
int twolocation = list.get(j).getLocataionIndex();
// 通过比较两个的牌型得到他们的牌型比较总分
List<int[]> twoPlayers = compareTwoPlayers(msg, msf);
int playerCount[] = new int[3];
int playerCount1[] = new int[3];
//闲家的倍数
int xianBei[]=info.getXianbei();
int maxbei=info.getXianbei()[onelocation]*info.getXianbei()[twolocation];
/** 玩家打枪的得分 */
if (twoPlayers.get(0)[0] > twoPlayers.get(1)[0] && twoPlayers.get(0)[1] > twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] > twoPlayers.get(1)[2]) {
if(index==onelocation){
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers,4*maxbei,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}else{
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 2*maxbei,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}
/** 玩家打枪的得分 */
} else if (twoPlayers.get(0)[0] < twoPlayers.get(1)[0] && twoPlayers.get(0)[1] < twoPlayers.get(1)[1]
&& twoPlayers.get(0)[2] < twoPlayers.get(1)[2]) {
if(index==twolocation){
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers,4*maxbei,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}else{
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 2*maxbei,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}
} else {
Map<Integer, int[]>countmap=getPlayCount(map,twoPlayers, 1*maxbei,mapaiIndex,onelocation,twolocation);
playerCount = countmap.get(0);
playerCount1 =countmap.get(1);
}
map.put(i, playerCount);
map.put(j, playerCount1);
}
}
return map;
}
public static Map<Integer, int[]> getPlayCount(Map<Integer, int[]> map,List<int[]> twoPlayers,int bei,List<Integer> mapaiIndex,int onelocation,int twolocation){
Map<Integer, int[]>map1=new HashMap<>();
int playerCount[] = new int[3];
int playerCount1[] = new int[3];
if (mapaiIndex.size() > 0) {
for (int index : mapaiIndex) {
if (index == onelocation) {
playerCount[0] = map.get(onelocation)[0] + twoPlayers.get(0)[0] *2* bei;
playerCount[1] = map.get(onelocation)[1] + twoPlayers.get(0)[1] *2* bei;
playerCount[2] = map.get(onelocation)[2] + twoPlayers.get(0)[2] *2* bei;
playerCount1[0] = map.get(twolocation)[0] + twoPlayers.get(1)[0] *2* bei;
playerCount1[1] = map.get(twolocation)[1] + twoPlayers.get(1)[1] *2* bei;
playerCount1[2] = map.get(twolocation)[2] + twoPlayers.get(1)[2] *2* bei;
}
if (index == twolocation) {
playerCount[0] = map.get(onelocation)[0] + twoPlayers.get(0)[0] *2* bei;
playerCount[1] = map.get(onelocation)[1] + twoPlayers.get(0)[1] *2* bei;
playerCount[2] = map.get(onelocation)[2] + twoPlayers.get(0)[2] *2* bei;
playerCount1[0] = map.get(twolocation)[0] + twoPlayers.get(1)[0] *2* bei;
playerCount1[1] = map.get(twolocation)[1] + twoPlayers.get(1)[1] *2* bei;
playerCount1[2] = map.get(twolocation)[2] + twoPlayers.get(1)[2] *2* bei;
}
}
} else {// 只有打枪,没有马牌
playerCount[0] = map.get(onelocation)[0] + twoPlayers.get(0)[0] * bei;
playerCount[1] = map.get(onelocation)[1] + twoPlayers.get(0)[1] * bei;
playerCount[2] = map.get(onelocation)[2] + twoPlayers.get(0)[2] * bei;
playerCount1[0] = map.get(twolocation)[0] + twoPlayers.get(1)[0] * bei;
playerCount1[1] = map.get(twolocation)[1] + twoPlayers.get(1)[1] * bei;
playerCount1[2] = map.get(twolocation)[2] + twoPlayers.get(1)[2] * bei;
}
map1.put(0, playerCount);
map1.put(1, playerCount1);
return map1;
}
/**
* 通过比较两个的牌型得到他们的牌型比较总分
* @param list
* @param list1
* @return
*/
public static List<int[]> compareSpecial(List<int[]> list, List<int[]> list1){
//将所有的数全部加入到数组当中
int one[]={list.get(0)[0],list.get(0)[1],list.get(0)[2],list.get(1)[0],list.get(1)[1],list.get(1)[2]
,list.get(1)[3],list.get(1)[4],list.get(2)[0],list.get(2)[1],list.get(2)[2],list.get(2)[3],list.get(2)[4]};
int two[]={list1.get(0)[0],list1.get(0)[1],list1.get(0)[2],list1.get(1)[0],list1.get(1)[1],list1.get(1)[2]
,list1.get(1)[3],list1.get(1)[4],list1.get(2)[0],list1.get(2)[1],list1.get(2)[2],list1.get(2)[3],list1.get(2)[4]};
Arrays.sort(one);
Arrays.sort(two);
List<int[]> twoPlayers=new ArrayList<>();
//全部都是普通牌型的情况
int a=SssTypeUtil.specialTypeGetWeight(one);
int b=SssTypeUtil.specialTypeGetWeight(two);
if(a==0&&b==0){
twoPlayers = compareTwoPlayers(list, list1);
}else{
//特殊牌型的比牌 先判断出是什么样的特殊牌型
if(SssTypeUtil.specialTypeGetWeight(one)>0||SssTypeUtil.specialTypeGetWeight(two)>0){
int oneNum[] = {0,0,0};
int twoNum[] = {0,0,0};
twoPlayers.add(oneNum);
twoPlayers.add(twoNum);}
}
return twoPlayers;
}
/**
* 比较两个玩家之间的牌型得分,得出的结果是玩家一对一比较之后得出的分数
*
* @param list
* @param list1
* @return
*/
public static List<int[]> compareTwoPlayers(List<int[]> list, List<int[]> list1) {
/**
* 存放两个玩家比较牌之后各部分得分信息
*/
List<int[]> twoPlayers = new ArrayList<>();
// 首先定义两个长度为3的空数组(用于存放两个玩家三手牌比较之后的得分)
int oneNum[] = new int[3];
int twoNum[] = new int[3];
// 调用封装好的得分方法,分别获取头道,中道,尾道的得分
int tou[] = touCompare(list.get(0), list1.get(0));
int zhong[] = zhongCompare(list.get(1), list1.get(1));
int wei[] = weiCompare(list.get(2), list1.get(2));
// 获取到第一个玩家的得分
oneNum[0] = tou[0];
oneNum[1] = zhong[0];
oneNum[2] = wei[0];
// 获取到第二个玩家的得分
twoNum[0] = tou[1];
twoNum[1] = zhong[1];
twoNum[2] = wei[1];
// 返回玩家三顿牌比牌结果
twoPlayers.add(oneNum);
twoPlayers.add(twoNum);
return twoPlayers;
}
/**
* 比较玩家======>>之间头墩的得分
*
* @param pai
* @param pai1
* @return
*/
public static int[] touCompare(int pai[], int pai1[]) {
int tou[] = new int[2];
// 判断头墩三张牌的比较方法,第一中情况:当第一个玩家头墩大于第二个玩家的情形
if(stu.getPaiWeight(pai) == 5 || stu.getPaiWeight(pai1) == 5){
tou=touCompareIsSanGui(pai,pai1);
}else if (stu.getPaiWeight(pai) == 4 || stu.getPaiWeight(pai1) == 4) {
tou = touCompareIsSanTiao(pai, pai1);
} else {
tou = touCompareNotIsSanTiao(pai, pai1);
}
return tou;
}
/**
* 判断玩家======>>中墩牌型的得分
*
* @param pai
* @param pai1
* @return
*/
public static int[] zhongCompare(int pai[], int pai1[]) {
int zhong[] = new int[2];
if (stu.getSssShouPaiType(pai) == 10 || stu.getSssShouPaiType(pai1) == 10) {
zhong = zhongCompareIsTeShuType(pai, pai1, 14);
} else if (stu.getSssShouPaiType(pai) == 9 || stu.getSssShouPaiType(pai1) == 9) {
zhong = zhongCompareIsTeShuType(pai, pai1, 10);
} else if (stu.getSssShouPaiType(pai) == 8 || stu.getSssShouPaiType(pai1) == 8) {
zhong = zhongCompareIsTeShuType(pai, pai1, 8);
} else if (stu.getSssShouPaiType(pai) == 7 || stu.getSssShouPaiType(pai1) == 7) {
zhong = zhongCompareIsTeShuType(pai, pai1, 2);
} else {
zhong = zhongCompareIsOtherType(pai, pai1);
}
return zhong;
}
/**
* 判断玩家=======>尾墩牌型的得分
*
* @param pai
* @param pai1
* @return
*/
public static int[] weiCompare(int pai[], int pai1[]) {
int wei[] = new int[2];
if (stu.getSssShouPaiType(pai) == 10 || stu.getSssShouPaiType(pai1) == 10) {
wei = weiCompareIsTeShuType(pai, pai1, 7);
} else if (stu.getSssShouPaiType(pai) == 9 || stu.getSssShouPaiType(pai1) == 9) {
wei = weiCompareIsTeShuType(pai, pai1, 5);
} else if (stu.getSssShouPaiType(pai) == 8 || stu.getSssShouPaiType(pai1) == 8) {
wei = weiCompareIsTeShuType(pai, pai1, 4);
} else {
wei = zhongCompareIsOtherType(pai, pai1);
}
return wei;
}
/***
* 比较两个用户头墩是三鬼的情况
* @param pai
* @param pai1
* @return
*/
public static int[] touCompareIsSanGui(int pai[], int pai1[]){
int tou[] = new int[2];
if(stu.getPaiWeight(pai)>stu.getPaiWeight(pai1)){
tou[0]=20;
tou[1]=-20;
}else if(stu.getPaiWeight(pai)==stu.getPaiWeight(pai1)){
tou[0]=0;
tou[1]=0;
}else{
tou[0]=-20;
tou[1]=20;
}
return tou;
}
/**
* 比较两个用户头墩是三条的情况
*
* @param pai
* @param pai1
* @return
*/
public static int[] touCompareIsSanTiao(int pai[], int pai1[]) {
int tou[] = new int[2];
if (stu.getPaiWeight(pai) > stu.getPaiWeight(pai1)) {
tou[0] = 3;
tou[1] = -3;
} else if (stu.getPaiWeight(pai) == stu.getPaiWeight(pai1)) {
if (paiNum(pai[0]) > paiNum(pai1[0])) {
tou[0] = 3;
tou[1] = -3;
} else if (paiNum(pai[0]) == paiNum(pai1[0])) {
tou[0] = 0;
tou[1] = 0;
} else {
tou[0] = -3;
tou[1] = 3;
}
} else {
tou[0] = -3;
tou[1] = 3;
}
return tou;
}
/**
* 比较两个用户头墩不是三条的情况
*
* @param pai
* @param pai1
* @return
*/
public static int[] touCompareNotIsSanTiao(int pai[], int pai1[]) {
int tou[] = new int[2];
if (stu.getPaiWeight(pai) > stu.getPaiWeight(pai1)) {
tou[0] = 1;
tou[1] = -1;
// 第一个玩家和第二个玩家头墩相同的情况
} else if (stu.getPaiWeight(pai) == stu.getPaiWeight(pai1)) {
// 牌型相同-------->>对子的情形下
if (stu.getPaiWeight(pai) == 2) {
int player4[] = arrayDui(pai);
int player5[] = arrayDui(pai1);
for (int j = 0; j < 2; j++) {
if (paiNum(player4[j]) > paiNum(player5[j])) {
tou[0] = 1;
tou[1] = -1;
break;
} else if (paiNum(player4[j]) == paiNum(player5[j])) {
tou[0] = 0;
tou[1] = 0;
continue;
} else {
tou[0] = -1;
tou[1] = 1;
break;
}
}
// 牌型相同------->>不是对子的情况
} else {
// 将数组的内容全部倒序排序;
int player2[] = arraysChangeIndex(pai);
int player3[] = arraysChangeIndex(pai1);
// 遍历数组中的单个数字进行 大小比较
for (int i = 0; i < 3; i++) {
// 三种情况下的结果
if (paiNum(player2[i]) > paiNum(player3[i])) {
tou[0] = 1;
tou[1] = -1;
break;
} else if (paiNum(player2[i]) == paiNum(player3[i])) {
tou[0] = 0;
tou[1] = 0;
continue;
} else {
tou[0] = -1;
tou[1] = 1;
break;
}
}
}
// 第一个玩家小于第二个玩家手牌的情形
} else {
tou[0] = -1;
tou[1] = 1;
}
return tou;
}
/**
* 中墩=======>>特殊牌型(7.葫芦,8.铁支,9.同花顺,10.五同)
*
* @param pai
* @param pai1
* @param score
* @return
*/
public static int[] zhongCompareIsTeShuType(int pai[], int pai1[], int score) {
int zhong[] = new int[2];
if (stu.getSssShouPaiType(pai) > stu.getSssShouPaiType(pai1)) {
zhong[0] = score;
zhong[1] = -score;
} else if (stu.getSssShouPaiType(pai) == stu.getSssShouPaiType(pai1)) {
if (score == 14) {// 五同
if (paiNum(pai[0]) > paiNum(pai1[0])) {
zhong[0] = score;
zhong[1] = -score;
} else {
zhong[0] = -score;
zhong[1] = score;
}
} else if (score == 10) {// 同花顺
for (int i = 0; i < 5; i++) {
if (paiNum(arraysChangeIndex(pai)[i]) > paiNum(arraysChangeIndex(pai1)[i])) {
zhong[0] = score;
zhong[1] = -score;
break;
} else if (paiNum(arraysChangeIndex(pai)[i]) == paiNum(arraysChangeIndex(pai1)[i])) {
zhong[0] = 0;
zhong[1] = 0;
continue;
} else {
zhong[0] = -score;
zhong[1] = score;
break;
}
}
} else if (score == 8) {// 铁支
for (int i = 0; i < 2; i++) {
if (getSpecialOne(pai)[i] >getSpecialOne(pai1)[i]) {
zhong[0] = score;
zhong[1] = -score;
break;
} else if (getSpecialOne(pai)[i] == getSpecialOne(pai1)[i]) {
zhong[0] = 0;
zhong[1] = 0;
continue;
} else {
zhong[0] = -score;
zhong[1] = score;
break;
}
}
} else {// 葫芦
for (int i = 0; i < 2; i++) {
if (getSpecialTwo(pai)[i]> getSpecialTwo(pai1)[i]) {
zhong[0] = score;
zhong[1] = -score;
break;
} else if (getSpecialTwo(pai)[i]== getSpecialTwo(pai1)[i]) {
zhong[0] = 0;
zhong[1] = 0;
continue;
} else {
zhong[0] = -score;
zhong[1] = score;
break;
}
}
}
} else {
zhong[0] = -score;
zhong[1] = score;
}
return zhong;
}
/**
* 尾墩======>>特殊牌型的判断得分(8.铁支,9.同花顺,10.五同)
*
* @param pai
* @param pai1
* @param score
* @return
*/
public static int[] weiCompareIsTeShuType(int pai[], int pai1[], int score) {
int wei[] = new int[2];
if (stu.getSssShouPaiType(pai) > stu.getSssShouPaiType(pai1)) {
wei[0] = score;
wei[1] = -score;
} else if (stu.getSssShouPaiType(pai) == stu.getSssShouPaiType(pai1)) {
if (score == 10) {// 五同
if (paiNum(pai[0]) > paiNum(pai1[0])) {
wei[0] = score;
wei[1] = -score;
} else {
wei[0] = -score;
wei[1] = score;
}
} else if (score == 5) {// 同花顺
for (int i = 0; i < 5; i++) {
if (paiNum(arraysChangeIndex(pai)[i]) > paiNum(arraysChangeIndex(pai1)[i])) {
wei[0] = score;
wei[1] = -score;
break;
} else if (paiNum(arraysChangeIndex(pai)[i]) == paiNum(arraysChangeIndex(pai1)[i])) {
wei[0] = 0;
wei[1] = 0;
continue;
} else {
wei[0] = -score;
wei[1] = score;
break;
}
}
} else {// 铁支
for (int i = 0; i < 2; i++) {
if (getSpecialOne(pai)[i] > getSpecialOne(pai1)[i]) {
wei[0] = score;
wei[1] = -score;
break;
} else if (getSpecialOne(pai)[i] == getSpecialOne(pai1)[i]) {
wei[0] = 0;
wei[1] = 0;
continue;
} else {
wei[0] = -score;
wei[1] = score;
break;
}
}
}
} else {
wei[0] = -score;
wei[1] = score;
}
return wei;
}
/**
* 中墩,尾墩通用=======>>除了这几种特殊牌型(7.葫芦,8.铁支,9.同花顺,10.五同)之外的牌型
*
* @param pai
* @param pai1
* @param score
* @return
*/
public static int[] zhongCompareIsOtherType(int pai[], int pai1[]) {
int zhong[] = new int[2];
// 判断中尾五张牌:第一个玩家大于第二个玩家的情况
if (stu.getSssShouPaiType(pai) > stu.getSssShouPaiType(pai1)) {
zhong[0] = 1;
zhong[1] = -1;
// 第一个玩家等于第二个玩家的情况
} else if (stu.getSssShouPaiType(pai) == stu.getSssShouPaiType(pai1)) {
// 拿出五张牌里面比较特殊的五个牌型-------->8:铁支7:葫芦4:三条3:两对2:一对
int fanwei[] = { 7, 4, 3, 2 };
// 定义一个boolean变量,用于判断当前牌是否属于特殊牌型
boolean tiaoJianOne = false;
// 用于存放改变之后的分数数组信息
int player[] = null;
int player1[] = null;
// 判断是否属于特殊牌型,并且加以标记
for (int f = 0; f < 4; f++) {
if (stu.getSssShouPaiType(pai) == fanwei[f]) {
tiaoJianOne = true;
}
}
// 是特殊牌型的情形之下
if (tiaoJianOne == true) {
player = getSpecialPorke(stu.getSssShouPaiType(pai), pai);
player1 = getSpecialPorke(stu.getSssShouPaiType(pai1), pai1);
for (int j = 0; j < player.length; j++) {
if (player[j] > player1[j]) {
zhong[0] = 1;
zhong[1] = -1;
break;
} else if (player[j] == player1[j]) {
zhong[0] = 0;
zhong[1] = 0;
continue;
} else {
zhong[0] = -1;
zhong[1] = 1;
break;
}
}
// 不是特殊牌型的情形下
} else {
player = arraysChangeIndex(pai);
player1 = arraysChangeIndex(pai1);
// 遍历数组中的单个数字进行 大小比较
for (int j = 0; j < 5; j++) {
if (paiNum(player[j]) > paiNum(player1[j])) {
zhong[0] = 1;
zhong[1] = -1;
break;
} else if (paiNum(player[j]) == paiNum(player1[j])) {
zhong[0] = 0;
zhong[1] = 0;
continue;
} else {
zhong[0] = -1;
zhong[1] = 1;
break;
}
}
}
// 第一个玩家小于第二个玩家的情形
} else {
zhong[0] = -1;
zhong[1] = 1;
}
return zhong;
}
/**
* 判断牌的数值
*
* @param pai
* @return
*/
public static int paiNum(int pai) {
return pai / 4 + 2;
}
/**
* 将数组从大到小进行排序,并且将得到的数组返回回来
*
* @param arrays
* @return
*/
public static int[] arraysChangeIndex(int[] arrays) {
int temp;
for (int i = 0; i < arrays.length; i++) {
for (int j = i + 1; j < arrays.length; j++) {
if (arrays[i] < arrays[j]) {
temp = arrays[i];
arrays[i] = arrays[j];
arrays[j] = temp; // 两个数交换位置
}
}
}
return arrays;
}
/**
* 将整个数组全部变换为牌的大小
*
* @param array
* @return
*/
public static int[] arrayForNum(int array[]) {
int arrays[] = new int[5];
for (int i = 0; i < 5; i++) {
arrays[i] = paiNum(array[i]);
}
return arrays;
}
/**
* 获取到五张牌之下,玩家特殊牌型的牌型排列数组
*
* @param power
* @param array
* @return
*/
public static int[] getSpecialPorke(int power, int array[]) {
int resultpai[] = null;
switch (power) {
// 铁支
case 8:
resultpai = getSpecialOne(array);
break;
// 葫芦
case 7:
resultpai = getSpecialTwo(array);
break;
// 三条
case 4:
resultpai = getSpecialThree(array);
break;
// 两对
case 3:
resultpai = getSpecialFour(array);
break;
// 一对
case 2:
resultpai = getSpecialFive(array);
break;
default:
break;
}
return resultpai;
}
/**
* 判断三张牌是对子的情况下进行排序
*/
public static int[] arrayDui(int[] array) {
int[] duiZi = new int[2];
// 将对子情况下的数组进行排序
if (paiNum(array[0]) == paiNum(array[1])) {
duiZi[0] = array[0];
duiZi[1] = array[2];
} else if (paiNum(array[1]) == paiNum(array[2])) {
duiZi[0] = array[1];
duiZi[1] = array[0];
} else {
duiZi[0] = array[0];
duiZi[1] = array[1];
}
return duiZi;
}
/**
* 铁支(炸弹加上一张)------>>选出其正确的数组排列方式
*
* @return
*/
public static int[] getSpecialOne(int array1[]) {
int array[] = arrayForNum(array1);
int shuzu[] = new int[2];
if (array[0] != array[1]) {
shuzu[0] = array[1];
shuzu[1] = array[0];
} else {
shuzu[0] = array[0];
shuzu[1] = array[4];
}
return shuzu;
}
/**
* 葫芦(一对加上一个三条)------>>选出其正确的数组排列方式
*
* @return
*/
public static int[] getSpecialTwo(int array1[]) {
int array[] = arrayForNum(array1);
int shuzu[] = new int[2];
if (array[0] == array[1] && array[1] == array[2]) {
shuzu[0] = array[0];
shuzu[1] = array[3];
} else {
shuzu[0] = array[3];
shuzu[1] = array[0];
}
return shuzu;
}
/**
* 三条(一个三条加上两张单牌)------>>选出其正确的数组排列方式
*
* @return
*/
public static int[] getSpecialThree(int array1[]) {
int array[] = arrayForNum(array1);
int shuzu[] = new int[3];
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
if (array[i] == array[j]) {
if (i == 0) {
shuzu[0] = array[0];
if (array[3] > array[4]) {
shuzu[1] = array[3];
shuzu[2] = array[4];
} else {
shuzu[1] = array[4];
shuzu[2] = array[3];
}
} else if (i == 1) {
if (array[0] > array[4]) {
shuzu[0] = array[1];
shuzu[1] = array[0];
shuzu[2] = array[4];
} else {
shuzu[0] = array[1];
shuzu[1] = array[4];
shuzu[2] = array[0];
}
} else {
if (array[0] > array[1]) {
shuzu[0] = array[2];
shuzu[1] = array[0];
shuzu[2] = array[1];
} else {
shuzu[0] = array[2];
shuzu[1] = array[1];
shuzu[2] = array[0];
}
}
}
}
}
return shuzu;
}
/**
* 两个对子加上一张单牌------>>选出其正确的数组排列方式
*
* @return
*/
public static int[] getSpecialFour(int array1[]) {
int array[] = arrayForNum(array1);
int shuzu[] = new int[3];
// 例子2,2,3,3,1双对子第一种情况
if (array[3] != array[4]) {
// 判断第一队和第二队的大小情况
if (array[0] > array[2]) {
shuzu[0] = array[0];
shuzu[1] = array[2];
shuzu[2] = array[4];
} else {
shuzu[0] = array[2];
shuzu[1] = array[0];
shuzu[2] = array[4];
}
// 例子1,2,2,3,3双对子第一种情况
} else if (array[0] > array[1]) {
if (array[1] > array[3]) {
shuzu[0] = array[1];
shuzu[1] = array[3];
shuzu[2] = array[0];
} else {
shuzu[0] = array[3];
shuzu[1] = array[1];
shuzu[2] = array[0];
}
// 例子2,2,1,3,3双对子第一种情况
} else {
if (array[0] > array[3]) {
shuzu[0] = array[0];
shuzu[1] = array[3];
shuzu[2] = array[2];
} else {
shuzu[0] = array[3];
shuzu[1] = array[0];
shuzu[2] = array[2];
}
}
return shuzu;
}
/**
* 一个对子的情况之下------>>选出其正确的数组排列方式
*
* @return
*/
public static int[] getSpecialFive(int array1[]) {
int array[] = arrayForNum(array1);
int shuzu[] = new int[4];
List<Integer> list = new ArrayList<>();
int tihuanPais[] = new int[3];
boolean b = false;
// 选择出相同的一对牌
for (int i = 0; i < 5; i++) {
for (int j = i + 1; j < 5; j++) {
// 找出对子的值
if (array[i] == array[j]) {
shuzu[0] = array[i];
b = true;
break;
}
}
// 控制外层循环的结束
if (b == true) {
break;
}
}
// 挑选出不相同的三张散牌,将其放入到集合当中
for (int i = 0; i < 5; i++) {
if (array[i] != shuzu[0]) {
list.add(array[i]);
}
}
for (int i = 0; i < 3; i++) {
tihuanPais[i] = list.get(i);
}
shuzu[1] = arraysChangeIndex(tihuanPais)[0];
shuzu[2] = arraysChangeIndex(tihuanPais)[1];
shuzu[3] = arraysChangeIndex(tihuanPais)[2];
// 选择出对子以外的所有散牌
return shuzu;
}
}