Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
/* Box Cell Occupied Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#include "CommonFramework/GlobalAutoPaths.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h"
#include "PokemonFRLG_BoxCellOccupiedDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{

BoxCellOccupiedDetector::BoxCellOccupiedDetector(Color color)
: m_color(color)
, m_box(0.007, 0.556, 0.296, 0.253)
{}

void BoxCellOccupiedDetector::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, GameSettings::instance().GAME_BOX.inner_to_outer(m_box));
}

bool BoxCellOccupiedDetector::detect(const ImageViewRGB32& screen){
const ImageViewRGB32 game_screen = extract_box_reference(screen, GameSettings::instance().GAME_BOX);
return image_stats(extract_box_reference(game_screen, m_box)).stddev.sum() > 10.0;
}

class Test_BoxCellOccupiedDetector : public UnitTest{
public:
Test_BoxCellOccupiedDetector(const std::string& image, bool expected)
: UnitTest("PokemonFRLG::BoxCellOccupiedDetector - " + image)
, m_image(UNIT_TEST_RESOURCE_PATH() + image)
, m_expected(expected)
{}

virtual UnitTestResult run(Logger& logger, CancellableScope& scope) const override{
ImageRGB32 image(m_image);
BoxCellOccupiedDetector detector;
const bool result = detector.detect(image);
if (result == m_expected){
return true;
}
return m_expected ? "Expected an occupied cell, received empty." : "Expected an empty cell, received occupied.";
}

private:
std::string m_image;
bool m_expected;
};

void add_tests_BoxCellOccupiedDetector(UnitTestDatabase& database){
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/Arcanine_M_100_White.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/BoxHand_Closed_Gold.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/BoxHand_Closed_White.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/BoxHand_Gold_HD60Pro_NV12.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/BoxHand_Gold_HD60Pro_YUYV.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/BoxHand_White_HD60Pro_NV12.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/BoxHand_White_HD60Pro_YUYV.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/BoxSelection_Gold.png", false);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/BoxSelection_Gold2.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/BoxSelection_White.png", false);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/BoxSelection_White2.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/Caterpie_F_4_White.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/CloseSelection_Gold.png", false);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/CloseSelection_White.png", false);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/Diglett_F_20_White.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/Doduo-NV12.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/Doduo-YUYV.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/Dragonite_F_100_Whtie.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/Nidokinq_M_23_White.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/nidoran-f-mjpeg.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/nidoran-f-NV12.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/nidoran-f-YUYV.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/nidoran-m-mjpeg.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/nidoran-m-NV12.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/nidoran-m-YUYV.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/PartySelection_Gold.png", false);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/PartySelection_White.png", false);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/Rhydon-NV12.png", true);
database.add<Test_BoxCellOccupiedDetector>("PokemonFRLG/Box/Rhydon-YUYV.png", true);
}

}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* Box Cell Occupied Detector
*
* From: https://github.com/PokemonAutomation/
*
*/

#ifndef PokemonAutomation_PokemonFRLG_BoxCellOccupiedDetector_H
#define PokemonAutomation_PokemonFRLG_BoxCellOccupiedDetector_H

#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/VisualDetector.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonFRLG{

// Reads the current selection's information panel, not every cell in the grid.
class BoxCellOccupiedDetector : public StaticScreenDetector{
public:
BoxCellOccupiedDetector(Color color = COLOR_RED);

virtual void make_overlays(VideoOverlaySet& items) const override;
virtual bool detect(const ImageViewRGB32& screen) override;

private:
Color m_color;
ImageFloatBox m_box;
};

void add_tests_BoxCellOccupiedDetector(UnitTestDatabase& database);

}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "Common/Cpp/Filesystem/Filesystem.h"
#include "Common/Cpp/TestRunners/UnitTestDatabase.h"
#include "CommonFramework/StaticGlobals.h"
#include "Inference/Box/PokemonFRLG_BoxCellOccupiedDetector.h"
#include "Inference/Box/PokemonFRLG_BoxGenderReader.h"
#include "Inference/Box/PokemonFRLG_BoxSelectionModeDetector.h"
#include "Inference/Dialogs/PokemonFRLG_BattleDialogs.h"
Expand Down Expand Up @@ -263,6 +264,7 @@ void add_tests_ExitWildBattle(UnitTestDatabase& database){

void add_tests(UnitTestDatabase& database){
add_tests_AdvanceWhiteDialogDetector(database);
add_tests_BoxCellOccupiedDetector(database);
add_tests_BoxGenderReader(database);
add_tests_BoxSelectionModeDetector(database);
add_tests_SelectionDialogDetector(database);
Expand Down
2 changes: 2 additions & 0 deletions SerialPrograms/cmake/SourceFiles.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,8 @@ file(GLOB LIBRARY_SOURCES
Source/PokemonBDSP/Programs/Trading/PokemonBDSP_TradeRoutines.h
Source/PokemonBDSP/Resources/PokemonBDSP_NameDatabase.cpp
Source/PokemonBDSP/Resources/PokemonBDSP_NameDatabase.h
Source/VideoGames/PokemonFRLG/Inference/Box/PokemonFRLG_BoxCellOccupiedDetector.cpp
Source/VideoGames/PokemonFRLG/Inference/Box/PokemonFRLG_BoxCellOccupiedDetector.h
Source/VideoGames/PokemonFRLG/Inference/Box/PokemonFRLG_BoxGenderReader.cpp
Source/VideoGames/PokemonFRLG/Inference/Box/PokemonFRLG_BoxGenderReader.h
Source/VideoGames/PokemonFRLG/Inference/Box/PokemonFRLG_BoxSelectionModeDetector.cpp
Expand Down
Loading