// mark as alive: // TODO - 1. chains with at least two shared liberities of alive stones // DONE - 2. chains with at least one shared protected liberties neighboring an alive chain public void MarkSafe(SafetyMap safetyMap, Color color) { bool lDone = false; while (!lDone) { if (ProtectedLiberitiesLeft.Count == 0) { return; } List <int> lNewProtectedLiberitiesLeft = new List <int>(ProtectedLiberitiesLeft.Count); foreach (int lIndex in ProtectedLiberitiesLeft) { bool lSafeNeighbor = false; List <GoBlock> lNonSafeNeighbors = new List <GoBlock>(); foreach (int lNeighbor in Board.Coord.Neighbors[lIndex]) { if (Board.Cells[lNeighbor].Color == color) { if (safetyMap[lNeighbor].IsAlive) { lSafeNeighbor = true; } else if (!lNonSafeNeighbors.Contains((GoBlock)Board.Cells[lNeighbor].Block)) { lNonSafeNeighbors.Add((GoBlock)Board.Cells[lNeighbor].Block); } } } if ((lSafeNeighbor) && (lNonSafeNeighbors.Count != 0)) { foreach (GoBlock lGoBlock in lNonSafeNeighbors) { safetyMap.AddAliveBlock(lGoBlock); } } if ((lSafeNeighbor) && (lNonSafeNeighbors.Count == 0)) { lNewProtectedLiberitiesLeft.Add(lIndex); } } lDone = (ProtectedLiberitiesLeft.Count == lNewProtectedLiberitiesLeft.Count); ProtectedLiberitiesLeft = lNewProtectedLiberitiesLeft; } }
public void UpdateSafetyKnowledge(SafetyMap safetyMap) { foreach (GoBlock lGoBlock in Blocks.Keys) { safetyMap.AddAliveBlock(lGoBlock); foreach (ColorEnclosedRegion lColorEnclosedRegion in Blocks[lGoBlock]) { safetyMap.AddTerritoryBlocks(lColorEnclosedRegion.EmptyBlocks, Color); safetyMap.AddDeadBlocks(lColorEnclosedRegion.InteriorAttackerBlocks); } } }
// mark as alive: // TODO - 1. chains with at least two shared liberities of alive stones // DONE - 2. chains with at least one shared protected liberties neighboring an alive chain public void MarkSafe(SafetyMap safetyMap, Color color) { bool lDone = false; while (!lDone) { if (ProtectedLiberitiesLeft.Count == 0) return; List<int> lNewProtectedLiberitiesLeft = new List<int>(ProtectedLiberitiesLeft.Count); foreach (int lIndex in ProtectedLiberitiesLeft) { bool lSafeNeighbor = false; List<GoBlock> lNonSafeNeighbors = new List<GoBlock>(); foreach (int lNeighbor in Board.Coord.Neighbors[lIndex]) if (Board.Cells[lNeighbor].Color == color) { if (safetyMap[lNeighbor].IsAlive) lSafeNeighbor = true; else if (!lNonSafeNeighbors.Contains((GoBlock)Board.Cells[lNeighbor].Block)) lNonSafeNeighbors.Add((GoBlock)Board.Cells[lNeighbor].Block); } if ((lSafeNeighbor) && (lNonSafeNeighbors.Count != 0)) foreach (GoBlock lGoBlock in lNonSafeNeighbors) safetyMap.AddAliveBlock(lGoBlock); if ((lSafeNeighbor) && (lNonSafeNeighbors.Count == 0)) lNewProtectedLiberitiesLeft.Add(lIndex); } lDone = (ProtectedLiberitiesLeft.Count == lNewProtectedLiberitiesLeft.Count); ProtectedLiberitiesLeft = lNewProtectedLiberitiesLeft; } }
public void UpdateSafetyKnowledge(SafetyMap safetyMap) { foreach (GoBlock lGoBlock in Blocks.Keys) { safetyMap.AddAliveBlock(lGoBlock); foreach (ColorEnclosedRegion lColorEnclosedRegion in Blocks[lGoBlock]) { safetyMap.AddTerritoryBlocks(lColorEnclosedRegion.EmptyBlocks, Color); safetyMap.AddDeadBlocks(lColorEnclosedRegion.InteriorAttackerBlocks); } } }