Esempio n. 1
0
 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;
 }
Esempio n. 2
0
        //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);
        }
Esempio n. 3
0
 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;
 }
Esempio n. 4
0
            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);
            }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 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;
 }
Esempio n. 7
0
 public static Color toForeColor(DiseaseColor c)
 {
     switch (c)
     {
         case DiseaseColor.YELLOW:
             return Color.Black;
         default:
             return Color.White;
     }
 }
Esempio n. 8
0
        public static Color toForeColor(DiseaseColor c)
        {
            switch (c)
            {
            case DiseaseColor.YELLOW:
                return(Color.Black);

            default:
                return(Color.White);
            }
        }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
        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);
        }
Esempio n. 11
0
        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);
        }
Esempio n. 12
0
        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);
        }
Esempio n. 13
0
 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;
     }
 }
Esempio n. 14
0
        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);
            }
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
 public int diseaseLevel(City city, DiseaseColor color)
 {
     return(cities[city.cityNumber].disease(color));
 }
Esempio n. 17
0
        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;
        }
Esempio n. 18
0
 public CureCityAction(City position, DiseaseColor color)
 {
     this.position = position;
     this.color = color;
 }
Esempio n. 19
0
 public int disease(DiseaseColor color)
 {
     return diseases[(int)color];
 }
Esempio n. 20
0
 private CureDiseaseAction(DiseaseColor color)
 {
     this.color = color;
 }
Esempio n. 21
0
 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;
 }
Esempio n. 22
0
        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;
        }
Esempio n. 23
0
 public int disease(DiseaseColor color)
 {
     return(diseases[(int)color]);
 }
Esempio n. 24
0
 public int diseaseLevel(City city, DiseaseColor color)
 {
     return cities[city.cityNumber].disease(color);
 }
Esempio n. 25
0
 private CureDiseaseAction(DiseaseColor color)
 {
     this.color = color;
 }
Esempio n. 26
0
 public CureCityAction(City position, DiseaseColor color)
 {
     this.position = position;
     this.color    = color;
 }
Esempio n. 27
0
        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;
        }