// Victory Points awarded from the number of specific structure colour each neighbours constructed private static void AddVictoryNeighboursColour(Player p, Player east, Player west, CardColour c, int amount) { p.addScore(Score.VICTORY, GetVictoryNeighboursColour(east, west, c, amount)); }
public MainGame(Game1 theGame) : base("background", 1.0f) { LABELWIDTH = SEC1WIDTH / 2 - MARGIN; CARDWIDTH = (Game1.WIDTH - 8 * (MARGIN * 2) - 30) / MAXHANDSIZE; CARDHEIGHT = (int) (CARDWIDTH * 1.612); LABELLENGTH = (SEC1WIDTH - MARGIN) / 5; RESOURCELENGTH = (SEC1WIDTH - 3 * MARGIN) * 4 / 5; player = null; wonder = null; lastPlayed = new Dictionary<string, Visual>(); hand = new SortedDictionary<string, Visual>(); leftButton = new Button(new Vector2(Game1.WIDTH - 27, 200 + CARDHEIGHT / 2 - 7), 15, 15, "", "Font1", "left"); leftButton.z = 1; hand.Add("paperleft", new Visual(new Vector2(Game1.WIDTH - 27, 190), 30, CARDHEIGHT + 30, "paperleft")); hand.Add("leftButton", leftButton.setBorder(false)); close = new Button(new Vector2(Game1.WIDTH - Game1.WIDTH / 9, Game1.HEIGHT * 5/ 8), 75, 40, "Close", "Font1"); lastPlayed.Add("bg", new Visual(new Vector2(Game1.WIDTH / 3, Game1.HEIGHT / 6), Game1.WIDTH * 2 / 3, Game1.HEIGHT * 2 / 3, "bg")); lastPlayed.Add("close", close); seatVisuals = new Dictionary<int, Dictionary<string, Visual>>(); baseVisuals = new Dictionary<String, Visual>(); baseVisuals.Add("Label1", new Visual(new Vector2(MARGIN, MARGIN), LABELWIDTH, LABELHEIGHT, "Players", "Font1", null, Color.Gray, "grayback")); baseVisuals.Add("Label2", new Visual(new Vector2(MARGIN + LABELWIDTH, MARGIN), LABELWIDTH, LABELHEIGHT, "icons")); baseVisuals.Add("Divider1", new Visual(new Vector2(SEC1WIDTH - 1, 0), DIVIDERWIDTH, Game1.HEIGHT, "line", Color.Silver)); baseVisuals.Add("Divider2", new Visual(new Vector2(0, SEC1HEIGHT - 1), Game1.WIDTH, DIVIDERWIDTH, "line", Color.Silver)); baseVisuals.Add("Age", new Visual(new Vector2(Game1.WIDTH - MARGIN - 75, MARGIN), 75, 75, "age1")); baseVisuals.Add("discard", new Visual(new Vector2(Game1.WIDTH - MARGIN - 60, MARGIN * 3 + 120), 60, 60, "0", "Font1", null, Color.White, "deck")); baseVisuals["discard"].setLeftMargin(15); baseVisuals["discard"].setTopMargin(9); }
//Checks how a player with neighbours west and east would have to spend in order to meet the given cost //Returns -1 if the player cannot possibly build the card (including if his neighbours have the required //resources, but he cannot afford to purchase them) //Returns 0 if the player has all of the required resources and does not need to purchase any //Otherwise, returns the total number of coins it would cost the player at minimum to purchase the //required resources to meet the cost public static int constructCost(Player player, Player west, Player east, Dictionary<Resource, int> cost) { //check if cost is in coins if (cost.ContainsKey(Resource.COIN)) return (cost[Resource.COIN] > player.getResourceNum(Resource.COIN)) ? -1 : cost[Resource.COIN]; //split the cost into raw and manufactured goods to deal with them separately, as they do not affect each other Dictionary<Resource, int> rawCost = new Dictionary<Resource, int>(); foreach (Resource r in rawGoods) if (cost.ContainsKey(r)) rawCost.Add(r, cost[r]); Dictionary<Resource, int> manCost = new Dictionary<Resource, int>(); foreach (Resource r in manGoods) if (cost.ContainsKey(r)) manCost.Add(r, cost[r]); //get resource lists List<List<Resource>> playerRaw = buildResourceList(player, rawGoods, true); List<List<Resource>> playerMan = buildResourceList(player, manGoods, true); List<List<Resource>> eastRaw = buildResourceList(east, rawGoods, false); List<List<Resource>> westRaw = buildResourceList(west, rawGoods, false); List<List<Resource>> neighbourMan = buildResourceList(east, manGoods, false); neighbourMan.AddRange(buildResourceList(west, manGoods, false)); //calculate cost of manufactured goods int numManPurchased = countPurchases(manCost, playerMan, neighbourMan); int totalCoinCost = numManPurchased * player.mcost; //calculate cost of raw goods if (player.rcostEast == player.rcostWest) { //All neighbour resources can be grouped together, since they cost the same amount List<List<Resource>> neighbourRaw = eastRaw; neighbourRaw.AddRange(westRaw); int numRawPurchased = countPurchases(rawCost, playerRaw, neighbourRaw); totalCoinCost += numRawPurchased * player.rcostWest; } else { //east and west neighbour resorces must be considered separately, as they cost different amounts //countPurchases() will return the coin cost, not just the number of resources purchased int numRawPurchased; if (player.rcostEast < player.rcostWest) numRawPurchased = countPurchases(rawCost, playerRaw, eastRaw, westRaw); else numRawPurchased = countPurchases(rawCost, playerRaw, westRaw, eastRaw); totalCoinCost += numRawPurchased; } return totalCoinCost>player.getResourceNum(Resource.COIN)?-1:totalCoinCost; }
// Victory Points returned for the number of defeat tokens each neighbouring city has private static int GetVictoryNeighboursConflict(Player east, Player west) { return east.getScoreType(Score.DEFEAT) + west.getScoreType(Score.DEFEAT); }
// Babylon B [2nd stage] // Handle this at the end of every age to play the last card if // Player can pay for it, or discard to earn 3 coins or build the third wonder. // EXTRA TURN basically private static void LastCard(Player p, Card c) { // stuff }
//OLD CODE //Returns the part of the given cost that the player cannot meet with his own single resources //Does not consider the player's resource choices private static Dictionary<Resource, int> outsourcedCosts(Player player, Dictionary<Resource, int> cost, List<List<Resource>> remainingPlayerChoices, bool self) { Dictionary<Resource, int> remaining = new Dictionary<Resource, int>(); Dictionary<Resource, int> coveredByChoices = new Dictionary<Resource, int>(); //Costs that are covered by choices (each item in here is the only relevant application of the choice used) foreach (Resource r in cost.Keys) coveredByChoices.Add(r, 0); if (remainingPlayerChoices != null) { foreach (List<Resource> choice in self ? player.getTotalChoices() : player.getPublicChoices()) { int numRelevant = 0; Resource coveredResource = Resource.COIN; foreach (Resource r in choice) if (cost.ContainsKey(r)) { numRelevant++; coveredResource = r; } if (numRelevant == 1) coveredByChoices[coveredResource]++; else remainingPlayerChoices.Add(choice); } } foreach (Resource r in cost.Keys) { if (cost[r] > player.getResourceNum(r) + coveredByChoices[r] && r != Resource.COIN) remaining.Add(r, cost[r] - player.getResourceNum(r)); } return remaining; }
// Science Choice - player chooses which science to gain from the card at the end of the game // NOTE: Should we have this as a max function? eg. Find max of gear, tablet, compass and just add 1? private static void AddScienceChoice(Player p, int x) { int gear = p.getScoreNum(Score.GEAR); int compass = p.getScoreNum(Score.COMPASS); int tablet = p.getScoreNum(Score.TABLET); if (x == 1) { int max1 = CalculateScience((gear + 1), compass, tablet); int max2 = CalculateScience(gear, (compass + 1), tablet); int max3 = CalculateScience(gear, compass, (tablet + 1)); int maxScore = Math.Max(Math.Max(max1, max2), max3); if (maxScore == max1) p.addScore(Score.GEAR, 1); else if (maxScore == max2) p.addScore(Score.COMPASS, 1); else if (maxScore == max3) p.addScore(Score.TABLET, 1); } else if (x == 2) { int max1 = CalculateScience(gear + 2, compass, tablet); int max2 = CalculateScience(gear, compass + 2, tablet); int max3 = CalculateScience(gear, compass, tablet + 2); int max4 = CalculateScience(gear + 1, compass + 1, tablet); int max5 = CalculateScience(gear + 1, compass, tablet + 1); int max6 = CalculateScience(gear, compass + 1, tablet + 1); int maxScore = Math.Max(Math.Max(Math.Max(Math.Max(Math.Max(max1, max2), max3), max4), max5), max6); if (maxScore == max1) p.addScore(Score.GEAR, 2); else if (maxScore == max2) p.addScore(Score.COMPASS, 2); else if (maxScore == max3) p.addScore(Score.TABLET, 2); else if (maxScore == max4) { p.addScore(Score.GEAR, 1); p.addScore(Score.COMPASS, 1); } else if (maxScore == max5) { p.addScore(Score.GEAR, 1); p.addScore(Score.TABLET, 1); } else if (maxScore == max6) { p.addScore(Score.COMPASS, 1); p.addScore(Score.TABLET, 1); } } }
// Victory Points awarded // Through the number of specific structure colour the player has constructed private static void AddVictoryColour(Player p, CardColour c, int amount) { p.addScore(Score.VICTORY, GetVictoryColour(p, c, amount)); }
public static Dictionary<Resource, int> outsourcedCosts(Player player, Dictionary<Resource, int> cost) { return outsourcedCosts(player, cost, null, false); }
// Returns the number of coins awarded from the number of specific structure colour each neighbours have constructed private static int GetCoinAllColour(Player p, Player east, Player west, CardColour c, int amount) { return (p.getCardColourCount(c) + east.getCardColourCount(c) + west.getCardColourCount(c)) * amount; }
private void Initialize() { lock (this) { if (init) return; trade = new TradeInterface(); player = Game1.client.getSelf(); int westSeat = (player.getSeat() - 1 < 0) ? Game1.client.getState().getPlayers().Count - 1 : player.getSeat() - 1; int eastSeat = (player.getSeat() + 1 > Game1.client.getState().getPlayers().Count - 1) ? 0 : player.getSeat() + 1; east = Game1.client.getState().getPlayers().Values.ElementAt(eastSeat); west = Game1.client.getState().getPlayers().Values.ElementAt(westSeat); foreach (Player p in Game1.client.getState().getPlayers().Values) { Visual conflict = new Visual(new Vector2(Game1.WIDTH - MARGIN - 60, MARGIN * 2 + 75), 60, 60, "0", "Font1", null, Color.White, "conflict"); conflict.setLeftMargin(19); conflict.setTopMargin(20); conflict.LoadContent();//BAD HACKS Visual stages = new Visual(new Vector2(Game1.WIDTH - 100, Game1.HEIGHT - 150), 100, 100, "stage13").setVisible(false); Game1.wonders[p.getBoard().getName()].setPosition(new Vector2(5 + SEC1WIDTH, 5 + SEC1HEIGHT)).setWidth(WONDERWIDTH * 2 + 10).setHeight(WONDERHEIGHT * 2).setTexture(p.getBoard().getImageName()); seatVisuals.Add(p.getSeat(), new Dictionary<string, Visual>() { { "wonder", Game1.wonders[p.getBoard().getName()] }, { "conflict", conflict }, { "stages", stages } }); baseVisuals.Add("player" + p.getSeat(), new Visual(new Vector2(MARGIN, MARGIN * 2 + (MARGIN + LABELHEIGHT) * (p.getSeat() + 1)), DROPDOWNWIDTH, LABELHEIGHT, (p.getSeat() + 1) + "|" + p.getName(), "Font1", Color.White, (p.getSeat() == player.getSeat()) ? Color.Orange : Color.Gray, "grayback")); baseVisuals.Add("status" + p.getSeat(), new Visual(new Vector2(MARGIN + LABELWIDTH, MARGIN * 2 + (MARGIN + LABELHEIGHT) * (p.getSeat() + 1)), LABELWIDTH, LABELHEIGHT, "blank")); baseVisuals.Add("gear" + p.getSeat(), new Visual(new Vector2(MARGIN + LABELWIDTH + (LABELWIDTH * 1 / 24), MARGIN * 2 + (MARGIN + LABELHEIGHT) * (p.getSeat() + 1)), p.getScoreNum(Score.GEAR).ToString(), "Font1")); baseVisuals.Add("tablet" + p.getSeat(), new Visual(new Vector2(MARGIN + LABELWIDTH + (LABELWIDTH * 5 / 24), MARGIN * 2 + (MARGIN + LABELHEIGHT) * (p.getSeat() + 1)), p.getScoreNum(Score.TABLET).ToString(), "Font1")); baseVisuals.Add("compas" + p.getSeat(), new Visual(new Vector2(MARGIN + LABELWIDTH + (LABELWIDTH * 9 / 24), MARGIN * 2 + (MARGIN + LABELHEIGHT) * (p.getSeat() + 1)), p.getScoreNum(Score.COMPASS).ToString(), "Font1")); baseVisuals.Add("victory" + p.getSeat(), new Visual(new Vector2(MARGIN + LABELWIDTH + (LABELWIDTH * 13 / 24), MARGIN * 2 + (MARGIN + LABELHEIGHT) * (p.getSeat() + 1)), p.getScoreNum(Score.VICTORY_BLUE).ToString(), "Font1")); baseVisuals.Add("army" + p.getSeat(), new Visual(new Vector2(MARGIN + LABELWIDTH + (LABELWIDTH * 19 / 24), MARGIN * 2 + (MARGIN + LABELHEIGHT) * (p.getSeat() + 1)), p.getScoreNum(Score.ARMY).ToString(), "Font1")); } baseVisuals.Add("resources", new Visual(new Vector2(LABELLENGTH + MARGIN * 2, SEC1HEIGHT + MARGIN * 2), RESOURCELENGTH, LABELHEIGHT, "resourceBar")); baseVisuals.Add("west", new Visual(new Vector2(MARGIN, SEC1HEIGHT + LABELHEIGHT + MARGIN * 3), LABELLENGTH, LABELHEIGHT, (westSeat + 1) + "|" + "West", "Font1", null, null, "grayback")); baseVisuals.Add("east", new Visual(new Vector2(MARGIN, SEC1HEIGHT + LABELHEIGHT * 2 + MARGIN * 4), LABELLENGTH, LABELHEIGHT, (eastSeat + 1) + "|" + "East", "Font1", null, null, "grayback")); baseVisuals.Add("self", new Visual(new Vector2(MARGIN, Game1.HEIGHT - (MARGIN + LABELHEIGHT)), LABELLENGTH, LABELHEIGHT, "Self", "Font1", null, null, "grayback")); baseVisuals.Add("westresources", new Visual(new Vector2(LABELLENGTH + MARGIN * 2, SEC1HEIGHT + LABELHEIGHT + MARGIN * 3), RESOURCELENGTH, LABELHEIGHT, "emptyResourceBar")); baseVisuals.Add("eastresources", new Visual(new Vector2(LABELLENGTH + MARGIN * 2, SEC1HEIGHT + LABELHEIGHT * 2 + MARGIN * 4), RESOURCELENGTH, LABELHEIGHT, "emptyResourceBar")); baseVisuals.Add("selfresources", new Visual(new Vector2(LABELLENGTH + MARGIN * 2, Game1.HEIGHT - (MARGIN + LABELHEIGHT)), RESOURCELENGTH, LABELHEIGHT, "emptyResourceBar")); int RESOURCEHEIGHT = SEC1HEIGHT + LABELHEIGHT + MARGIN * 3; for (int i = 0; i < NUMRESOURCES; i++) { baseVisuals.Add("west" + i, new Visual(new Vector2(LABELLENGTH + MARGIN * 2 + RESOURCELENGTH * i / 8 + 5, RESOURCEHEIGHT), west.getResourceNum((Resource)i) + "", "Font1")); baseVisuals.Add("east" + i, new Visual(new Vector2(LABELLENGTH + MARGIN * 2 + RESOURCELENGTH * i / 8 + 5, RESOURCEHEIGHT + LABELHEIGHT + MARGIN), east.getResourceNum((Resource)i) + "", "Font1")); baseVisuals.Add("self" + i, new Visual(new Vector2(LABELLENGTH + MARGIN * 2 + RESOURCELENGTH * i / 8 + 5, Game1.HEIGHT - (MARGIN + LABELHEIGHT)), player.getResourceNum((Resource)i) + "", "Font1")); if ((Resource)i == Resource.COIN) { baseVisuals["east" + i].setLeftMargin(-2); baseVisuals["west" + i].setLeftMargin(-2); baseVisuals["self" + i].setLeftMargin(-2); } } hand.Add("papermiddle", new Visual(new Vector2(MARGIN + 30 + (CARDWIDTH / 2 + MARGIN) * (7 - player.getHand().Count) + 1, 190), Game1.WIDTH - (MARGIN + 30 + (CARDWIDTH / 2 + MARGIN) * (7 - player.getHand().Count)), CARDHEIGHT + 25, "papermiddle")); //updatePlayed(); updateHands(); updateScroll(); //updatePlayers(); baseVisuals.Add("Scorehead", new Visual(new Vector2(Game1.WIDTH / 4, Game1.HEIGHT / 4), Game1.WIDTH / 2, 50, "scorehead").setVisible(false)); int n = 1; foreach (Player p in Game1.client.getState().getPlayers().Values) { baseVisuals.Add("name" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH / 4, Game1.HEIGHT / 4 + 40 * n), (int)(Game1.WIDTH / 2 * 0.296f), 40, p.getName(), "Font1", null, null, "line").setVisible(false)); baseVisuals.Add("conflict" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH / 4 + (int)(Game1.WIDTH / 2 * 0.296f), Game1.HEIGHT / 4 + 40 * n), SCOREWIDTH, 40, p.getScoreNum(Score.CONFLICT).ToString(), "Font1", null, null, "line").setVisible(false)); baseVisuals.Add("coin" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH / 4 + (int)(Game1.WIDTH / 2 * 0.296f) + SCOREWIDTH, Game1.HEIGHT / 4 + 40 * n), SCOREWIDTH, 40, p.getScoreNum(Score.COIN).ToString(), "Font1", null, null, "line").setVisible(false)); baseVisuals.Add("stages" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH / 4 + (int)(Game1.WIDTH / 2 * 0.296f) + SCOREWIDTH * 2, Game1.HEIGHT / 4 + 40 * n), SCOREWIDTH, 40, p.getScoreNum(Score.STAGES).ToString(), "Font1", null, null, "line").setVisible(false)); baseVisuals.Add("blue" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH / 4 + (int)(Game1.WIDTH / 2 * 0.296f) + SCOREWIDTH * 3, Game1.HEIGHT / 4 + 40 * n), SCOREWIDTH, 40, p.getScoreNum(Score.VICTORY_BLUE).ToString(), "Font1", null, null, "line").setVisible(false)); baseVisuals.Add("commerce" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH / 4 + (int)(Game1.WIDTH / 2 * 0.296f) + SCOREWIDTH * 4, Game1.HEIGHT / 4 + 40 * n), SCOREWIDTH, 40, p.getScoreNum(Score.COMMERCE).ToString(), "Font1", null, null, "line").setVisible(false)); baseVisuals.Add("guild" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH / 4 + (int)(Game1.WIDTH / 2 * 0.296f) + SCOREWIDTH * 5, Game1.HEIGHT / 4 + 40 * n), SCOREWIDTH, 40, p.getScoreNum(Score.GUILD).ToString(), "Font1", null, null, "line").setVisible(false)); baseVisuals.Add("science" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH / 4 + (int)(Game1.WIDTH / 2 * 0.296f) + SCOREWIDTH * 6, Game1.HEIGHT / 4 + 40 * n), SCOREWIDTH, 40, p.getScoreNum(Score.SCIENCE).ToString(), "Font1", null, null, "line").setVisible(false)); baseVisuals.Add("sum" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH / 4 + (int)(Game1.WIDTH / 2 * 0.296f) + SCOREWIDTH * 7, Game1.HEIGHT / 4 + 40 * n), SCOREWIDTH, 40, p.getScoreNum(Score.VICTORY).ToString(), "Font1", null, null, "line").setVisible(false)); lastPlayed.Add("player" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH * ((n - 1) % 4 + 2) / 6 + MARGIN, Game1.HEIGHT * ((int)(n / 5) * 2 + 1) / 6 + MARGIN), Game1.WIDTH / 6 - MARGIN * 5, LABELHEIGHT, (p.getSeat() +1) + "|" + p.getName(), "Font1", null, null, "grayback")); lastPlayed.Add("action" + p.getSeat(), new Visual(new Vector2(Game1.WIDTH * ((n - 1) % 4 + 2) / 6 + MARGIN, Game1.HEIGHT * ((int)(n / 5) * 2 + 1) / 6 + LABELHEIGHT + MARGIN * 2), Game1.WIDTH / 6 - MARGIN * 6, Game1.HEIGHT / 3 - MARGIN * 3 - LABELHEIGHT, "coin")); n++; } quit = new Button(new Vector2(Game1.WIDTH / 2 - 70, Game1.HEIGHT / 4 + 40 * n + MARGIN), 140, 50, "Quit", "Font1"); baseVisuals.Add("quit", quit.setVisible(false)); seatViewed = player.getSeat(); activeVisuals = seatVisuals[seatViewed]; LoadContent(); init = true; } }
// Olympia B [3rd stage] // The third stage allows the player to "copy" a Guild (purple card) of // their choice built by one of their two neighboring cities at the end of the game private static void CopyGuild(Player p, Player east, Player west) { p.addPlayed(GetGuildCopyCard(p, east, west)); }
// Olympia A // the player can, once per Age, build a structure of their choice for free private static void FreeBuild(Player p, Card c, int age) { // stuff p.addPlayed(c); }
// Victory Points awarded from the number of wonderstages the player has built private static void AddVictoryWonder(Player p) { p.addScore(Score.VICTORY, p.getBoard().getStagesBuilt()); }
// Victory Points awarded from the number of conflict points each neighbour has private static void AddVictoryNeighboursConflict(Player p, Player east, Player west) { p.addScore(Score.VICTORY, GetVictoryNeighboursConflict(east, west)); }
// Victory Points, Army, Science or any other generic score // This could probably be used to replace alot of generic score functions private static void AddScore(Player p, Score s, int points) { p.addScore(s, points); }
// Trading Cost for East && West of manufactured Resources private static void SetManufactedTrade(Player p) { p.mcost = 1; }
public void addPlayer(Player _player) { players.Add(_player.getID(), _player); }
private static void SetRawTradeWest(Player p) { p.rcostWest = 1; }
public static List<List<int>> getResourcePurchaseSplits(Dictionary<Resource, int> cost, Player player, Player east, Player west) { List<List<int>> splits = new List<List<int>>(); //check if cost is in coins if (cost.ContainsKey(Resource.COIN)) { splits.Add(new List<int> { 0, 0 }); return splits; } //split the cost into raw and manufactured goods to deal with them separately, as they do not affect each other Dictionary<Resource, int> rawCost = new Dictionary<Resource, int>(); foreach (Resource r in rawGoods) if (cost.ContainsKey(r)) rawCost.Add(r, cost[r]); Dictionary<Resource, int> manCost = new Dictionary<Resource, int>(); foreach (Resource r in manGoods) if (cost.ContainsKey(r)) manCost.Add(r, cost[r]); //get resource lists List<List<Resource>> playerRaw = buildResourceList(player, rawGoods, true); List<List<Resource>> playerMan = buildResourceList(player, manGoods, true); List<List<Resource>> eastRaw = buildResourceList(east, rawGoods, false); List<List<Resource>> westRaw = buildResourceList(west, rawGoods, false); List<List<Resource>> eastMan = buildResourceList(east, manGoods, false); List<List<Resource>> westMan = buildResourceList(west, manGoods, false); getRemainingCostAndChoices(rawCost, playerRaw, rawCost, playerRaw); //rawCost and playerRaw should now be updated to apply player's raw goods to the cost, including choices //where only one choice is relevant, etc. playerRaw should only contain choices with multiple elements that //can't be reconciled simply. List<List<List<Resource>>> playerRawChoiceCombos = enumerateCombos(playerRaw); List<List<int>> rawSplits = new List<List<int>>(); if (playerRawChoiceCombos.Count == 0) { List<List<Dictionary<Resource, int>>> rawCostSplits = splitCost(rawCost); foreach (List<Dictionary<Resource, int>> costSplit in rawCostSplits) { Dictionary<Resource, int> cantCover = new Dictionary<Resource, int>(); List<List<Resource>> remainingResources = new List<List<Resource>>(); getRemainingCostAndChoices(costSplit[0], eastRaw, cantCover, remainingResources); if (cantCover.Count > 0 && cantCover.Values.Count(x => x > 0) > 0) continue; getRemainingCostAndChoices(costSplit[1], westRaw, cantCover, remainingResources); if (cantCover.Count > 0 && cantCover.Values.Count(x => x > 0) > 0) continue; rawSplits.Add(new List<int> { costSplit[0].Values.Sum() * player.rcostEast, costSplit[1].Values.Sum() * player.rcostWest }); } } foreach (List<List<Resource>> combo in playerRawChoiceCombos) { Dictionary<Resource, int> remainingRawCost = new Dictionary<Resource, int>(); getRemainingCostAndChoices(rawCost, combo, remainingRawCost, combo); List<List<Dictionary<Resource, int>>> rawCostSplits = splitCost(remainingRawCost); foreach (List<Dictionary<Resource, int>> costSplit in rawCostSplits) { Dictionary<Resource, int> cantCover = new Dictionary<Resource, int>(); List<List<Resource>> remainingResources = new List<List<Resource>>(); getRemainingCostAndChoices(costSplit[0], eastRaw, cantCover, remainingResources); if (cantCover.Count > 0 && cantCover.Values.Count(x => x > 0) > 0) continue; getRemainingCostAndChoices(costSplit[1], westRaw, cantCover, remainingResources); if (cantCover.Count > 0 && cantCover.Values.Count(x => x > 0) > 0) continue; rawSplits.Add(new List<int> { costSplit[0].Values.Sum()*player.rcostEast, costSplit[1].Values.Sum()*player.rcostWest }); } } getRemainingCostAndChoices(manCost, playerMan, manCost, playerMan); //manCost and playerMan should now be updated to apply player's man goods to the cost, including choices //where only one choice is relevant, etc. playerMan should only contain choices with multiple elements that //can't be reconciled simply. List<List<List<Resource>>> playerManChoiceCombos = enumerateCombos(playerMan); List<List<int>> manSplits = new List<List<int>>(); if (playerManChoiceCombos.Count == 0) { List<List<Dictionary<Resource, int>>> manCostSplits = splitCost(manCost); foreach (List<Dictionary<Resource, int>> costSplit in manCostSplits) { Dictionary<Resource, int> cantCover = new Dictionary<Resource, int>(); List<List<Resource>> remainingResources = new List<List<Resource>>(); getRemainingCostAndChoices(costSplit[0], eastMan, cantCover, remainingResources); if (cantCover.Count > 0 && cantCover.Values.Count(x => x > 0) > 0) continue; getRemainingCostAndChoices(costSplit[1], westMan, cantCover, remainingResources); if (cantCover.Count > 0 && cantCover.Values.Count(x => x > 0) > 0) continue; rawSplits.Add(new List<int> { costSplit[0].Values.Sum() * player.mcost, costSplit[1].Values.Sum() * player.mcost }); } } foreach (List<List<Resource>> combo in playerManChoiceCombos) { Dictionary<Resource, int> remainingManCost = new Dictionary<Resource, int>(); getRemainingCostAndChoices(manCost, combo, remainingManCost, combo); List<List<Dictionary<Resource, int>>> manCostSplits = splitCost(remainingManCost); foreach (List<Dictionary<Resource, int>> costSplit in manCostSplits) { Dictionary<Resource, int> cantCover = new Dictionary<Resource, int>(); List<List<Resource>> remainingResources = new List<List<Resource>>(); getRemainingCostAndChoices(costSplit[0], eastMan, cantCover, remainingResources); if (cantCover.Count > 0 && cantCover.Values.Count(x => x > 0) > 0) continue; getRemainingCostAndChoices(costSplit[1], westMan, cantCover, remainingResources); if (cantCover.Count > 0 && cantCover.Values.Count(x => x > 0) > 0) continue; rawSplits.Add(new List<int> { costSplit[0].Values.Sum() * player.mcost, costSplit[1].Values.Sum() * player.mcost }); } } if (rawSplits.Count == 0) rawSplits.Add(new List<int> { 0, 0 }); if (manSplits.Count == 0) manSplits.Add(new List<int> { 0, 0 }); foreach (List<int> option in rawSplits) foreach (List<int> option2 in manSplits) splits.Add(new List<int> { option[0] + option2[0], option[1] + option2[1] }); return splits; }
// Returns the number of coins awarded with the basis of Wonder stages built private static int GetCoinWonder(Player p, int amount) { return p.getBoard().getStagesBuilt() * amount; }
// Victory Points awarded from the number of wonderstages built from each neighbour including the player private static void AddVictoryAllWonders(Player p, Player east, Player west) { p.addScore(Score.VICTORY, GetVictoryAllWonders(p, east, west)); }
public TradeInterface() : base("bg", new Vector2(Game1.WIDTH / 3, Game1.HEIGHT / 6), Game1.WIDTH * 2 / 3, Game1.HEIGHT * 2 / 3) { CARDHEIGHT = height - MARGIN * 2; CARDWIDTH = (int) (CARDHEIGHT / CARDRATIO) - MARGIN * 2; SECTIONWIDTH = (width - MARGIN * 4) / 3; RSIZE = (int)(height * 0.054f); self = Game1.client.getSelf(); west = Game1.client.westPlayer(self); east = Game1.client.eastPlayer(self); visuals1 = new Dictionary<string, Visual>(); trade = new Dictionary<string, Visual>(); requirements = new Dictionary<Visual, Resource>(); selfChoices = new List<TradeChoice>(); eastChoices = new List<TradeChoice>(); westChoices = new List<TradeChoice>(); card = new Visual(new Vector2(pos.X + MARGIN, pos.Y + MARGIN), CARDWIDTH, CARDHEIGHT, null); buildCard = new Button(new Vector2(pos.X + width - 150, pos.Y + MARGIN + height * 0 / 4), 100, 50, "Card", "Font1"); buildStage = new Button(new Vector2(pos.X + width - 150, pos.Y + MARGIN * 2 + height * 1 / 4), 100, 50, "Stage", "Font1"); sellCard = new Button(new Vector2(pos.X + width - 150, pos.Y + MARGIN * 3 + height * 2 / 4), 100, 50, "Sell", "Font1"); close = new Button(new Vector2(pos.X + width - 150, pos.Y + MARGIN * 4 + height * 3 / 4), 100, 50, "Close", "Font1"); back = new Button(new Vector2(pos.X + width / 5, pos.Y + height * 9 / 10), 100, 40, "Back", "Font1"); build = new Button(new Vector2(pos.X + width * 3 / 5, pos.Y + height * 9 / 10), 100, 40, "Build", "Font1"); visuals1.Add("buildcard", buildCard); visuals1.Add("buildstage", buildStage); visuals1.Add("sellCard", sellCard); visuals1.Add("card", card); visuals1.Add("close", close); trade.Add("discount", new Visual(new Vector2(pos.X + MARGIN * 2, pos.Y + MARGIN), "Requirements:", "Font1", Color.Black)); trade.Add("costborder", new Visual(new Vector2(pos.X + MARGIN - 1, pos.Y + MARGIN - 1), SECTIONWIDTH + 2, (int)(RSIZE * 2.5f) + 2, "border").setBorder(false)); trade.Add("label1", new Visual(new Vector2(pos.X + MARGIN * 2, pos.Y + (int)(RSIZE * 2.5) + MARGIN * 2), "West", "Font1", Color.Black)); trade.Add("border1", new Visual(new Vector2(pos.X + MARGIN - 1, pos.Y + (int)(RSIZE * 2.5) + MARGIN * 2 - 1), SECTIONWIDTH + 2, (int)(RSIZE * 1.5f) + 2, "border").setBorder(false)); trade.Add("label2", new Visual(new Vector2(pos.X + SECTIONWIDTH + MARGIN * 3, pos.Y + (int)(RSIZE * 2.5) + MARGIN * 2), "Self", "Font1", Color.Black)); trade.Add("border2", new Visual(new Vector2(pos.X + SECTIONWIDTH + MARGIN * 2 - 1, pos.Y + (int)(RSIZE * 2.5) + MARGIN * 2 - 1), SECTIONWIDTH + 2, (int)(RSIZE * 1.5f) + 2, "border").setBorder(false)); trade.Add("label3", new Visual(new Vector2(pos.X + (SECTIONWIDTH + MARGIN) * 2 + MARGIN * 2, pos.Y + (int)(RSIZE * 2.5) + MARGIN * 2), "East", "Font1", Color.Black)); trade.Add("border3", new Visual(new Vector2(pos.X + (SECTIONWIDTH + MARGIN) * 2 + MARGIN - 1, pos.Y + (int)(RSIZE * 2.5) + MARGIN * 2 - 1), SECTIONWIDTH + 2, (int)(RSIZE * 1.5f) + 2, "border").setBorder(false)); trade.Add("border4", new Visual(new Vector2(pos.X + (SECTIONWIDTH + MARGIN) * 0 + MARGIN - 1, pos.Y + RSIZE * 4 + MARGIN * 3 - 1), SECTIONWIDTH + 2, RSIZE * 6 + 2, "border").setBorder(false)); trade.Add("border5", new Visual(new Vector2(pos.X + (SECTIONWIDTH + MARGIN) * 1 + MARGIN - 1, pos.Y + RSIZE * 4 + MARGIN * 3 - 1), SECTIONWIDTH + 2, RSIZE * 9 + 2, "border").setBorder(false)); trade.Add("border6", new Visual(new Vector2(pos.X + (SECTIONWIDTH + MARGIN) * 2 + MARGIN - 1, pos.Y + RSIZE * 4 + MARGIN * 3 - 1), SECTIONWIDTH + 2, RSIZE * 6 + 2, "border").setBorder(false)); trade.Add("border7", new Visual(new Vector2(pos.X + (SECTIONWIDTH + MARGIN) * 0 + MARGIN - 1, pos.Y + RSIZE * 10 + MARGIN * 3 - 1), SECTIONWIDTH + 2, RSIZE * 3 + 2, "border").setBorder(false)); trade.Add("border8", new Visual(new Vector2(pos.X + (SECTIONWIDTH + MARGIN) * 2 + MARGIN - 1, pos.Y + RSIZE * 10 + MARGIN * 3 - 1), SECTIONWIDTH + 2, RSIZE * 3 + 2, "border").setBorder(false)); westHelpers = new Dictionary<Resource, TradeHelper>(); eastHelpers = new Dictionary<Resource, TradeHelper>(); foreach (Resource r in Enum.GetValues(typeof(Resource))){ if (r != Resource.COIN) { westHelpers.Add(r, new TradeHelper(r, 3, new Vector2(pos.X + MARGIN * 2, pos.Y + ((int)r + 4) * RSIZE + MARGIN * 3))); eastHelpers.Add(r, new TradeHelper(r, 3, new Vector2(pos.X + SECTIONWIDTH * 2 + MARGIN * 4, pos.Y + ((int)r + 4) * RSIZE + MARGIN * 3))); } } trade.Add("back", back); trade.Add("build", build); trade.Add("rwest", new Visual(new Vector2(pos.X + width * 1 / 3 + MARGIN, pos.Y + MARGIN), 110, 45, "rwest")); trade.Add("reast", new Visual(new Vector2(pos.X + width * 1 / 3 + MARGIN, pos.Y + MARGIN), 110, 45, "reast")); trade.Add("rboth", new Visual(new Vector2(pos.X + width * 1 / 3 + MARGIN, pos.Y + MARGIN), 110, 45, "rboth")); trade.Add("mboth", new Visual(new Vector2(pos.X + width * 2 / 3 + MARGIN * 2, pos.Y + MARGIN), 110, 45, "mboth")); trade.Add("westCoin", new Visual(new Vector2(pos.X + SECTIONWIDTH/3 + MARGIN - 1, pos.Y + (int)(RSIZE * 13) + MARGIN * 5 - 1), RSIZE * 2, RSIZE * 2, westCoin.ToString(), "Font1", Color.Black, Color.White, "coin", Game1.HEIGHT / 70).setBorder(false)); trade.Add("selfCoin", new Visual(new Vector2(pos.X + SECTIONWIDTH / 3 + (SECTIONWIDTH + MARGIN) * 1 + MARGIN - 1, pos.Y + (int)(RSIZE * 13) + MARGIN * 5 - 1), RSIZE * 2, RSIZE * 2, (self.getResourceNum(Resource.COIN) - westCoin - eastCoin).ToString(), "Font1", Color.Black, Color.White, "coin", Game1.HEIGHT / 70).setBorder(false)); trade.Add("eastCoin", new Visual(new Vector2(pos.X + SECTIONWIDTH / 3 + (SECTIONWIDTH + MARGIN) * 2 + MARGIN - 1, pos.Y + (int)(RSIZE * 13) + MARGIN * 5 - 1), RSIZE * 2, RSIZE * 2, eastCoin.ToString(), "Font1", Color.Black, Color.White, "coin", Game1.HEIGHT / 70).setBorder(false)); for (int i = 0; i < 7; i++) { requirements.Add(new Visual(new Vector2(pos.X + MARGIN * 2 + RSIZE * i, pos.Y + MARGIN + 30), RSIZE, RSIZE, null).setVisible(false), Resource.CLAY); } activeVisuals = visuals1; hideTrade(); }
// Returns the best Guild Card to copy from the player's neighbours private static Card GetGuildCopyCard(Player p, Player east, Player west) { List<string> guilds = new List<string>(); Dictionary<string, int> guildScore = new Dictionary<string, int>(); string bestCard = null; int bestScore = 0; // Guild Cards taken from East Player foreach (string c in east.getPlayed()) if (CardLibrary.getCard(c).colour.Equals(CardColour.PURPLE)) guilds.Add(c); // Guild Cards taken from West Player foreach (string c in west.getPlayed()) if (CardLibrary.getCard(c).colour.Equals(CardColour.PURPLE)) guilds.Add(c); // Looping through the Guild Cards available to calculate the best guild foreach (string cardID in guilds) { guildScore.Add(cardID, 0); foreach (Effect e in CardLibrary.getCard(cardID).effects) { if (e.type.Equals(Effect.TypeType.VICTORY) && e.from.Equals(Effect.FromType.NEIGHBOURS)) { if (cardType.ContainsKey(e.basis)) guildScore[cardID] = GetVictoryNeighboursColour(east, west, cardType[e.basis], e.amount); else if (e.basis.Equals(Effect.BasisType.DEFEAT)) { //Need to finish the function called here guildScore[cardID] = GetVictoryNeighboursConflict(east, west); } } else if (e.type.Equals(Effect.TypeType.VICTORY) && e.from.Equals(Effect.FromType.PLAYER) && cardType.ContainsKey(e.basis)) guildScore[cardID] += GetVictoryColour(p, cardType[e.basis], e.amount); // Added multiple times else if (e.type.Equals(Effect.TypeType.VICTORY) && e.from.Equals(Effect.FromType.ALL) && e.basis.Equals(Effect.BasisType.WONDER)) guildScore[cardID] = GetVictoryAllWonders(p, east, west); else if (e.type.Equals(Effect.TypeType.SCHOICE)) { //CalculateScience(g c t) int gear = p.getScoreNum(Score.GEAR); int comp = p.getScoreNum(Score.COMPASS); int tab = p.getScoreNum(Score.TABLET); int maxScience = Math.Max(Math.Max( CalculateScience(gear + 1, comp, tab), CalculateScience(gear, comp + 1, tab)), CalculateScience(gear, comp, tab + 1)); guildScore[cardID] = maxScience; } } } // End Foreach string cardID in guilds // Finding the best guild Card foreach (KeyValuePair<string, int> key in guildScore) { if (key.Value > bestScore) { bestScore = key.Value; bestCard = key.Key; } } // Returning the Best Guild Card return CardLibrary.getCard(bestCard); }
//Checks whether a player can build a card from a chain public static bool canChainBuild(Player player, Card card) { foreach (string cardID in player.getPlayed()) if (card.chains.Contains(CardLibrary.getCard(cardID).name)) return true; return false; }
// Victory Points returned from the number of wonderstages built from each neighbour including the player private static int GetVictoryAllWonders(Player p, Player east, Player west) { return p.getBoard().getStagesBuilt() + east.getBoard().getStagesBuilt() + west.getBoard().getStagesBuilt(); }
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; }
// Victory Points returned from the number of specific structure colour the player has constructed private static int GetVictoryColour(Player p, CardColour c, int amount) { return p.getCardColourCount(c) * amount; }
// Victory Points returned from the number of specific structure colour each neighbours constructed private static int GetVictoryNeighboursColour(Player east, Player west, CardColour c, int amount) { return (east.getCardColourCount(c) + west.getCardColourCount(c)) * amount; }
private static void AddResourceUnPurchaseable(Player p, List<Resource> r) { p.addPrivateChoices(r); }