change to english ocr

This commit is contained in:
yanweitong 2024-01-05 00:39:17 +08:00
parent 5f846b18c0
commit 972f378389
3 changed files with 75 additions and 19 deletions

View File

@ -128,7 +128,7 @@ pub mod pokemmo_const_value{
#[derive(Debug)]
pub enum PokemmoStatus {
// 遇见闪光
MeetShiny,
MeetTarget,
// 无状态
Free,
// 加载遇怪动画

View File

@ -15,7 +15,7 @@ pub mod pokemmo {
use crate::joystick::joystick::joystick::{move_once_by_mode, MoveMode, quick_press};
use crate::ocr::ocr::ocr::find_string_in_image;
use crate::pokemmo::const_value::pokemmo_const_value::{BUTTON_HL_1, BUTTON_HL_2, BUTTON_HL_3, BUTTON_HL_4, GROUP_5_1, GROUP_5_2, GROUP_5_3, GROUP_5_4, GROUP_5_5, LAST_TEXT_AREA, LOGO, PokemmoStatus, SINGLE_BATTLE, TEMP_BATTLE_TEXT_AREA, TEXT_AREA};
use crate::pokemmo::const_value::pokemmo_const_value::PokemmoStatus::{Free, InBattle, LoadBattle, MeetShiny, Running};
use crate::pokemmo::const_value::pokemmo_const_value::PokemmoStatus::{Free, InBattle, LoadBattle, MeetTarget, Running};
use crate::screen::screen::screen::{Area, screen_shot};
// 单遇闪光
@ -28,7 +28,7 @@ pub mod pokemmo {
loop {
trace!("当前状态:{:?}",status);
match status {
PokemmoStatus::MeetShiny => {
PokemmoStatus::MeetTarget => {
return;
}
PokemmoStatus::Free => {
@ -37,13 +37,13 @@ pub mod pokemmo {
move_index = move_index + 1;
let text = get_last_string();
trace!("查询战斗文字 : {}",text);
if text.contains("野生") || text.contains("派出") {
if text.contains("wild") || text.contains("sent") {
info!("遇怪:{}.",text);
meet_pokemmo = text.clone();
status = LoadBattle;
}else {
let temp_battle = read_area(TEMP_BATTLE_TEXT_AREA);
if temp_battle.contains("战斗") || temp_battle.contains("逃跑"){
if temp_battle.contains("fight") || temp_battle.contains("run"){
status = LoadBattle;
}
}
@ -64,20 +64,20 @@ pub mod pokemmo {
PokemmoStatus::InBattle => {
trace!("检查遇怪种类..");
let text = get_text_list();
let filter_text: Vec<String> = text.into_iter().filter(|x| x.contains("野生")).collect();
let filter_text: Vec<String> = text.into_iter().filter(|x| x.contains("wild")).collect();
if filter_text.is_empty() {
error!("遇怪错误!");
return;
}
let filter_size = filter_text.len();
let pokemon_text = filter_text[filter_size - 1].clone();
if pokemon_text.contains("怪群") {
if pokemon_text.contains("horde") {
info!("遇见怪群");
let five_names = read_group_5();
for name in five_names {
for key_word in key_words {
if name.contains(key_word) {
status = MeetShiny;
status = MeetTarget;
return;
}
}
@ -88,7 +88,7 @@ pub mod pokemmo {
for key_word in key_words {
if name.contains(key_word) || meet_pokemmo.contains(key_word) {
info!("遇见{}",key_word);
status = MeetShiny;
status = MeetTarget;
return;
}
}
@ -117,7 +117,7 @@ pub mod pokemmo {
let mut last_word = get_last_string();
// 读取十次后默认成功
let mut times = 0_usize;
while !last_word.contains("成功")
while !last_word.contains("escaped")
&& !last_word.contains("中逃跑")
&& !last_word.contains("不能跑")
&& times < 10{
@ -126,7 +126,7 @@ pub mod pokemmo {
thread::sleep(Duration::from_millis(200));
times = times + 1;
}
if last_word.contains("成功") || last_word.contains("逃跑") {
if last_word.contains("escaped") || last_word.contains("safely") {
trace!("逃跑成功.");
status = Free;
} else {
@ -175,7 +175,7 @@ pub mod pokemmo {
let image_width = image.width();
let image_height = image.height();
let dy_image = DynamicImage::from(RgbaImage::from_vec(image_width, image_height, image_data).unwrap());
let text = find_string_in_image(&dy_image, psm);
let text = find_string_in_image(&dy_image, psm).to_lowercase();
return text;
}

View File

@ -11,13 +11,15 @@ mod tests {
#[test]
fn try_meet_shiny(){
simple_logging::log_to_file("./test/log/meet_shiny.log",LevelFilter::Info).expect("set log failed");
simple_logging::log_to_file("./test/log/meet_shiny2.log",LevelFilter::Info).expect("set log failed");
let key_words = vec![
"".to_string(),
"".to_string(),
"".to_string(),
"".to_string(),
"shiny".to_string(),
// 闪电鸟
"zapdos".to_string(),
"zap".to_string(),
"pdos".to_string(),
];
single_meet_shiny(&key_words);
@ -26,7 +28,7 @@ mod tests {
#[test]
fn print_shortcut() {
let text = screen_shot(Some(TEMP_BATTLE_TEXT_AREA));
let text = screen_shot(Some(TEXT_AREA));
print_image(text, "temp_battle_text".to_string());
}
@ -58,10 +60,15 @@ mod tests {
}
#[test]
fn find_text() {
let text = screen_shot(Some(TEMP_BATTLE_TEXT_AREA));
print_image(text, "51".to_string());
let text = read_area(TEMP_BATTLE_TEXT_AREA);
println!("text in image: {}",text);
}
@ -94,4 +101,53 @@ mod tests {
}
println!("dis = {}",dis);
}
}
#[test]
fn cal_win_influence(){
let list = vec![
("巨钳螳螂",0.4848_f32,0.5072_f32),
("烈咬陆鲨",0.3482_f32,0.5126_f32),
("快龙",0.3227_f32,0.5178_f32),
("宝石海星",0.2184_f32,0.5239_f32),
("清洗洛托姆",0.2181_f32,0.5174_f32),
("火神蛾",0.1276_f32,0.4852_f32),
];
for (name, usage, win) in list{
let win_rate = win - 0.5_f32;
let influence = ((win_rate * (usage * usage + 2_f32 * usage + (1_f32 - usage))) - usage * usage ) / (2_f32 * usage * (1_f32 - usage));
println!("{}, win rate {}, influence {}", name, win_rate, influence);
}
}
}