fn phase_2(mech: &impl MechInstruments) -> Vec<MechCommand> {

     let last_scan = mech.last_radar_scan().unwrap_or(vec![]);
     let within_secondary = last_scan.iter().filter(|e| enemy_within_range(mech.secondary_range(), &mech.position(), &e.location)).collect::<Vec<_>>();
     let within_primary = within_secondary.iter().filter(|e| enemy_within_range(mech.primary_range(),  &mech.position(), &e.location)).map(|e| *e).collect::<Vec<_>>();

     if let Some(enemy) = find_enemy(within_primary) {
               let mut fire = vec![
                    mech.fire_primary(mech.direction_to(&enemy.location)),
               ];
               fire.append(&mut evasive_maneuvers(mech, mech.world_size()));
               fire
     } else if let Some(enemy) = find_enemy(within_secondary) {
          vec![
               mech.fire_secondary(mech.direction_to(&enemy.location))
          ]
     } else {
          let mut move_mech = evasive_maneuvers(mech, mech.world_size());
          move_mech.append(&mut vec![mech.request_radar()]);
          move_mech
     }
}
// Secondary fire if no mechs are within primary range, primary if there is an enemy within range and then evasive maneuvers
Secondary fire if no mechs are within primary range, primary if there is an enemy within range and then evasive maneuvers
Secondary fire if no mechs are within primary range primary if there is an enemy within range and then evasive maneuvers
fn phase_2(mech: &impl MechInstruments) -> Vec<MechCommand> {
     let last_scan = mech.last_radar_scan().unwrap_or(vec![]);
     let within_secondary = last_scan.iter().filter(|e| enemy_within_range(mech.secondary_range(), &mech.position(), &e.location)).collect::<Vec<_>>();
     let within_primary = within_secondary.iter().filter(|e| enemy_within_range(mech.primary_range(),  &mech.position(), &e.location)).map(|e| *e).collect::<Vec<_>>();
     if let Some(enemy) = find_enemy(within_primary) {
               let mut fire = vec![
                    mech.fire_primary(mech.direction_to(&enemy.location)),
               ];
               fire.append(&mut evasive_maneuvers(mech, mech.world_size()));
               fire
     } else if let Some(enemy) = find_enemy(within_secondary) {
          vec![
               mech.fire_secondary(mech.direction_to(&enemy.location))
          ]
     } else {
          let mut move_mech = evasive_maneuvers(mech, mech.world_size());
          move_mech.append(&mut vec![mech.request_radar()]);
          move_mech
     }
}
fn phase_2 ( mech : & impl MechInstruments ) -> Vec < MechCommand > { let last_scan = mech . last_radar_scan ( ) . unwrap_or ( vec ! [ ] ) ; let within_secondary = last_scan . iter ( ) . filter ( | e | enemy_within_range ( mech . secondary_range ( ) , & mech . position ( ) , & e . location ) ) . collect :: < Vec < _ > > ( ) ; let within_primary = within_secondary . iter ( ) . filter ( | e | enemy_within_range ( mech . primary_range ( ) , & mech . position ( ) , & e . location ) ) . map ( | e | * e ) . collect :: < Vec < _ > > ( ) ; if let Some ( enemy ) = find_enemy ( within_primary ) { let mut fire = vec ! [ mech fire_primary ( mech direction_to ( enemy location ) ) ] ; fire . append ( & mut evasive_maneuvers ( mech , mech . world_size ( ) ) ) ; fire } else if let Some ( enemy ) = find_enemy ( within_secondary ) { vec ! [ mech fire_secondary ( mech direction_to ( enemy location ) ) ] } else { let mut move_mech = evasive_maneuvers ( mech , mech . world_size ( ) ) ; move_mech . append ( & mut vec ! [ mech request_radar ( ) ] ) ; move_mech } }
Secondary fire if no mechs are within primary range, primary if there is an enemy within range and then evasive maneuvers
Secondary fire if no mechs are within primary range primary if there is an enemy within range and then evasive maneuvers
mech
&impl MechInstruments
mech
&impl MechInstruments