@@ -37,6 +37,10 @@ def __init__(self):
3737 self .running = True
3838 self .config = Config ()
3939 self .tick = 0
40+
41+ # Initialize player early-game protection
42+ self .playerCreature .damageReduction = self .config .playerDamageReduction
43+ self .playerCreature .log .append ("%s has early-game protection!" % self .playerCreature .name )
4044
4145 def initiateEntityActions (self ):
4246 entities_to_remove = [] # Track entities that die this turn
@@ -59,8 +63,18 @@ def initiateEntityActions(self):
5963 entity .decreaseChanceToFight ()
6064 self .createChildEntity (parents [0 ], parents [1 ])
6165 elif decision == "fight" :
62- if target == self .playerCreature and self .config .godMode :
63- continue
66+ # Enhanced protection: during grace period, reduce attacks on player
67+ if target == self .playerCreature :
68+ if self .config .godMode :
69+ continue
70+ # During grace period, 85% chance to skip attacking the player
71+ if (self .tick < self .config .earlyGameGracePeriod and
72+ random .randint (1 , 100 ) <= 85 ):
73+ entity .log .append (
74+ "%s decided not to attack %s." % (entity .name , target .name )
75+ )
76+ continue
77+
6478 entity .increaseChanceToFight ()
6579 entity .decreaseChanceToBefriend ()
6680 entity .fight (target )
@@ -78,6 +92,14 @@ def initiateEntityActions(self):
7892 for entity in entities_to_remove :
7993 self .environment .removeEntity (entity )
8094
95+ def updatePlayerProtection (self ):
96+ """Update player protection based on current tick"""
97+ if self .tick >= self .config .earlyGameGracePeriod :
98+ # Grace period has ended
99+ if hasattr (self .playerCreature , 'damageReduction' ) and self .playerCreature .damageReduction > 0 :
100+ self .playerCreature .damageReduction = 0
101+ self .playerCreature .log .append ("%s's protection has worn off!" % self .playerCreature .name )
102+
81103 def regenerateAllEntities (self ):
82104 """Regenerate health for all living entities"""
83105 for entity in self .environment .getEntities ():
@@ -186,6 +208,12 @@ def printSummary(self):
186208 "%s's chance to be nice was %d percent."
187209 % (self .playerCreature .name , self .playerCreature .chanceToBefriend )
188210 )
211+
212+ # Show protection status
213+ if hasattr (self .playerCreature , 'damageReduction' ) and self .playerCreature .damageReduction > 0 :
214+ protection_percent = int (self .playerCreature .damageReduction * 100 )
215+ print ("%s still has %d%% damage reduction." % (self .playerCreature .name , protection_percent ))
216+
189217 if self .playerCreature .isAlive ():
190218 print (
191219 "%s ended with %d health (out of %d max)."
@@ -198,6 +226,7 @@ def printSummary(self):
198226 else :
199227 print ("%s died during the simulation." % self .playerCreature .name )
200228 print ("Kreatures still alive: %d" % self .environment .getNumEntities ())
229+ print ("Simulation ran for %d ticks." % self .tick )
201230
202231 def printStats (self ):
203232 print ("=== Stats ===" )
@@ -224,6 +253,7 @@ def run(self):
224253 pass
225254
226255 self .initiateEntityActions ()
256+ self .updatePlayerProtection () # Update player protection status
227257 self .regenerateAllEntities () # Regenerate health for all entities
228258 time .sleep (self .config .tickLength )
229259 self .tick += 1
@@ -238,5 +268,6 @@ def run(self):
238268 self .printStats ()
239269
240270
241- kreatures = Kreatures ()
242- kreatures .run ()
271+ if __name__ == "__main__" :
272+ kreatures = Kreatures ()
273+ kreatures .run ()
0 commit comments