コード例 #1
0
        public static void RunTriadSolverTests(string path)
        {
            string testRoot = AssetManager.Get().CreateFilePath(path);
            IEnumerable <string> configPaths = Directory.EnumerateFiles(testRoot, "*.json");

            foreach (var configPath in configPaths)
            {
                Logger.WriteLine("==> Testing: " + Path.GetFileNameWithoutExtension(configPath));
                bool bNeedsDebugRun = false;

                try
                {
                    TriadGameScreenMemory.RunTest(configPath, bNeedsDebugRun);
                    TriadGameSession.RunTest(configPath, bNeedsDebugRun);
                }
                catch (Exception ex)
                {
                    Logger.WriteLine("Exception:" + ex);
                    bNeedsDebugRun = true;
                }

                if (bNeedsDebugRun)
                {
                    TriadGameScreenMemory.RunTest(configPath, bNeedsDebugRun);
                    TriadGameSession.RunTest(configPath, bNeedsDebugRun);
                }
            }
        }
コード例 #2
0
ファイル: TestManager.cs プロジェクト: uk959595/FFTriadBuddy
        public static void RunTriadSolverTests(string path)
        {
            string testRoot = AssetManager.Get().CreateFilePath(path);
            IEnumerable <string> configPaths = Directory.EnumerateFiles(testRoot, "*.json");

            foreach (var configPath in configPaths)
            {
                Logger.WriteLine("==> Testing: " + Path.GetFileNameWithoutExtension(configPath));
                TriadGameScreenMemory.RunTest(configPath);
            }
        }
コード例 #3
0
ファイル: FormOverlay.cs プロジェクト: purutu/FFTriadBuddy
        public FormOverlay()
        {
            InitializeComponent();

            cactpotBoard = new HitInvisibleLabel[9] {
                labelCactpot0, labelCactpot1, labelCactpot2, labelCactpot3, labelCactpot4, labelCactpot5, labelCactpot6, labelCactpot7, labelCactpot8
            };
            boardControls = new CardCtrl[9] {
                cardCtrl1, cardCtrl2, cardCtrl3, cardCtrl4, cardCtrl5, cardCtrl6, cardCtrl7, cardCtrl8, cardCtrl9
            };
            for (int Idx = 0; Idx < boardControls.Length; Idx++)
            {
                boardControls[Idx].defaultBackColor  = panelBoard.BackColor;
                boardControls[Idx].drawMode          = ECardDrawMode.OwnerOnly;
                boardControls[Idx].bBlinkHighlighted = false;
                boardControls[Idx].bEnableHitTest    = false;
                boardControls[Idx].SetCard(null);
                boardControls[Idx].Tag = Idx;
            }

            redDeckKnownCards = new CardCtrl[5] {
                cardCtrlRedKnown0, cardCtrlRedKnown1, cardCtrlRedKnown2, cardCtrlRedKnown3, cardCtrlRedKnown4
            };
            redDeckUnknownCards = new CardCtrl[5] {
                cardCtrlRedVar0, cardCtrlRedVar1, cardCtrlRedVar2, cardCtrlRedVar3, cardCtrlRedVar4
            };
            for (int Idx = 0; Idx < redDeckKnownCards.Length; Idx++)
            {
                redDeckKnownCards[Idx].defaultBackColor  = panelDeckDetails.BackColor;
                redDeckKnownCards[Idx].drawMode          = ECardDrawMode.ImageOnly;
                redDeckKnownCards[Idx].bBlinkHighlighted = false;
                redDeckKnownCards[Idx].bEnableHitTest    = false;
                redDeckKnownCards[Idx].SetCard(null);
                redDeckKnownCards[Idx].Tag = Idx;

                redDeckUnknownCards[Idx].defaultBackColor  = panelDeckDetails.BackColor;
                redDeckUnknownCards[Idx].drawMode          = ECardDrawMode.ImageOnly;
                redDeckUnknownCards[Idx].bBlinkHighlighted = false;
                redDeckUnknownCards[Idx].bEnableHitTest    = false;
                redDeckUnknownCards[Idx].SetCard(null);
                redDeckUnknownCards[Idx].Tag = Idx;
            }

            panelMarkerBoard.Visible    = false;
            panelMarkerDeck.Visible     = false;
            panelMarkerSwap.Visible     = false;
            panelMarkerLine.Visible     = false;
            panelDetails.Visible        = false;
            panelBoard.Visible          = false;
            panelCactpot.Visible        = false;
            panelDebug.Visible          = false;
            panelSwapWarning.Visible    = false;
            panelScanResolution.Visible = false;
            labelStatus.Focus();
            labelSwapWarningIcon.Image = SystemIcons.Warning.ToBitmap();

            bHasValidMarkerDeck       = false;
            bHasValidMarkerBoard      = false;
            bCanAdjustSummaryLocation = false;
            bCanStopTurnScan          = true;
            bCanAutoCapture           = false;
            dashAnimOffset            = 0;
            scanId       = 0;
            screenMemory = new TriadGameScreenMemory();

            Location = Screen.PrimaryScreen.Bounds.Location;
            Size     = Screen.PrimaryScreen.Bounds.Size;
            UpdateOverlayLocation(10, 10);
            UpdateAutoCaptureMarker();
            UpdateStatusDescription();
        }
コード例 #4
0
        public static void RunTest(string configPath, bool debugMode)
        {
            string testName = System.IO.Path.GetFileNameWithoutExtension(configPath);

            string configText = System.IO.File.ReadAllText(configPath);

            JsonParser.ObjectValue rootOb = JsonParser.ParseJson(configText);
            if (rootOb["type"] != "Screen")
            {
                return;
            }

            ScannerTriad.VerifyConfig configData = new ScannerTriad.VerifyConfig();
            configData.Load(rootOb);

            // setup npc & modifiers
            TriadNpc testNpc = TriadNpcDB.Get().Find(configData.npc);

            if (testNpc == null)
            {
                string exceptionMsg = string.Format("Test {0} failed! Can't find npc: {1}", testName, configData.npc);
                throw new Exception(exceptionMsg);
            }

            ScannerTriad.GameState screenGame = new ScannerTriad.GameState();
            if (mapValidationRules == null)
            {
                mapValidationRules = new Dictionary <string, TriadGameModifier>();
                foreach (TriadGameModifier mod in ImageHashDB.Get().modObjects)
                {
                    mapValidationRules.Add(mod.GetCodeName(), mod);
                }
            }

            foreach (string modName in configData.rules)
            {
                screenGame.mods.Add(mapValidationRules[modName]);
            }

            Func <ScannerTriad.VerifyCard, TriadCard> ConvertToTriadCard = configCard =>
            {
                if (configCard.state == ScannerTriad.ECardState.None)
                {
                    return(null);
                }
                if (configCard.state == ScannerTriad.ECardState.Hidden)
                {
                    return(TriadCardDB.Get().hiddenCard);
                }

                TriadCard matchingCard = !string.IsNullOrEmpty(configCard.name) ?
                                         TriadCardDB.Get().Find(configCard.name) :
                                         TriadCardDB.Get().Find(configCard.sides[0], configCard.sides[1], configCard.sides[2], configCard.sides[3]);

                if (matchingCard == null)
                {
                    string exceptionMsg = string.Format("Test {0} failed! Can't match validation card: '{1}' [{2},{3},{4},{5}]", testName,
                                                        configCard.name, configCard.sides[0], configCard.sides[1], configCard.sides[2], configCard.sides[3]);
                    throw new Exception(exceptionMsg);
                }

                return(matchingCard);
            };

            bool needsLockedBlue = false;

            for (int idx = 0; idx < 5; idx++)
            {
                screenGame.blueDeck[idx] = ConvertToTriadCard(configData.deckBlue[idx]);
                screenGame.redDeck[idx]  = ConvertToTriadCard(configData.deckRed[idx]);

                if (configData.deckBlue[idx].state == ScannerTriad.ECardState.Locked)
                {
                    needsLockedBlue = true;
                }
            }

            if (needsLockedBlue)
            {
                for (int idx = 0; idx < 5; idx++)
                {
                    if (configData.deckBlue[idx].state == ScannerTriad.ECardState.Visible)
                    {
                        screenGame.forcedBlueCard = screenGame.blueDeck[idx];
                        break;
                    }
                }
            }

            for (int idx = 0; idx < 9; idx++)
            {
                screenGame.board[idx]      = ConvertToTriadCard(configData.board[idx]);
                screenGame.boardOwner[idx] =
                    configData.board[idx].state == ScannerTriad.ECardState.PlacedBlue ? ETriadCardOwner.Blue :
                    configData.board[idx].state == ScannerTriad.ECardState.PlacedRed ? ETriadCardOwner.Red :
                    ETriadCardOwner.Unknown;
            }

            TriadGameScreenMemory screenMemory = new TriadGameScreenMemory {
                logScan = false
            };

            screenMemory.OnNewScan(screenGame, testNpc);
            screenMemory.gameSession.SolverFindBestMove(screenMemory.gameState, out int solverBoardPos, out TriadCard solverTriadCard, out TriadGameResultChance bestChance);

            if (bestChance.expectedResult == ETriadGameState.BlueLost && bestChance.winChance <= 0.0f && bestChance.drawChance <= 0.0f)
            {
                string exceptionMsg = string.Format("Test {0} failed! Can't find move!", testName);
                throw new Exception(exceptionMsg);
            }
        }