Пример #1
0
        public void SendPatterns(PatternCollection patternCollection)
        {
            lock (this)
            {
                if (State != ConnectionState.Negotiated)
                {
                    Abort();
                    return;
                }

                CommandNbr++;

                if (patternCollection != null)
                {
                    StringBuilder lString = new StringBuilder();

                    foreach (Pattern lPattern in patternCollection)
                    {
                        lString.Append(lPattern.ToString().Replace("\t", " ").Replace("~", " ").Replace("\n", "~").Replace("\r", ""));
                        lString.Append("\t");
                    }

                    SendCommand("add_patterns", FormatIdNbr(CommandNbr, 1), lString.ToString().TrimEnd('\t'));
                }
                else
                {
                    SendCommand("add_patterns", FormatIdNbr(CommandNbr, 1), "");
                }

                State = ConnectionState.SendingPatterns;
            }
        }
Пример #2
0
        public PatternDetector(PatternCollection patterns)
        {
            PatternCollection = patterns;
            DFAMatrixBuilder lDFAMatrixBuilder = new DFAMatrixBuilder(patterns);

            DFAMatrix = lDFAMatrixBuilder.GetMatrix();
        }
 public void Add(PatternCollection patternCollection)
 {
     foreach (Pattern lPattern in patternCollection)
     {
         Add(lPattern);
     }
 }
Пример #4
0
        // temp. for testing
        static void MatrixCompileToFile()
        {
            PatternCollection lPatterns = new PatternCollection();

            if (!lPatterns.Load(@"Patterns/fuseki9.db"))
            {
                Console.WriteLine("ERROR: Unable to load patterns");
                return;
            }

            Console.WriteLine("STATUS: Loaded " + lPatterns.Count + " Patterns.");

            SimpleTimer lTimer = new SimpleTimer();

            Console.WriteLine(lTimer.StartTime.ToString());

            DFAMatrixBuilder lDFAMatrixBuilder = new DFAMatrixBuilder();

            lDFAMatrixBuilder.Add(lPatterns);

            Console.WriteLine(DateTime.Now.ToString());

            lDFAMatrixBuilder.BuildThreaded();

            Console.WriteLine(DateTime.Now.ToString());

            Console.WriteLine("Seconds: " + lTimer.SecondsElapsed.ToString());

            MemFile lMemFile = new MemFile();

            lMemFile.Write(lDFAMatrixBuilder.GetMatrix().ToString());

            lMemFile.SaveFile(@"Patterns/fuseki9.cdb");
        }
 public NagCoordinator(int portNumber, PatternCollection patternCollection)
 {
     Service           = new TCPService(portNumber, 10000, NewWorker, GetCount);
     PatternCollection = patternCollection;
     OnNag             = null;
     Service.StartListeningAsync();
 }
Пример #6
0
 public NagCoordinator(int portNumber, PatternCollection patternCollection)
 {
     Service = new TCPService(portNumber, 10000, NewWorker, GetCount);
     PatternCollection = patternCollection;
     OnNag = null;
     Service.StartListeningAsync();
 }
 public FusekiDetector(PatternCollection patterns)
 {
     foreach (Pattern lPattern in patterns)
     {
         if (lPattern.IsFixedFuseki())
         {
             Add(lPattern);
         }
     }
 }
Пример #8
0
 public void Add(PatternCollection patternCollection)
 {
     if (patternCollection != null)
     {
         foreach (Pattern lPattern in patternCollection)
         {
             Patterns.Add(lPattern);
         }
     }
 }
Пример #9
0
        public void Add(PatternCollection patterns)
        {
            DFAMatrixBuilder lDFAMatrixBuilder = new DFAMatrixBuilder(DFAMatrix);

            lDFAMatrixBuilder.Add(patterns);
            PatternCollection.Add(patterns);

            DFAMatrix lDFAMatrix = lDFAMatrixBuilder.GetMatrix();

            lock (this)
            {
                DFAMatrix = lDFAMatrix;
            }
        }
Пример #10
0
        protected bool _LoadMatrix(MemFile memFile, PatternCollection patternCollection)
        {
            try
            {
                int lMatrixSize = Convert.ToInt32(memFile.ReadLine());

                DFANodes = new List <DFANode>(lMatrixSize);

                for (int i = 1; i < lMatrixSize; i++)
                {
                    //			Console.Error.Write(memFile.LineNbr.ToString() + " - " + i.ToString() + " - "+lMatrixSize.ToString());

                    DFANode lDFANode = new DFANode();

                    for (int z = 0; z < 4; z++)
                    {
                        lDFANode[z] = Convert.ToInt32(memFile.ReadPart('\t').Trim());
                    }

                    int lNodePatterns = Convert.ToInt32(memFile.ReadPart('\t').Trim());

                    if (lNodePatterns > 0)
                    {
                        lDFANode.Attributes = new List <PatternKey>(lNodePatterns);
                    }

                    for (int p = 0; p < lNodePatterns; p++)
                    {
                        int    lPatternTransformation = Convert.ToInt32(memFile.ReadPart(':').Trim());
                        string lPatternKey            = memFile.ReadPart('\t').Trim();

                        int lTransformation = Convert.ToInt32(memFile.ReadPart('\t').Trim());

                        Pattern lPattern = patternCollection.FindByKey(lPatternKey);

                        lDFANode.Add(new PatternKey(lPattern, lTransformation));
                    }

                    memFile.ReadLine();
                    DFANodes.Add(lDFANode);
                }
            }
            catch (Exception e)
            {
                return(SetErrorMessage("Matrix Error - Line # " + memFile.LineNbr.ToString() + ":", e));
            }

            return(false);
        }
Пример #11
0
        // temp. for testing
        /// <summary>
        /// Launches the test.
        /// </summary>
        /// <returns></returns>
        public static int LaunchTest2()
        {
            GoBoard    lGoBoard    = new GoBoard(9);
            GameRecord lGameRecord = new GameRecord();

            SGFCollection lSGFCollection = new SGFCollection();

            lSGFCollection.LoadSGFFromMemory(SGFGameSamples.DYER);
            lSGFCollection.RetrieveGame(lGameRecord);
            GameRecordBoardAdapter.Apply(lGameRecord, lGoBoard, false);

            lGoBoard.Dump();

            PatternCollection lPatternCollection = new PatternCollection(@"Patterns\test.db");

            NagCoordinator lNagCoordinator = new NagCoordinator(9999, lPatternCollection);

            lNagCoordinator.Initialize(lGoBoard);
            ThreadPoolHelperWithParam <int> .Execute(LaunchWorker, 9999);

            ThreadPoolHelperWithParam <int> .Execute(LaunchWorker, 9999);

            ThreadPoolHelperWithParam <int> .Execute(LaunchWorker, 9999);

            ThreadPoolHelperWithParam <int> .Execute(LaunchWorker, 9999);

            Thread.Sleep(1000 * 1);

            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);


            Thread.Sleep(1000 * 300);

            return(0);
        }
Пример #12
0
        public DFAMatrix(string filename)
        {
            MemFile lMemFile = new MemFile(filename);

            if (lMemFile.IsError())
            {
                SetErrorMessage(lMemFile);
                return;
            }

            PatternCollection lPatternCollection = new PatternCollection(lMemFile);

            if (lPatternCollection.IsError())
            {
                SetErrorMessage(lPatternCollection);
            }

            _LoadMatrix(lMemFile, lPatternCollection);
        }
Пример #13
0
        protected static void AddPatterns(GoBoard goBoard, SearchEngine searchEngine, List <string> parameters, string id, Worker.SendResponse proxy)
        {
            PatternCollection lPatternCollection = new PatternCollection();

            foreach (string lString in parameters)
            {
                string lPattern = lString.Replace("~", "\n");
                lPatternCollection.Add(new Pattern(lPattern));
            }

            if (lPatternCollection.Count != 0)
            {
                if (searchEngine.SearchOptions.PatternDetector == null)
                {
                    searchEngine.SearchOptions.PatternDetector = new PatternDetector();
                }

                searchEngine.SearchOptions.PatternDetector.Add(lPatternCollection);
            }

            Respond(proxy, id);
        }
Пример #14
0
        // temp. for testing
        /// <summary>
        /// Launches the test.
        /// </summary>
        /// <returns></returns>
        public static int LaunchTest()
        {
            GoBoard    lGoBoard    = new GoBoard(9);
            GameRecord lGameRecord = new GameRecord();

            SGFCollection lSGFCollection = new SGFCollection();

            //lSGFCollection.LoadSGFFromMemory(SGFGameSamples.DYER);
//			lSGFCollection.LoadSGFFile(@"x:\CodePlex\test2.sgf");
//			lSGFCollection.RetrieveGame(lGameRecord);
//			GameRecordBoardAdapter.Apply(lGameRecord, lGoBoard, false);

            lGoBoard.Dump();

            PatternCollection lPatternCollection = new PatternCollection(@"Patterns\test.db");

            NagCoordinator lNagCoordinator = new NagCoordinator(9999, lPatternCollection);

            //ThreadPoolHelperWithParam<int>.Execute(LaunchWorker, 9999);

            Thread.Sleep(1000 * 14);

            SearchEngine lSearchEngine = new SearchEngine(lGoBoard);

            lSearchEngine.SetSearchMethod(SearchMethodType.AlphaBeta_NAG_ID_TT);
            lSearchEngine.SetNagCoordinator(lNagCoordinator);
            lSearchEngine.SearchOptions.MaxPly          = 40;
            lSearchEngine.SearchOptions.MaxSeconds      = 2000;
            lSearchEngine.SearchOptions.PatternDetector = new PatternDetector(lPatternCollection);

            lSearchEngine.SimpleSearch(Color.Black);

            Thread.Sleep(1000 * 10);

            return(0);
        }
Пример #15
0
        // temp. for testing
        /// <summary>
        /// Launches the test.
        /// </summary>
        /// <returns></returns>
        public static int LaunchTest2()
        {
            GoBoard lGoBoard = new GoBoard(9);
            GameRecord lGameRecord = new GameRecord();

            SGFCollection lSGFCollection = new SGFCollection();
            lSGFCollection.LoadSGFFromMemory(SGFGameSamples.DYER);
            lSGFCollection.RetrieveGame(lGameRecord);
            GameRecordBoardAdapter.Apply(lGameRecord, lGoBoard, false);

            lGoBoard.Dump();

            PatternCollection lPatternCollection = new PatternCollection(@"Patterns\test.db");

            NagCoordinator lNagCoordinator = new NagCoordinator(9999, lPatternCollection);

            lNagCoordinator.Initialize(lGoBoard);
            ThreadPoolHelperWithParam<int>.Execute(LaunchWorker, 9999);
            ThreadPoolHelperWithParam<int>.Execute(LaunchWorker, 9999);
            ThreadPoolHelperWithParam<int>.Execute(LaunchWorker, 9999);
            ThreadPoolHelperWithParam<int>.Execute(LaunchWorker, 9999);
            Thread.Sleep(1000 * 1);

            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);
            lNagCoordinator.CreateNagPoints(lGoBoard, -10000, 10000, Color.Black, 30, 0, 0, 1);

            Thread.Sleep(1000 * 300);

            return 0;
        }
Пример #16
0
        // temp. for testing
        /// <summary>
        /// Launches the test.
        /// </summary>
        /// <returns></returns>
        public static int LaunchTest()
        {
            GoBoard lGoBoard = new GoBoard(9);
            GameRecord lGameRecord = new GameRecord();

            SGFCollection lSGFCollection = new SGFCollection();
            //lSGFCollection.LoadSGFFromMemory(SGFGameSamples.DYER);
            //			lSGFCollection.LoadSGFFile(@"x:\CodePlex\test2.sgf");
            //			lSGFCollection.RetrieveGame(lGameRecord);
            //			GameRecordBoardAdapter.Apply(lGameRecord, lGoBoard, false);

            lGoBoard.Dump();

            PatternCollection lPatternCollection = new PatternCollection(@"Patterns\test.db");

            NagCoordinator lNagCoordinator = new NagCoordinator(9999, lPatternCollection);

            //ThreadPoolHelperWithParam<int>.Execute(LaunchWorker, 9999);

            Thread.Sleep(1000 * 14);

            SearchEngine lSearchEngine = new SearchEngine(lGoBoard);

            lSearchEngine.SetSearchMethod(SearchMethodType.AlphaBeta_NAG_ID_TT);
            lSearchEngine.SetNagCoordinator(lNagCoordinator);
            lSearchEngine.SearchOptions.MaxPly = 40;
            lSearchEngine.SearchOptions.MaxSeconds = 2000;
            lSearchEngine.SearchOptions.PatternDetector = new PatternDetector(lPatternCollection);

            lSearchEngine.SimpleSearch(Color.Black);

            Thread.Sleep(1000 * 10);

            return 0;
        }
Пример #17
0
        public void SendPatterns(PatternCollection patternCollection)
        {
            lock (this)
            {
                if (State != ConnectionState.Negotiated)
                {
                    Abort();
                    return;
                }

                CommandNbr++;

                if (patternCollection != null)
                {
                    StringBuilder lString = new StringBuilder();

                    foreach (Pattern lPattern in patternCollection)
                    {
                        lString.Append(lPattern.ToString().Replace("\t", " ").Replace("~", " ").Replace("\n", "~").Replace("\r", ""));
                        lString.Append("\t");
                    }

                    SendCommand("add_patterns", FormatIdNbr(CommandNbr, 1), lString.ToString().TrimEnd('\t'));
                }
                else
                    SendCommand("add_patterns", FormatIdNbr(CommandNbr, 1), "");

                State = ConnectionState.SendingPatterns;
            }
        }
Пример #18
0
        public void Add(PatternCollection patterns)
        {
            DFAMatrixBuilder lDFAMatrixBuilder = new DFAMatrixBuilder(DFAMatrix);
            lDFAMatrixBuilder.Add(patterns);
            PatternCollection.Add(patterns);

            DFAMatrix lDFAMatrix = lDFAMatrixBuilder.GetMatrix();

            lock (this)
            {
                DFAMatrix = lDFAMatrix;
            }
        }
Пример #19
0
 public PatternDetector(PatternCollection patterns)
 {
     PatternCollection = patterns;
     DFAMatrixBuilder lDFAMatrixBuilder = new DFAMatrixBuilder(patterns);
     DFAMatrix = lDFAMatrixBuilder.GetMatrix();
 }
Пример #20
0
 public DFAMatrixBuilder(PatternCollection patternCollection)
 {
     DFAMatrixes = new Stack<DFAMatrix>();
     Add(patternCollection);
     Build();
 }
Пример #21
0
 public void Add(PatternCollection patternCollection)
 {
     foreach (Pattern lPattern in patternCollection)
         Add(lPattern);
 }
Пример #22
0
        // temp. for testing
        static void MatrixCompileToFile()
        {
            PatternCollection lPatterns = new PatternCollection();

            if (!lPatterns.Load(@"Patterns/fuseki9.db"))
            {
                Console.WriteLine("ERROR: Unable to load patterns");
                return;
            }

            Console.WriteLine("STATUS: Loaded " + lPatterns.Count + " Patterns.");

            SimpleTimer lTimer = new SimpleTimer();

            Console.WriteLine(lTimer.StartTime.ToString());

            DFAMatrixBuilder lDFAMatrixBuilder = new DFAMatrixBuilder();

            lDFAMatrixBuilder.Add(lPatterns);

            Console.WriteLine(DateTime.Now.ToString());

            lDFAMatrixBuilder.BuildThreaded();

            Console.WriteLine(DateTime.Now.ToString());

            Console.WriteLine("Seconds: " + lTimer.SecondsElapsed.ToString());

            MemFile lMemFile = new MemFile();

            lMemFile.Write(lDFAMatrixBuilder.GetMatrix().ToString());

            lMemFile.SaveFile(@"Patterns/fuseki9.cdb");
        }
Пример #23
0
        protected bool _LoadMatrix(MemFile memFile, PatternCollection patternCollection)
        {
            try
            {
                int lMatrixSize = Convert.ToInt32(memFile.ReadLine());

                DFANodes = new List<DFANode>(lMatrixSize);

                for (int i = 1; i < lMatrixSize; i++)
                {
                    //			Console.Error.Write(memFile.LineNbr.ToString() + " - " + i.ToString() + " - "+lMatrixSize.ToString());

                    DFANode lDFANode = new DFANode();

                    for (int z = 0; z < 4; z++)
                        lDFANode[z] = Convert.ToInt32(memFile.ReadPart('\t').Trim());

                    int lNodePatterns = Convert.ToInt32(memFile.ReadPart('\t').Trim());

                    if (lNodePatterns > 0)
                        lDFANode.Attributes = new List<PatternKey>(lNodePatterns);

                    for (int p = 0; p < lNodePatterns; p++)
                    {
                        int lPatternTransformation = Convert.ToInt32(memFile.ReadPart(':').Trim());
                        string lPatternKey = memFile.ReadPart('\t').Trim();

                        int lTransformation = Convert.ToInt32(memFile.ReadPart('\t').Trim());

                        Pattern lPattern = patternCollection.FindByKey(lPatternKey);

                        lDFANode.Add(new PatternKey(lPattern, lTransformation));
                    }

                    memFile.ReadLine();
                    DFANodes.Add(lDFANode);
                }
            }
            catch (Exception e)
            {
                return SetErrorMessage("Matrix Error - Line # " + memFile.LineNbr.ToString() + ":", e);
            }

            return false;
        }
Пример #24
0
 public FusekiDetector(PatternCollection patterns)
 {
     foreach (Pattern lPattern in patterns)
         if (lPattern.IsFixedFuseki())
             Add(lPattern);
 }
Пример #25
0
        public static GTPInternalResponse GTPLoadPatterns(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            if (gtpCommand.GetParameterCount() < 1)
                return MissingParameterResponse();

            string lFullPath = (!string.IsNullOrEmpty(gtpGoBoard.Directory)) ?
                gtpGoBoard.Directory + Path.DirectorySeparatorChar + gtpCommand.GetParameter(0)
                : gtpCommand.GetParameter(0);

            PatternCollection lPatternCollection = new PatternCollection(lFullPath);

            if (!lPatternCollection.Load(lFullPath))
                return new GTPInternalResponse(false, "unable to load patterns");

            gtpGoBoard.SearchEngine.SearchOptions.PatternDetector.Add(lPatternCollection);

            return new GTPInternalResponse(true, "loaded");
        }
Пример #26
0
        public DFAMatrix(string filename)
        {
            MemFile lMemFile = new MemFile(filename);

            if (lMemFile.IsError())
            {
                SetErrorMessage(lMemFile);
                return;
            }

            PatternCollection lPatternCollection = new PatternCollection(lMemFile);

            if (lPatternCollection.IsError())
                SetErrorMessage(lPatternCollection);

            _LoadMatrix(lMemFile, lPatternCollection);
        }
Пример #27
0
        protected static void AddPatterns(GoBoard goBoard, SearchEngine searchEngine, List<string> parameters, string id, Worker.SendResponse proxy)
        {
            PatternCollection lPatternCollection = new PatternCollection();

            foreach (string lString in parameters)
            {
                string lPattern = lString.Replace("~", "\n");
                lPatternCollection.Add(new Pattern(lPattern));
            }

            if (lPatternCollection.Count != 0)
            {
                if (searchEngine.SearchOptions.PatternDetector == null)
                    searchEngine.SearchOptions.PatternDetector = new PatternDetector();

                searchEngine.SearchOptions.PatternDetector.Add(lPatternCollection);
            }

            Respond(proxy, id);
        }
 public DFAMatrixBuilder(PatternCollection patternCollection)
 {
     DFAMatrixes = new Stack <DFAMatrix>();
     Add(patternCollection);
     Build();
 }
Пример #29
0
 public void Add(PatternCollection patternCollection)
 {
     if (patternCollection != null)
         foreach (Pattern lPattern in patternCollection)
             Patterns.Add(lPattern);
 }
Пример #30
0
        public static GTPInternalResponse GTPTest(GTPGoBoard gtpGoBoard, GTPCommand gtpCommand)
        {
            PatternCollection lPatternCollection = new PatternCollection(@"patterns\test.db");
            gtpGoBoard.SearchEngine.SearchOptions.PatternDetector.Add(lPatternCollection);

            gtpGoBoard.SearchEngine.SearchOptions.MaxPly = 3;

            return GTPTopMoves(gtpGoBoard, Color.Black);
        }