public Region(Region region, int cutPoint, int start)
        {
            Width = region.Width;
            Count = 0;
            Grid  = new bool[Width * Width];

            CoordinateSystem lCoord = CoordinateSystem.GetCoordinateSystem(Width);

            if (!lCoord.OnBoard(start))
            {
                return;
            }

            Stack <int> lFill = new Stack <int>();

            lFill.Push(start);

            while (lFill.Count > 0)
            {
                int lAt = lFill.Pop();
                Add(lAt);

                foreach (int lNeighbor in lCoord.GetNeighbors(lAt))
                {
                    if ((lNeighbor != cutPoint) &&
                        (region.Contains(lNeighbor)) &&
                        (!Contains(lNeighbor)))
                    {
                        lFill.Push(lNeighbor);
                    }
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Verifies the specified SGF coordinates translate correctly.
        /// </summary>
        /// <param name="coordinate">The coordinate.</param>
        /// <returns></returns>
        public static bool VerifySGF(int boardSize, string coordinate, string outVariation)
        {
            int lPoint = CoordinateSystem.AtFromSGF(coordinate, boardSize);

            CoordinateSystem lCoord = CoordinateSystem.GetCoordinateSystem(boardSize);

            string lCoordinate = lCoord.ToString(lPoint);

            Assert.AreEqual(outVariation.ToLower(), lCoordinate.ToLower(), coordinate);

            return(outVariation.ToLower() == lCoordinate.ToLower());
        }
Beispiel #3
0
        /// <summary>
        /// Verifies the specified GO/GTP coordinates translate correctly.
        /// </summary>
        /// <param name="coordinate">The coordinate.</param>
        /// <returns></returns>
        public static bool Verify(int boardSize, string coordinate)
        {
            int lPoint = CoordinateSystem.At(coordinate, boardSize);

            CoordinateSystem lCoord = CoordinateSystem.GetCoordinateSystem(boardSize);

            string lCoordinate = lCoord.ToString(lPoint);

            Assert.AreEqual(coordinate.ToLower(), lCoordinate.ToLower());

            return(coordinate.ToLower() == lCoordinate.ToLower());
        }
        public bool IsAdjacent(int index)
        {
            foreach (int lNeighbor in CoordinateSystem.GetCoordinateSystem(Width).GetNeighbors(index))
            {
                if (Contains(lNeighbor))
                {
                    return(true);
                }
            }

            return(false);
        }
        public GoBoard(GoBoard goBoard, bool includeUndo)
        {
            Coord        = CoordinateSystem.GetCoordinateSystem(goBoard.BoardSize);
            SafetySolver = goBoard.SafetySolver;
            Komi         = goBoard.Komi;
            Clear();

            foreach (KeyValuePair <Color, int> lMove in goBoard.MoveList)
            {
                PlayStone(lMove.Value, lMove.Key, includeUndo);
            }
        }
        public bool IsInterior(int index)
        {
            if (Count == 0)
            {
                return(false);
            }

            if (!Contains(index))
            {
                return(false);
            }

            foreach (int lNeighbot in CoordinateSystem.GetCoordinateSystem(Width).GetNeighbors(index))
            {
                if (!Contains(lNeighbot))
                {
                    return(false);
                }
            }

            return(true);
        }
        public static bool IsIntersection(IContains inter, int move)
        {
            if (inter.GetSize() <= 2)
            {
                return(false);
            }

            int lWidth = inter.GetWidth();

            int ActiveMice = 0;

            int[] lMousePosition  = new int[4];
            int[] lMouseDirection = new int[4];

            int[] lMouseNextDirection = new int[4];
            int[] lMouseByDirection   = new int[4];

            CoordinateSystem lCoord = CoordinateSystem.GetCoordinateSystem(lWidth);

            for (int i = 0; i < 4; i++)
            {
                int lNeightbor = lCoord.GetNeighbor(move, i);

                if (lCoord.OnBoard(lNeightbor) && inter.Contains(lNeightbor))
                {
                    lMousePosition[ActiveMice]  = lNeightbor;
                    lMouseDirection[ActiveMice] = i;
                    lMouseByDirection[i]        = ActiveMice;

                    if (ActiveMice > 0)
                    {
                        lMouseNextDirection[ActiveMice - 1] = i;
                    }

                    ActiveMice++;
                }
                else
                {
                    lMouseByDirection[i] = -1;                          // no mouse
                }
            }

            if (ActiveMice == 1)
            {
                return(false);
            }

            lMouseNextDirection[ActiveMice - 1] = 0;             // it's never used!

            for (int CurrentMouse = 0; CurrentMouse < ActiveMice - 1; CurrentMouse++)
            {
                int CurrentMousePosition          = lMousePosition[CurrentMouse];
                int CurrentMouseDirection         = lMouseDirection[CurrentMouse];
                int CurrentMouseOriginalDirection = CurrentMouseDirection;

                while (CurrentMousePosition != move)
                {
                    int lRightDirection = CoordinateSystem.TurnClockWise(CurrentMouseDirection);
                    int lRightPosition  = lCoord.GetNeighbor(CurrentMousePosition, lRightDirection);

                    // if (can turn right & move)
                    if (CoordinateSystem.OnBoard(lRightPosition, lWidth) && inter.Contains(lRightPosition))
                    {
                        // yes, turn turn and move
                        CurrentMousePosition  = lRightPosition;
                        CurrentMouseDirection = lRightDirection;
                    }
                    else
                    {
                        while (true)
                        {
                            int lStraightPosition = lCoord.GetNeighbor(CurrentMousePosition, CurrentMouseDirection);

                            // if (can go straight) (
                            if (CoordinateSystem.OnBoard(lStraightPosition, lWidth) && inter.Contains(lStraightPosition))
                            {
                                // yes, go straight
                                CurrentMousePosition = lStraightPosition;

                                break;
                            }
                            else
                            {
                                // else, change direction clockwise and try-again (loop)
                                CurrentMouseDirection = CoordinateSystem.TurnCounterClockWise(CurrentMouseDirection);
                            }
                        }
                    }
                }

                // right back where we started
                int FromDirection = CoordinateSystem.TurnAround(CurrentMouseDirection);

                // if mice returned from a direction other than the next direction, then there is a split
                if (lMouseNextDirection[CurrentMouse] != FromDirection)
                {
                    return(true);
                }

                // if mouse came back from original direction then there is a split
                if (CurrentMouseOriginalDirection == FromDirection)
                {
                    return(true);                       // should never reach here
                }
                // by now we know that the next mouse must merge, so no split
                if (CurrentMouse == ActiveMice - 1)
                {
                    return(false);
                }
            }

            return(false);
        }
 public GoBoard(int boardSize)
 {
     Coord        = CoordinateSystem.GetCoordinateSystem(boardSize);
     SafetySolver = SafetySolverType.Muller04;
     Clear();
 }
 public void SetBoardSize(int boardSize)
 {
     Coord = CoordinateSystem.GetCoordinateSystem(boardSize);
     Clear();
 }
Beispiel #10
0
        public override string ToString()
        {
            SGFCollection lSGFCollection = new SGFCollection();
            SGFSequence   lSGFSequence   = new SGFSequence();
            SGFNode       lSGFNode       = new SGFNode();

            CoordinateSystem lCoord = CoordinateSystem.GetCoordinateSystem(BoardSize);

            lSGFNode.AddProperty(new SGFProperty("GM", "1"));
            lSGFNode.AddProperty(new SGFProperty("FF", "4"));
            lSGFNode.AddProperty(new SGFProperty("CA", "UTF-8"));
            lSGFNode.AddProperty(new SGFProperty("SZ", BoardSize));
            lSGFNode.AddProperty(new SGFProperty("KM", Convert.ToString(Komi)));

            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("GN", GameName));
            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("ID", Identification));
            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("DT", Date));
            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("PB", BlackPlayerName));
            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("PW", WhitePlayerName));
            //			lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("RS", Result));
            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("C", Comment));
            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("RU", Rules));
            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("PC", Place));
            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("WR", WhiteRank));
            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("BR", BlackRank));
            lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("RE", Result));

            if (TimeLimit != 0)
            {
                lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("TM", TimeLimit));
            }

            if (HandicapStones > 0)
            {
                lSGFNode.AddPropertyIfNotEmpty(new SGFProperty("HE", HandicapStones));
            }

            lSGFSequence.AddNode(lSGFNode);

            foreach (GameMove lGameMove in Moves)
            {
                lSGFNode = new SGFNode();

                lSGFNode.AddProperty(new SGFProperty(
                                         (lGameMove.SetupMove ? "A" : "") + (lGameMove.Player.IsBlack ? "B" : "W")
                                         , lCoord.ToSGFString(lGameMove.Move)));

                lSGFSequence.AddNode(lSGFNode);
            }

            if ((Territory[0].Count != 0) || (Territory[1].Count != 0))
            {
                lSGFNode = new SGFNode();

                for (int lTerritoryIndex = 0; lTerritoryIndex < 2; lTerritoryIndex++)
                {
                    if (Territory[lTerritoryIndex].Count != 0)
                    {
                        foreach (int lIndex in Territory[lTerritoryIndex])
                        {
                            lSGFNode.AddProperty(new SGFProperty(
                                                     "T" + (lTerritoryIndex == 0 ? "B" : "W"), lCoord.ToSGFString(lIndex)));
                        }
                    }
                }
                lSGFSequence.AddNode(lSGFNode);
            }

            lSGFCollection.AddSequence(lSGFSequence);

            return(lSGFCollection.ToString());
        }