4至直的连直,3到直接的视频扑克
我正在从常规的52张卡片甲板上创建一个扑克5卡手动评估器,并根据排名列表评估采取的理想策略。此列表中包括可能的组合,例如“ 4至直层”,“ 4到外部直线”,“ 3到直层”等。
这是我的卡类:
public class Card implements Comparable<Card> {
private char rank;
private char suit;
private int value;
public Card(char rank, char suit, int value) {
this.rank = rank;
this.suit = suit;
this.value = value;
}
与一些getRank()
,getsuit()
和getValue()
方法。我的手是card []
5个元素的数组。
卡'<代码>值从2
到14
,其中2 = '2'
和14 = 'a'
。 我很难提出一种简单的算法(我已经看到了使用hashmaps和bit basks的实现,但似乎很复杂),因为所有边缘案例和>
>
可以是低王牌。在评估之前,所有手均以降序排序(“ 2C 5C 5C 8S ks QH”
变为“ KS QH 8S 5C 2C”
)。
我创建了一个isstraight()函数:
private boolean isStraight(Card[] sortedHand) {
if (sortedHand[0].getValue() == sortedHand[1].getValue() - 1
&& sortedHand[1].getValue() == sortedHand[2].getValue() - 1
&& sortedHand[2].getValue() == sortedHand[3].getValue() - 1
&& sortedHand[3].getValue() == sortedHand[4].getValue() - 1
) return true;
// Case where there is a Low Ace
if (sortedHand[0].getValue() == 14) {
if (sortedHand[1].getValue() == 5
&& sortedHand[2].getValue() == 4
&& sortedHand[3].getValue() == 3
&& sortedHand[4].getValue() == 2
) return true;
}
return false;
}
但是也许最好的是概括并创建一个函数,该函数将返回直线丢失的卡数(如果是笔直的情况,它将返回0,甚至是另一个方面的相反方式返回5),但我对如何做到这一点不知所措。
同样,我有一个isflush()方法:
private boolean isFlush(Card[] sortedHand) {
int sameSuit = 0;
char Suit = sortedHand[0].getSuit();
for (int i = 0; i < sortedHand.length; i++) {
if (sortedHand[i].getSuit() == Suit)
sameSuit++;
}
return sameSuit == 5;
}
但是,返回齐平丢失的卡片数量并没有普遍。
任何输入都非常感谢!
I'm creating a Poker 5-cards Hand Evaluator out of a regular 52-card deck, and evaluate the perfect strategy to take based on a ranked list. Included in this list are possible combinations such as "4 to a Straight Flush", "4 to an Outside Straight", "3 to a Straight Flush" and so on.
This is my card class:
public class Card implements Comparable<Card> {
private char rank;
private char suit;
private int value;
public Card(char rank, char suit, int value) {
this.rank = rank;
this.suit = suit;
this.value = value;
}
Along with some getRank()
, getSuit()
and getValue()
methods. My hand is a Card[]
array of 5 elements.
The cards' value
goes from 2
to 14
, where 2 = '2'
and 14 = 'A'
.
I'm having trouble coming up with a simple algorithm (I've seen implementations using HashMaps and bit masks, but it seems rather complex) to check for the aforementioned combinations, because of all the edge cases and the fact that the A
can be a low Ace. All hands are sorted in descending order before being evaluated ("2C 5C 8S KS QH"
becomes "KS QH 8S 5C 2C"
).
I created a isStraight() function:
private boolean isStraight(Card[] sortedHand) {
if (sortedHand[0].getValue() == sortedHand[1].getValue() - 1
&& sortedHand[1].getValue() == sortedHand[2].getValue() - 1
&& sortedHand[2].getValue() == sortedHand[3].getValue() - 1
&& sortedHand[3].getValue() == sortedHand[4].getValue() - 1
) return true;
// Case where there is a Low Ace
if (sortedHand[0].getValue() == 14) {
if (sortedHand[1].getValue() == 5
&& sortedHand[2].getValue() == 4
&& sortedHand[3].getValue() == 3
&& sortedHand[4].getValue() == 2
) return true;
}
return false;
}
But maybe what would be best would be to generalize and create a function that would return the number of cards missing for a straight (it would return 0 in case of a straight - or even the other way around returning 5), but I'm at a loss on how to do that.
Likewise, I have a isFlush() method:
private boolean isFlush(Card[] sortedHand) {
int sameSuit = 0;
char Suit = sortedHand[0].getSuit();
for (int i = 0; i < sortedHand.length; i++) {
if (sortedHand[i].getSuit() == Suit)
sameSuit++;
}
return sameSuit == 5;
}
but it isn't generalized to return the number of cards missing for a flush.
Any input is greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论