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
Expand Up @@ -67,6 +67,20 @@ void travel_back_to_lady(ProControllerContext& context){
ssf_press_left_joystick(context, {+1, +1}, 960ms, 960ms);
}

void travel_to_spin_location2(ProControllerContext& context){
ssf_press_left_joystick(context, {+1, -0.126}, 800ms, 2000ms);
ssf_press_left_joystick(context, {+1, -1}, 400ms, 400ms);
}
void travel_back_to_lady2(ProControllerContext& context){
ssf_press_left_joystick(context, {0, -1}, 240ms, 240ms);
ssf_press_left_joystick(context, {+1, -0.126}, 2080ms, 2080ms);
ssf_press_left_joystick(context, {-1, 0}, 400ms, 3200ms);
ssf_mash1_button(context, BUTTON_R, 800ms); // bike boost
ssf_do_nothing(context, 2400ms);
ssf_press_left_joystick(context, {+0.5, +1}, 960ms, 960ms);
ssf_press_left_joystick(context, {+1, +1}, 960ms, 960ms);
}



}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ void move_while_mashing_B (ProControllerContext& context, Milliseconds duratio
void spin_and_mash_A (ProControllerContext& context, Milliseconds duration);
void travel_to_spin_location(ProControllerContext& context);
void travel_back_to_lady (ProControllerContext& context);
void travel_to_spin_location2(ProControllerContext& context);
void travel_back_to_lady2 (ProControllerContext& context);



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/* Box Egg Detector
*
* From: https://github.com/PokemonAutomation/
*
*/


#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/ImageMatch/ImageCropper.h"
#include "CommonTools/ImageMatch/ExactImageMatcher.h"
#include "PokemonSwSh/Resources/PokemonSwSh_PokemonSprites.h"
#include "PokemonSwSh_BoxEggDetector.h"

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

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSwSh{



const ImageMatch::ExactImageMatcher& EGG_MATCHER(){
static ImageMatch::ExactImageMatcher matcher(RESOURCE_PATH() + "PokemonSwSh/EggTemplate.png");
return matcher;
}

BoxEggDetector::BoxEggDetector(SlotLocation side, uint8_t row, double min_euclidean_distance, Color color)
: m_min_euclidean_distance_squared(min_euclidean_distance * min_euclidean_distance)
, m_color(color){
if (side == SlotLocation::PARTY){
if (row > 5){
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "INVALID party row for BoxEggDetector");
}
m_box = ImageFloatBox(0.045414, 0.1255 * row + 0.2401, 0.023882, 0.043856);
}else if (side == SlotLocation::BOX){
if (row > 4){
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "INVALID box row for BoxEggDetector");
}
m_box = ImageFloatBox(0.270241, 0.1255 * row + 0.2401, 0.023882, 0.049);
}else{
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "INVALID SlotLocation for BoxEggDetector");
}
}

void BoxEggDetector::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_box);
}

bool BoxEggDetector::detect(const ImageViewRGB32& screen){

std::vector<ImageViewRGB32> crops = get_crop_candidates(extract_box_reference(screen, m_box));

// int i = 0;
double rmsd_threshold = 80;
for (const ImageViewRGB32& crop : crops){
// crop.save("image" + std::to_string(i) + ".png");
// i++;
double rmsd = EGG_MATCHER().rmsd(crop);
// cout << "RMSD: " << std::to_string(rmsd) << endl;
if (rmsd < rmsd_threshold){
return true;
}
}

return false;
}

auto BoxEggDetector::get_crop_candidates(const ImageViewRGB32& image) const -> std::vector<ImageViewRGB32>{
ImageStats border = image_border_stats(image);
// cout << border.average << border.stddev << endl;
// image.save("image1.png");
ImagePixelBox box = ImageMatch::enclosing_rectangle_with_pixel_filter(
image,
[&](Color pixel){
// if (qAlpha(pixel) == 0){
// return false;
// }
// FloatPixel p(pixel);
// cout << p << endl;
double r = (double)pixel.red() - border.average.r;
double g = (double)pixel.green() - border.average.g;
double b = (double)pixel.blue() - border.average.b;
bool stop = r*r + g*g + b*b >= m_min_euclidean_distance_squared;
if (stop){
// FloatPixel p(pixel);
// cout << p << " : " << r << " " << g << " " << b << endl;
}
return stop;
}
);
std::vector<ImageViewRGB32> ret;
ret.emplace_back(extract_box_reference(image, box));
return ret;
}









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

#ifndef PokemonAutomation_PokemonSwSh_BoxEggDetector_H
#define PokemonAutomation_PokemonSwSh_BoxEggDetector_H

#include <vector>
#include "Common/Cpp/Color.h"
#include "CommonTools/VisualDetector.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSwSh{


enum class SlotLocation{
PARTY, // player's party
BOX, // one of the 5 x 6 slots in the box
};

class BoxEggDetector : public StaticScreenDetector{
public:
BoxEggDetector(SlotLocation side, uint8_t row, double min_euclidean_distance = 100, Color color = COLOR_BLUE);

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

std::vector<ImageViewRGB32> get_crop_candidates(const ImageViewRGB32& image) const;

private:
double m_min_euclidean_distance_squared;
Color m_color;
ImageFloatBox m_box;
};



}
}
}
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/* Box Empty Slot Detector
*
* From: https://github.com/PokemonAutomation/
*
*/


#include "Common/Cpp/Exceptions.h"
#include "CommonFramework/Globals.h"
#include "CommonFramework/ImageTypes/ImageRGB32.h"
#include "CommonFramework/ImageTypes/ImageViewRGB32.h"
#include "CommonFramework/ImageTools/ImageStats.h"
#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h"
#include "CommonTools/ImageMatch/ImageCropper.h"
#include "CommonTools/ImageMatch/ExactImageMatcher.h"
#include "PokemonSwSh/Resources/PokemonSwSh_PokemonSprites.h"
#include "PokemonSwSh_BoxEmptySlotDetector.h"

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

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSwSh{




BoxEmptySlotDetector::BoxEmptySlotDetector(SlotLocation side, uint8_t row, uint8_t column, Color color)
: m_color(color){
if (side == SlotLocation::PARTY){
if (row > 5){
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "INVALID party row for BoxEmptySlotDetector");
}
m_box = ImageFloatBox(0.087527, 0.1255 * row + 0.192607, 0.079869, 0.089494);
}else if (side == SlotLocation::BOX){
if (row > 4 || column > 5){
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "INVALID box row/column for BoxEmptySlotDetector");
}
m_box = ImageFloatBox(0.0705 * column + 0.265, 0.1255 * row + 0.260700, 0.043, 0.023346);
}else{
throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "INVALID SlotLocation for BoxEmptySlotDetector");
}
}

void BoxEmptySlotDetector::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_box);
}

bool BoxEmptySlotDetector::detect(const ImageViewRGB32& screen){
ImageStats stats = image_stats(extract_box_reference(screen, m_box));

const double max_stddev_sum = 50;
const double stddev = stats.stddev.sum();
// cout << "BoxEmptySlotDetector::detect: stddev sum " << stddev << " vs max " << max_stddev_sum << endl;

// if the stddev.sum() is low, it's likely an empty slot
return stddev <= max_stddev_sum;
}






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

#ifndef PokemonAutomation_PokemonSwSh_BoxEmptySlotDetector_H
#define PokemonAutomation_PokemonSwSh_BoxEmptySlotDetector_H

#include "Common/Cpp/Color.h"
#include "CommonTools/VisualDetector.h"
#include "CommonFramework/ImageTools/ImageBoxes.h"
#include "PokemonSwSh_BoxEggDetector.h"
// #include "CommonTools/ImageMatch/ExactImageDictionaryMatcher.h"
// #include "CommonTools/ImageMatch/CroppedImageDictionaryMatcher.h"

namespace PokemonAutomation{
namespace NintendoSwitch{
namespace PokemonSwSh{

// Determine if given slot is empty

class BoxEmptySlotDetector : public StaticScreenDetector{
public:
BoxEmptySlotDetector(SlotLocation side, uint8_t row, uint8_t column, Color color = COLOR_BLUE);

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


private:
Color m_color;
ImageFloatBox m_box;
};



}
}
}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,24 @@ bool BlackDialogBoxDetector::process_frame(const ImageViewRGB32& frame, WallCloc
return detected && m_stop_on_detected;
}

BlackDialogBoxDetector2::BlackDialogBoxDetector2(Color color)
: m_color(color)
, m_bottom(0.184009, 0.945419, 0.554217, 0.021442)
, m_left(0.175246, 0.807018, 0.019715, 0.064327)
, m_right(0.808324, 0.810916, 0.014239, 0.146199)
{}
void BlackDialogBoxDetector2::make_overlays(VideoOverlaySet& items) const{
items.add(m_color, m_bottom);
items.add(m_color, m_left);
items.add(m_color, m_right);
}

bool BlackDialogBoxDetector2::detect(const ImageViewRGB32& screen){
return is_grey(extract_box_reference(screen, m_bottom), 50, 300)
&& is_black(extract_box_reference(screen, m_left), 200, 50)
&& is_black(extract_box_reference(screen, m_right), 200, 50);
}




Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,28 @@ class BlackDialogBoxDetector : public VisualInferenceCallback{
std::atomic<bool> m_detected;
};

// Detect the bigger black dialog box. It is used in places such as egg hatching detection
class BlackDialogBoxDetector2 : public StaticScreenDetector{
public:
BlackDialogBoxDetector2(Color color = COLOR_RED);

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


protected:
Color m_color;
ImageFloatBox m_bottom;
ImageFloatBox m_left;
ImageFloatBox m_right;
};
class BlackDialogBoxWatcher2 : public DetectorToFinder<BlackDialogBoxDetector2>{
public:
BlackDialogBoxWatcher2(Color color = COLOR_RED)
: DetectorToFinder("BlackDialogBoxWatcher2", std::chrono::milliseconds(250), color)
{}
};


class WhiteDialogBoxDetector : public StaticScreenDetector{
public:
Expand Down
Loading
Loading