pub fn make_move(&self, move_: Move) -> Option<Stage> {
        // Preconditions:
        // * There are no overlapping vehicles
        // * Vehicle parts are completely within the bounds of the stage
        // * The direction of the movement matches the alignment of the vehicle (e.g. a vertical
        //   car moves up or down, never left or right)

        // Get the car in question
        let vehicle = &self.vehicles[move_.vehicle_id];

        // Get the square to which the car would move
        // Note: we allow underflow, because the resulting coordinates will fall out of the stage
        let dest = vehicle.destination_point(move_.direction);

        // Reject the move if the target square is out of bounds
        if dest.x >= self.width || dest.y >= self.height {
            return None;
        }

        // Reject the move if the target square is already occupied
        for vehicle in &self.vehicles {
            if vehicle.covers_point(&dest) {
                return None;
            }
        }

        // Generate and return the new stage
        let mut stage = self.clone();
        stage.vehicles[move_.vehicle_id].move_(move_.direction);
        Some(stage)
    }
/// Return the stage generated by applying the given move, or `Nothing` if the move is invalid
Return the stage generated by applying the given move, or `Nothing` if the move is invalid
Return the stage generated by applying the given move or ` Nothing ` if the move is invalid
pub fn make_move(&self, move_: Move) -> Option<Stage> {
        // Preconditions:
        // * There are no overlapping vehicles
        // * Vehicle parts are completely within the bounds of the stage
        // * The direction of the movement matches the alignment of the vehicle (e.g. a vertical
        //   car moves up or down, never left or right)
        // Get the car in question
        let vehicle = &self.vehicles[move_.vehicle_id];
        // Get the square to which the car would move
        // Note: we allow underflow, because the resulting coordinates will fall out of the stage
        let dest = vehicle.destination_point(move_.direction);
        // Reject the move if the target square is out of bounds
        if dest.x >= self.width || dest.y >= self.height {
            return None;
        }
        // Reject the move if the target square is already occupied
        for vehicle in &self.vehicles {
            if vehicle.covers_point(&dest) {
                return None;
            }
        }
        // Generate and return the new stage
        let mut stage = self.clone();
        stage.vehicles[move_.vehicle_id].move_(move_.direction);
        Some(stage)
    }
pub fn make_move ( & self , move_ : Move ) -> Option < Stage > { // Preconditions: // * There are no overlapping vehicles // * Vehicle parts are completely within the bounds of the stage // * The direction of the movement matches the alignment of the vehicle (e.g. a vertical //   car moves up or down, never left or right) // Get the car in question let vehicle = & self . vehicles [ move_ . vehicle_id ] ; // Get the square to which the car would move // Note: we allow underflow, because the resulting coordinates will fall out of the stage let dest = vehicle . destination_point ( move_ . direction ) ; // Reject the move if the target square is out of bounds if dest . x >= self . width || dest . y >= self . height { return None ; } // Reject the move if the target square is already occupied for vehicle in & self . vehicles { if vehicle . covers_point ( & dest ) { return None ; } } // Generate and return the new stage let mut stage = self . clone ( ) ; stage . vehicles [ move_ . vehicle_id ] . move_ ( move_ . direction ) ; Some ( stage ) }
Return the stage generated by applying the given move, or `Nothing` if the move is invalid
Return the stage generated by applying the given move or ` Nothing ` if the move is invalid
&self
move_
Move
&self
move_
Move