私はC#でポーカーハンド評価法を書こうとしています。私はストレートを除いてlinqを使って、すべてのポーカーハンドでこれを行うことができました。 ストレートで演奏されないものは、各カードごとに1ずつ増加する5枚のカードで構成されています。エースは高くても低くてもよい。c#ポーカーストレートを確認する
スーツ、ランク、値(J = 11、Q = 12など)を持つcardというオブジェクトを作成しました。私の方法には、7枚のカード(ホールカードとボード)を含むこのオブジェクトのリストが渡されます。
ストレートは、プレーヤーが5または10の場合にのみ作成できます。
他のポーカーハンドのメソッドを以下に見てください。ストレートメソッドのアイディアがあれば教えてください。擬似コードも問題ありません。
public bool CheckPair(List<Card> cards)
{
//see if exactly 2 cards card the same rank.
return cards.GroupBy(card => card.Rank).Count(group => group.Count() == 2) == 1;
}
public bool CheckTwoPair(List<Card> cards)
{
//see if there are 2 lots of exactly 2 cards card the same rank.
return cards.GroupBy(card => card.Rank).Count(group => group.Count() >= 2) == 2;
}
public bool CheckTrips(List<Card> cards)
{
//see if exactly 3 cards card the same rank.
return cards.GroupBy(card => card.Rank).Any(group => group.Count() == 3);
}
public bool CheckStraight(List<Card> cards)
{
// order by decending to see order
var cardsInOrder = cards.OrderByDescending(a => a.Value).ToList();
// check for ace as can be high and low
if (cardsInOrder.First().Rank == "A")
{
// check if straight with ace has has 2 values
bool highStraight = cards.Where(a => a.Rank == "K" || a.Rank == "Q" || a.Rank == "J" || a.Rank == "10").Count() == 4;
bool lowStraight = cards.Where(a => a.Rank == "2" || a.Rank == "3" || a.Rank == "4" || a.Rank == "5").Count() == 4;
// return true if straight with ace
if (lowStraight == true || highStraight == true)
{
return true;
}
}
else
{
// check for straight here
return true;
}
// no straight if reached here.
return false;
}
public bool CheckFlush(List<Card> cards)
{
//see if 5 or more cards card the same rank.
return cards.GroupBy(card => card.Suit).Count(group => group.Count() >= 5) == 1;
}
public bool CheckFullHouse(List<Card> cards)
{
// check if trips and pair is true
return CheckPair(cards) && CheckTrips(cards);
}
public bool CheckQuads(List<Card> cards)
{
//see if exactly 4 cards card the same rank.
return cards.GroupBy(card => card.Rank).Any(group => group.Count() == 4);
}
// need to check same 5 cards
public bool CheckStraightFlush(List<Card> cards)
{
// check if flush and straight are true.
return CheckFlush(cards) && CheckStraight(cards);
}
あなただけの楽しみのために、または実際の使用のためにこれを予定していますか?実際の使用には、非常に高速になるように慎重に設計された既存のライブラリが存在するためです。 – Evk
[配列の配列が連続しているかどうかを確認するための機能的な方法](0120-998-002) – fubo
こんにちは、それはちょうど挑戦のabitのです。 –