154 lines
4.2 KiB
Rust
154 lines
4.2 KiB
Rust
#[cfg(test)]
|
|
mod tests {
|
|
use std::thread::sleep;
|
|
use std::time::Duration;
|
|
use image::io::Reader as ImageReader;
|
|
use log::LevelFilter;
|
|
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, MAP_CITY, SHORTCUT_KEY_1, SHORTCUT_KEY_5, SINGLE_BATTLE, TEMP_BATTLE_TEXT_AREA, TEXT_AREA};
|
|
use crate::pokemmo::pokemmo::pokemmo::{check_screen_active, get_choose_btn, get_last_string, read_area, read_group_5, single_meet_shiny};
|
|
use crate::screen::screen::screen::{print_image, screen_shot};
|
|
|
|
|
|
#[test]
|
|
fn try_meet_shiny(){
|
|
simple_logging::log_to_file("./test/log/meet_shiny2.log",LevelFilter::Info).expect("set log failed");
|
|
|
|
let key_words = vec![
|
|
"shiny".to_string(),
|
|
// 闪电鸟
|
|
"zapdos".to_string(),
|
|
"zap".to_string(),
|
|
"pdos".to_string(),
|
|
|
|
];
|
|
single_meet_shiny(&key_words);
|
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
fn print_shortcut() {
|
|
let text = screen_shot(Some(TEXT_AREA));
|
|
print_image(text, "temp_battle_text".to_string());
|
|
}
|
|
|
|
#[test]
|
|
fn print_group_5() {
|
|
let group_5_1 = screen_shot(Some(GROUP_5_1));
|
|
print_image(group_5_1, "group_5_1".to_string());
|
|
let group_5_2 = screen_shot(Some(GROUP_5_2));
|
|
print_image(group_5_2, "group_5_2".to_string());
|
|
let group_5_3 = screen_shot(Some(GROUP_5_3));
|
|
print_image(group_5_3, "group_5_3".to_string());
|
|
let group_5_4 = screen_shot(Some(GROUP_5_4));
|
|
print_image(group_5_4, "group_5_4".to_string());
|
|
let group_5_5 = screen_shot(Some(GROUP_5_5));
|
|
print_image(group_5_5, "group_5_5".to_string());
|
|
}
|
|
|
|
#[test]
|
|
fn print_button() {
|
|
let btn_hl_1 = screen_shot(Some(BUTTON_HL_1));
|
|
print_image(btn_hl_1, "btn_hl_1".to_string());
|
|
let btn_hl_2 = screen_shot(Some(BUTTON_HL_2));
|
|
print_image(btn_hl_2, "btn_hl_2".to_string());
|
|
let btn_hl_3 = screen_shot(Some(BUTTON_HL_3));
|
|
print_image(btn_hl_3, "btn_hl_3".to_string());
|
|
let btn_hl_4 = screen_shot(Some(BUTTON_HL_4));
|
|
print_image(btn_hl_4, "btn_hl_4".to_string());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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);
|
|
|
|
}
|
|
|
|
|
|
#[test]
|
|
fn get_active_btn() {
|
|
let index_op = get_choose_btn();
|
|
if index_op.is_some(){
|
|
println!("激活索引:{}",index_op.unwrap());
|
|
}else {
|
|
println!("无激活索引");
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
fn compare_logo() {
|
|
let active_logo = ImageReader::open("./resources/pokemmo/image/logo_active.png").expect("read active logo image failed").decode().expect("decode image failed");
|
|
let active_logo_data = active_logo.as_bytes().to_vec();
|
|
|
|
let na_logo = ImageReader::open("./resources/pokemmo/image/logo_unactive.png").expect("read active logo image failed").decode().expect("decode image failed");
|
|
let na_logo_data = na_logo.as_bytes().to_vec();
|
|
|
|
let size = active_logo_data.len();
|
|
|
|
let mut dis = 0_isize;
|
|
for i in 0 .. size{
|
|
dis += na_logo_data[i.clone()].clone() as isize - active_logo_data[i.clone()].clone() as isize;
|
|
}
|
|
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);
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|