@@ -78,11 +78,14 @@ export class NationNukeBehavior {
7878 UnitType . Factory ,
7979 ) ;
8080 const structureTiles = structures . map ( ( u ) => u . tile ( ) ) ;
81+ const difficulty = this . game . config ( ) . gameConfig ( ) . difficulty ;
82+ // Use more random tiles on Impossible difficulty to improve chances of finding a perfect SAM outranging spot
83+ const numRandomTiles = difficulty === Difficulty . Impossible ? 30 : 10 ;
8184 const randomTiles = randTerritoryTileArray (
8285 this . random ,
8386 this . game ,
8487 nukeTarget ,
85- 10 ,
88+ numRandomTiles ,
8689 ) ;
8790 const allTiles = randomTiles . concat ( structureTiles ) ;
8891
@@ -104,7 +107,6 @@ export class NationNukeBehavior {
104107 if ( spawnTile === false ) continue ;
105108
106109 // In team games, avoid nuking the same position as a teammate
107- const difficulty = this . game . config ( ) . gameConfig ( ) . difficulty ;
108110 if (
109111 this . game . config ( ) . gameConfig ( ) . gameMode === GameMode . Team &&
110112 difficulty !== Difficulty . Easy &&
@@ -114,7 +116,6 @@ export class NationNukeBehavior {
114116 }
115117
116118 // On Hard & Impossible, avoid trajectories that can be intercepted by enemy SAMs
117-
118119 if (
119120 ( difficulty === Difficulty . Hard ||
120121 difficulty === Difficulty . Impossible ) &&
@@ -396,12 +397,12 @@ export class NationNukeBehavior {
396397 . nukeMagnitudes ( nuke . type ( ) ) . inner ;
397398
398399 // Check if the blast zones overlap
399- // They overlap if distance between targets < max of the two radii
400+ // They overlap if distance between targets < sum of the two radii
400401 const distSquared = this . game . euclideanDistSquared ( tile , targetTile ) ;
401- const maxRadius = Math . max ( ourInnerRadius , teammateInnerRadius ) ;
402- const maxRadiusSquared = maxRadius * maxRadius ;
402+ const sumRadius = ourInnerRadius + teammateInnerRadius ;
403+ const sumRadiusSquared = sumRadius * sumRadius ;
403404
404- if ( distSquared <= maxRadiusSquared ) {
405+ if ( distSquared <= sumRadiusSquared ) {
405406 return true ;
406407 }
407408 }
@@ -557,6 +558,37 @@ export class NationNukeBehavior {
557558 if ( hasSam ) return - 1 ;
558559 }
559560
561+ // On Impossible difficulty and a hydrogen bomb, add value for SAMs that can be outranged
562+ if (
563+ difficulty === Difficulty . Impossible &&
564+ nukeType === UnitType . HydrogenBomb
565+ ) {
566+ const hydroMagnitude = this . game
567+ . config ( )
568+ . nukeMagnitudes ( UnitType . HydrogenBomb ) ;
569+ const nearbySams = this . game . nearbyUnits (
570+ tile ,
571+ hydroMagnitude . outer ,
572+ UnitType . SAMLauncher ,
573+ ) ;
574+
575+ for ( const sam of nearbySams ) {
576+ const samLevel = sam . unit . level ( ) ;
577+ if ( samLevel >= 5 ) continue ; // Can't outrange level 5+ SAMs
578+
579+ const samRange = this . game . config ( ) . samRange ( samLevel ) ;
580+ const distToSam = Math . sqrt (
581+ this . game . euclideanDistSquared ( tile , sam . unit . tile ( ) ) ,
582+ ) ;
583+
584+ // Check if we can outrange this SAM
585+ if ( distToSam > samRange ) {
586+ // Add significant value for destroying a SAM that we can outrange
587+ tileValue += 100_000 * samLevel ;
588+ }
589+ }
590+ }
591+
560592 // Prefer tiles that are closer to a silo (but preserve structure value)
561593 const siloTiles = silos . map ( ( u ) => u . tile ( ) ) ;
562594 const result = closestTwoTiles ( this . game , siloTiles , [ tile ] ) ;
0 commit comments