use DIR_POS for box testing

This commit is contained in:
mos 2024-10-29 19:33:19 +01:00
parent 412072abda
commit 41af614d74
1 changed files with 3 additions and 2 deletions

View File

@ -189,6 +189,8 @@ struct State {
} }
impl State { impl State {
const DIR_POS: &'static [Pos] = &[Pos(0, -1), Pos(0, 1), Pos(-1, 0), Pos(1, 0)];
fn new(lvl: Level) -> Self { fn new(lvl: Level) -> Self {
State { lvl } State { lvl }
} }
@ -250,10 +252,9 @@ impl State {
} }
fn test_box(&self, pos: Pos, bt: bool) -> bool { fn test_box(&self, pos: Pos, bt: bool) -> bool {
let dir: &[Pos] = &[Pos(0, -1), Pos(0, 1), Pos(-1, 0), Pos(1, 0)];
let mut mbc = 0; let mut mbc = 0;
for i in dir { for i in Self::DIR_POS {
match self.lvl[pos + *i] { match self.lvl[pos + *i] {
Cell::Goal(false) | Cell::None => { Cell::Goal(false) | Cell::None => {
let dpos = pos - *i; let dpos = pos - *i;