4 changed files with 51 additions and 33 deletions
@ -1,24 +1,29 @@ |
|||||
pub struct Behaviour { |
pub struct Behaviour { |
||||
pub moves: Vec<(i8, i8)>, //this is a placeholder
|
pub moves: Vec<(i8, i8)>, //this is a placeholder
|
||||
pub dirs: [u8; 4], // up right down left
|
pub dirs: [u8; 4], // up right down left
|
||||
} |
} |
||||
|
|
||||
impl Behaviour { |
impl Behaviour { |
||||
pub fn new(m: Vec<(i8, i8)>, d: [u8; 4]) -> Behaviour { |
pub fn new(m: Vec<(i8, i8)>, d: [u8; 4]) -> Behaviour { |
||||
Behaviour { |
Behaviour { moves: m, dirs: d } |
||||
moves: m, |
} |
||||
dirs: d, |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
pub fn validate_dest(&self, origin: (u8, u8), destination: (u8, u8)) -> bool { // original plan was to use match but i felt for loops would work better since we dont yet know the extent of moves vector
|
pub fn validate_dest(&self, origin: (u8, u8), destination: (u8, u8)) -> bool { |
||||
//println!("origin: ({}, {}), destination: ({}, {})", origin.0, origin.1, destination.0, destination.1);
|
// original plan was to use match but i felt for loops would work better since we dont yet know the extent of moves vector
|
||||
for moveset in self.moves.iter() { |
//println!("origin: ({}, {}), destination: ({}, {})", origin.0, origin.1, destination.0, destination.1);
|
||||
for dir in self.dirs.iter() { // mind blanking need to add something to confirm which direction we are iterating through
|
for moveset in self.moves.iter() { |
||||
if (((origin.0 as i8) + (*dir as i8) * moveset.0) as u8, ((origin.1 as i8) - (*dir as i8) * moveset.1) as u8) == destination { return true; } // flip the second component of calculation because the grid works from top left isntead of bot left like a piss
|
for dir in self.dirs.iter() { |
||||
} |
// mind blanking need to add something to confirm which direction we are iterating through
|
||||
} |
if ( |
||||
return false; |
((origin.0 as i8) + (*dir as i8) * moveset.0) as u8, |
||||
} |
((origin.1 as i8) - (*dir as i8) * moveset.1) as u8, |
||||
|
) == destination |
||||
|
{ |
||||
|
return true; |
||||
|
} // flip the second component of calculation because the grid works from top left isntead of bot left like a piss
|
||||
|
} |
||||
|
} |
||||
|
return false; |
||||
|
} |
||||
} |
} |
||||
// ok remember wghen i said in chat i didnt think enough on the directions concept. well that was pretty fucked up.
|
// ok remember wghen i said in chat i didnt think enough on the directions concept. well that was pretty fucked up.
|
Loading…
Reference in new issue