Skip to content

Commit 1134e03

Browse files
committed
trading and open summary works
1 parent 058d453 commit 1134e03

File tree

2 files changed

+93
-60
lines changed

2 files changed

+93
-60
lines changed

SerialPrograms/Source/PokemonLGPE/Inference/PokemonLGPE_ShinySymbolDetector.cpp

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -13,48 +13,32 @@
1313
#include "CommonTools/Images/ImageFilter.h"
1414
#include "PokemonLGPE_ShinySymbolDetector.h"
1515

16-
//#include <iostream>
17-
//using std::cout;
18-
//using std::endl;
16+
#include <iostream>
17+
using std::cout;
18+
using std::endl;
1919

2020
namespace PokemonAutomation{
2121
namespace NintendoSwitch{
2222
namespace PokemonLGPE{
2323

2424
ShinySymbolDetector::ShinySymbolDetector(Color color)
25-
: m_box_star(0.204, 0.095, 0.033, 0.053)
25+
: m_box_star(0.666, 0.779, 0.028, 0.044)
2626
{}
2727
void ShinySymbolDetector::make_overlays(VideoOverlaySet& items) const{
2828
items.add(COLOR_RED, m_box_star);
2929
}
3030
bool ShinySymbolDetector::read(Logger& logger, const ImageViewRGB32& frame){
31-
const bool replace_color_within_range = true;
32-
33-
//Filter out background
34-
ImageRGB32 filtered_region = filter_rgb32_range(
35-
extract_box_reference(frame, m_box_star),
36-
combine_rgb(138, 97, 221), combine_rgb(200, 181, 239), Color(0), replace_color_within_range
37-
);
38-
ImageStats stats = image_stats(filtered_region);
39-
40-
/*
41-
filtered_region.save("./filtered_only.png");
42-
cout << stats.average.r << endl;
43-
cout << stats.average.g << endl;
44-
cout << stats.average.b << endl;
45-
*/
46-
4731
/*
4832
Shiny:
49-
R: 196.632, G: 196.771, B: 145.863
33+
Add infer box: (0.6660, 0.7790, 0.0280, 0.0440), RGB avg [159, 123, 125] avg sum 408 ratio [0.391, 0.301, 0.308] stddev [74.898, 54.696, 53.354] sum 182.948 crop size (54, 48)
34+
5035
Not shiny:
51-
R: 181.862, G: 180.686, B: 193.999
36+
Add infer box: (0.6660, 0.7790, 0.0280, 0.0440), RGB avg [82, 113, 100] avg sum 295 ratio [0.276, 0.384, 0.340] stddev [15.477, 2.178, 2.648] sum 20.303 crop size (54, 48)
5237
*/
5338

54-
if (stats.average.r + 100 > stats.average.b){
55-
return true;
56-
}
57-
return false;
39+
40+
const auto stats = image_stats(extract_box_reference(frame, m_box_star));
41+
return stats.stddev.sum() > 100;
5842
}
5943

6044

SerialPrograms/Source/PokemonLGPE/Programs/PokemonLGPE_AlolanTrade.cpp

Lines changed: 83 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ std::unique_ptr<StatsTracker> AlolanTrade_Descriptor::make_stats() const{
5959
AlolanTrade::AlolanTrade()
6060
: NUM_TRADES(
6161
"<b>Number of Pokemon to trade:</b>",
62-
LockMode::UNLOCK_WHILE_RUNNING,
63-
30
62+
LockMode::LOCK_WHILE_RUNNING,
63+
30, 1
6464
)
6565
, GO_HOME_WHEN_DONE(false)
6666
, NOTIFICATION_SHINY(
@@ -76,7 +76,7 @@ AlolanTrade::AlolanTrade()
7676
})
7777
{
7878
PA_ADD_OPTION(NUM_TRADES);
79-
//PA_ADD_OPTION(GO_HOME_WHEN_DONE);
79+
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
8080
PA_ADD_OPTION(NOTIFICATIONS);
8181
}
8282

@@ -89,12 +89,13 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
8989
WARNING: JOYCON TEST PROGRAM. Not well tested. Minimum infra to get this running. Bare minimum in general.
9090
Use at your own risk, it won't skip update checks and the like.
9191
FLASH RIGHT JOYCON. YOU NEED RIGHT JOYCON. YOU NEED THE HOME BUTTON. (this means no on-switch screenshots)
92-
Also don't remap any of the buttons in the switch button mapping settings. Yet?
92+
Also don't remap any of the buttons in the switch button mapping settings. Yet? Could use this to add Home and Screenshot.
9393
9494
Preconditions:
9595
DO NOT have any Pokemon you want to keep in your boxes. Move them out to Home first.
9696
Favoriting a Pokemon does not prevent it from being traded.
9797
This must not be your first time doing the trade. (I've done all the trades, can't check first time trade behavior.)
98+
In your boxes, sort by ORDER CAUGHT
9899
99100
Setup:
100101
Catch the Kanto variant of the target.
@@ -111,26 +112,6 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
111112
get rid of all this blindly mashing A in general...so need everything really.
112113
*/
113114

114-
//to check pokemon in menu boxes - not used
115-
//Open menu - always defaults to center (Party)
116-
/* Menu:
117-
Play with Partner
118-
Pokedex - Bag - Party - Communicate - Save
119-
(Press Y for options)
120-
121-
sort boxes by recently caught and press left to get to most recent pokemon
122-
*/
123-
124-
/*
125-
pbf_press_button(context, BUTTON_A, 200ms, 2000ms);
126-
pbf_press_button(context, BUTTON_HOME, 200ms, 2000ms);
127-
pbf_move_joystick(context, 128, 0, 100ms, 100ms);
128-
pbf_move_joystick(context, 128, 0, 100ms, 100ms);
129-
pbf_move_joystick(context, 255, 128, 100ms, 100ms);
130-
pbf_move_joystick(context, 128, 0, 100ms, 100ms);
131-
pbf_press_button(context, BUTTON_X, 200ms, 2000ms);
132-
*/
133-
134115
bool shiny_found = false;
135116
while (!shiny_found) {
136117
//Run trades
@@ -160,7 +141,7 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
160141
}
161142

162143
//Wait for trade to complete.
163-
BlackScreenOverWatcher trade_completed(COLOR_RED);
144+
BlackScreenOverWatcher trade_completed(COLOR_YELLOW);
164145
int ret2 = wait_until(
165146
env.console, context,
166147
std::chrono::seconds(120),
@@ -179,36 +160,104 @@ void AlolanTrade::program(SingleSwitchProgramEnvironment& env, CancellableScope&
179160
env.log("Trade completed.");
180161
}
181162

182-
//After black screen fade is done, a summary will appear.
183-
//pbf_wait(context, 250);
163+
//Summary will appear the first time you trade in a session(?) Close that as well.
164+
//Exit menu and dialog.
165+
pbf_mash_button(context, BUTTON_B, 3000ms);
184166
context.wait_for_all_requests();
185167

168+
stats.trades++;
169+
env.update_stats();
170+
}
171+
172+
//to check pokemon in menu boxes
173+
//Open menu - always defaults to center (Party)
174+
/* Menu:
175+
Play with Partner
176+
Pokedex - Bag - Party - Communicate - Save (these all have a colored line under when selected)
177+
(Press Y for options)
178+
179+
sort boxes by recently caught and press left to get to most recent pokemon
180+
*/
181+
182+
//Wait a bit.
183+
pbf_press_button(context, BUTTON_X, 0ms, 2500ms);
184+
context.wait_for_all_requests();
185+
186+
//Open menu, open party, open boxes
187+
env.log("Opening boxes.");
188+
pbf_press_button(context, BUTTON_X, 200ms, 500ms);
189+
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
190+
pbf_press_button(context, BUTTON_Y, 200ms, 1500ms);
191+
context.wait_for_all_requests();
192+
193+
//Sort by order caught
194+
env.log("Sorting by order caught.");
195+
pbf_press_button(context, BUTTON_Y, 200ms, 1000ms);
196+
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
197+
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
198+
context.wait_for_all_requests();
199+
200+
//Press left to go to last (most recent) Pokemon
201+
env.log("Opening summary of most recent Pokemon.");
202+
pbf_move_joystick(context, 0, 128, 100ms, 100ms);
203+
context.wait_for_all_requests();
204+
205+
//View summary - it takes a moment to load, wait is below
206+
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
207+
pbf_move_joystick(context, 128, 255, 100ms, 100ms);
208+
pbf_move_joystick(context, 128, 255, 100ms, 100ms);
209+
pbf_press_button(context, BUTTON_A, 200ms, 100ms);
210+
context.wait_for_all_requests();
211+
212+
//Wait.
213+
pbf_press_button(context, BUTTON_X, 0ms, 5000ms);
214+
context.wait_for_all_requests();
215+
216+
//Now check for shinies. Check everything that was traded.
217+
for (uint16_t i = 0; i < NUM_TRADES; i++) {
186218
VideoSnapshot screen = env.console.video().snapshot();
187219
ShinySymbolDetector shiny_checker(COLOR_YELLOW);
188-
shiny_found = shiny_checker.read(env.console.logger(), screen);
220+
bool check = shiny_checker.read(env.console.logger(), screen);
189221

190-
if (shiny_found) {
222+
if (check) {
191223
env.log("Shiny detected!");
192224
stats.shinies++;
225+
env.update_stats();
193226
send_program_status_notification(env, NOTIFICATION_SHINY, "Shiny found!", screen, true);
194-
break;
227+
shiny_found = true;
195228
}
196229
else {
197230
env.log("Not shiny.");
198-
stats.trades++;
199231
}
232+
233+
//Move left, check next.
234+
pbf_move_joystick(context, 0, 128, 100ms, 100ms);
235+
pbf_press_button(context, BUTTON_X, 0ms, 2000ms);
236+
context.wait_for_all_requests();
200237
}
201238

202239
if (!shiny_found) {
203-
//Go to home, reset game
204-
//How to handle sideways joycons vs in-game? What if a set is paired?
205-
//Set as-is for now - I only have one ESP32, don't know how we're handling multiple joycons w/our usual home functions
240+
//TODO? Check if home button even exists before attempting to reset.
241+
//This way, if on left joycon, stop the program and alert the user.
206242

207243
env.log("Out of Pokemon to trade. Resetting game.");
208244
send_program_status_notification(
209245
env, NOTIFICATION_STATUS_UPDATE,
210246
"Out of Pokemon to trade. Resetting game."
211247
);
248+
249+
//TODO: Need to make proper GameEntry eventually
250+
//Thankfully, Joycon is upright after going to home.
251+
//Go to home and close game
252+
pbf_press_button(context, BUTTON_HOME, 200ms, 3000ms);
253+
pbf_press_button(context, BUTTON_X, 200ms, 1000ms);
254+
pbf_press_button(context, BUTTON_A, 200ms, 1000ms);
255+
256+
//Enter game from home
257+
//break;
258+
259+
stats.resets++;
260+
env.update_stats();
212261
}
213262
}
214263

0 commit comments

Comments
 (0)