예제 #1
0
        public PatternMap FindPatterns(GoBoard goBoard, Color playerToMove)
        {
            PatternMap lPatternMap = new PatternMap(goBoard, playerToMove);

            if (DFAMatrix == null)
            {
                return(lPatternMap);
            }

            for (int lOrigin = 0; lOrigin < goBoard.Coord.BoardArea; lOrigin++)
            {
                if (goBoard.GetSafetyStatus(lOrigin).IsUndecided)
                {
                    if (goBoard.IsLegal(lOrigin, playerToMove))
                    {
                        Coordinate lStart = new Coordinate(goBoard.Coord.GetColumn(lOrigin), goBoard.Coord.GetRow(lOrigin));

                        int lState = 1;

                        Coordinate lSpiral = new Coordinate(0, 0);

                        while (true)
                        {
                            Coordinate lAt = lStart + lSpiral;
                            lSpiral.SpiralNext();

                            char c = '#';

                            if (lAt.IsOnBoard(goBoard.BoardSize))
                            {
                                c = goBoard.GetColor(goBoard.Coord.At(lAt.X, lAt.Y)).ToChar();

                                if (playerToMove.IsBlack)
                                {
                                    // patterns are stored in white moves next
                                    // so flip colors when is black's turn
                                    if (c == 'O')
                                    {
                                        c = 'X';
                                    }
                                    else if (c == 'X')
                                    {
                                        c = 'O';
                                    }
                                }
                            }

                            lState = DFAMatrix.GetPatterns(lState, c, lPatternMap, lStart, lOrigin);

                            if (lState == 0)
                            {
                                break;
                            }
                        }
                    }
                }
            }
            return(lPatternMap);
        }
예제 #2
0
        public static string ToVariableDFA(Pattern pattern, int transform)
        {
            StringBuilder lDFA    = new StringBuilder(200);
            Coordinate    lSpiral = new Coordinate(0, 0);

            int lArea = pattern.Width * pattern.Height;

            while (lArea > 0)
            {
                Coordinate p = pattern.Origin + lSpiral.Transform(transform);
                lSpiral.SpiralNext();

                lDFA.Append(pattern.GetVariable(p));

                if (pattern.IsInPattern(p))
                {
                    lArea--;
                }
            }

            return(lDFA.ToString().TrimEnd());
        }
예제 #3
0
        public PatternMap FindPatterns(GoBoard goBoard, Color playerToMove, List<int> legalMoves)
        {
            PatternMap lPatternMap = new PatternMap(goBoard, playerToMove);

            if (DFAMatrix == null)
                return lPatternMap;

            foreach (int lOrigin in legalMoves)
            {
                int lState = 1;

                Coordinate lStart = new Coordinate(goBoard.Coord.GetColumn(lOrigin), goBoard.Coord.GetRow(lOrigin));
                Coordinate lSpiral = new Coordinate(0, 0);

                while (true)
                {
                    Coordinate lAt = lStart + lSpiral;
                    lSpiral.SpiralNext();

                    char c = '#';

                    if (lAt.IsOnBoard(goBoard.BoardSize))
                    {
                        c = goBoard.GetColor(goBoard.Coord.At(lAt.X, lAt.Y)).ToChar();

                        if (playerToMove.IsBlack)
                        {
                            // patterns are stored in white moves next
                            // so flip colors when is black's turn
                            if (c == 'O') c = 'X'; else if (c == 'X') c = 'O';
                        }

                    }

                    lState = DFAMatrix.GetPatterns(lState, c, lPatternMap, lStart, lOrigin);

                    if (lState == 0)
                        break;
                }
            }
            return lPatternMap;
        }
예제 #4
0
        public static string ToVariableDFA(Pattern pattern, int transform)
        {
            StringBuilder lDFA = new StringBuilder(200);
            Coordinate lSpiral = new Coordinate(0, 0);

            int lArea = pattern.Width * pattern.Height;

            while (lArea > 0)
            {
                Coordinate p = pattern.Origin + lSpiral.Transform(transform);
                lSpiral.SpiralNext();

                lDFA.Append(pattern.GetVariable(p));

                if (pattern.IsInPattern(p))
                    lArea--;
            }

            return lDFA.ToString().TrimEnd();
        }