我需要知道如何使用 C# 在纸牌游戏中实现贪心算法。游戏是回合制游戏。当AI应该发一些牌时,必须基于已经在桌上的其他牌的最新状态。有没有人对此有解决方案,或者可能是我开始的参考?提前致谢!
现在我只完成了洗牌的代码:
List<int> cards = new List<int>();
for (int j = 1; j <= 2; j++)
{
for (int i = 1; i <= 54; i++)
{
cards.Add(i);
}
}
List<int> ShuffledCards = new List<int>();
Random random = new Random();
int iterations = cards.Count;
int index = 0;
for (int j = 1; j <= 2; j++)
{
for (int i = 0; i < iterations; i++)
{
index = random.Next(0, iterations - i);
ShuffledCards.Add(cards[index]);
cards.RemoveAt(index);
}
iterations = cards.Count;
index = 0;
}
ShuffledCards.Reverse(0, ShuffledCards.Count);
ShuffledCards.RemoveRange(0, 8);
ShuffledCards.Reverse(0, ShuffledCards.Count);