transfer to deploy server

This commit is contained in:
Eason
2024-04-25 17:08:40 +08:00
parent 96d458597e
commit 1a777943ff
17 changed files with 2093 additions and 0 deletions

35
pyr/src/data/config.rs Normal file
View File

@ -0,0 +1,35 @@
use serde::{Deserialize, Serialize};
lazy_static::lazy_static! {
pub static ref CONFIG: Config = {
match std::fs::read_to_string("config.toml"){
Ok(content)=>toml::from_str(&content).unwrap(),
Err(_)=>Config::default()
}
};
}
#[derive(Serialize, Deserialize)]
pub struct Config {
pub exploration_rate: u32,
pub update_frequency: usize,
pub batch_size: usize,
pub replay_size: usize,
pub learning_rate: f64,
pub gamma: f64,
pub train: bool,
}
impl Default for Config {
fn default() -> Self {
Self {
exploration_rate: 1024,
update_frequency: 150,
batch_size: 32,
replay_size: 250,
learning_rate: 0.04,
gamma: 0.99,
train: true,
}
}
}

37
pyr/src/data/internal.rs Normal file
View File

@ -0,0 +1,37 @@
#[derive(Clone)]
pub struct Player {
pub x: f32,
pub y: f32,
pub height: f32,
pub width: f32,
pub level: f32,
pub velocity: f32,
pub score: f32,
}
#[derive(Clone)]
pub struct Opponent {
pub x: f32,
pub y: f32,
pub level: f32,
}
#[derive(Clone, Debug)]
pub struct Food {
pub x: f32,
pub y: f32,
pub width: f32,
pub height: f32,
pub score: f32,
}
impl Default for Food {
fn default() -> Self {
Food {
x: 1000000.0,
y: 1000000.0,
width: 1.0,
height: 1.0,
score: 0.0,
}
}
}

13
pyr/src/data/mod.rs Normal file
View File

@ -0,0 +1,13 @@
mod config;
mod internal;
mod raw;
pub mod parser {
pub use super::config::CONFIG;
pub use super::raw::*;
}
pub mod prelude {
pub use super::internal::*;
pub use super::raw::Direction;
}

82
pyr/src/data/raw.rs Normal file
View File

@ -0,0 +1,82 @@
use super::internal::*;
#[repr(C)]
#[derive(Debug)]
pub struct RawOverall {
pub frame: u64,
score: i64,
score_to_pass: i64,
self_x: i64,
self_y: i64,
self_h: i64,
self_w: i64,
self_vel: i64,
self_lv: i64,
opponent_x: i64,
opponent_y: i64,
opponent_lv: i64,
}
impl RawOverall {
pub fn get_player(&self) -> Player {
Player {
x: (self.self_x - 350) as f32,
y: (self.self_y - 350) as f32,
height: self.self_h as f32,
width: self.self_w as f32,
level: self.self_lv as f32,
velocity: self.self_vel as f32,
score: self.score as f32,
}
}
pub fn get_opponent(&self) -> Opponent {
Opponent {
x: (self.opponent_x - 350) as f32,
y: (self.opponent_y - 350) as f32,
level: self.opponent_lv as f32,
}
}
}
#[repr(C)]
#[derive(Debug, Clone)]
pub struct RawFood {
pub h: i64,
pub w: i64,
pub x: i64,
pub y: i64,
pub score: i64,
pub kind: i32,
}
impl From<RawFood> for Food {
fn from(value: RawFood) -> Self {
Food {
x: value.x as f32,
y: value.y as f32,
width: value.w as f32,
height: value.h as f32,
score: value.score as f32,
}
}
}
#[repr(i32)]
#[derive(Debug)]
pub enum FoodKind {
Food1 = 1,
Food2 = 2,
Food3 = 3,
Garbage1 = 4,
Garbage2 = 5,
Garbage3 = 6,
}
#[repr(i32)]
pub enum Direction {
Up = 1,
Down = 2,
Left = 3,
Right = 4,
None = 5,
}