public IGrid<Cell> On(IGrid<Cell> grid, Cell startAt = null)
        {
            if (startAt == null)
            {
                startAt = grid.RandomCell();
            }

            var stack = new Stack<Cell>();
            stack.Push(startAt);

            while (stack.Count != 0)
            {
                var current = stack.Peek();
                var neighbours = current.Neighbours().Where(n => n.Links.Count == 0).ToList();
                if (neighbours.Count == 0)
                {
                    stack.Pop();
                }
                else
                {
                    var neighbour = neighbours[rand.Next(neighbours.Count)];
                    current.Link(neighbour);
                    stack.Push(neighbour);
                }


            }

            return grid;
        }
Exemple #2
0
 protected override Color? BackgroundColorFor(Cell cell)
 {
     var distance = Distances[cell];
     decimal intensity = (_maximum - distance) / (decimal)_maximum;
     int dark = (int)Math.Round(255 * intensity);
     int bright = (int)(128 + Math.Round(127 * intensity));
     return Color.FromArgb(dark, bright, dark);
 }
Exemple #3
0
 public void Link(Cell cell, bool bidi = true)
 {
     Links.Add(cell);
     if (bidi)
     {
         cell.Link(this, false);
     }
 }
Exemple #4
0
        public void Unlink(Cell cell, bool bidi = true)
        {
            Links.Remove(cell);

            if (bidi)
            {
                cell.Unlink(this, false);
            }
        }
Exemple #5
0
 protected override string CellContents(Cell cell)
 {
     if (Distances.ContainsKey(cell))
     {
         return Base36.Encode(Distances[cell]);
     }
     else
     {
         return base.CellContents(cell);
     }
 }
Exemple #6
0
 public static void FillForest(Cell[,] map)
 {
     var lines = System.IO.File.ReadAllLines("../../1.txt");
     map = new Cell[lines.Count(), lines[0].Count()];
     for (int i = 0; i < lines.Length; i++)
     {
         var line = lines[i];
         for (int j = 0; j < line.Count(); j++)
         {
             var newCell = GetCellFromChar(line[j]);
             map[i, j] = newCell;
         }
     }
 }
Exemple #7
0
        public void Download(StreamReader reader, out Cell[,] map)
        {
            string line;
            List<string> lines = new List<string>();
            while ((line = reader.ReadLine()) != null)
                lines.Add(line);

            map = new Cell[lines.Count, lines[0].Count()];

            for (int i = 0; i < lines.Count; i++)
            {
                var line2 = lines[i];
                for (int j = 0; j < line2.Count(); j++)
                {
                    var newCell = GetCellFromChar(line2[j]);
                    map[i, j] = newCell;
                }
            }
        }
        protected override Color? BackgroundColorFor(Cell cell)
        {

            if (cell.Links.Count == 1)
            {
                return Color.DarkSlateBlue;
            }

            if (cell.Links.Count == 2)
            {
                return Color.Gray;
            }
            if (cell.Links.Count == 3)
            {
                return Color.LightGray;
            }

            return base.BackgroundColorFor(cell);



        }
Exemple #9
0
 public bool IsLinked(Cell cell)
 {
     return Links.Contains(cell);
 }
Exemple #10
0
 protected bool Equals(Cell toCompareTo)
 {
     return X == toCompareTo.X && Y == toCompareTo.Y;
 }