public void ToggleRandomCell() { int count = smallGrid.Count(); int index = Random.Range(0, count); PointyHexPoint randomPoint = smallGrid[index]; if (randomPoint == endNode || randomPoint == startNode) { return; } if ((!logicalGrid[randomPoint] || !(Random.value < 0.5f)) && (logicalGrid[randomPoint] || !(Random.value < 20f / iterationCount + 0.02f))) { return; } List <PointyHexPoint> neighborHood = logicalGrid.GetAllNeighbors(randomPoint).ToList(); neighborHood.Add(randomPoint); var closedCells = from point in neighborHood where !logicalGrid[point] select point; var pointyHexPoints = closedCells as PointyHexPoint[] ?? closedCells.ToArray(); if (pointyHexPoints.Count() >= 7) { return; } bool closedCellsAreConnected; if (pointyHexPoints.Any()) { closedCellsAreConnected = Algorithms.IsConnected( logicalGrid, pointyHexPoints, (x, y) => (logicalGrid[x] == logicalGrid[y])); } else { closedCellsAreConnected = true; } if (closedCellsAreConnected) { ToggleCellAt(randomPoint); } }
public bool IsClosed(PointyHexPoint point) { var neighbors = grid.GetAllNeighbors(point).ToList(); bool isClosed = true; //We use for loop so that we can use the index in the access operation below for (int i = 0; i < neighbors.Count(); i++) { if (grid.Contains(neighbors[i])) { //(i + 3) % 6 is the opposite neighbor //Here we abuse the fact that neighbors are returned in (anti-clockwise) order. if (grid[point].EdgeData[i] != grid[neighbors[i]].EdgeData[(i + 3) % 6]) { isClosed = false; } } } return(isClosed); }