11import {
22 Difficulty ,
33 Game ,
4+ GameMode ,
45 Player ,
56 PlayerType ,
67 Relation ,
@@ -59,7 +60,7 @@ export class NationAllianceBehavior {
5960
6061 for ( const enemy of borderingEnemies ) {
6162 if (
62- this . random . chance ( 20 ) &&
63+ this . random . chance ( 30 ) &&
6364 isAcceptablePlayerType ( enemy ) &&
6465 this . player . canSendAllianceRequest ( enemy ) &&
6566 this . getAllianceDecision ( enemy , false )
@@ -86,18 +87,27 @@ export class NationAllianceBehavior {
8687 }
8788 return false ;
8889 }
90+ // Reject if otherPlayer has allied with 50% or more of all players (Hard and Impossible only)
91+ // To make sure there are enough non-friendly players in the game to stop the crown with nukes
92+ if ( this . hasTooManyAlliances ( otherPlayer ) ) {
93+ return false ;
94+ }
8995 // Before caring about the relation, first check if the otherPlayer is a threat
9096 // Easy (dumb) nations are blinded by hatred, they don't care about threats, they care about the relation
9197 // Impossible (smart) nations on the other hand are analyzing the facts
9298 if ( this . isAlliancePartnerThreat ( otherPlayer ) ) {
93- if ( ! isResponse && this . random . chance ( 3 ) ) {
99+ if ( ! isResponse && this . random . chance ( 6 ) ) {
94100 this . emojiBehavior . sendEmoji ( otherPlayer , EMOJI_SCARED_OF_THREAT ) ;
95101 }
96- if ( isResponse && this . random . chance ( 3 ) ) {
102+ if ( isResponse && this . random . chance ( 6 ) ) {
97103 this . emojiBehavior . sendEmoji ( otherPlayer , EMOJI_LOVE ) ;
98104 }
99105 return true ;
100106 }
107+ // Maybe reject if we are in a team game (allying makes less sense there)
108+ if ( this . shouldRejectInTeamGame ( ) ) {
109+ return false ;
110+ }
101111 // Reject if relation is bad
102112 if ( this . player . relation ( otherPlayer ) < Relation . Neutral ) {
103113 if ( isResponse && this . random . chance ( 3 ) ) {
@@ -124,6 +134,21 @@ export class NationAllianceBehavior {
124134 return this . isAlliancePartnerSimilarlyStrong ( otherPlayer ) ;
125135 }
126136
137+ private hasTooManyAlliances ( otherPlayer : Player ) : boolean {
138+ const { difficulty } = this . game . config ( ) . gameConfig ( ) ;
139+ if (
140+ difficulty !== Difficulty . Hard &&
141+ difficulty !== Difficulty . Impossible
142+ ) {
143+ return false ;
144+ }
145+
146+ const totalPlayers = this . game . players ( ) . length ;
147+ const otherPlayerAlliances = otherPlayer . alliances ( ) . length ;
148+
149+ return otherPlayerAlliances >= totalPlayers * 0.5 ;
150+ }
151+
127152 private isConfused ( ) : boolean {
128153 const { difficulty } = this . game . config ( ) . gameConfig ( ) ;
129154 switch ( difficulty ) {
@@ -207,6 +232,26 @@ export class NationAllianceBehavior {
207232 }
208233 }
209234
235+ private shouldRejectInTeamGame ( ) : boolean {
236+ if ( this . game . config ( ) . gameConfig ( ) . gameMode !== GameMode . Team ) {
237+ return false ;
238+ }
239+
240+ const { difficulty } = this . game . config ( ) . gameConfig ( ) ;
241+ switch ( difficulty ) {
242+ case Difficulty . Easy :
243+ return false ; // 0% chance to reject on easy
244+ case Difficulty . Medium :
245+ return this . random . nextInt ( 0 , 100 ) < 20 ; // 20% chance to reject on medium
246+ case Difficulty . Hard :
247+ return this . random . nextInt ( 0 , 100 ) < 40 ; // 40% chance to reject on hard
248+ case Difficulty . Impossible :
249+ return this . random . nextInt ( 0 , 100 ) < 60 ; // 60% chance to reject on impossible
250+ default :
251+ assertNever ( difficulty ) ;
252+ }
253+ }
254+
210255 private checkAlreadyEnoughAlliances ( otherPlayer : Player ) : boolean {
211256 const { difficulty } = this . game . config ( ) . gameConfig ( ) ;
212257 switch ( difficulty ) {
0 commit comments