diff --git a/src/lib.rs b/src/lib.rs index 843a046..13e123f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,8 @@ pub enum Error { BadMove(Pos), } +type Result = std::result::Result; + #[derive(PartialEq, Copy, Clone)] enum Direction { U, @@ -129,7 +131,7 @@ impl std::fmt::Display for Level { } impl Level { - fn read(file: R) -> Result { + fn read(file: R) -> std::result::Result { let (mut player, mut size) = (Pos::default(), Pos::default()); let map = file @@ -155,13 +157,13 @@ impl Level { '.' => Ok(Cell::None), _ => Err(ReadError::BadSymbol), }) - .collect::>>() + .collect::>>() }) - .collect::, _>>()?; + .collect::, _>>()?; Ok(Self { size, player, map }) } - fn read_rle(map: String) -> Result { + fn read_rle(map: String) -> std::result::Result { let mut n: usize = 1; Self::read( @@ -199,7 +201,7 @@ impl State { }; } - fn move_pos(&mut self, pos: Pos) -> Result<(bool, bool), Error> { + fn move_pos(&mut self, pos: Pos) -> Result<(bool, bool)> { let dpos = self.lvl.player + pos; if ((dpos.1 * self.lvl.size.0) + dpos.0) as usize >= self.lvl.map.len() { @@ -233,7 +235,7 @@ impl State { Ok((false, false)) } - fn move_dir(&mut self, dir: Direction) -> Result<(bool, bool), Error> { + fn move_dir(&mut self, dir: Direction) -> Result<(bool, bool)> { match dir { Direction::U => self.move_pos(Pos(0, -1)), Direction::D => self.move_pos(Pos(0, 1)), @@ -369,7 +371,7 @@ impl Agent { } } - fn move_dna(&mut self) -> Result { + fn move_dna(&mut self) -> Result { if self.dir == self.dna.len() || self.goal == Solution::None { Ok(Solution::None) } else { @@ -388,7 +390,7 @@ impl Agent { } } - fn evaluate(&mut self) -> Result<(), Error> { + fn evaluate(&mut self) -> Result<()> { loop { let player = self.state.lvl.player; @@ -464,11 +466,11 @@ impl Population { } } - fn step(&mut self) -> Result<(), Error> { + fn step(&mut self) -> Result<()> { self.life .par_iter_mut() .map(|a| a.evaluate()) - .collect::, _>>()?; + .collect::>>()?; self.life.par_sort_by(|a, b| b.score.total_cmp(&a.score)); if self.life[0].goal != Solution::Win { @@ -508,7 +510,7 @@ impl Population { } } -pub fn run(config: Config, rle: Option) -> Result<(), Error> { +pub fn run(config: Config, rle: Option) -> Result<()> { rayon::ThreadPoolBuilder::new() .num_threads(config.num_threads) .build_global() @@ -538,7 +540,7 @@ pub fn run(config: Config, rle: Option) -> Result<(), Error> { for _ in 0..config.gen_depth { let mut pop = Population::new(&config, map.clone()); - if let Some(agent) = || -> Result, Error> { + if let Some(agent) = || -> Result> { while pop.gen < config.gen_max { pop.step()?;