pub fn drive_to_address(
    driver: Driver,
    target_address: u64,
    max_steps: usize,
) -> Result<Vec<Driver>> {
    let mut drivers = vec![driver];
    let mut final_drivers = Vec::new();

    for _step in 0..max_steps {
        if (_step & 0xfff) == 0 {
            println!(
                "drive_to_address step={} drivers.len()={} final_drivers.len()={}",
                _step,
                drivers.len(),
                final_drivers.len()
            );
        }
        let mut step_drivers = Vec::new();
        for driver in drivers {
            for driver in driver.step()? {
                if driver
                    .address()
                    .map(|address| address == target_address)
                    .unwrap_or(false)
                {
                    final_drivers.push(driver);
                } else {
                    step_drivers.push(driver);
                }
            }
        }
        drivers = step_drivers;
        if drivers.len() > DRIVER_CULL_SIZE {
            let mut i = 2;
            // keep the last handful of drivers
            while i < drivers.len() - 2 {
                drivers.remove(i);
                i += 1;
            }
        }
        if final_drivers.len() > DRIVER_CULL_SIZE {
            let mut i = 2;
            // keep the last handful of drivers
            while i < final_drivers.len() - 2 {
                final_drivers.remove(i);
                i += 1;
            }
        }
        if drivers.is_empty() {
            break;
        }
    }

    // TODO HACK for debugging
    if final_drivers.is_empty() {
        Ok(drivers)
    } else {
        Ok(final_drivers)
    }
}
/// Drive the given driver until it hits the given driver, or until max_steps
/// has been hit.
///
/// Collects drivers once they hit the desired address
Drive the given driver until it hits the given driver, or until max_steps
has been hit.

Collects drivers once they hit the desired address
Drive the given driver until it hits the given driver or until max_steps has been hit . Collects drivers once they hit the desired address
pub fn drive_to_address(
    driver: Driver,
    target_address: u64,
    max_steps: usize,
) -> Result<Vec<Driver>> {
    let mut drivers = vec![driver];
    let mut final_drivers = Vec::new();
    for _step in 0..max_steps {
        if (_step & 0xfff) == 0 {
            println!(
                "drive_to_address step={} drivers.len()={} final_drivers.len()={}",
                _step,
                drivers.len(),
                final_drivers.len()
            );
        }
        let mut step_drivers = Vec::new();
        for driver in drivers {
            for driver in driver.step()? {
                if driver
                    .address()
                    .map(|address| address == target_address)
                    .unwrap_or(false)
                {
                    final_drivers.push(driver);
                } else {
                    step_drivers.push(driver);
                }
            }
        }
        drivers = step_drivers;
        if drivers.len() > DRIVER_CULL_SIZE {
            let mut i = 2;
            // keep the last handful of drivers
            while i < drivers.len() - 2 {
                drivers.remove(i);
                i += 1;
            }
        }
        if final_drivers.len() > DRIVER_CULL_SIZE {
            let mut i = 2;
            // keep the last handful of drivers
            while i < final_drivers.len() - 2 {
                final_drivers.remove(i);
                i += 1;
            }
        }
        if drivers.is_empty() {
            break;
        }
    }
    // TODO HACK for debugging
    if final_drivers.is_empty() {
        Ok(drivers)
    } else {
        Ok(final_drivers)
    }
}
pub fn drive_to_address ( driver : Driver , target_address : u64 , max_steps : usize , ) -> Result < Vec < Driver > > { let mut drivers = vec ! [ driver ] ; let mut final_drivers = Vec :: new ( ) ; for _step in 0 .. max_steps { if ( _step & 0xfff ) == 0 { println ! ( " " _step drivers len ( ) final_drivers len ( ) ) ; } let mut step_drivers = Vec :: new ( ) ; for driver in drivers { for driver in driver . step ( ) ? { if driver . address ( ) . map ( | address | address == target_address ) . unwrap_or ( false ) { final_drivers . push ( driver ) ; } else { step_drivers . push ( driver ) ; } } } drivers = step_drivers ; if drivers . len ( ) > DRIVER_CULL_SIZE { let mut i = 2 ; // keep the last handful of drivers while i < drivers . len ( ) - 2 { drivers . remove ( i ) ; i += 1 ; } } if final_drivers . len ( ) > DRIVER_CULL_SIZE { let mut i = 2 ; // keep the last handful of drivers while i < final_drivers . len ( ) - 2 { final_drivers . remove ( i ) ; i += 1 ; } } if drivers . is_empty ( ) { break ; } } // TODO HACK for debugging if final_drivers . is_empty ( ) { Ok ( drivers ) } else { Ok ( final_drivers ) } }
Drive the given driver until it hits the given driver, or until max_steps
has been hit.
Drive the given driver until it hits the given driver or until max_steps has been hit .
driver
Driver
target_address
u64
max_steps
usize