私は現在、複数のプレーヤーの手を比較し、勝者が誰であるかを決定するポーカー評価者を作成しています。しかし、実際の比較とタイブレークの方法は、はるかに多くの作業が必要です。私のコードを単純化する方法はありますか?私はすべてのソースコードを投稿していないので、以下で呼び出されるメソッドのいくつかの機能について議論する予定です。ポーカー評価のコードを簡素化する助けが必要
int HandEval(Card [] hand)は、配列の配列をとり、
int GetHighCard(Card [] hand)は、カードの配列をとり、タイブレークに使用されたハイカードのランクを返します(つまり、1つの種類のカードよりも高いスコアを持ちます)。 。種類の3の場合には、これらの3種類のいずれかのランクが返されます)
public void FindWinner()
{
int maxScore = 0;
int maxRank = 0;
List<String> potentialWinners = new List<string>();
List<Card[]> candHand = new List<Card[]>();
Dictionary<string, Card[]> deckTable = new Dictionary<string, Card[]>();
Dictionary<string, int> scoreTable = new Dictionary<string, int>();
Dictionary<string, int> highTable = new Dictionary<string, int>();
//place each player to deckTable which holds the player name and their hand
//place each player to scoreTable which holds the player name and the score of their hand
for (int i = 0; i < players.Count; i++)
{
deckTable.Add(players[i].GetName(), players[i].GetSorted());
scoreTable.Add(players[i].GetName(), HandEval(players[i].GetSorted()));
}
//display the player name and the score of their hand
foreach (KeyValuePair<string, int> pair in scoreTable)
{
Console.WriteLine("{0}, {1}", pair.Key, +pair.Value);
}
//find the max score of the current game
foreach (var kvp in scoreTable)
{
if (kvp.Value > maxScore)
{
maxScore = kvp.Value;
}
}
//display the max score
Console.WriteLine("The maximum score is " + maxScore);
//for all players with the max score, add them to the potential winners list
foreach (var kvp in scoreTable)
{
if (kvp.Value == maxScore)
{
potentialWinners.Add(kvp.Key);
}
}
//if there are more than one potential winner, run the tie-break checks
if (potentialWinners.Count > 1)
{
Console.WriteLine("Potential winners include: ");
for (int i = 0; i < potentialWinners.Count(); i++)
{
Console.WriteLine("" + potentialWinners[i] + "");
}
//add the name of the potential winners and the rank of the high card as a key value pair to highTable
for (int i = 0; i < potentialWinners.Count(); i++)
{
if (deckTable.ContainsKey(potentialWinners[i]))
{
Card[] cHand = deckTable[potentialWinners[i]];
highTable.Add(potentialWinners[i], GetHighCard(cHand));
}
}
Console.WriteLine("Displaying potential winners with their high card rank.");
foreach (KeyValuePair<string, int> pair in highTable)
{
Console.WriteLine("{0}, {1}", pair.Key, pair.Value);
}
//find the max rank of high card from all potential winners
foreach (var kvp in highTable)
{
if (kvp.Value > maxRank)
{
maxRank = kvp.Value;
}
}
Console.WriteLine("The final winner after tie-breaking is");
//display the winner(s) with the highest rank of card
foreach (var kvp in highTable)
{
if (kvp.Value == maxRank)
{
Console.WriteLine("" + kvp.Key + "");
}
}
}
//if there is only one potential winner, display the name
else
{
Console.WriteLine("The final winner is");
Console.WriteLine(potentialWinners[0]);
}
}
}
すべてのヘルプやヒントを大幅に高く評価されます!あなたは基本的にループのために2回同じことを呼び出している
これはCodeReviewの方が良いでしょう –
スタックオーバーフローから質問を削除するのは珍しいことです。この考えは、トピックが検索エンジンによって容易に見つけられる何らかの種類のデータベースを作成することです。いくつかの古いコードでは恥ずかしいやり方ではない、経験豊富なコーダーとして誰も生まれていない。私が古いコードを見るたびに、たぶん1歳になるかもしれません。 – Aziuth