private static List<List<Resource>> buildResourceList(Player p, List<Resource> rSet, bool self) { List<List<Resource>> resources = new List<List<Resource>>(); Dictionary<Resource, int> playerResources = p.getResources(); List<List<Resource>> playerChoices = self?p.getTotalChoices():p.getPublicChoices(); foreach (Resource r in rSet) if (r != Resource.COIN) for (int i = 0; i < playerResources[r]; i++) resources.Add(new List<Resource> { r }); foreach (List<Resource> choice in playerChoices) { List<Resource> l = new List<Resource>(); l.AddRange(choice); if (!rSet.Contains(l[0])) continue; resources.Add(l); } return resources; }
public static Card GetBestResourceCard(Player p, Player east, Player west) { Dictionary<Resource, double> priorityList = new Dictionary<Resource, double>(); Dictionary<Card, double> cardValue = new Dictionary<Card, double>(); List<string> hand = p.getHand(); List<Card> cards = new List<Card>(); Card candidate = null; // Might not use this double eastFactor = 1 - p.rcostEast/3; double westFactor = 1 - p.rcostWest/3; double mcost = 1 - p.mcost/3; foreach (KeyValuePair<Resource, int> r in p.getResources()) { priorityList[r.Key] += r.Value; } foreach (KeyValuePair<Resource, int> r in east.getResources()) { priorityList[r.Key] += eastFactor * r.Value; } foreach (KeyValuePair<Resource, int> r in west.getResources()) { priorityList[r.Key] += westFactor * r.Value; } foreach (string c in hand) { Card currCard = CardLibrary.getCard(c); foreach (Effect e in currCard.effects) { if (resourceType.ContainsKey(e.type)) { cards.Add(currCard); break; } } } foreach (Card c in cards) { cardValue.Add(c, 0); foreach (Effect e in c.effects) { if (resourceType.ContainsKey(e.type)) { if (cardValue[c] == 0) { cardValue[c] += priorityList[resourceType[e.type]]; break; } else { cardValue[c] += cardValue[c] + priorityList[resourceType[e.type]]; break; } } } } foreach (KeyValuePair<Card, double> k in cardValue) { if (candidate == null) candidate = k.Key; if (cardValue[candidate] > k.Value) candidate = k.Key; } return candidate; }