I need to know how to implement a greedy algorithm in a card game using C #. The game is a turn-based game. When an AI needs to issue some cards, it should be based on the last state of other cards that are already on the table. Does anyone have a solution for this or maybe a link for me to get started? Thanks in advance!
So far I have just finished the code for shuffling cards:
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);
source
share