~nybble/langtons-termite

771112f932fc2965ea54d70eaf3468e5b0da2264 — Steve Sprang 4 months ago ec9c4cb
Simplify reversibility.
1 files changed, 5 insertions(+), 7 deletions(-)

M src/world.rs
M src/world.rs => src/world.rs +5 -7
@@ 233,14 233,13 @@ impl World {

    pub fn reverse_movement(&mut self) {
        self.movement = self.movement.reverse();

        // turn around and move forward one cell
        self.orientation = self.orientation.flip();
        self.step(self.orientation);
    }

    pub fn move_termite(&mut self) -> (usize, usize) {
        if self.movement == Movement::Backward {
            self.step(self.orientation);
        }

        let (char_x, char_y) = (self.x / 2, self.y / 4);
        let (bit_x,  bit_y)  = (self.x % 2, self.y % 4);



@@ 257,9 256,8 @@ impl World {
        // toggle pixel
        *byte ^= mask;

        if self.movement == Movement::Forward {
            self.step(self.orientation);
        }
        // move forward one cell
        self.step(self.orientation);

        // return the affected char coordinates
        (char_x, char_y)