use action space
This commit is contained in:
parent
d8b781011b
commit
1a301178f8
|
@ -4,12 +4,13 @@ use std::{
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::dataset::TankItem;
|
use super::dataset::TankItem;
|
||||||
|
use super::feature::ACTION_SPACE;
|
||||||
use crate::{ffi::prelude::*, Backend};
|
use crate::{ffi::prelude::*, Backend};
|
||||||
use burn::{backend::wgpu::WgpuDevice, module::Module, record::NoStdTrainingRecorder};
|
use burn::{backend::wgpu::WgpuDevice, module::Module, record::NoStdTrainingRecorder};
|
||||||
use rand::{thread_rng, Rng};
|
use rand::{thread_rng, Rng};
|
||||||
|
|
||||||
use super::model::{DQNModel, DQNModelConfig};
|
use super::model::{DQNModel, DQNModelConfig};
|
||||||
const EXPLORE_RATE: f32 = 0.4;
|
const EXPLORE_RATE: f32 = 0.2;
|
||||||
|
|
||||||
pub struct App<'a> {
|
pub struct App<'a> {
|
||||||
model: DQNModel<Backend>,
|
model: DQNModel<Backend>,
|
||||||
|
@ -64,7 +65,7 @@ impl<'a> App<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
let action = match thread_rng().gen_ratio((4096.0 * EXPLORE_RATE) as u32, 4096) {
|
let action = match thread_rng().gen_ratio((4096.0 * EXPLORE_RATE) as u32, 4096) {
|
||||||
true => match thread_rng().gen_range(0..15 as i32) {
|
true => match thread_rng().gen_range(0..ACTION_SPACE as i32) {
|
||||||
0 => Action::Forward,
|
0 => Action::Forward,
|
||||||
1 => Action::Backward,
|
1 => Action::Backward,
|
||||||
2 => Action::TurnRight,
|
2 => Action::TurnRight,
|
||||||
|
@ -72,8 +73,7 @@ impl<'a> App<'a> {
|
||||||
4 => Action::AimRight,
|
4 => Action::AimRight,
|
||||||
5 => Action::AimLeft,
|
5 => Action::AimLeft,
|
||||||
6 => Action::Shoot,
|
6 => Action::Shoot,
|
||||||
7 => Action::TurnRight,
|
_ => unreachable!("Invalid action"),
|
||||||
_ => Action::Forward,
|
|
||||||
},
|
},
|
||||||
false => self.predict_action(state),
|
false => self.predict_action(state),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue