-
Notifications
You must be signed in to change notification settings - Fork 80
LGPE Snorlax #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
LGPE Snorlax #583
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
88d0f36
copy sound detector and listener for LGPE
kichithewolf ef1c5ab
setting and panel
kichithewolf 0896e03
lgpe battle menu detector
kichithewolf 50d6611
partial working legendary reset, soundlistener fixes
kichithewolf d29f3c9
target selection
kichithewolf bfa5836
BattleMenu->Arrow
kichithewolf 618e07b
legendaryreset fixes
kichithewolf 0e059f2
handle shiny battle
kichithewolf File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
SerialPrograms/Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| /* Battle Arrow Detector | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" | ||
| #include "Kernels/Waterfill/Kernels_Waterfill_Session.h" | ||
| #include "CommonFramework/Globals.h" | ||
| #include "CommonFramework/ImageTypes/ImageViewRGB32.h" | ||
| #include "CommonTools/Images/BinaryImage_FilterRgb32.h" | ||
| #include "CommonTools/ImageMatch/ExactImageMatcher.h" | ||
| #include "PokemonLGPE_BattleArrowDetector.h" | ||
|
|
||
| //#include <iostream> | ||
| //using std::cout; | ||
| //using std::endl; | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
| namespace PokemonLGPE{ | ||
|
|
||
| const ImageMatch::ExactImageMatcher& BATTLE_ARROW(){ | ||
| static ImageMatch::ExactImageMatcher matcher(RESOURCE_PATH() + "PokemonLGPE/BattleArrow.png"); | ||
| return matcher; | ||
| } | ||
|
|
||
| BattleArrowDetector::BattleArrowDetector(Color color, const ImageFloatBox& box) | ||
| : m_color(color) | ||
| , m_box(box) | ||
| {} | ||
| void BattleArrowDetector::make_overlays(VideoOverlaySet& items) const{ | ||
| items.add(m_color, m_box); | ||
| } | ||
| bool BattleArrowDetector::detect(const ImageViewRGB32& screen) const{ | ||
| using namespace Kernels::Waterfill; | ||
|
|
||
| ImageViewRGB32 region = extract_box_reference(screen, m_box); | ||
|
|
||
| const ImageMatch::ExactImageMatcher& matcher = BATTLE_ARROW(); | ||
|
|
||
| auto matrix = compress_rgb32_to_binary_range(region, 0xffc0c0c0, 0xffffffff); | ||
| auto session = make_WaterfillSession(matrix); | ||
| auto iter = session->make_iterator(100); | ||
| WaterfillObject object; | ||
|
|
||
| //static int c = 0; | ||
| while (iter->find_next(object, false)){ | ||
| double aspect_ratio = object.aspect_ratio(); | ||
| if (aspect_ratio < 1.0 || aspect_ratio > 1.3){ | ||
| continue; | ||
| } | ||
| ImageViewRGB32 cropped = extract_box_reference(region, object); | ||
| //cropped.save("test-object-" + std::to_string(c++) + ".png"); | ||
| double rmsd = matcher.rmsd(cropped); | ||
| //cout << rmsd << endl; | ||
| if (rmsd < 110){ | ||
| return true; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
| } | ||
| } |
53 changes: 53 additions & 0 deletions
53
SerialPrograms/Source/PokemonLGPE/Inference/Battles/PokemonLGPE_BattleArrowDetector.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /* Battle Arrow Detector | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PokemonAutomation_PokemonLGPE_BattleArrowDetector_H | ||
| #define PokemonAutomation_PokemonLGPE_BattleArrowDetector_H | ||
|
|
||
| #include <chrono> | ||
| #include <atomic> | ||
| #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" | ||
| #include "Common/Cpp/Color.h" | ||
| #include "CommonFramework/ImageTools/ImageBoxes.h" | ||
| #include "CommonTools/VisualDetector.h" | ||
| #include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
| namespace PokemonLGPE{ | ||
|
|
||
| class BattleArrowDetector : public StaticScreenDetector{ | ||
| public: | ||
| /* | ||
| |Fight|Pokemon|Bag|Run| for wild battle | ||
| |---|Fight|Pokemon|Bag| for trainer battle | ||
| (align right) | ||
| Don't know what changes for a double battle. | ||
| */ | ||
| //Arrow bounces back and forth. | ||
| BattleArrowDetector(Color color, const ImageFloatBox& box = {0.546, 0.863, 0.045, 0.068}); //Wild battle. | ||
|
|
||
| virtual void make_overlays(VideoOverlaySet& items) const override; | ||
| virtual bool detect(const ImageViewRGB32& screen) const override; | ||
|
|
||
| protected: | ||
| Color m_color; | ||
| ImageFloatBox m_box; | ||
| }; | ||
| class BattleArrowWatcher : public DetectorToFinder<BattleArrowDetector>{ | ||
| public: | ||
| BattleArrowWatcher(Color color = COLOR_RED) | ||
| : DetectorToFinder("BattleArrowWatcher", std::chrono::milliseconds(100), color) | ||
| {} | ||
| }; | ||
|
|
||
|
|
||
|
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| #endif |
47 changes: 47 additions & 0 deletions
47
SerialPrograms/Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| /* Shiny Sound Detector | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #include "CommonTools/Audio/AudioTemplateCache.h" | ||
| #include "CommonTools/Audio/SpectrogramMatcher.h" | ||
| #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" | ||
| #include "PokemonLGPE/PokemonLGPE_Settings.h" | ||
| #include "PokemonLGPE_ShinySoundDetector.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
| namespace PokemonLGPE{ | ||
|
|
||
|
|
||
| ShinySoundDetector::ShinySoundDetector(Logger& logger, DetectedCallback detected_callback) | ||
| // Use a yellow as the detection color because the shiny animation is yellow. | ||
| : AudioPerSpectrumDetectorBase( | ||
| logger, | ||
| "ShinySoundDetector", | ||
| "Shiny sound", | ||
| COLOR_YELLOW, | ||
| detected_callback | ||
| ) | ||
| {} | ||
|
|
||
|
|
||
| float ShinySoundDetector::get_score_threshold() const{ | ||
| return (float)GameSettings::instance().SHINY_SOUND_THRESHOLD; | ||
| } | ||
|
|
||
| std::unique_ptr<SpectrogramMatcher> ShinySoundDetector::build_spectrogram_matcher(size_t sample_rate){ | ||
| return std::make_unique<SpectrogramMatcher>( | ||
| "Shiny Sound", | ||
| AudioTemplateCache::instance().get_throw("PokemonLGPE/ShinySound", sample_rate), | ||
| SpectrogramMatcher::Mode::SPIKE_CONV, sample_rate, | ||
| GameSettings::instance().SHINY_SOUND_LOW_FREQUENCY | ||
| ); | ||
| } | ||
|
|
||
|
|
||
|
|
||
| } | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
SerialPrograms/Source/PokemonLGPE/Inference/Sounds/PokemonLGPE_ShinySoundDetector.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* Shiny Sound Detector | ||
| * | ||
| * From: https://github.com/PokemonAutomation/ | ||
| * | ||
| */ | ||
|
|
||
| #ifndef PokemonAutomation_PokemonLGPE_ShinySoundDetector_H | ||
| #define PokemonAutomation_PokemonLGPE_ShinySoundDetector_H | ||
|
|
||
| #include "CommonTools/Audio/AudioPerSpectrumDetectorBase.h" | ||
|
|
||
| namespace PokemonAutomation{ | ||
| namespace NintendoSwitch{ | ||
| namespace PokemonLGPE{ | ||
|
|
||
|
|
||
| class ShinySoundDetector : public AudioPerSpectrumDetectorBase{ | ||
| public: | ||
| // Warning: The callback will be called from the audio inference thread. | ||
| ShinySoundDetector(Logger& logger, DetectedCallback detected_callback); | ||
|
|
||
| // Implement AudioPerSpectrumDetectorBase::get_score_threshold() | ||
| virtual float get_score_threshold() const override; | ||
|
|
||
| protected: | ||
| // Implement AudioPerSpectrumDetectorBase::build_spectrogram_matcher() | ||
| virtual std::unique_ptr<SpectrogramMatcher> build_spectrogram_matcher(size_t sample_rate) override; | ||
| }; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| } | ||
| } | ||
| } | ||
| #endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's put this one under dev or beta until the auto-battle is added since the program won't be as useful until then.
It might also be worth experimenting with changing the clock to see if that does anything to stop the timer.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changing clock doesn't work.
Static legendaries don't run once the battle phase is done. The battle arrow looks like its reused in the catching menus,
so I should have a solution soon.this is done.