add constants for agent rewards and penalties

This commit is contained in:
mos 2024-11-13 13:47:24 +01:00
parent f226635edd
commit 79357432d7
1 changed files with 13 additions and 6 deletions

View File

@ -343,6 +343,13 @@ struct Agent {
}
impl Agent {
const WIN_REWARD: f32 = 100000.0;
const BOX_REWARD: f32 = 0.00021;
const COL_PENALTY: f32 = 0.00080;
const LOSS_PENALTY: f32 = 0.0032;
const INACTIVE_PENALTY: f32 = 0.0010;
const BOX_DIFF: f32 = 1024.0;
const DIR_TABLE: &'static [Direction] =
&[Direction::U, Direction::D, Direction::L, Direction::R];
@ -390,11 +397,11 @@ impl Agent {
let (mb, hit) = self.state.move_dir(self.dna[self.dir])?;
if mb {
self.score += 0.00021;
self.score += Self::BOX_REWARD;
}
if hit {
self.score -= 0.00080;
self.score -= Self::COL_PENALTY;
}
self.dir += 1;
@ -409,23 +416,23 @@ impl Agent {
match self.move_dna()? {
Solution::Ok => (),
Solution::Win => {
self.score += 100000.0;
self.score += Self::WIN_REWARD;
self.goal = Solution::Win;
break;
}
Solution::None => {
self.score -= 0.0032;
self.score -= Self::LOSS_PENALTY;
self.goal = Solution::None;
break;
}
}
if player == self.state.lvl.player {
self.score -= 0.0010;
self.score -= Self::INACTIVE_PENALTY;
}
}
self.score -= 1024.0 + self.state.dist_boxes() as f32;
self.score -= Self::BOX_DIFF + self.state.dist_boxes() as f32;
Ok(())
}