From 79357432d78e2f8f5665d7f50415c519bf92055c Mon Sep 17 00:00:00 2001 From: mos Date: Wed, 13 Nov 2024 13:47:24 +0100 Subject: [PATCH] add constants for agent rewards and penalties --- src/lib.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 868b772..853ed1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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(()) }