// 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 void BuildThreaded()
        {
            Console.Error.WriteLine("Building...");
            SimpleTimer lTimer = new SimpleTimer();

            if (DFAMatrixes.Count < 64)
            {
                Build();
            }
            else
            {
                DFAMatrixBuilder lDFAMatrixBuilder1 = new DFAMatrixBuilder(DFAMatrixes, DFAMatrixes.Count / 3);
                Thread           lThread1           = new Thread(new ThreadStart(lDFAMatrixBuilder1.Build));
                lThread1.Start();

                DFAMatrixBuilder lDFAMatrixBuilder2 = new DFAMatrixBuilder(DFAMatrixes, DFAMatrixes.Count / 2);
                Thread           lThread2           = new Thread(new ThreadStart(lDFAMatrixBuilder2.Build));
                lThread2.Start();

                Build();

                lThread1.Join();
                lThread2.Join();

                DFAMatrixes.Push(lDFAMatrixBuilder1.DFAMatrixes.Pop());
                DFAMatrixes.Push(lDFAMatrixBuilder2.DFAMatrixes.Pop());

                Build();
            }

            Console.Error.WriteLine("Build Time: " + lTimer.SecondsElapsed.ToString() + " Seconds");
            Console.Error.WriteLine("Nodes: " + GetMatrix().DFANodes.Count.ToString());
        }
        public static void GamePlayTestSolver(int tests, bool withSolver)
        {
            GoBoard    lGoBoard    = new GoBoard(19);
            GameRecord lGameRecord = new GameRecord();

            SGFCollection lSGFCollection = new SGFCollection();

            lSGFCollection.LoadSGFFromMemory(SGFGameSamples.GAME_1993_ZHONG_JIALIN_HANE_YASUMASA_1);
            lSGFCollection.RetrieveGame(lGameRecord, 0);

            SimpleTimer lSimpleTimer = new SimpleTimer();

            GameRecordBoardAdapter.Apply(lGameRecord, lGoBoard, true);
            //lGameRecord.Apply(lGoBoard, true);

            for (int i = 0; i < tests; i++)
            {
                if (withSolver)
                {
                    lGoBoard.SafetyStatusMap = null;
                    int lSafePoints = lGoBoard.CountSafePoints(Color.Black);
                    lSafePoints += lGoBoard.CountSafePoints(Color.White);
                }
            }

            lSimpleTimer.Stop();

            Console.Write("19x19 Game - Solver [ ");
            Console.Write("] # " + tests.ToString() + " times. ");
            Console.Write("Elapsed: " + lSimpleTimer.MilliSecondsElapsed.ToString() + " ms ");
            Console.WriteLine("Avg.: " + (lSimpleTimer.MilliSecondsElapsed / tests).ToString() + " ms ");

            return;
        }
Example #4
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns></returns>
        public SimpleTimer Clone()
        {
            SimpleTimer lSimpleTimer = new SimpleTimer();

            lSimpleTimer.StartTick = StartTick;
            lSimpleTimer.EndTick   = EndTick;

            return(lSimpleTimer);
        }
        // temp. for testing
        static void LoadCompiledMatrix()
        {
            Console.WriteLine(DateTime.Now.ToString());
            SimpleTimer lTimer = new SimpleTimer();

            DFAMatrix lDFAMatrix = new DFAMatrix(@"Patterns/fuseki9.cdb");

            Console.WriteLine(lDFAMatrix.DFANodes.Count);

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

            GC.Collect();
        }
Example #6
0
        public static void GamePlayTest(int tests, bool withUndo, bool withSolver)
        {
            GoBoard lGoBoard = new GoBoard(19);
            GameRecord lGameRecord = new GameRecord();

            SGFCollection lSGFCollection = new SGFCollection();
            lSGFCollection.LoadSGFFromMemory(SGFGameSamples.GAME_1993_ZHONG_JIALIN_HANE_YASUMASA_1);
            lSGFCollection.RetrieveGame(lGameRecord, 0);

            SimpleTimer lSimpleTimer = new SimpleTimer();

            for (int i = 0; i < tests; i++)
            {
                GameRecordBoardAdapter.Apply(lGameRecord, lGoBoard, true);
                //lGameRecord.Apply(lGoBoard, true);

                if (withSolver)
                {
                    int lSafePoints = lGoBoard.CountSafePoints(Color.Black);
                    lSafePoints += lGoBoard.CountSafePoints(Color.White);
                }

                if (withUndo)
                    while (lGoBoard.CanUndo())
                        lGoBoard.Undo();
            }

            lSimpleTimer.Stop();

            Console.Write("19x19 Game [ ");
            Console.Write((withUndo ? "+Undo " : ""));
            Console.Write((withSolver ? "+Solver " : ""));
            Console.Write("] # "+tests.ToString()+" times. ");
            Console.Write("Elapsed: " + lSimpleTimer.MilliSecondsElapsed.ToString() + " ms ");
            Console.WriteLine("Avg.: " + (lSimpleTimer.MilliSecondsElapsed / tests).ToString() + " ms ");

            return;
        }
Example #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleTimer"/> class.
 /// </summary>
 /// <param name="simpleTimer">The simple timer.</param>
 public SimpleTimer(SimpleTimer simpleTimer)
 {
     StartTick = simpleTimer.StartTick;
     EndTick   = simpleTimer.EndTick;
 }
Example #8
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");
        }
Example #9
0
        // temp. for testing
        static void LoadCompiledMatrix()
        {
            Console.WriteLine(DateTime.Now.ToString());
            SimpleTimer lTimer = new SimpleTimer();

            DFAMatrix lDFAMatrix = new DFAMatrix(@"Patterns/fuseki9.cdb");

            Console.WriteLine(lDFAMatrix.DFANodes.Count);

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

            GC.Collect();
        }
Example #10
0
        public void BuildThreaded()
        {
            Console.Error.WriteLine("Building...");
            SimpleTimer lTimer = new SimpleTimer();

            if (DFAMatrixes.Count < 64)
                Build();
            else
            {
                DFAMatrixBuilder lDFAMatrixBuilder1 = new DFAMatrixBuilder(DFAMatrixes, DFAMatrixes.Count / 3);
                Thread lThread1 = new Thread(new ThreadStart(lDFAMatrixBuilder1.Build));
                lThread1.Start();

                DFAMatrixBuilder lDFAMatrixBuilder2 = new DFAMatrixBuilder(DFAMatrixes, DFAMatrixes.Count / 2);
                Thread lThread2 = new Thread(new ThreadStart(lDFAMatrixBuilder2.Build));
                lThread2.Start();

                Build();

                lThread1.Join();
                lThread2.Join();

                DFAMatrixes.Push(lDFAMatrixBuilder1.DFAMatrixes.Pop());
                DFAMatrixes.Push(lDFAMatrixBuilder2.DFAMatrixes.Pop());

                Build();
            }

            Console.Error.WriteLine("Build Time: " + lTimer.SecondsElapsed.ToString() + " Seconds");
            Console.Error.WriteLine("Nodes: " + GetMatrix().DFANodes.Count.ToString());
        }
Example #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SimpleTimer"/> class.
 /// </summary>
 /// <param name="simpleTimer">The simple timer.</param>
 public SimpleTimer(SimpleTimer simpleTimer)
 {
     StartTick = simpleTimer.StartTick;
     EndTick = simpleTimer.EndTick;
 }
Example #12
0
        /// <summary>
        /// Clones this instance.
        /// </summary>
        /// <returns></returns>
        public SimpleTimer Clone()
        {
            SimpleTimer lSimpleTimer = new SimpleTimer();

            lSimpleTimer.StartTick = StartTick;
            lSimpleTimer.EndTick = EndTick;

            return lSimpleTimer;
        }