-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2014-05-22代码游戏 #34
Comments
定义了一些java对象。不好放全部代码了。就贴比较重要的算法吧:判断牌型+牌型之间比较(含同牌型最大牌面方色比较) public static int numNotZero(int[] array) {
int j = 0;
for (int i : array) {
if (i > 0) {
j++;
}
}
return j;
}
public static int maxNum(int[] array) {
int max = 0;
for (int i : array) {
if (i > max) {
max = i;
}
}
return max;
}
public static int[] record(Card[] cards) {
int[] array = new int[13];
for (Card c : cards) {
array[c.getNumber() - 2]++;
}
return array;
}
public static int whichType(Card[] cards) {
int[] array = record(cards);
int type = 0;
int num = numNotZero(array);
int max = maxNum(array);
if (num == 2) {
if (max == 4) {
type = Card.Fullhouse;
} else if (max == 3) {
type = Card.ThreeWithakind;
}
} else if (num == 3) {
if (max == 3) {
type = Card.ThreeWithCard;
} else if (max == 2) {
type = Card.TwoPair;
}
} else if (num == 4) {
if (max == 2) {
type = Card.OnePair;
}
} else if (num == 5) {
boolean isStraight = isStraight(array);
boolean isFullhouse = isFullhouse(cards);
if (isStraight && isFullhouse) {
type = Card.StraightFlush;
} else if (isStraight) {
type = Card.Straight;
} else if (isFullhouse) {
type = Card.Fullhouse;
} else {
type = Card.Zilch;
}
}
return type;
}
public static boolean compareBig(Card[] cardsA, Card[] cardsB) {
int typeA = whichType(cardsA);
int typeB = whichType(cardsB);
boolean isBig = true;
if (typeA < typeB) {
return true;
} else if (typeA > typeB) {
return false;
} else {
sort(cardsA);
sort(cardsB);
if (Card.StraightFlush == typeA) {
// 都是同花顺
isBig = compareNumAndColor(cardsA[0], cardsB[0]);
} else if (Card.FourofaKind == typeA) {
// 都是四条
isBig = compareNumAndColor(cardsA[0], cardsB[0]);
} else if (Card.Fullhouse == typeA) {
// 都是同花
isBig = compareColorAndNum(cardsA[0], cardsB[0]);
} else if (Card.Straight == typeA) {
// 都是顺子
isBig = compareNumAndColor(cardsA[0], cardsB[0]);
} else if (Card.ThreeWithakind == typeA) {
// 都是三条带一对
isBig = compareNumAndColor(cardsA[2], cardsB[2]);
} else if (Card.ThreeWithCard == typeA) {
// 都是三条带散牌
isBig = compareNumAndColor(cardsA[2], cardsB[2]);
} else if (Card.TwoPair == typeA) {
// 都是两对
int tA = twoPairType(cardsA);
int tB = twoPairType(cardsB);
Card tmp1, tmp2, tmp3, tmp4;
if (tA == 2) {
tmp1 = cardsA[0];
tmp2 = cardsA[3];
} else if (tA == 1) {
tmp1 = cardsA[0];
tmp2 = cardsA[2];
} else {
tmp1 = cardsA[1];
tmp2 = cardsA[3];
}
if (tB == 2) {
tmp3 = cardsB[0];
tmp4 = cardsB[3];
} else if (tB == 1) {
tmp3 = cardsB[0];
tmp4 = cardsB[2];
} else {
tmp3 = cardsB[1];
tmp4 = cardsB[3];
}
isBig = comparePairNum(tmp1, tmp2, tmp3, tmp4);
} else if (Card.OnePair == typeA) {
// 都是一对
isBig = compareNumAndColor(cardsA[onePairType(cardsA)], cardsB[onePairType(cardsB)]);
} else {
// 散牌
isBig = compareNumAndColor(cardsA[0], cardsB[0]);
}
}
return isBig;
} |
统计花色和牌型,每种牌计算数量 public class soha {
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
梭哈游戏
要求:给定两副牌型(每副5张),比较大小
1.不考虑花色
数字比较:A>K>Q>J>10>9>8 >7>6>5>4>3>2
牌型比较:四条>三条加一对>顺子>三条>二对>单对>散牌
2.考虑花色
牌型比较:同花顺>四条>三条加一对>同花>顺子>三条>二对>单对>散牌。
The text was updated successfully, but these errors were encountered: