fn seek_and_destroy_target(mech: &impl MechInstruments, scan: Vec<RadarPing>) -> Vec<MechCommand> {
     let scan = scan
          .iter()
          .filter(|s| distance_to(&mech.position(), &s.location) <= mech.primary_range())
          .filter(|s| s.foe)
          .collect::<Vec<_>>();

     match mech.register_get(EBX) {
          Some(RegisterValue::Text(target)) => {
               if let Some(target) = scan
                    .iter()
                    .filter(|s| s.id == *target)
                    .collect::<Vec<_>>()
                    .get(0)
               {
                    vec![
                         mech.fire_primary(mech.direction_to(&target.location)),
                         mech.fire_primary(mech.direction_to(&target.location)),
                    ]
               } else if let Some(target) = scan.get(0) {
                    vec![
                         mech.register_set(EBX, RegisterValue::Text(target.id.clone())),
                         mech.fire_primary(mech.direction_to(&target.location)),
                         mech.fire_primary(mech.direction_to(&target.location)),
                    ]
               } else {
                    vec![mech.request_radar(), mech.register_acc(ECX, 1)]
               }
          }
          _ => {
               if let Some(target) = scan.get(0) {
                    vec![
                         mech.register_set(EBX, RegisterValue::Text(target.id.clone())),
                         mech.fire_primary(mech.direction_to(&target.location)),
                         mech.fire_primary(mech.direction_to(&target.location)),
                    ]
               } else {
                    vec![mech.request_radar(), mech.register_acc(ECX, 1)]
               }
          }
     }
}
// Returns None if target already exists in the register
// Returns a mech command to set the target otherwise
Returns None if target already exists in the register
Returns a mech command to set the target otherwise
Returns None if target already exists in the register Returns a mech command to set the target otherwise
fn seek_and_destroy_target(mech: &impl MechInstruments, scan: Vec<RadarPing>) -> Vec<MechCommand> {
     let scan = scan
          .iter()
          .filter(|s| distance_to(&mech.position(), &s.location) <= mech.primary_range())
          .filter(|s| s.foe)
          .collect::<Vec<_>>();
     match mech.register_get(EBX) {
          Some(RegisterValue::Text(target)) => {
               if let Some(target) = scan
                    .iter()
                    .filter(|s| s.id == *target)
                    .collect::<Vec<_>>()
                    .get(0)
               {
                    vec![
                         mech.fire_primary(mech.direction_to(&target.location)),
                         mech.fire_primary(mech.direction_to(&target.location)),
                    ]
               } else if let Some(target) = scan.get(0) {
                    vec![
                         mech.register_set(EBX, RegisterValue::Text(target.id.clone())),
                         mech.fire_primary(mech.direction_to(&target.location)),
                         mech.fire_primary(mech.direction_to(&target.location)),
                    ]
               } else {
                    vec![mech.request_radar(), mech.register_acc(ECX, 1)]
               }
          }
          _ => {
               if let Some(target) = scan.get(0) {
                    vec![
                         mech.register_set(EBX, RegisterValue::Text(target.id.clone())),
                         mech.fire_primary(mech.direction_to(&target.location)),
                         mech.fire_primary(mech.direction_to(&target.location)),
                    ]
               } else {
                    vec![mech.request_radar(), mech.register_acc(ECX, 1)]
               }
          }
     }
}
fn seek_and_destroy_target ( mech : & impl MechInstruments , scan : Vec < RadarPing > ) -> Vec < MechCommand > { let scan = scan . iter ( ) . filter ( | s | distance_to ( & mech . position ( ) , & s . location ) <= mech . primary_range ( ) ) . filter ( | s | s . foe ) . collect :: < Vec < _ > > ( ) ; match mech . register_get ( EBX ) { Some ( RegisterValue :: Text ( target ) ) => { if let Some ( target ) = scan . iter ( ) . filter ( | s | s . id == * target ) . collect :: < Vec < _ > > ( ) . get ( 0 ) { vec ! [ mech fire_primary ( mech direction_to ( target location ) ) mech fire_primary ( mech direction_to ( target location ) ) ] } else if let Some ( target ) = scan . get ( 0 ) { vec ! [ mech register_set ( EBX RegisterValue Text ( target id clone ( ) ) ) mech fire_primary ( mech direction_to ( target location ) ) mech fire_primary ( mech direction_to ( target location ) ) ] } else { vec ! [ mech request_radar ( ) mech register_acc ( ECX 1 ) ] } } _ => { if let Some ( target ) = scan . get ( 0 ) { vec ! [ mech register_set ( EBX RegisterValue Text ( target id clone ( ) ) ) mech fire_primary ( mech direction_to ( target location ) ) mech fire_primary ( mech direction_to ( target location ) ) ] } else { vec ! [ mech request_radar ( ) mech register_acc ( ECX 1 ) ] } } } }
Returns None if target already exists in the register
Returns a mech command to set the target otherwise
Returns None if target already exists in the register Returns a mech command to set the target otherwise
mech
&impl MechInstruments
scan
Vec<RadarPing>
mech
&impl MechInstruments
scan
Vec<RadarPing>