Java 扑克牌手评价的最简单算法
我正在考虑Java 扑克牌手评价的最简单算法,java,r,algorithm,data-structures,poker,Java,R,Algorithm,Data Structures,Poker,我正在考虑Java中的扑克手(5张牌)评估。现在我追求的是简单和清晰,而不是性能和效率。我可能可以写一个“幼稚”的算法,但它需要很多代码 我还看到了一些扑克评估库,它们使用哈希和按位操作,但它们看起来相当复杂 什么是“最干净、最简单”的扑克评估算法 如果您将一只手表示为一个数组,例如,卡对象,那么我将有一些方法来循环通过这个数组,并确定它是否有一个2-of-a-kind、flush等,如果有,它是什么类型;因此,如果一只手有三个5s,则可以使用3ofaKind()方法返回5。然后我会建立一个可能
Java
中的扑克手(5张牌)评估。现在我追求的是简单和清晰,而不是性能和效率。我可能可以写一个“幼稚”的算法,但它需要很多代码
我还看到了一些扑克评估库,它们使用哈希和按位操作,但它们看起来相当复杂
什么是“最干净、最简单”的扑克评估算法 如果您将一只手表示为一个数组,例如,
卡
对象,那么我将有一些方法来循环通过这个数组,并确定它是否有一个2-of-a-kind、flush等,如果有,它是什么类型;因此,如果一只手有三个5s,则可以使用3ofaKind()
方法返回5。然后我会建立一个可能性的层次结构(例如,一种可能性的3比一种可能性的2高),并从那里开始工作。方法本身应该非常容易编写。查找表是解决该问题最直接、最简单的方法,也是最快的方法。诀窍是管理表的大小,并保持使用模式足够简单,以便快速处理()。显然,从理论上讲,你可以对每只手进行编码,然后进行一系列计算,然后——噗——一次查表,就完成了。不幸的是,这样一个表对于大多数机器来说都是巨大且不可管理的,而且在内存大量交换的情况下,总是会让您重击磁盘
所谓的“二加二”解决方案是一张10米的大桌子,但实际上需要为手中的每张牌查找一张桌子。您不太可能找到一个更快更简单的算法
其他解决方案涉及更多的压缩表和更复杂的索引,但它们易于理解且速度相当快(尽管比2+2慢得多)。这就是您看到的有关哈希等的语言——将表大小减少到更易于管理的大小的技巧
在任何情况下,查找解决方案都比柱状图-排序-跳舞-你的头上-比较-特殊情况-和-按方式-是-它-刷新解决方案快几个数量级,几乎没有一个值得再看一眼。如果你只想了解它是如何工作的,这里有一个简单的算法:
HandStrength(ourcards,boardcards)
{
ahead = tied = behind = 0
ourrank = Rank(ourcards,boardcards)
/* Consider all two-card combinations
of the remaining cards. */
for each case(oppcards)
{
opprank = Rank(oppcards,boardcards)
if(ourrank>opprank)
ahead += 1
else if(ourrank==opprank)
tied += 1
else /* < */
behind += 1
}
handstrength = (ahead+tied/2) / (ahead+tied+behind)
return(handstrength)
}
握力(我们的卡、板卡)
{
前=平=后=0
我们的等级=等级(我们的卡,董事卡)
*考虑所有两种卡组合
剩下的牌中的一张*/
每种情况(OPP卡)
{
opprank=等级(oppcards,boardcards)
如果(ourrank>opprank)
超前+=1
else if(ourrank==opprank)
平局+=1
else/*<*/
后面+=1
}
手的力量=(前+平/2)/(前+平+后)
返回(手的力量)
}
它来自Darse Billings的“计算机扑克中的算法和评估”。这里是Python(2.x)中一个非常简短但完整的基于直方图的5张扑克评分函数。如果转换为Java,它将变得相当长
def poker(hands):
scores = [(i, score(hand.split())) for i, hand in enumerate(hands)]
winner = sorted(scores , key=lambda x:x[1])[-1][0]
return hands[winner]
def score(hand):
ranks = '23456789TJQKA'
rcounts = {ranks.find(r): ''.join(hand).count(r) for r, _ in hand}.items()
score, ranks = zip(*sorted((cnt, rank) for rank, cnt in rcounts)[::-1])
if len(score) == 5:
if ranks[0:2] == (12, 3): #adjust if 5 high straight
ranks = (3, 2, 1, 0, -1)
straight = ranks[0] - ranks[4] == 4
flush = len({suit for _, suit in hand}) == 1
'''no pair, straight, flush, or straight flush'''
score = ([1, (3,1,1,1)], [(3,1,1,2), (5,)])[flush][straight]
return score, ranks
>>> poker(['8C TS KC 9H 4S', '7D 2S 5D 3S AC', '8C AD 8D AC 9C', '7C 5H 8D TD KS'])
'8C AD 8D AC 9C'
下面是一个简单的五手牌比较方法,我正在使用它来帮助初始填充查找表:
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.Ordering.from;
import static com.google.common.collect.Ordering.natural;
import static java.util.Comparator.comparing;
import static java.util.Comparator.comparingInt;
import java.util.Comparator;
import java.util.EnumSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.function.Function;
import com.google.common.collect.EnumMultiset;
import com.google.common.collect.Multiset;
import com.google.common.collect.Multiset.Entry;
import com.google.common.collect.Ordering;
public class Hand implements Comparable<Hand> {
public final Category category;
private final LinkedList<Rank> distinctRanks = new LinkedList<>();
public Hand(Set<Card> cards) {
checkArgument(cards.size() == 5);
Set<Suit> suits = EnumSet.noneOf(Suit.class);
Multiset<Rank> ranks = EnumMultiset.create(Rank.class);
for (Card card : cards) {
suits.add(card.suit);
ranks.add(card.rank);
}
Set<Entry<Rank>> entries = ranks.entrySet();
for (Entry<Rank> entry : byCountThenRank.immutableSortedCopy(entries)) {
distinctRanks.addFirst(entry.getElement());
}
Rank first = distinctRanks.getFirst();
int distinctCount = distinctRanks.size();
if (distinctCount == 5) {
boolean flush = suits.size() == 1;
if (first.ordinal() - distinctRanks.getLast().ordinal() == 4) {
category = flush ? STRAIGHT_FLUSH : STRAIGHT;
}
else if (first == ACE && distinctRanks.get(1) == FIVE) {
category = flush ? STRAIGHT_FLUSH : STRAIGHT;
// ace plays low, move to end
distinctRanks.addLast(distinctRanks.removeFirst());
}
else {
category = flush ? FLUSH : HIGH_CARD;
}
}
else if (distinctCount == 4) {
category = ONE_PAIR;
}
else if (distinctCount == 3) {
category = ranks.count(first) == 2 ? TWO_PAIR : THREE_OF_A_KIND;
}
else {
category = ranks.count(first) == 3 ? FULL_HOUSE : FOUR_OF_A_KIND;
}
}
@Override
public final int compareTo(Hand that) {
return byCategoryThenRanks.compare(this, that);
}
private static final Ordering<Entry<Rank>> byCountThenRank;
private static final Comparator<Hand> byCategoryThenRanks;
static {
Comparator<Entry<Rank>> byCount = comparingInt(Entry::getCount);
Comparator<Entry<Rank>> byRank = comparing(Entry::getElement);
byCountThenRank = from(byCount.thenComparing(byRank));
Comparator<Hand> byCategory = comparing((Hand hand) -> hand.category);
Function<Hand, Iterable<Rank>> getRanks =
(Hand hand) -> hand.distinctRanks;
Comparator<Hand> byRanks =
comparing(getRanks, natural().lexicographical());
byCategoryThenRanks = byCategory.thenComparing(byRanks);
}
public enum Category {
HIGH_CARD,
ONE_PAIR,
TWO_PAIR,
THREE_OF_A_KIND,
STRAIGHT,
FLUSH,
FULL_HOUSE,
FOUR_OF_A_KIND,
STRAIGHT_FLUSH;
}
public enum Rank {
TWO,
THREE,
FOUR,
FIVE,
SIX,
SEVEN,
EIGHT,
NINE,
TEN,
JACK,
QUEEN,
KING,
ACE;
}
public enum Suit {
DIAMONDS,
CLUBS,
HEARTS,
SPADES;
}
public enum Card {
TWO_DIAMONDS(TWO, DIAMONDS),
THREE_DIAMONDS(THREE, DIAMONDS),
FOUR_DIAMONDS(FOUR, DIAMONDS),
FIVE_DIAMONDS(FIVE, DIAMONDS),
SIX_DIAMONDS(SIX, DIAMONDS),
SEVEN_DIAMONDS(SEVEN, DIAMONDS),
EIGHT_DIAMONDS(EIGHT, DIAMONDS),
NINE_DIAMONDS(NINE, DIAMONDS),
TEN_DIAMONDS(TEN, DIAMONDS),
JACK_DIAMONDS(JACK, DIAMONDS),
QUEEN_DIAMONDS(QUEEN, DIAMONDS),
KING_DIAMONDS(KING, DIAMONDS),
ACE_DIAMONDS(ACE, DIAMONDS),
TWO_CLUBS(TWO, CLUBS),
THREE_CLUBS(THREE, CLUBS),
FOUR_CLUBS(FOUR, CLUBS),
FIVE_CLUBS(FIVE, CLUBS),
SIX_CLUBS(SIX, CLUBS),
SEVEN_CLUBS(SEVEN, CLUBS),
EIGHT_CLUBS(EIGHT, CLUBS),
NINE_CLUBS(NINE, CLUBS),
TEN_CLUBS(TEN, CLUBS),
JACK_CLUBS(JACK, CLUBS),
QUEEN_CLUBS(QUEEN, CLUBS),
KING_CLUBS(KING, CLUBS),
ACE_CLUBS(ACE, CLUBS),
TWO_HEARTS(TWO, HEARTS),
THREE_HEARTS(THREE, HEARTS),
FOUR_HEARTS(FOUR, HEARTS),
FIVE_HEARTS(FIVE, HEARTS),
SIX_HEARTS(SIX, HEARTS),
SEVEN_HEARTS(SEVEN, HEARTS),
EIGHT_HEARTS(EIGHT, HEARTS),
NINE_HEARTS(NINE, HEARTS),
TEN_HEARTS(TEN, HEARTS),
JACK_HEARTS(JACK, HEARTS),
QUEEN_HEARTS(QUEEN, HEARTS),
KING_HEARTS(KING, HEARTS),
ACE_HEARTS(ACE, HEARTS),
TWO_SPADES(TWO, SPADES),
THREE_SPADES(THREE, SPADES),
FOUR_SPADES(FOUR, SPADES),
FIVE_SPADES(FIVE, SPADES),
SIX_SPADES(SIX, SPADES),
SEVEN_SPADES(SEVEN, SPADES),
EIGHT_SPADES(EIGHT, SPADES),
NINE_SPADES(NINE, SPADES),
TEN_SPADES(TEN, SPADES),
JACK_SPADES(JACK, SPADES),
QUEEN_SPADES(QUEEN, SPADES),
KING_SPADES(KING, SPADES),
ACE_SPADES(ACE, SPADES);
public final Rank rank;
public final Suit suit;
Card(Rank rank, Suit suit) {
this.rank = rank;
this.suit = suit;
}
}
}
import static com.google.common.base.premissions.checkArgument;
导入静态com.google.common.collect.Ordering.from;
导入静态com.google.common.collect.Ordering.natural;
导入静态java.util.Comparator.Comparating;
导入静态java.util.Comparator.comparingInt;
导入java.util.Comparator;
导入java.util.EnumSet;
导入java.util.LinkedList;
导入java.util.Set;
导入java.util.function.function;
导入com.google.common.collect.EnumMultiset;
导入com.google.common.collect.Multiset;
导入com.google.common.collect.Multiset.Entry;
导入com.google.common.collect.Ordering;
公营手工器具{
公共最终类别;
private final LinkedList distinctRanks=新LinkedList();
公众手牌(套牌){
checkArgument(cards.size()==5);
Set suits=EnumSet.noneOf(Suit.class);
Multiset-ranks=EnumMultiset.create(Rank.class);
用于(卡片:卡片){
套装。添加(卡片。套装);
等级。添加(卡片。等级);
}
Set entries=ranks.entrySet();
for(条目:byCountThenRank.immutableSortedCopy(条目)){
distinctRanks.addFirst(entry.getElement());
}
Rank first=distinctRanks.getFirst();
int distinctCount=distinctRanks.size();
如果(distinctCount==5){
布尔flush=suits.size()==1;
if(first.ordinal()-distinctRanks.getLast().ordinal()==4){
类别=齐平?直线\u齐平:直线;
}
else if(first==ACE&&distinctRanks.get(1)==FIVE){
类别=齐平?直线\u齐平:直线;
//王牌打低,移动到终点
addLast(distinctRanks.removeFirst());
}
否则{
类别=刷新?刷新:高\u卡;
}
}
else if(distinctCount==4){
类别=一对;
}
else if(distinctCount==3){
类别=等级。计数(第一)=2?两对:三种类型;
}
否则{
类别=等级。计数(第一)=3?满座:四个种类;
}
}
@凌驾
公共最终整数比较(交给){
返回byCategoryThenRanks.compare(这个,那个);
}
按CountThenRank进行私有静态最终排序;
私人静态最终薪酬
def holdem(board, hands):
scores = [(evaluate((board + ' ' + hand).split()), i) for i, hand in enumerate(hands)]
best = max(scores)[0]
return [x[1] for x in filter(lambda(x): x[0] == best, scores)]
def evaluate(hand):
ranks = '23456789TJQKA'
if len(hand) > 5: return max([evaluate(hand[:i] + hand[i+1:]) for i in range(len(hand))])
score, ranks = zip(*sorted((cnt, rank) for rank, cnt in {ranks.find(r): ''.join(hand).count(r) for r, _ in hand}.items())[::-1])
if len(score) == 5: # if there are 5 different ranks it could be a straight or a flush (or both)
if ranks[0:2] == (12, 3): ranks = (3, 2, 1, 0, -1) # adjust if 5 high straight
score = ([1,(3,1,2)],[(3,1,3),(5,)])[len({suit for _, suit in hand}) == 1][ranks[0] - ranks[4] == 4] # high card, straight, flush, straight flush
return score, ranks
def test():
print holdem('9H TC JC QS KC', [
'JS JD', # 0
'AD 9C', # 1 A-straight
'JD 2C', # 2
'AC 8D', # 3 A-straight
'QH KH', # 4
'TS 9C', # 5
'AH 3H', # 6 A-straight
'3D 2C', # 7
# '8C 2C', # 8 flush
])
test()
var J=11, Q=12, K=13, A=14, C=1, D=2, H=4, S=8;
function evaluateHand(cs, ss) {
var pokerHands = ["4 of a Kind", "Straight Flush","Straight","Flush","High Card","1 Pair","2 Pair","Royal Flush", "3 of a Kind","Full House"];
var v,i,o,s = 1 << cs[0] | 1 << cs[1] | 1 << cs[2] | 1 << cs[3] | 1 << cs[4];
for (i = -1, v = o = 0; i < 5; i++, o = Math.pow(2, cs[i] * 4)) {v += o * ((v / o & 15) + 1);}
v = v % 15 - ((s / (s & -s) == 31) || (s == 0x403c) ? 3 : 1);
v -= (ss[0] == (ss[1] | ss[2] | ss[3] | ss[4])) * ((s == 0x7c00) ? -5 : 1);
return pokerHands[v];
}
evaluateHand([A,10,J,K,Q],[C,C,C,C,C]); // Royal Flush
library(tidyverse)
library(gtools)
hand_value <- function(playerhand) {
numbers <- str_split("23456789TJQKA", "")[[1]]
suits <- str_split("DCHS", "")[[1]]
playerhand <- data.frame(card = playerhand) %>% separate(card, c("number", "suit"), sep = 1)
number_values <- data.frame(number = numbers, value = LETTERS[2:14], stringsAsFactors = FALSE)
playerhand_number <- playerhand %>%
group_by(number) %>%
count(number) %>%
inner_join(number_values, by = "number") %>%
arrange(desc(n), desc(value))
playerhand_suit <- playerhand %>%
group_by(suit) %>%
count(suit) %>%
arrange(desc(n))
if (nrow(playerhand_number) == 5)
{
if (playerhand_number[1,1] == 'A' & playerhand_number[2,1] == '5')
playerhand_number <- data.frame(playerhand_number[,1:2], value = str_split("EDCBA", "")[[1]], stringsAsFactors = FALSE)
straight <- asc(playerhand_number[1,3]) - asc(playerhand_number[5,3]) == 4
} else
straight = FALSE
flush <- nrow(playerhand_suit) == 1
if (flush)
{
if (straight)
playerhand_number <- data.frame(playerhand_number[,c(1,3)], n = c(5, 0, 0, 0, 0), stringsAsFactors = FALSE) else
playerhand_number <- data.frame(playerhand_number[,c(1,3)], n = c(3, 1, 1, 2, 0), stringsAsFactors = FALSE)
} else
{
if (straight)
playerhand_number <- data.frame(playerhand_number[,c(1,3)], n = c(3, 1, 1, 1, 0), stringsAsFactors = FALSE)
}
playerhand_value <- append(append(c(playerhand_number$n), rep("0", 5 - nrow(playerhand_number))), c(playerhand_number$value))
playerhand_value <- paste(playerhand_value, collapse = '')
playerhand_value
}
l <- c("8C TS KC 9H 4S", "7D 2S 5D 3S AC", "8C AD 8D AC 9C", '7C 5H 8D TD KS')
t <- as_tibble(l)
t <- t %>% mutate(hand = str_split(value, " ")) %>% select(hand)
t <- t %>% mutate(value = sapply(t[,1]$hand, hand_value)) %>% arrange(desc(value))
paste(t[[1]][[1]], collapse = " ")
[1] "8C AD 8D AC 9C"
class PokerHand constructor(hand: String) : Comparable<PokerHand> {
companion object {
const val WIN = 1
const val TIE = 0
const val LOSS = -1
}
val cards: List<Card>
val isStraightFlush: Boolean
get() = isStraight && isFlush
val isFourOfAKind: Boolean
get() = cards.groupBy { it.weight }.map { it.value }.any { it.size == 4 }
val isFullHouse: Boolean
get() = cards.groupBy { it.weight }.map { it.value }.size == 2
val isFlush: Boolean
get() = cards.groupBy { it.suit }.map { it.value }.size == 1
val isStraight: Boolean
get() = cards.map { it.weight.ordinal } == (cards[0].weight.ordinal..cards[0].weight.ordinal + 4).toList()
val isThreeOfAKind: Boolean
get() = cards.groupBy { it.weight }.map { it.value }.any { it.size == 3 }
val isTwoPair: Boolean
get() = cards.groupBy { it.weight }.map { it.value }.filter { it.size == 2 }.count() == 2
val isPair: Boolean
get() = cards.groupBy { it.weight }.map { it.value }.any { it.size == 2 }
init {
val cards = ArrayList<Card>()
hand.split(" ").forEach {
when (it.length != 2) {
true -> throw RuntimeException("A card code must be two characters")
else -> cards += Card(Weight.forCode(it[0]), Suit.forCode(it[1]))
}
}
if (cards.size != 5) {
throw RuntimeException("There must be five cards in a hand")
}
this.cards = cards.sortedBy { it.weight.ordinal }
}
override fun compareTo(other: PokerHand): Int = when {
(this.isStraightFlush || other.isStraightFlush) ->
if (this.isStraightFlush) if (other.isStraightFlush) compareByHighCard(other) else WIN else LOSS
(this.isFourOfAKind || other.isFourOfAKind) ->
if (this.isFourOfAKind) if (other.isFourOfAKind) compareByHighCard(other) else WIN else LOSS
(this.isFullHouse || other.isFullHouse) ->
if (this.isFullHouse) if (other.isFullHouse) compareByHighCard(other) else WIN else LOSS
(this.isFlush || other.isFlush) ->
if (this.isFlush) if (other.isFlush) compareByHighCard(other) else WIN else LOSS
(this.isStraight || other.isStraight) ->
if (this.isStraight) if (other.isStraight) compareByHighCard(other) else WIN else LOSS
(this.isThreeOfAKind || other.isThreeOfAKind) ->
if (this.isThreeOfAKind) if (other.isThreeOfAKind) compareByHighCard(other) else WIN else LOSS
(this.isTwoPair || other.isTwoPair) ->
if (this.isTwoPair) if (other.isTwoPair) compareByHighCard(other) else WIN else LOSS
(this.isPair || other.isPair) ->
if (this.isPair) if (other.isPair) compareByHighCard(other) else WIN else LOSS
else -> compareByHighCard(other)
}
private fun compareByHighCard(other: PokerHand, index: Int = 4): Int = when {
(index < 0) -> TIE
cards[index].weight === other.cards[index].weight -> compareByHighCard(other, index - 1)
cards[index].weight.ordinal > other.cards[index].weight.ordinal -> WIN
else -> LOSS
}
Table Cards
{ Value: '9', Suit: 'H' }
{ Value: 'A', Suit: 'H' }
{ Value: '9', Suit: 'D' }
{ Value: '7', Suit: 'S' }
{ Value: '6', Suit: 'S' }
A 2 3 4 5 6 7 8 9 10 J Q K A
Spades
[ 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0 ]
Diamonds
[ 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0 ]
Clubs
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Hearts
[ 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ]
def poker(hands):
scores = [(i, score(hand.split())) for i, hand in enumerate(hands)]
winner = sorted(scores , key=lambda x:x[1])[-1][0]
return hands[winner]
def score(hand):
ranks = '23456789TJQKA'
rcounts = {ranks.find(r): ''.join(hand).count(r) for r, _ in hand}.items()
score, ranks = zip(*sorted((cnt, rank) for rank, cnt in rcounts)[::-1])
if len(score) == 5:
if ranks[0:2] == (12, 3): #adjust if 5 high straight
ranks = (3, 2, 1, 0, -1)
straight = ranks[0] - ranks[4] == 4
flush = len({suit for _, suit in hand}) == 1
'''no pair, straight, flush, or straight flush'''
score = ([(1,), (3,1,1,1)], [(3,1,1,2), (5,)])[flush][straight]
return score, ranks
>>> poker(['8C TS KC 9H 4S', '7D 2S 5D 3S AC', '8C AD 8D AC 9C', '7C 5H 8D TD KS'])
'8C AD 8D AC 9C'
public class Line
{
private List<Card> _cardsToAnalyse;
public Line()
{
Cards = new List<Card>(5);
}
public List<Card> Cards { get; }
public string PriceName { get; private set; }
public int Result()
{
_cardsToAnalyse = Cards;
var valueComparer = new CardValueComparer();
_cardsToAnalyse.Sort(valueComparer);
if (ContainsStraightFlush(_cardsToAnalyse))
{
PriceName = "Straight Flush";
return PayTable.StraightFlush;
}
if (ContainsFourOfAKind(_cardsToAnalyse))
{
PriceName = "Quadra";
return PayTable.FourOfAKind;
}
if (ContainsStraight(_cardsToAnalyse))
{
PriceName = "Straight";
return PayTable.Straight;
}
if (ContainsFullen(_cardsToAnalyse))
{
PriceName = "Full House";
return PayTable.Fullen;
}
if (ContainsFlush(_cardsToAnalyse))
{
PriceName = "Flush";
return PayTable.Flush;
}
if (ContainsThreeOfAKind(_cardsToAnalyse))
{
PriceName = "Trinca";
return PayTable.ThreeOfAKind;
}
if (ContainsTwoPairs(_cardsToAnalyse))
{
PriceName = "Dois Pares";
return PayTable.TwoPairs;
}
if (ContainsPair(_cardsToAnalyse))
{
PriceName = "Um Par";
return PayTable.Pair;
}
return 0;
}
private bool ContainsFullen(List<Card> _cardsToAnalyse)
{
var valueOfThree = 0;
// Search for 3 of a kind
Card previousCard1 = null;
Card previousCard2 = null;
foreach (var c in Cards)
{
if (previousCard1 != null && previousCard2 != null)
if (c.Value == previousCard1.Value && c.Value == previousCard2.Value)
valueOfThree = c.Value;
previousCard2 = previousCard1;
previousCard1 = c;
}
if (valueOfThree > 0)
{
Card previousCard = null;
foreach (var c in Cards)
{
if (previousCard != null)
if (c.Value == previousCard.Value)
if (c.Value != valueOfThree)
return true;
previousCard = c;
}
return false;
}
return false;
}
private bool ContainsPair(List<Card> Cards)
{
Card previousCard = null;
foreach (var c in Cards)
{
if (previousCard != null)
if (c.Value == previousCard.Value)
return true;
previousCard = c;
}
return false;
}
private bool ContainsTwoPairs(List<Card> Cards)
{
Card previousCard = null;
var countPairs = 0;
foreach (var c in Cards)
{
if (previousCard != null)
if (c.Value == previousCard.Value)
countPairs++;
previousCard = c;
}
if (countPairs == 2)
return true;
return false;
}
private bool ContainsThreeOfAKind(List<Card> Cards)
{
Card previousCard1 = null;
Card previousCard2 = null;
foreach (var c in Cards)
{
if (previousCard1 != null && previousCard2 != null)
if (c.Value == previousCard1.Value && c.Value == previousCard2.Value)
return true;
previousCard2 = previousCard1;
previousCard1 = c;
}
return false;
}
private bool ContainsFlush(List<Card> Cards)
{
return Cards[0].Naipe == Cards[1].Naipe &&
Cards[0].Naipe == Cards[2].Naipe &&
Cards[0].Naipe == Cards[3].Naipe &&
Cards[0].Naipe == Cards[4].Naipe;
}
private bool ContainsStraight(List<Card> Cards)
{
return Cards[0].Value + 1 == Cards[1].Value &&
Cards[1].Value + 1 == Cards[2].Value &&
Cards[2].Value + 1 == Cards[3].Value &&
Cards[3].Value + 1 == Cards[4].Value
||
Cards[1].Value + 1 == Cards[2].Value &&
Cards[2].Value + 1 == Cards[3].Value &&
Cards[3].Value + 1 == Cards[4].Value &&
Cards[4].Value == 13 && Cards[0].Value == 1;
}
private bool ContainsFourOfAKind(List<Card> Cards)
{
Card previousCard1 = null;
Card previousCard2 = null;
Card previousCard3 = null;
foreach (var c in Cards)
{
if (previousCard1 != null && previousCard2 != null && previousCard3 != null)
if (c.Value == previousCard1.Value &&
c.Value == previousCard2.Value &&
c.Value == previousCard3.Value)
return true;
previousCard3 = previousCard2;
previousCard2 = previousCard1;
previousCard1 = c;
}
return false;
}
private bool ContainsStraightFlush(List<Card> Cards)
{
return ContainsFlush(Cards) && ContainsStraight(Cards);
}
}