Skip to content

Commit

Permalink
Fix end of battle detection.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Nov 18, 2023
1 parent f2727ae commit 670dcb2
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ ImageRGB32::ImageRGB32(QImage image){
else if (format != QImage::Format_ARGB32 && format != QImage::Format_RGB32){
std::cout << "Non standard QImage format: " + std::to_string((int)format) << std::endl;
// image = image.convertToFormat(QImage::Format_ARGB32);
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid QImage format." + std::to_string((int)format));
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid QImage format: " + std::to_string((int)format));
}
m_width = image.width();
m_height = image.height();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_Lobby.h"
#include "PokemonSV/Inference/PokemonSV_StatHexagonReader.h"
#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h"
#include "PokemonSwSh/Inference/PokemonSwSh_ReceivePokemonDetector.h"



Expand Down Expand Up @@ -238,11 +239,17 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
VideoOverlaySet overlays(overlay);


// PokemonSwSh::ReceivePokemonDetector caught_detector(true);
// caught_detector.process_frame();


#if 0
start_game_from_home(
console, context,
true, 0, 0,
10
);
#endif

#if 0
// UpdateMenuWatcher update_menu(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@
*
*/

#include "Common/Compiler.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "PokemonSwSh_ReceivePokemonDetector.h"

#include <iostream>
using std::cout;
using std::endl;
//#include <iostream>
//using std::cout;
//using std::endl;

namespace PokemonAutomation{
namespace NintendoSwitch{
Expand All @@ -39,6 +38,7 @@ bool ReceivePokemonDetector::process_frame(const ImageViewRGB32& frame, WallCloc
bool ret = receive_is_over(frame);
bool triggered = m_triggered.load(std::memory_order_acquire);
m_triggered.store(triggered | ret, std::memory_order_release);
// cout << "m_has_been_orange = " << m_has_been_orange << endl;
return ret && m_stop_on_detected;
}
bool ReceivePokemonDetector::receive_is_over(const ImageViewRGB32& frame){
Expand All @@ -51,6 +51,18 @@ bool ReceivePokemonDetector::receive_is_over(const ImageViewRGB32& frame){
FloatPixel actual1 = stats1.average;
FloatPixel actual2 = stats2.average;

// cout << actual0 << actual1 << actual2 << endl;

if (actual0.sum() < 100){
return m_has_been_orange;
}
if (actual1.sum() < 100){
return m_has_been_orange;
}
if (actual2.sum() < 100){
return m_has_been_orange;
}

expected /= expected.sum();
actual0 /= actual0.sum();
actual1 /= actual1.sum();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,9 @@ CatchResults basic_catcher(


// Wait for end of battle.
// console.video().snapshot()->save("test0.png");
{
console.log("Waiting for black screen end...");
BlackScreenOverWatcher black_screen_detector;
run_until(
console, context,
Expand All @@ -171,9 +173,12 @@ CatchResults basic_catcher(
},
{{black_screen_detector}}
);
console.log("Waiting for black screen end... Found!");
}

// Look for the orange caught screen.
// console.video().snapshot()->save("test1.png");
// context.wait_for(std::chrono::milliseconds(5000));
{
ReceivePokemonDetector caught_detector(true);

Expand All @@ -197,7 +202,9 @@ CatchResults basic_catcher(
}

// pbf_wait(context, 5 * TICKS_PER_SECOND);
// console.video().snapshot()->save("test2.png");
{
console.log("Waiting for black screen end...");
BlackScreenOverWatcher black_screen_detector;
run_until(
console, context,
Expand All @@ -206,6 +213,7 @@ CatchResults basic_catcher(
},
{{black_screen_detector}}
);
console.log("Waiting for black screen end... Found!");
}

results.result = CatchResult::POKEMON_CAUGHT;
Expand Down

0 comments on commit 670dcb2

Please sign in to comment.