public static void Generate(Grid grid) { foreach (IEnumerable <Cell> row in grid.Rows()) { var run = new List <Cell>(); foreach (Cell cell in row) { run.Add(cell); bool atEasternBoundary = cell.East == null; bool atNorthernBoundary = cell.North == null; bool shouldCloseOut = atEasternBoundary || (!atNorthernBoundary && random.Next(2) == 0); if (shouldCloseOut) { Cell member = run.Random(); if (member.North != null) { member.Link(member.North); } run.Clear(); } else { cell.Link(cell.East); } } } }
public void TestLinkBidirectional() { var cell1 = new Cell(); var cell2 = new Cell(); cell1.Link(cell2); Assert.IsTrue(cell1.IsLinked(cell2)); Assert.IsTrue(cell2.IsLinked(cell1)); }
public void TestLink() { var cell1 = new Cell(); var cell2 = new Cell(); cell1.Link(cell2, false); Assert.IsTrue(cell1.IsLinked(cell2)); Assert.IsFalse(cell2.IsLinked(cell1)); }
public Cell Link(Cell cell, bool bidirectional = true) { _Links[cell] = true; if (bidirectional) { cell.Link(this, false); } return(this); }
public void Link(Cell cell, bool bidirectional = true) { if (!_links.ContainsKey(cell)) { _links.Add(cell, true); } if (bidirectional) { cell.Link(this, false); } }
public Cell Link(Cell cell, bool bidirectional = true) { _Links[cell] = true; if (bidirectional) { cell.Link(this, false); } return this; }