@@ -381,24 +381,30 @@ private void RunDefenderAssignment()
381381 }
382382 }
383383
384- // fill deficits: prioritize squads by attacker strength (strongest attacker squads get top floaters first)
384+ // Round-robin deficit fill: cover as many attacked planets as possible before any squad gets a
385+ // second floater. Each round walks squads in attacker-strength order so the top-WHR floater lands
386+ // on the highest-stakes battle first; remaining rounds spread the rest across still-deficit squads.
385387 var squadsByAttackerStrength = FormedSquads
386388 . OrderByDescending ( s => s . Attackers . Any ( ) ? s . Attackers . Average ( a => GetPlayerWhr ( a ) ) : 0.0 )
387389 . ToList ( ) ;
388390
389- foreach ( var squad in squadsByAttackerStrength )
391+ while ( floatingPool . Count > 0 )
390392 {
391- var deficit = squad . TeamSize - squad . Defenders . Count ;
392- if ( deficit <= 0 || floatingPool . Count == 0 ) continue ;
393+ bool progressed = false ;
394+ foreach ( var squad in squadsByAttackerStrength )
395+ {
396+ if ( squad . Defenders . Count >= squad . TeamSize ) continue ;
393397
394- var allowedFactions = squadDefendingFactions [ squad ] ;
395- var eligible = floatingPool
396- . Where ( x => defenderFactionId . ContainsKey ( x ) && defenderFactionId [ x ] . HasValue && allowedFactions . Contains ( defenderFactionId [ x ] . Value ) )
397- . Take ( deficit )
398- . ToList ( ) ;
398+ var allowedFactions = squadDefendingFactions [ squad ] ;
399+ var pick = floatingPool . FirstOrDefault ( x =>
400+ defenderFactionId . ContainsKey ( x ) && defenderFactionId [ x ] . HasValue && allowedFactions . Contains ( defenderFactionId [ x ] . Value ) ) ;
401+ if ( pick == null ) continue ;
399402
400- squad . Defenders . AddRange ( eligible ) ;
401- foreach ( var p in eligible ) floatingPool . Remove ( p ) ;
403+ squad . Defenders . Add ( pick ) ;
404+ floatingPool . Remove ( pick ) ;
405+ progressed = true ;
406+ }
407+ if ( ! progressed ) break ;
402408 }
403409 }
404410
0 commit comments