public CityData adjustDisease(DiseaseColor color, int adjustment) { CityData result = new CityData(this); int newValue = result.diseases[(int)color] + adjustment; Debug.Assert(newValue <= 3 && newValue >= 0); result.diseases[(int)color] = newValue; return result; }
//dangerous...modifies the Map public Map addDisease(City c, int num = 1) { Map result = new Map(this); DiseaseColor color = c.color; for (int i = 0; i < num; i++) { if (result.cities[c.cityNumber].disease(color) < 3) { result.cities[c.cityNumber] = result.cities[c.cityNumber].adjustDisease(color, 1); if (result.diseaseLevel(c, color) == 3) { result.aboutToOutbreak = new List <City>(result.aboutToOutbreak); result.aboutToOutbreak.Add(c); } result.numInfectionsInCities++; } else { //outbreak List <City> outbreaks = new List <City>(); outbreaks.Add(c); List <City> toEvaluate = new List <City>(); toEvaluate.AddRange(c.adjacent); while (toEvaluate.Count != 0) { City current = toEvaluate.ElementAt(0); toEvaluate.RemoveAt(0); if (outbreaks.Contains(current)) { continue; } if (result.cities[current.cityNumber].disease(color) < 3) { result.cities[current.cityNumber] = result.cities[current.cityNumber].adjustDisease(color, 1); } else { toEvaluate.AddRange(current.adjacent); outbreaks.Add(current); } result.numInfectionsInCities++; if (result.diseaseLevel(current, color) == 3) { result.aboutToOutbreak = new List <City>(result.aboutToOutbreak); result.aboutToOutbreak.Add(current); } } result._outbreakCount += outbreaks.Count; } } return(result); }
public City(string name, DiseaseColor color, int number, float x = 0, float y = 0) { this.name = name; this.color = color; adjacent = new List <City>(); relativeX = x; relativeY = y; cityNumber = number; }
public CityData adjustDisease(DiseaseColor color, int adjustment) { CityData result = new CityData(this); int newValue = result.diseases[(int)color] + adjustment; Debug.Assert(newValue <= 3 && newValue >= 0); result.diseases[(int)color] = newValue; return(result); }
public void CityConstructorTest() { string name = "New York"; DiseaseColor color = DiseaseColor.BLACK; City target = new City(name, color, 1); Assert.AreEqual(name, target.name); Assert.AreEqual(color, target.color); }
public City(string name, DiseaseColor color, int number, float x = 0, float y = 0) { this.name = name; this.color = color; adjacent = new List<City>(); relativeX = x; relativeY = y; cityNumber = number; }
public static Color toForeColor(DiseaseColor c) { switch (c) { case DiseaseColor.YELLOW: return Color.Black; default: return Color.White; } }
public static Color toForeColor(DiseaseColor c) { switch (c) { case DiseaseColor.YELLOW: return(Color.Black); default: return(Color.White); } }
public GameState cureDisease(DiseaseColor color) { GameState result = new GameState(this); result.curesFound = new bool[4]; for (int i = 0; i < 4; i++) { result.curesFound[i] = curesFound[i]; } result.curesFound[(int)color] = true; return(result); }
public List <CureCityAction> getCureActionsFor(Player player) { List <CureCityAction> cures = new List <CureCityAction>(); for (int i = 0; i < 4; i++) { DiseaseColor color = (DiseaseColor)i; if (diseaseLevel(player.position, color) > 0) { cures.Add(new CureCityAction(player.position, color)); } } return(cures); }
public Map removeDisease(City city, DiseaseColor color) { Map result = new Map(this); result.cities[city.cityNumber] = result.cities[city.cityNumber].adjustDisease(color, -1); result.numInfectionsInCities--; if (result.aboutToOutbreak.Contains(city) && result.diseaseLevel(city, city.color) != 3) { result.aboutToOutbreak = new List <City>(result.aboutToOutbreak); result.aboutToOutbreak.Remove(city); } return(result); }
public City addCity(String name, DiseaseColor color, float x = 0f, float y = 0f) { City city = new City(name, color, numCities, x, y); numCities++; CityData[] newData = new CityData[numCities]; for (int i = 0; i < numCities - 1; i++) { newData[i] = cities[i]; } cities = newData; cities[city.cityNumber] = new CityData(); allCities.Add(city); return(city); }
public static Color toBackColor(DiseaseColor c) { switch (c) { case DiseaseColor.YELLOW: return Color.Yellow; case DiseaseColor.BLUE: return Color.DarkBlue; case DiseaseColor.ORANGE: return Color.DarkOrange; case DiseaseColor.BLACK: return Color.Black; default: return Color.PaleGoldenrod; } }
public static Color toBackColor(DiseaseColor c) { switch (c) { case DiseaseColor.YELLOW: return(Color.Yellow); case DiseaseColor.BLUE: return(Color.DarkBlue); case DiseaseColor.ORANGE: return(Color.DarkOrange); case DiseaseColor.BLACK: return(Color.Black); default: return(Color.PaleGoldenrod); } }
public GameState recalcBestCardHolder(GameState newGs, Player playerObj, DiseaseColor card) { int player = playerObj.playernum; if (bestCardHolder[(int)card].Key != player) { return(newGs); } int bestColor = -1; int bestPlayer = -1; foreach (Player p in newGs.players) { int totalColor = 0; foreach (City c in p.cards) { if (c.color == card) { totalColor++; } if (totalColor > bestColor) { bestColor = totalColor; bestPlayer = p.playernum; } } } KeyValuePair <int, int>[] newbestCardHolder = new KeyValuePair <int, int> [4]; for (int i = 0; i < 4; i++) { newbestCardHolder[i] = newGs.bestCardHolder[i]; } newbestCardHolder[(int)card] = new KeyValuePair <int, int>(bestPlayer, bestColor); newGs.bestCardHolder = newbestCardHolder; return(newGs); }
public int diseaseLevel(City city, DiseaseColor color) { return(cities[city.cityNumber].disease(color)); }
public City addCity(String name, DiseaseColor color, float x = 0f, float y = 0f) { City city = new City(name, color, numCities, x, y); numCities++; CityData[] newData = new CityData[numCities]; for (int i = 0; i < numCities - 1; i++) { newData[i] = cities[i]; } cities = newData; cities[city.cityNumber] = new CityData(); allCities.Add(city); return city; }
public CureCityAction(City position, DiseaseColor color) { this.position = position; this.color = color; }
public int disease(DiseaseColor color) { return diseases[(int)color]; }
private CureDiseaseAction(DiseaseColor color) { this.color = color; }
public GameState cureDisease(DiseaseColor color) { GameState result = new GameState(this); result.curesFound = new bool[4]; for (int i = 0; i < 4; i++) { result.curesFound[i] = curesFound[i]; } result.curesFound[(int)color] = true; return result; }
public GameState recalcBestCardHolder(GameState newGs, Player playerObj, DiseaseColor card) { int player = playerObj.playernum; if (bestCardHolder[(int)card].Key != player) { return newGs; } int bestColor = -1; int bestPlayer = -1; foreach (Player p in newGs.players) { int totalColor = 0; foreach (City c in p.cards) { if(c.color == card) { totalColor++; } if (totalColor > bestColor) { bestColor = totalColor; bestPlayer = p.playernum; } } } KeyValuePair<int, int>[] newbestCardHolder = new KeyValuePair<int, int>[4]; for (int i = 0; i < 4; i++) { newbestCardHolder[i] = newGs.bestCardHolder[i]; } newbestCardHolder[(int)card] = new KeyValuePair<int, int>(bestPlayer, bestColor); newGs.bestCardHolder = newbestCardHolder; return newGs; }
public int disease(DiseaseColor color) { return(diseases[(int)color]); }
public int diseaseLevel(City city, DiseaseColor color) { return cities[city.cityNumber].disease(color); }
public Map removeDisease(City city, DiseaseColor color) { Map result = new Map(this); result.cities[city.cityNumber] = result.cities[city.cityNumber].adjustDisease(color, -1); result.numInfectionsInCities --; if (result.aboutToOutbreak.Contains(city) && result.diseaseLevel(city, city.color) != 3) { result.aboutToOutbreak = new List<City>(result.aboutToOutbreak); result.aboutToOutbreak.Remove(city); } return result; }