Beispiel #1
0
        public List <int> SharedLibertyPoints(GoChain goChain)
        {
            List <int> lSharedLibertyPoints = new List <int>();

            if ((Liberities.Count <= 1) || (goChain.Liberities.Count <= 1))
            {
                return(lSharedLibertyPoints);
            }

            Region lShared = new Region(Liberities, goChain.Liberities, Region.MergeType.And);

            foreach (int lPoint in UsedLiberities)
            {
                lShared.Remove(lPoint);
            }

            foreach (int lPoint in goChain.UsedLiberities)
            {
                lShared.Remove(lPoint);
            }

            lSharedLibertyPoints = lShared.ToList();

            return(lSharedLibertyPoints);
        }
Beispiel #2
0
 public GoEmptyBlock(GoEmptyBlock goEmptyBlock, int pCutPoint, int direction)
     : base(goEmptyBlock.Board, Color.Empty)
 {
     Members    = new Region(goEmptyBlock.Members, pCutPoint, direction);
     MemberList = Members.ToList();
 }
Beispiel #3
0
 public GoEmptyBlock(GoBlock goBlock)
     : base(goBlock.Board, Color.Empty)
 {
     Members    = new Region(goBlock.Members);
     MemberList = Members.ToList();              // slow might be a faster way
 }
Beispiel #4
0
        public bool IsOneVital()
        {
            if (Is1Vital.IsKnown)
            {
                return(Is1Vital.IsTrue);
            }

            if (EnclosingBlocks.Count == 0)
            {
                Is1Vital = TriState.False;
                return(false);
            }

            // step 1

            // build miai stragety
            MiaiStrategy = new MiaiStrategy();

            Region lAccessibleLibertiesAvailable = new Region(AccessibleLiberties);

            if (!CreateBlocksConnectionStrategy(lAccessibleLibertiesAvailable, MiaiStrategy))
            {
                Is1Vital = TriState.False;
                return(false);
            }

            // step 2

            // future: add miai accessible interior empty points to the set of accessible liberties,
            // and also use protected liberties for the chaining.

            Region lNewAccessibleRegion = new Region(AccessibleLiberties);

            foreach (GoBlock lGoBlock in InteriorDefenderBlocks)
            {
                lNewAccessibleRegion.Add(lGoBlock.Liberties);
            }

            // step 2a - add miai accessible interior empty points to the set of accessible liberties
            // rough implementation

            Region lMiaiAccessibleInteriorRegion = new Region(Board.BoardSize);

            if (Version >= 2004)
            {
                foreach (int lIndex in EmptyArea)
                {
                    if (!lNewAccessibleRegion.Contains(lIndex))
                    {
                        List <int> llAccessibleNeighborPoints = new List <int>(4);
                        foreach (int lNeighbor in Board.Coord.GetNeighbors(lIndex))
                        {
                            if (lNewAccessibleRegion.Contains(lNeighbor))
                            {
                                llAccessibleNeighborPoints.Add(lNeighbor);
                            }
                        }

                        if (llAccessibleNeighborPoints.Count >= 2)
                        {
                            lMiaiAccessibleInteriorRegion.Add(lIndex);
                        }
                    }
                }
            }

            lNewAccessibleRegion.Add(lMiaiAccessibleInteriorRegion);

            // step 3

            Region lEmptyAndNotAccessible = new Region(EmptyArea);

            lEmptyAndNotAccessible.Remove(lNewAccessibleRegion);

            List <int> lList        = lEmptyAndNotAccessible.ToList();
            int        lMinAdjacent = 2;

            while (lList.Count != 0)
            {
                List <int> lRemove = new List <int>();

                foreach (int lIndex in lList)
                {
                    List <int> lAccessibleLibertiesForPoint = new List <int>(4);

                    foreach (int lNeighbor in Board.Coord.GetNeighbors(lIndex))
                    {
                        if (lNewAccessibleRegion.Contains(lNeighbor))
                        {
                            lAccessibleLibertiesForPoint.Add(lNeighbor);
                        }
                    }

                    if (lAccessibleLibertiesForPoint.Count < 2)
                    {
                        Is1Vital = TriState.False;
                        return(false);
                    }

                    if ((lAccessibleLibertiesForPoint.Count == 2) || (lAccessibleLibertiesForPoint.Count == lMinAdjacent))
                    {
                        lNewAccessibleRegion.Remove(lAccessibleLibertiesForPoint[0]);
                        lNewAccessibleRegion.Remove(lAccessibleLibertiesForPoint[1]);

                        MiaiStrategy.Add(lIndex, lAccessibleLibertiesForPoint[0], lAccessibleLibertiesForPoint[1]);
                        lRemove.Add(lIndex);
                        lMinAdjacent = 2;
                    }
                }

                if (lList.Count == lRemove.Count)
                {
                    lList.Clear();
                }
                else
                {
                    foreach (int lPoint in lRemove)
                    {
                        lList.Remove(lPoint);
                    }
                }

                if (lRemove.Count == 0)
                {
                    lMinAdjacent++;
                }
            }

            Is1Vital = TriState.True;
            return(true);
        }
Beispiel #5
0
        public bool IsOneVital()
        {
            if (Is1Vital.IsKnown)
                return (Is1Vital.IsTrue);

            if (EnclosingBlocks.Count == 0)
            {
                Is1Vital = TriState.False;
                return false;
            }

            // step 1

            // build miai stragety
            MiaiStrategy = new MiaiStrategy();

            Region lAccessibleLibertiesAvailable = new Region(AccessibleLiberties);

            if (!CreateBlocksConnectionStrategy(lAccessibleLibertiesAvailable, MiaiStrategy))
            {
                Is1Vital = TriState.False;
                return false;
            }

            // step 2

            // future: add miai accessible interior empty points to the set of accessible liberties,
            // and also use protected liberties for the chaining.

            Region lNewAccessibleRegion = new Region(AccessibleLiberties);

            foreach (GoBlock lGoBlock in InteriorDefenderBlocks)
                lNewAccessibleRegion.Add(lGoBlock.Liberties);

            // step 2a - add miai accessible interior empty points to the set of accessible liberties
            // rough implementation

            Region lMiaiAccessibleInteriorRegion = new Region(Board.BoardSize);

            if (Version >= 2004)
            {
                foreach (int lIndex in EmptyArea)
                    if (!lNewAccessibleRegion.Contains(lIndex))
                    {
                        List<int> llAccessibleNeighborPoints = new List<int>(4);
                        foreach (int lNeighbor in Board.Coord.GetNeighbors(lIndex))
                            if (lNewAccessibleRegion.Contains(lNeighbor))
                                llAccessibleNeighborPoints.Add(lNeighbor);

                        if (llAccessibleNeighborPoints.Count >= 2)
                        {
                            lMiaiAccessibleInteriorRegion.Add(lIndex);
                        }
                    }
            }

            lNewAccessibleRegion.Add(lMiaiAccessibleInteriorRegion);

            // step 3

            Region lEmptyAndNotAccessible = new Region(EmptyArea);
            lEmptyAndNotAccessible.Remove(lNewAccessibleRegion);

            List<int> lList = lEmptyAndNotAccessible.ToList();
            int lMinAdjacent = 2;

            while (lList.Count != 0)
            {
                List<int> lRemove = new List<int>();

                foreach (int lIndex in lList)
                {
                    List<int> lAccessibleLibertiesForPoint = new List<int>(4);

                    foreach (int lNeighbor in Board.Coord.GetNeighbors(lIndex))
                        if (lNewAccessibleRegion.Contains(lNeighbor))
                            lAccessibleLibertiesForPoint.Add(lNeighbor);

                    if (lAccessibleLibertiesForPoint.Count < 2)
                    {
                        Is1Vital = TriState.False;
                        return false;
                    }

                    if ((lAccessibleLibertiesForPoint.Count == 2) || (lAccessibleLibertiesForPoint.Count == lMinAdjacent))
                    {
                        lNewAccessibleRegion.Remove(lAccessibleLibertiesForPoint[0]);
                        lNewAccessibleRegion.Remove(lAccessibleLibertiesForPoint[1]);

                        MiaiStrategy.Add(lIndex, lAccessibleLibertiesForPoint[0], lAccessibleLibertiesForPoint[1]);
                        lRemove.Add(lIndex);
                        lMinAdjacent = 2;
                    }
                }

                if (lList.Count == lRemove.Count)
                    lList.Clear();
                else
                    foreach (int lPoint in lRemove)
                        lList.Remove(lPoint);

                if (lRemove.Count == 0)
                    lMinAdjacent++;
            }

            Is1Vital = TriState.True;
            return true;
        }
Beispiel #6
0
        public List<int> SharedLibertyPoints(GoChain goChain)
        {
            List<int> lSharedLibertyPoints = new List<int>();

            if ((Liberities.Count <= 1) || (goChain.Liberities.Count <= 1))
                return lSharedLibertyPoints;

            Region lShared = new Region(Liberities, goChain.Liberities, Region.MergeType.And);

            foreach (int lPoint in UsedLiberities)
                lShared.Remove(lPoint);

            foreach (int lPoint in goChain.UsedLiberities)
                lShared.Remove(lPoint);

            lSharedLibertyPoints = lShared.ToList();

            return lSharedLibertyPoints;
        }
Beispiel #7
0
 public GoEmptyBlock(GoEmptyBlock goEmptyBlock, int pCutPoint, int direction)
     : base(goEmptyBlock.Board, Color.Empty)
 {
     Members = new Region(goEmptyBlock.Members, pCutPoint, direction);
     MemberList = Members.ToList();
 }
Beispiel #8
0
 public GoEmptyBlock(GoBlock goBlock)
     : base(goBlock.Board, Color.Empty)
 {
     Members = new Region(goBlock.Members);
     MemberList = Members.ToList();	// slow might be a faster way
 }