private void FindPredefinedBlocksWithoutPassage() { foreach (var position in blocks.GetAllOccupiedBlocks()) { int x = position.x, y = position.y; var block = blocks[x, y].PredefinedBlock; var passageChecker = new BlockPassageChecker(x, y, block, map); bool hasPassage = false; Debug.Log($"Find Passages for block=({x}, {y})"); foreach (var direction in Direction.All) { if (block.HasDoor(direction) && passageChecker.HasPassage(direction)) { hasPassage = true; break; } Debug.Log($"block=({x}, {y}) dir={direction} no passage"); } if (!hasPassage) { Debug.Log($"block=({x}, {y}) ANY passage!"); } } }
private void RemoveBlockDoorWithoutPassage() { foreach (var blockPositions in blocks.GetAllOccupiedBlocks()) { int x = blockPositions.x, y = blockPositions.y; var block = blocks[x, y]; var passageChecker = new BlockPassageChecker(x, y, block.PredefinedBlock, map); var currentBitmask = block.Bitmask; var newBitmask = currentBitmask; foreach (var direction in Direction.All) { if (block.PredefinedBlock.HasDoor(direction) && !passageChecker.HasPassage(direction)) { newBitmask &= ~direction.Bitmask; Debug.Log($"block=({x}, {y}) need to remove {direction} door"); } } if (currentBitmask != newBitmask) { if (TryGetBlockMatchingMask(newBitmask, out var newPredefinedBlock)) { PutBlock(x, y, newPredefinedBlock); } else { Debug.Log($"block=({x}, {y}) cannot find block by mask={newBitmask}"); } } } }