add constants for agent rewards and penalties
This commit is contained in:
parent
f226635edd
commit
79357432d7
19
src/lib.rs
19
src/lib.rs
|
@ -343,6 +343,13 @@ struct Agent {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl 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] =
|
const DIR_TABLE: &'static [Direction] =
|
||||||
&[Direction::U, Direction::D, Direction::L, Direction::R];
|
&[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])?;
|
let (mb, hit) = self.state.move_dir(self.dna[self.dir])?;
|
||||||
|
|
||||||
if mb {
|
if mb {
|
||||||
self.score += 0.00021;
|
self.score += Self::BOX_REWARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
if hit {
|
if hit {
|
||||||
self.score -= 0.00080;
|
self.score -= Self::COL_PENALTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.dir += 1;
|
self.dir += 1;
|
||||||
|
@ -409,23 +416,23 @@ impl Agent {
|
||||||
match self.move_dna()? {
|
match self.move_dna()? {
|
||||||
Solution::Ok => (),
|
Solution::Ok => (),
|
||||||
Solution::Win => {
|
Solution::Win => {
|
||||||
self.score += 100000.0;
|
self.score += Self::WIN_REWARD;
|
||||||
self.goal = Solution::Win;
|
self.goal = Solution::Win;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
Solution::None => {
|
Solution::None => {
|
||||||
self.score -= 0.0032;
|
self.score -= Self::LOSS_PENALTY;
|
||||||
self.goal = Solution::None;
|
self.goal = Solution::None;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if player == self.state.lvl.player {
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue