扑克算法手牌评估器
我正在努力让我的扑克来评估玩家的手牌。我可以使用同花和 J 或更好的组合来工作,但在弄清楚如何完成其余部分时遇到了问题。关于如何将卡片评估为适当的类型有什么建议吗?
int Game::HandCheck()
{
//ROYAL FLUSH
//return 9;
//STRAIGHT FLUSH
//return 8;
//FOUR OF A KIND
//return 7;
//FULL HOUSE
//return 6;
//FLUSH
if( currentHand[ 0 ].GetSuit() == currentHand[ 1 ].GetSuit() && currentHand[ 1 ].GetSuit() == currentHand[ 2 ].GetSuit() &&
currentHand[ 2 ].GetSuit() == currentHand[ 3 ].GetSuit() && currentHand[ 4 ].GetSuit() == currentHand[ 4 ].GetSuit() )
return 5;
//STRAIGHT
//return 4;
//THREE OF A KIND
if( currentHand[ 0 ].GetValue() == currentHand[ 2 ].GetValue() && currentHand[ 0 ].GetValue() == currentHand[ 3 ].GetValue()
//return 3;
//TWO PAIR
//return 2;
//JACKS OR BETTER PAIR
for( int i = 0; i < 5; i++ )
{
if( currentHand[ i ].GetValue() == 11 || currentHand[ i ].GetValue() == 12 || currentHand[ i ].GetValue() == 13 || currentHand[ i ].GetValue() == 1 )
{
if( currentHand[ i ].GetValue() == currentHand[ i + 1 ].GetValue() || currentHand[ i ].GetValue() == currentHand[ i + 2 ].GetValue() || //pair
currentHand[ i ].GetValue() == currentHand[ i + 3 ].GetValue() || currentHand[ i ].GetValue() == currentHand[ i + 4 ].GetValue() )
return 1;
}
}
return 0;
}
I'm working on getting my Poker to evaluate the player hand. I can get the Flush and the jack or better pair to work but am running into problems figuring out how I would do the rest. Any suggestions on how I can evaluate the cards to the appropriate type?
int Game::HandCheck()
{
//ROYAL FLUSH
//return 9;
//STRAIGHT FLUSH
//return 8;
//FOUR OF A KIND
//return 7;
//FULL HOUSE
//return 6;
//FLUSH
if( currentHand[ 0 ].GetSuit() == currentHand[ 1 ].GetSuit() && currentHand[ 1 ].GetSuit() == currentHand[ 2 ].GetSuit() &&
currentHand[ 2 ].GetSuit() == currentHand[ 3 ].GetSuit() && currentHand[ 4 ].GetSuit() == currentHand[ 4 ].GetSuit() )
return 5;
//STRAIGHT
//return 4;
//THREE OF A KIND
if( currentHand[ 0 ].GetValue() == currentHand[ 2 ].GetValue() && currentHand[ 0 ].GetValue() == currentHand[ 3 ].GetValue()
//return 3;
//TWO PAIR
//return 2;
//JACKS OR BETTER PAIR
for( int i = 0; i < 5; i++ )
{
if( currentHand[ i ].GetValue() == 11 || currentHand[ i ].GetValue() == 12 || currentHand[ i ].GetValue() == 13 || currentHand[ i ].GetValue() == 1 )
{
if( currentHand[ i ].GetValue() == currentHand[ i + 1 ].GetValue() || currentHand[ i ].GetValue() == currentHand[ i + 2 ].GetValue() || //pair
currentHand[ i ].GetValue() == currentHand[ i + 3 ].GetValue() || currentHand[ i ].GetValue() == currentHand[ i + 4 ].GetValue() )
return 1;
}
}
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将创建一个直方图数组来进行计数。
填充数组。
如果恰好一个桶的计数为两个或更多,则您有一对、三趟或四趟。
如果两个桶的计数为二或更多,则您有两对或葫芦。
I would create a histogram array to do the counting.
Fill the array.
If exactly one bucket has of count of two or more, you have a pair, trips or four of a kind.
If two buckets have a count of two or more, you have two pair or a full house.
您的
Flush
算法正在将4
与自身进行比较:您的三类算法假设所有三个值都位于前三个位置:
也许三个相同的值存储在手牌的第一张、中间和最后一张牌中。
我不知道传统的扑克牌评估器是如何编写的,但我感觉它们执行了一些额外的计算:创建一个数组,按牌值索引,存储牌数的计数该值的:
Your
Flush
algorithm is comparing4
against itself:Your three-of-a-kind algorithm is assuming that all three values are in the first three positions:
Perhaps the three identical values are stored in the first, middle, and last cards in the hand.
I don't know how traditional poker hand evaluators are written, but I have a feeling that they perform some extra computations: create an array, indexed by card value, that stores the count of the number of cards of that value: