Ejemplo n.º 1
0
 override public void UpdateStrength(Area area)
 {
 }
Ejemplo n.º 2
0
        /**
         *  initializing the AreaBoard
         */
        private void InitializeAreaBoard()
        {
            for (int i = 0; i < Size * Size; i++)       // Filling up the AreaBoard with Areas of type (-1)
            {
                AreaBoard.Add(new Area(-1));
            }
            List <int>[] InfluencedLocationsList = new List <int> [4];
            for (int i = 0; i < 4; i++)                        // Adding 4 starting points
            {
                InfluencedLocationsList[i] = new List <int>(); // separate InfluencedList for every type of Area, containing list of free Areas (type=-1) that are influenced by current Type
                int location = Generator.Next(0, Size * Size);
                while (AreaBoard[location].Type != -1)
                {
                    location = Generator.Next(0, Size * Size);
                }
                AreaBoard[location] = new Area(i);
                LinkedList <int> potentialList = PotentialList(location);
                foreach (int loc in potentialList)
                {
                    if (AreaBoard[loc].Type == -1)
                    {
                        AreaBoard[loc].AddInfluence(i);
                        InfluencedLocationsList[i].Add(loc);
                    }
                }
            }

            int type = 0;                                     // type of Area to add

            while (AreaBoard.Exists(area => area.Type == -1)) // Filling up the Areaboard until there is no free spaces (Areas.type -1)
            {
                if (type > 3)
                {
                    type = 0;
                }
                int chosenLocation = -1;
                if (InfluencedLocationsList[type].Any())
                {
                    int        maxInfluence     = 0;
                    List <int> maxInfluenceList = new List <int>();
                    foreach (int loc in InfluencedLocationsList[type])                        // chosing one of the Areas that has max Influence of current Type
                    {
                        if (AreaBoard[loc].Influence[type] > maxInfluence)
                        {
                            maxInfluence = AreaBoard[loc].Influence[type];
                            maxInfluenceList.Clear();
                            maxInfluenceList.Add(loc);
                        }
                        else if (AreaBoard[loc].Influence[type] == maxInfluence)
                        {
                            maxInfluenceList.Add(loc);
                        }
                    }
                    chosenLocation = maxInfluenceList[Generator.Next(0, maxInfluenceList.Count())];
                }
                else                                                                   // there is no Area on InfluencedList, choosing random free Area on board
                {
                    chosenLocation = Generator.Next(0, Size * Size);
                    while (AreaBoard[chosenLocation].Type != -1)
                    {
                        chosenLocation = Generator.Next(0, Size * Size);
                    }
                }
                AreaBoard[chosenLocation] = new Area(type);
                for (int j = 0; j < 4; j++)
                {
                    InfluencedLocationsList[j].Remove(chosenLocation);              // removing locations from lists that are already taken
                }
                LinkedList <int> potentialList = PotentialList(chosenLocation);
                foreach (int loc in potentialList)                                  // adding new InfluencedAreas to the list
                {
                    if (AreaBoard[loc].Type == -1)
                    {
                        AreaBoard[loc].AddInfluence(type);
                        if (!InfluencedLocationsList[type].Contains(loc))
                        {
                            InfluencedLocationsList[type].Add(loc);
                        }
                    }
                }
                type++;
            }
        }