Atef Ramadan Atef Ramadan - 2 years ago 119
C# Question

C# uno game ai select wild color by hand

i was writing an uno AI but i faced a problem in wild card play..
i want the AI to select the best color to select in a wild card by his hand of cards but i couldn't get any idea doing it..

the card is a class which have Face string and Color enum

public class Card
public CardColor Color { get; set; }
public string Face { get; set; }

public Card(CardColor color, string face)
Color = color;
Face = face;

public enum CardColor
Red, Green, Blue, Yellow, Wild

and each play has a list of cards

public List<Card> Cards { get; set; }

now i need to select hand color to play the wild cards :/

Answer Source

Following on from my comment, if you want to determine the wild card colour by frequency of card colour in the list of cards you can do it like this:

var mostFrequentColor = Cards.GroupBy(c => c.Color)
                             .OrderByDescending(x => x.Count())
                             .FirstOrDefault(y => y.Color)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download