예제 #1
0
        public void AddHill(int col, int row, int team)
        {
            var hill = new Hill {
                X = col, Y = row, Team = team
            };

            if (team != 0)
            {
                var index = EnemyHills.BinarySearch(hill);
                if (index < 0)
                {
                    EnemyHills.Insert(~index, hill);
                    hill.DistanceMap           = new int[Width, Height];
                    hill.NeedRecalcDistanceMap = true;
                    hill.IsVisible             = true;
                }
                else
                {
                    EnemyHills[index].IsVisible = true;
                }
            }
            else
            if (!Hills.Contains(hill))
            {
                hill.DistanceMap           = new int[Width, Height];
                hill.StochasticMap         = new int[Width, Height];
                hill.NeedRecalcDistanceMap = true;
                hill.Live = true;
                Hills.Add(hill);
            }
            else
            {
                Hills.Where(h => h.Equals(hill)).First().Live = true;
            }
        }
예제 #2
0
        public static int GetTotalLeafCount(Location loc, Hill hill)
        {
            int width  = GameState.Instance.Width;
            int height = GameState.Instance.Height;
            var map    = GameState.Instance.Map;

            bool[,] leafs = new bool[width, height];

            var lastStep    = new List <Location>();
            var stepForward = new List <Location> {
                loc
            };

            leafs[loc.X, loc.Y] = true;
            while (stepForward.Count > 0)
            {
                lastStep.Clear();
                lastStep.AddRange(stepForward);
                stepForward.Clear();

                for (int i = 0; i < lastStep.Count; i++)
                {
                    for (int dir = 0; dir < 4; dir++)
                    {
                        var newLoc = lastStep[i] + Directions[dir];
                        //if (map[newLoc.X, newLoc.Y] != Tile.Unseen)
                        if (hill.DistanceMap[newLoc.X, newLoc.Y] > hill.DistanceMap[lastStep[i].X, lastStep[i].Y])
                        {
                            if (!leafs[newLoc.X, newLoc.Y])
                            {
                                stepForward.Add(newLoc);
                                leafs[newLoc.X, newLoc.Y] = true;
                            }
                        }
                    }
                }
            }

            int count = 0;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    if (leafs[x, y])
                    {
                        count++;
                    }
                }
            }

            return(count);
        }