pub fn move_forward(&mut self, grid: &Vec<Vec<BinaryCell>>) {
        // Get the cell state and position of the ant
        let (x, y, _) = self.position;

        // Check the orientation of the ant and move it one unit forward
        match self.orientation {
            // If the ant is facing north
            Direction4::North => {
                // Check that incremented value is within the grid bounds
                if y+1 < grid[0].len() {
                    // Increment the y position of the ant
                    self.position = (x, y+1, grid[x][y+1]);
                } else {
                    // If the y position is out of bounds, set the ant to inactive
                    self.active = false;
                }
            },

            // If the ant is facing east
            Direction4::East => {
                // Check that incremented value is within the grid bounds
                if x+1 < grid.len() {
                    // Increment the x position of the ant
                    self.position = (x+1, y, grid[x+1][y]);
                } else {
                    // If the x position is out of bounds, set the ant to inactive
                    self.active = false;
                }
            },

            // If the ant is facing south
            Direction4::South => {
                // Check if y is 0, decrement will result in out of bounds and a stack overflow
                if y == 0 {
                    // Set the ant to inactive
                    self.active = false;
                } else {
                    // Decrement the y position of the ant
                    self.position = (x, y-1, grid[x][y-1]);
                }
            },

            // If the ant is facing west
            Direction4::West => {
                // Check if x is 0, decrement will result in out of bounds and a stack overflow
                if x == 0 {
                    // Set the ant to inactive
                    self.active = false;
                } else {
                    // Decrement the x position of the ant
                    self.position = (x-1, y, grid[x-1][y]);
                }
            },
        };
    }
// A method that moves the turmite forward one step in the current direction
// Makes no change if the turmite is at the edge of the grid and kills the turmite.
A method that moves the turmite forward one step in the current direction
Makes no change if the turmite is at the edge of the grid and kills the turmite.
A method that moves the turmite forward one step in the current direction Makes no change if the turmite is at the edge of the grid and kills the turmite .
pub fn move_forward(&mut self, grid: &Vec<Vec<BinaryCell>>) {
        // Get the cell state and position of the ant
        let (x, y, _) = self.position;
        // Check the orientation of the ant and move it one unit forward
        match self.orientation {
            // If the ant is facing north
            Direction4::North => {
                // Check that incremented value is within the grid bounds
                if y+1 < grid[0].len() {
                    // Increment the y position of the ant
                    self.position = (x, y+1, grid[x][y+1]);
                } else {
                    // If the y position is out of bounds, set the ant to inactive
                    self.active = false;
                }
            },
            // If the ant is facing east
            Direction4::East => {
                // Check that incremented value is within the grid bounds
                if x+1 < grid.len() {
                    // Increment the x position of the ant
                    self.position = (x+1, y, grid[x+1][y]);
                } else {
                    // If the x position is out of bounds, set the ant to inactive
                    self.active = false;
                }
            },
            // If the ant is facing south
            Direction4::South => {
                // Check if y is 0, decrement will result in out of bounds and a stack overflow
                if y == 0 {
                    // Set the ant to inactive
                    self.active = false;
                } else {
                    // Decrement the y position of the ant
                    self.position = (x, y-1, grid[x][y-1]);
                }
            },
            // If the ant is facing west
            Direction4::West => {
                // Check if x is 0, decrement will result in out of bounds and a stack overflow
                if x == 0 {
                    // Set the ant to inactive
                    self.active = false;
                } else {
                    // Decrement the x position of the ant
                    self.position = (x-1, y, grid[x-1][y]);
                }
            },
        };
    }
pub fn move_forward ( & mut self , grid : & Vec < Vec < BinaryCell > > ) { // Get the cell state and position of the ant let ( x , y , _ ) = self . position ; // Check the orientation of the ant and move it one unit forward match self . orientation { // If the ant is facing north Direction4 :: North => { // Check that incremented value is within the grid bounds if y + 1 < grid [ 0 ] . len ( ) { // Increment the y position of the ant self . position = ( x , y + 1 , grid [ x ] [ y + 1 ] ) ; } else { // If the y position is out of bounds, set the ant to inactive self . active = false ; } } , // If the ant is facing east Direction4 :: East => { // Check that incremented value is within the grid bounds if x + 1 < grid . len ( ) { // Increment the x position of the ant self . position = ( x + 1 , y , grid [ x + 1 ] [ y ] ) ; } else { // If the x position is out of bounds, set the ant to inactive self . active = false ; } } , // If the ant is facing south Direction4 :: South => { // Check if y is 0, decrement will result in out of bounds and a stack overflow if y == 0 { // Set the ant to inactive self . active = false ; } else { // Decrement the y position of the ant self . position = ( x , y - 1 , grid [ x ] [ y - 1 ] ) ; } } , // If the ant is facing west Direction4 :: West => { // Check if x is 0, decrement will result in out of bounds and a stack overflow if x == 0 { // Set the ant to inactive self . active = false ; } else { // Decrement the x position of the ant self . position = ( x - 1 , y , grid [ x - 1 ] [ y ] ) ; } } , } ; }
A method that moves the turmite forward one step in the current direction
Makes no change if the turmite is at the edge of the grid and kills the turmite.
A method that moves the turmite forward one step in the current direction Makes no change if the turmite is at the edge of the grid and kills the turmite .
&mut self
grid
&Vec<Vec<BinaryCell>>
&mut self
grid
&Vec<Vec<BinaryCell>>