Skip to content

Commit

Permalink
Add stats reader for summaries.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mysticial committed Oct 1, 2023
1 parent 876c475 commit 5ba5f68
Show file tree
Hide file tree
Showing 13 changed files with 817 additions and 127 deletions.
2 changes: 2 additions & 0 deletions SerialPrograms/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,8 @@ file(GLOB MAIN_SOURCES
Source/PokemonSV/Inference/PokemonSV_WhiteButtonDetector.h
Source/PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.cpp
Source/PokemonSV/Inference/PokemonSV_ZeroGateWarpPromptDetector.h
Source/PokemonSV/Inference/PokemonSV_StatHexagonReader.cpp
Source/PokemonSV/Inference/PokemonSV_StatHexagonReader.h
Source/PokemonSV/Inference/Tera/PokemonSV_TeraCardDetector.cpp
Source/PokemonSV/Inference/Tera/PokemonSV_TeraCardDetector.h
Source/PokemonSV/Inference/Tera/PokemonSV_TeraCodeReader.cpp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <map>
#include "CommonFramework/Language.h"
#include "CommonFramework/Logging/Logger.h"
#include "OCR_RawOCR.h"
#include "OCR_NumberReader.h"

Expand Down
3 changes: 1 addition & 2 deletions SerialPrograms/Source/CommonFramework/OCR/OCR_NumberReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@
#ifndef PokemonAutomation_OCR_NumberReader_H
#define PokemonAutomation_OCR_NumberReader_H

#include "CommonFramework/Logging/Logger.h"

namespace PokemonAutomation{
class Logger;
class ImageViewRGB32;
namespace OCR{

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco
// using namespace NintendoSwitch::PokemonSwSh::MaxLairInternal;


#if 0
uint8_t low_iv;
uint8_t high_iv;

Expand All @@ -247,7 +248,7 @@ void TestProgramComputer::program(ProgramEnvironment& env, CancellableScope& sco
cout << "ok = " << ok << endl;
cout << "low = " << (int)low_iv << endl;
cout << "high = " << (int)high_iv << endl;

#endif



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
#include "PokemonSV/Inference/PokemonSV_BagDetector.h"
#include <filesystem>
#include "PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_Lobby.h"
#include "PokemonSV/Inference/PokemonSV_StatHexagonReader.h"



Expand Down Expand Up @@ -236,12 +237,74 @@ void TestProgram::program(MultiSwitchProgramEnvironment& env, CancellableScope&
VideoOverlaySet overlays(overlay);


SummaryStatsReader reader;
reader.make_overlays(overlays);

auto snapshot = console.video().snapshot();

#if 1
NatureAdjustments nature = reader.read_nature(logger, snapshot);
cout << "attack = " << (int)nature.attack << endl;
cout << "defense = " << (int)nature.defense << endl;
cout << "spatk = " << (int)nature.spatk << endl;
cout << "spdef = " << (int)nature.spdef << endl;
cout << "speed = " << (int)nature.speed << endl;

StatReads stats = reader.read_stats(logger, snapshot);
cout << "hp = " << stats.hp << endl;
cout << "attack = " << stats.attack << endl;
cout << "defense = " << stats.defense << endl;
cout << "spatk = " << stats.spatk << endl;
cout << "spdef = " << stats.spdef << endl;
cout << "speed = " << stats.speed << endl;

BaseStats base_stats{68, 65, 65, 125, 115, 80};
EVs evs{252, 0, 6, 252, 0, 0};
IvRanges ivs = reader.calc_ivs(logger, snapshot, base_stats, evs);
cout << "hp = " << (int)ivs.hp.low << " - " << (int)ivs.hp.high << endl;
cout << "attack = " << (int)ivs.attack.low << " - " << (int)ivs.attack.high << endl;
cout << "defense = " << (int)ivs.defense.low << " - " << (int)ivs.defense.high << endl;
cout << "spatk = " << (int)ivs.spatk.low << " - " << (int)ivs.spatk.high << endl;
cout << "spdef = " << (int)ivs.spdef.low << " - " << (int)ivs.spdef.high << endl;
cout << "speed = " << (int)ivs.speed.low << " - " << (int)ivs.speed.high << endl;
#endif


#if 0
cout << "attack: ";
reader.read_stat_adjustment({0.874, 0.293, 0.014, 0.024}, snapshot);
cout << "spatk: ";
reader.read_stat_adjustment({0.770, 0.293, 0.014, 0.024}, snapshot);
cout << "speed: ";
reader.read_stat_adjustment({0.822, 0.452, 0.014, 0.024}, snapshot);
#endif


#if 0
ImageFloatBox hp (0.823, 0.244, 0.012, 0.022);
ImageFloatBox atk (0.875, 0.294, 0.012, 0.022);
ImageFloatBox def (0.875, 0.402, 0.012, 0.022);
ImageFloatBox spatk (0.771, 0.294, 0.012, 0.022);
ImageFloatBox spdef (0.771, 0.402, 0.012, 0.022);
ImageFloatBox spd (0.823, 0.453, 0.012, 0.022);

overlays.add(COLOR_RED, hp);
overlays.add(COLOR_RED, atk);
overlays.add(COLOR_RED, def);
overlays.add(COLOR_RED, spatk);
overlays.add(COLOR_RED, spdef);
overlays.add(COLOR_RED, spd);
#endif



#if 0
PokemonSwSh::MaxLairInternal::LobbyJoinedDetector detector(2, false);

auto snapshot = console.video().snapshot();
// detector.VisualInferenceCallback::process_frame(snapshot);
detector.joined(snapshot, snapshot.timestamp);

#endif

// size_t errors = 0;
// attach_item_from_bag(env.program_info(), console, context, errors);
Expand Down
179 changes: 95 additions & 84 deletions SerialPrograms/Source/Pokemon/Pokemon_NatureChecker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,108 +5,119 @@
*/

#include <map>
#include "Common/Cpp/Exceptions.h"
#include "Pokemon_NatureChecker.h"

namespace PokemonAutomation{
namespace Pokemon{

const std::map<std::string, NatureCheckerValue> NatureCheckerValue_TOKEN_TO_ENUM{
{"Adamant", NatureCheckerValue::Adamant},
{"Bashful", NatureCheckerValue::Bashful},
{"Bold", NatureCheckerValue::Bold},
{"Brave", NatureCheckerValue::Brave},
{"Calm", NatureCheckerValue::Calm},
{"Careful", NatureCheckerValue::Careful},
{"Docile", NatureCheckerValue::Docile},
{"Gentle", NatureCheckerValue::Gentle},
{"Hardy", NatureCheckerValue::Hardy},
{"Hasty", NatureCheckerValue::Hasty},
{"Impish", NatureCheckerValue::Impish},
{"Jolly", NatureCheckerValue::Jolly},
{"Lax", NatureCheckerValue::Lax},
{"Lonely", NatureCheckerValue::Lonely},
{"Mild", NatureCheckerValue::Mild},
{"Modest", NatureCheckerValue::Modest},
{"Naive", NatureCheckerValue::Naive},
{"Naughty", NatureCheckerValue::Naughty},
{"Quiet", NatureCheckerValue::Quiet},
{"Quirky", NatureCheckerValue::Quirky},
{"Rash", NatureCheckerValue::Rash},
{"Relaxed", NatureCheckerValue::Relaxed},
{"Sassy", NatureCheckerValue::Sassy},
{"Serious", NatureCheckerValue::Serious},
{"Timid", NatureCheckerValue::Timid},
};
const std::map<NatureCheckerValue, std::string> NatureCheckerValue_ENUM_TO_TOKEN{
{NatureCheckerValue::UnableToDetect, "Unable to Detect"},
{NatureCheckerValue::Neutral, "Neutral"},
{NatureCheckerValue::Adamant, "Adamant"},
{NatureCheckerValue::Bashful, "Bashful"},
{NatureCheckerValue::Bold, "Bold"},
{NatureCheckerValue::Brave, "Brave"},
{NatureCheckerValue::Calm, "Calm"},
{NatureCheckerValue::Careful, "Careful"},
{NatureCheckerValue::Gentle, "Gentle"},
{NatureCheckerValue::Hardy, "Hardy"},
{NatureCheckerValue::Hasty, "Hasty"},
{NatureCheckerValue::Impish, "Impish"},
{NatureCheckerValue::Jolly, "Jolly"},
{NatureCheckerValue::Lax, "Lax"},
{NatureCheckerValue::Lonely, "Lonely"},
{NatureCheckerValue::Mild, "Mild"},
{NatureCheckerValue::Modest, "Modest"},
{NatureCheckerValue::Naive, "Naive"},
{NatureCheckerValue::Naughty, "Naughty"},
{NatureCheckerValue::Quiet, "Quiet"},
{NatureCheckerValue::Quirky, "Quirky"},
{NatureCheckerValue::Rash, "Rash"},
{NatureCheckerValue::Relaxed, "Relaxed"},
{NatureCheckerValue::Sassy, "Sassy"},
{NatureCheckerValue::Serious, "Serious"},
{NatureCheckerValue::Timid, "Timid"},
};

const std::map<std::pair<int, int>, NatureCheckerValue> NatureCheckerValue_HELPHINDER_TO_ENUM{
{{ 0, 2 }, NatureCheckerValue::Adamant},
{{ -1, -1 }, NatureCheckerValue::Neutral}, //Bashful, Docile, Hardy, Quirky, Serious
{{ 1, 0 }, NatureCheckerValue::Bold},
{{ 0, 4 }, NatureCheckerValue::Brave},
{{ 3, 0 }, NatureCheckerValue::Calm},
{{ 3, 2 }, NatureCheckerValue::Careful},
{{ 3, 1 }, NatureCheckerValue::Gentle},
{{ 4, 1 }, NatureCheckerValue::Hasty},
{{ 1, 2 }, NatureCheckerValue::Impish},
{{ 4, 2 }, NatureCheckerValue::Jolly},
{{ 1, 3 }, NatureCheckerValue::Lax},
{{ 0, 1 }, NatureCheckerValue::Lonely},
{{ 2, 1 }, NatureCheckerValue::Mild},
{{ 2, 0 }, NatureCheckerValue::Modest},
{{ 4, 3 }, NatureCheckerValue::Naive},
{{ 0, 3 }, NatureCheckerValue::Naughty},
{{ 2, 4 }, NatureCheckerValue::Quiet},
{{ 2, 3 }, NatureCheckerValue::Rash},
{{ 1, 4 }, NatureCheckerValue::Relaxed},
{{ 3, 4 }, NatureCheckerValue::Sassy},
{{ 4, 0 }, NatureCheckerValue::Timid},
};
const std::map<std::string, NatureCheckerValue>& NatureCheckerValue_TOKEN_TO_ENUM(){
static std::map<std::string, NatureCheckerValue> data{
{"Adamant", NatureCheckerValue::Adamant},
{"Bashful", NatureCheckerValue::Bashful},
{"Bold", NatureCheckerValue::Bold},
{"Brave", NatureCheckerValue::Brave},
{"Calm", NatureCheckerValue::Calm},
{"Careful", NatureCheckerValue::Careful},
{"Docile", NatureCheckerValue::Docile},
{"Gentle", NatureCheckerValue::Gentle},
{"Hardy", NatureCheckerValue::Hardy},
{"Hasty", NatureCheckerValue::Hasty},
{"Impish", NatureCheckerValue::Impish},
{"Jolly", NatureCheckerValue::Jolly},
{"Lax", NatureCheckerValue::Lax},
{"Lonely", NatureCheckerValue::Lonely},
{"Mild", NatureCheckerValue::Mild},
{"Modest", NatureCheckerValue::Modest},
{"Naive", NatureCheckerValue::Naive},
{"Naughty", NatureCheckerValue::Naughty},
{"Quiet", NatureCheckerValue::Quiet},
{"Quirky", NatureCheckerValue::Quirky},
{"Rash", NatureCheckerValue::Rash},
{"Relaxed", NatureCheckerValue::Relaxed},
{"Sassy", NatureCheckerValue::Sassy},
{"Serious", NatureCheckerValue::Serious},
{"Timid", NatureCheckerValue::Timid},
};
return data;
}
const std::map<NatureCheckerValue, std::string>& NatureCheckerValue_ENUM_TO_TOKEN(){
static std::map<NatureCheckerValue, std::string> data{
{NatureCheckerValue::UnableToDetect, "Unable to Detect"},
{NatureCheckerValue::Neutral, "Neutral"},
{NatureCheckerValue::Adamant, "Adamant"},
{NatureCheckerValue::Bashful, "Bashful"},
{NatureCheckerValue::Bold, "Bold"},
{NatureCheckerValue::Brave, "Brave"},
{NatureCheckerValue::Calm, "Calm"},
{NatureCheckerValue::Careful, "Careful"},
{NatureCheckerValue::Gentle, "Gentle"},
{NatureCheckerValue::Hardy, "Hardy"},
{NatureCheckerValue::Hasty, "Hasty"},
{NatureCheckerValue::Impish, "Impish"},
{NatureCheckerValue::Jolly, "Jolly"},
{NatureCheckerValue::Lax, "Lax"},
{NatureCheckerValue::Lonely, "Lonely"},
{NatureCheckerValue::Mild, "Mild"},
{NatureCheckerValue::Modest, "Modest"},
{NatureCheckerValue::Naive, "Naive"},
{NatureCheckerValue::Naughty, "Naughty"},
{NatureCheckerValue::Quiet, "Quiet"},
{NatureCheckerValue::Quirky, "Quirky"},
{NatureCheckerValue::Rash, "Rash"},
{NatureCheckerValue::Relaxed, "Relaxed"},
{NatureCheckerValue::Sassy, "Sassy"},
{NatureCheckerValue::Serious, "Serious"},
{NatureCheckerValue::Timid, "Timid"},
};
return data;
}
const std::map<std::pair<int, int>, NatureCheckerValue>& NatureCheckerValue_HELPHINDER_TO_ENUM(){
static std::map<std::pair<int, int>, NatureCheckerValue> data{
{{ 0, 2 }, NatureCheckerValue::Adamant},
{{ -1, -1 }, NatureCheckerValue::Neutral}, //Bashful, Docile, Hardy, Quirky, Serious
{{ 1, 0 }, NatureCheckerValue::Bold},
{{ 0, 4 }, NatureCheckerValue::Brave},
{{ 3, 0 }, NatureCheckerValue::Calm},
{{ 3, 2 }, NatureCheckerValue::Careful},
{{ 3, 1 }, NatureCheckerValue::Gentle},
{{ 4, 1 }, NatureCheckerValue::Hasty},
{{ 1, 2 }, NatureCheckerValue::Impish},
{{ 4, 2 }, NatureCheckerValue::Jolly},
{{ 1, 3 }, NatureCheckerValue::Lax},
{{ 0, 1 }, NatureCheckerValue::Lonely},
{{ 2, 1 }, NatureCheckerValue::Mild},
{{ 2, 0 }, NatureCheckerValue::Modest},
{{ 4, 3 }, NatureCheckerValue::Naive},
{{ 0, 3 }, NatureCheckerValue::Naughty},
{{ 2, 4 }, NatureCheckerValue::Quiet},
{{ 2, 3 }, NatureCheckerValue::Rash},
{{ 1, 4 }, NatureCheckerValue::Relaxed},
{{ 3, 4 }, NatureCheckerValue::Sassy},
{{ 4, 0 }, NatureCheckerValue::Timid},
};
return data;
}

NatureCheckerValue NatureCheckerValue_string_to_enum(const std::string& token){
auto iter = NatureCheckerValue_TOKEN_TO_ENUM.find(token);
if (iter == NatureCheckerValue_TOKEN_TO_ENUM.end()){
auto iter = NatureCheckerValue_TOKEN_TO_ENUM().find(token);
if (iter == NatureCheckerValue_TOKEN_TO_ENUM().end()){
return NatureCheckerValue::UnableToDetect;
}
return iter->second;
}

NatureCheckerValue NatureCheckerValue_helphinder_to_enum(const std::pair<int,int>& token) {
auto iter = NatureCheckerValue_HELPHINDER_TO_ENUM.find(token);
if (iter == NatureCheckerValue_HELPHINDER_TO_ENUM.end()) {
auto iter = NatureCheckerValue_HELPHINDER_TO_ENUM().find(token);
if (iter == NatureCheckerValue_HELPHINDER_TO_ENUM().end()) {
return NatureCheckerValue::UnableToDetect;
}
return iter->second;
}





const EnumDatabase<NatureCheckerValue>& NatureCheckerValue_Database(){
static EnumDatabase<NatureCheckerValue> database({
{NatureCheckerValue::Adamant, "adamant", "Adamant"},
Expand Down
Loading

0 comments on commit 5ba5f68

Please sign in to comment.