Пример #1
0
        public override void ValidateScan(string configPath, ScreenAnalyzer.EMode mode, MLDataExporter dataExporter)
        {
            string testName = Path.GetFileNameWithoutExtension(configPath);

            GameState validationState = LoadValidationConfig(configPath);

            if (validationState == null || cachedGameState == null)
            {
                string exceptionMsg = string.Format("Test {0} failed! Scan results:{1}, config path: {2}", testName, cachedGameState, configPath);
                throw new Exception(exceptionMsg);
            }

            if (dataExporter != null && cachedCircles != null)
            {
                int numPatterns = 0;
                for (int idx = 0; idx < 9; idx++)
                {
                    // generate additional sample images by offseting source bounds -5..5 px in each direction
                    // numbers only, empty field doesn't have enough details to care
                    if (validationState.board[idx] > 0)
                    {
                        for (int offsetX = -5; offsetX <= 5; offsetX++)
                        {
                            for (int offsetY = -5; offsetY <= 5; offsetY++)
                            {
                                Rectangle offsetBounds = cachedCircles[idx];
                                offsetBounds.Offset(offsetX, offsetY);

                                float[] exportValues = ExtractCirclePattern(screenAnalyzer.cachedFastBitmap, offsetBounds);
                                dataExporter.ExportValues(exportValues, validationState.board[idx]);
                                numPatterns++;
                            }
                        }
                    }
                    else
                    {
                        float[] exportValues = ExtractCirclePattern(screenAnalyzer.cachedFastBitmap, cachedCircles[idx]);
                        dataExporter.ExportValues(exportValues, validationState.board[idx]);
                        numPatterns++;
                    }
                }

                Logger.WriteLine("Exported ML entries:{0}", numPatterns);
            }

            for (int idx = 0; idx < 9; idx++)
            {
                if (cachedGameState.board[idx] != validationState.board[idx])
                {
                    string exceptionMsg = string.Format("Test {0} failed! Board[{1}] got:{2}, expected:{3}",
                                                        testName, idx,
                                                        cachedGameState.board[idx],
                                                        validationState.board[idx]);
                    throw new Exception(exceptionMsg);
                    //Logger.WriteLine(exceptionMsg);
                }
            }
        }
Пример #2
0
        public static void RunTests()
        {
            // ML run?
            exportDetectionPatterns = false;

            ScreenAnalyzer.EMode testMode = ScreenAnalyzer.EMode.AlwaysResetCache | ScreenAnalyzer.EMode.DebugScreenshotOnly | ScreenAnalyzer.EMode.AutoTest;

            RunTests("test/auto/cactpot", testMode | ScreenAnalyzer.EMode.ScanCactpot);
            RunTests("test/auto/triad", testMode | ScreenAnalyzer.EMode.ScanTriad);
            RunTriadSolverTests("test/auto/triad-solver");
        }
Пример #3
0
 public virtual void ValidateScan(string configPath, ScreenAnalyzer.EMode mode, MLDataExporter dataExporter)
 {
     throw new Exception("Scanner doesn't support tests!");
 }
Пример #4
0
        public static void RunTests(string path, ScreenAnalyzer.EMode mode)
        {
            ScreenAnalyzer screenAnalyzer = new ScreenAnalyzer();
            MLDataExporter dataExporter   = null;

            ScannerBase scannerOb = null;

            foreach (var kvp in screenAnalyzer.mapScanners)
            {
                if ((kvp.Key & mode) != ScreenAnalyzer.EMode.None)
                {
                    scannerOb = kvp.Value;
                    break;
                }
            }

            if (scannerOb == null)
            {
                throw new Exception("Test failed! Can't find scanner for requested type:" + mode);
            }

            if (exportDetectionPatterns)
            {
                dataExporter            = new MLDataExporter();
                dataExporter.exportPath = AssetManager.Get().CreateFilePath("ml/patternMatch/data");
                dataExporter.StartDataExport((mode & ScreenAnalyzer.EMode.ScanAll).ToString());
            }

            string testRoot = AssetManager.Get().CreateFilePath(path);
            IEnumerable <string> configPaths = Directory.EnumerateFiles(testRoot, "*.json");

            foreach (var configPath in configPaths)
            {
                string imagePath = configPath.Replace(".json", ".jpg");
                if (!File.Exists(imagePath))
                {
                    imagePath = imagePath.Replace(".jpg", ".png");
                }

                if (File.Exists(imagePath))
                {
                    Logger.WriteLine("==> Testing: " + Path.GetFileNameWithoutExtension(configPath));

                    bool bNeedsDebugRun = false;
                    screenAnalyzer.debugScreenshotPath = imagePath;
                    screenAnalyzer.debugScannerContext = null;

                    try
                    {
                        screenAnalyzer.DoWork(mode);
                        scannerOb.ValidateScan(configPath, mode, dataExporter);
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteLine("Exception:" + ex);
                        bNeedsDebugRun = true;
                    }

                    // retry, don't catch exceptions
                    if (bNeedsDebugRun && !exportDetectionPatterns)
                    {
                        screenAnalyzer.DoWork(mode | ScreenAnalyzer.EMode.Debug);
                        scannerOb.ValidateScan(configPath, mode | ScreenAnalyzer.EMode.Debug, null);
                    }
                }
            }

            if (exportDetectionPatterns)
            {
                dataExporter.FinishDataExport("ml-" + Path.GetFileNameWithoutExtension(path) + ".json");
            }
        }